Merge pull request #9149 from tradcliffe-expediagroup/tradcliffe/add-input-option-github-actions-dispatch

Tradcliffe/add input option GitHub actions dispatch
This commit is contained in:
Patrik Oldsberg
2022-01-26 21:58:34 +01:00
committed by GitHub
3 changed files with 43 additions and 2 deletions
@@ -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,
});
});
});
@@ -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,18 @@ 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. ',
type: 'object',
},
},
},
},
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 +86,7 @@ export function createGithubActionsDispatchAction(options: {
repo,
workflow_id: workflowId,
ref: branchOrTagName,
inputs: workflowInputs,
});
ctx.logger.info(`Workflow ${workflowId} dispatched successfully`);