From 6d9116fe9a8b8620691d4af8aa6c6d6e0003b502 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Mart=C3=ADn=20Vedriel?= Date: Thu, 4 Aug 2022 12:11:02 +0200 Subject: [PATCH] feat: Webhook accept jobs where not all labels are provided in job. (#2209) feat: Webhook accept jobs where not all labels are provided in job.in job. --- .../lambdas/webhook/src/webhook/handler.test.ts | 6 +++--- .../webhook/lambdas/webhook/src/webhook/handler.ts | 13 +++---------- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/modules/webhook/lambdas/webhook/src/webhook/handler.test.ts b/modules/webhook/lambdas/webhook/src/webhook/handler.test.ts index 500784638a..3a4b98ef68 100644 --- a/modules/webhook/lambdas/webhook/src/webhook/handler.test.ts +++ b/modules/webhook/lambdas/webhook/src/webhook/handler.test.ts @@ -159,7 +159,7 @@ describe('handler', () => { expect(sendActionRequest).toBeCalled(); }); - it('Check webhook does not accept jobs where not all labels are provided in job.', async () => { + it('Check webhook accept jobs where not all labels are provided in job.', async () => { process.env.RUNNER_LABELS = '["self-hosted", "test", "test2"]'; process.env.ENABLE_WORKFLOW_JOB_LABELS_CHECK = 'true'; process.env.WORKFLOW_JOB_LABELS_CHECK_ALL = 'true'; @@ -174,8 +174,8 @@ describe('handler', () => { { 'X-Hub-Signature': await webhooks.sign(event), 'X-GitHub-Event': 'workflow_job' }, event, ); - expect(resp.statusCode).toBe(202); - expect(sendActionRequest).not.toBeCalled; + expect(resp.statusCode).toBe(201); + expect(sendActionRequest).toBeCalled(); }); it('Check webhook does not accept jobs where not all labels are supported by the runner.', async () => { diff --git a/modules/webhook/lambdas/webhook/src/webhook/handler.ts b/modules/webhook/lambdas/webhook/src/webhook/handler.ts index 22f9f15a04..7394797236 100644 --- a/modules/webhook/lambdas/webhook/src/webhook/handler.ts +++ b/modules/webhook/lambdas/webhook/src/webhook/handler.ts @@ -177,16 +177,9 @@ function isRepoNotAllowed(repoFullName: string, repositoryWhiteList: string[]): function canRunJob(job: WorkflowJobEvent, runnerLabels: string[], workflowLabelCheckAll: boolean): boolean { const workflowJobLabels = job.workflow_job.labels; - let runnerMatch; - let jobMatch; - if (workflowLabelCheckAll) { - runnerMatch = runnerLabels.every((l) => workflowJobLabels.includes(l)); - jobMatch = workflowJobLabels.every((l) => runnerLabels.includes(l)); - } else { - runnerMatch = runnerLabels.some((l) => workflowJobLabels.includes(l)); - jobMatch = workflowJobLabels.some((l) => runnerLabels.includes(l)); - } - const match = jobMatch && runnerMatch; + const match = workflowLabelCheckAll + ? workflowJobLabels.every((l) => runnerLabels.includes(l)) + : workflowJobLabels.some((l) => runnerLabels.includes(l)); logger.debug( `Received workflow job event with labels: '${JSON.stringify(workflowJobLabels)}'. The event does ${