updated github:action:dispatch to include inputs to send to GitHub action

Signed-off-by: Tracey <tradcliffe@expediagroup.com>
This commit is contained in:
Tracey
2022-01-19 14:57:06 -07:00
parent 06562229bb
commit 2cd42a7ae5
2 changed files with 37 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,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`);