diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/githubActionsDispatch.test.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/githubActionsDispatch.test.ts index b725f825fe..6cdb2ee58c 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/githubActionsDispatch.test.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/githubActionsDispatch.test.ts @@ -66,7 +66,7 @@ describe('github:actions:dispatch', () => { }); }); - it('should call the githubApis for creating WorkflowDispatch', async () => { + it('should call the githubApis for creating WorkflowDispatch without an input object', async () => { mockGithubClient.rest.actions.createWorkflowDispatch.mockResolvedValue({ data: { foo: 'bar', @@ -90,4 +90,31 @@ describe('github:actions:dispatch', () => { ref: branchOrTagName, }); }); + + it('should call the githubApis for creating WorkflowDispatch with an input object', async () => { + mockGithubClient.rest.actions.createWorkflowDispatch.mockResolvedValue({ + data: { + foo: 'bar', + }, + }); + + const repoUrl = 'github.com?repo=repo&owner=owner'; + const workflowId = 'dispatch_workflow'; + const branchOrTagName = 'main'; + const workflowInputs = '{ "foo": "bar" }'; + const ctx = Object.assign({}, mockContext, { + input: { repoUrl, workflowId, branchOrTagName, workflowInputs }, + }); + await action.handler(ctx); + + expect( + mockGithubClient.rest.actions.createWorkflowDispatch, + ).toHaveBeenCalledWith({ + owner: 'owner', + repo: 'repo', + workflow_id: workflowId, + ref: branchOrTagName, + inputs: workflowInputs, + }); + }); }); diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/githubActionsDispatch.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/githubActionsDispatch.ts index eed74f2d04..43339ba5d3 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/githubActionsDispatch.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/githubActionsDispatch.ts @@ -36,6 +36,7 @@ export function createGithubActionsDispatchAction(options: { repoUrl: string; workflowId: string; branchOrTagName: string; + workflowInputs?: { [key: string]: string }; }>({ id: 'github:actions:dispatch', description: @@ -61,11 +62,17 @@ export function createGithubActionsDispatchAction(options: { 'The git branch or tag name used to dispatch the workflow', type: 'string', }, + workflowInputs: { + title: 'Workflow Inputs', + description: + 'Inputs keys and values to send to GitHub Action configured on the workflow file. The maximum number of properties is 10. Any default properties configured in the workflow file will be used when inputs are omitted.', + }, }, }, }, async handler(ctx) { - const { repoUrl, workflowId, branchOrTagName } = ctx.input; + const { repoUrl, workflowId, branchOrTagName, workflowInputs } = + ctx.input; ctx.logger.info( `Dispatching workflow ${workflowId} for repo ${repoUrl} on ${branchOrTagName}`, @@ -78,6 +85,7 @@ export function createGithubActionsDispatchAction(options: { repo, workflow_id: workflowId, ref: branchOrTagName, + inputs: workflowInputs, }); ctx.logger.info(`Workflow ${workflowId} dispatched successfully`);