Skip to content
This repository was archived by the owner on Jan 16, 2025. It is now read-only.

Commit 6d9116f

Browse files
authored
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.
1 parent 4e3b606 commit 6d9116f

File tree

2 files changed

+6
-13
lines changed

2 files changed

+6
-13
lines changed

Diff for: modules/webhook/lambdas/webhook/src/webhook/handler.test.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ describe('handler', () => {
159159
expect(sendActionRequest).toBeCalled();
160160
});
161161

162-
it('Check webhook does not accept jobs where not all labels are provided in job.', async () => {
162+
it('Check webhook accept jobs where not all labels are provided in job.', async () => {
163163
process.env.RUNNER_LABELS = '["self-hosted", "test", "test2"]';
164164
process.env.ENABLE_WORKFLOW_JOB_LABELS_CHECK = 'true';
165165
process.env.WORKFLOW_JOB_LABELS_CHECK_ALL = 'true';
@@ -174,8 +174,8 @@ describe('handler', () => {
174174
{ 'X-Hub-Signature': await webhooks.sign(event), 'X-GitHub-Event': 'workflow_job' },
175175
event,
176176
);
177-
expect(resp.statusCode).toBe(202);
178-
expect(sendActionRequest).not.toBeCalled;
177+
expect(resp.statusCode).toBe(201);
178+
expect(sendActionRequest).toBeCalled();
179179
});
180180

181181
it('Check webhook does not accept jobs where not all labels are supported by the runner.', async () => {

Diff for: modules/webhook/lambdas/webhook/src/webhook/handler.ts

+3-10
Original file line numberDiff line numberDiff line change
@@ -177,16 +177,9 @@ function isRepoNotAllowed(repoFullName: string, repositoryWhiteList: string[]):
177177

178178
function canRunJob(job: WorkflowJobEvent, runnerLabels: string[], workflowLabelCheckAll: boolean): boolean {
179179
const workflowJobLabels = job.workflow_job.labels;
180-
let runnerMatch;
181-
let jobMatch;
182-
if (workflowLabelCheckAll) {
183-
runnerMatch = runnerLabels.every((l) => workflowJobLabels.includes(l));
184-
jobMatch = workflowJobLabels.every((l) => runnerLabels.includes(l));
185-
} else {
186-
runnerMatch = runnerLabels.some((l) => workflowJobLabels.includes(l));
187-
jobMatch = workflowJobLabels.some((l) => runnerLabels.includes(l));
188-
}
189-
const match = jobMatch && runnerMatch;
180+
const match = workflowLabelCheckAll
181+
? workflowJobLabels.every((l) => runnerLabels.includes(l))
182+
: workflowJobLabels.some((l) => runnerLabels.includes(l));
190183

191184
logger.debug(
192185
`Received workflow job event with labels: '${JSON.stringify(workflowJobLabels)}'. The event does ${

0 commit comments

Comments
 (0)