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

Commit 9fcf33a

Browse files
fix(webhook): logic to find the workflow labels inside runner config supported labelsets. (#3278)
* fix: fixed the logic to find the workflow labels inside runner config supports labelsets. * fix: formatting. * fix: added a negative test case around this change. * fix: formatting.
1 parent 01a053e commit 9fcf33a

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

lambdas/functions/webhook/src/webhook/handler.test.ts

+28
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,34 @@ describe('handler', () => {
264264
expect(sendActionRequest).not.toBeCalled;
265265
});
266266

267+
it('Check webhook does not accept jobs where the job labels are spread across label matchers.', async () => {
268+
process.env.RUNNER_CONFIG = JSON.stringify([
269+
{
270+
...queuesConfig[0],
271+
matcherConfig: {
272+
labelMatchers: [
273+
['self-hosted', 'x64', 'linux'],
274+
['self-hosted', 'x64', 'on-demand'],
275+
],
276+
exactMatch: true,
277+
},
278+
},
279+
]);
280+
const event = JSON.stringify({
281+
...workflowjob_event,
282+
workflow_job: {
283+
...workflowjob_event.workflow_job,
284+
labels: ['self-hosted', 'linux', 'x64', 'on-demand'],
285+
},
286+
});
287+
const resp = await handle(
288+
{ 'X-Hub-Signature': await webhooks.sign(event), 'X-GitHub-Event': 'workflow_job' },
289+
event,
290+
);
291+
expect(resp.statusCode).toBe(202);
292+
expect(sendActionRequest).not.toBeCalled;
293+
});
294+
267295
it('Check webhook does not accept jobs where not all labels are supported by the runner.', async () => {
268296
process.env.RUNNER_CONFIG = JSON.stringify([
269297
{

lambdas/functions/webhook/src/webhook/handler.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,8 @@ function canRunJob(
167167
return runnerLabel.map((label) => label.toLowerCase());
168168
});
169169
const match = workflowLabelCheckAll
170-
? workflowJobLabels.every((wl) => runnerLabelsMatchers.some((rl) => rl.includes(wl.toLowerCase())))
171-
: workflowJobLabels.some((wl) => runnerLabelsMatchers.some((rl) => rl.includes(wl.toLowerCase())));
170+
? runnerLabelsMatchers.some((rl) => workflowJobLabels.every((wl) => rl.includes(wl.toLowerCase())))
171+
: runnerLabelsMatchers.some((rl) => workflowJobLabels.some((wl) => rl.includes(wl.toLowerCase())));
172172

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

0 commit comments

Comments
 (0)