Skip to content

Commit

Permalink
fix(webhook): logic to find the workflow labels inside runner config …
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
GuptaNavdeep1983 authored May 23, 2023
1 parent 01a053e commit 9fcf33a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
28 changes: 28 additions & 0 deletions lambdas/functions/webhook/src/webhook/handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,34 @@ describe('handler', () => {
expect(sendActionRequest).not.toBeCalled;
});

it('Check webhook does not accept jobs where the job labels are spread across label matchers.', async () => {
process.env.RUNNER_CONFIG = JSON.stringify([
{
...queuesConfig[0],
matcherConfig: {
labelMatchers: [
['self-hosted', 'x64', 'linux'],
['self-hosted', 'x64', 'on-demand'],
],
exactMatch: true,
},
},
]);
const event = JSON.stringify({
...workflowjob_event,
workflow_job: {
...workflowjob_event.workflow_job,
labels: ['self-hosted', 'linux', 'x64', 'on-demand'],
},
});
const resp = await handle(
{ 'X-Hub-Signature': await webhooks.sign(event), 'X-GitHub-Event': 'workflow_job' },
event,
);
expect(resp.statusCode).toBe(202);
expect(sendActionRequest).not.toBeCalled;
});

it('Check webhook does not accept jobs where not all labels are supported by the runner.', async () => {
process.env.RUNNER_CONFIG = JSON.stringify([
{
Expand Down
4 changes: 2 additions & 2 deletions lambdas/functions/webhook/src/webhook/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ function canRunJob(
return runnerLabel.map((label) => label.toLowerCase());
});
const match = workflowLabelCheckAll
? workflowJobLabels.every((wl) => runnerLabelsMatchers.some((rl) => rl.includes(wl.toLowerCase())))
: workflowJobLabels.some((wl) => runnerLabelsMatchers.some((rl) => rl.includes(wl.toLowerCase())));
? runnerLabelsMatchers.some((rl) => workflowJobLabels.every((wl) => rl.includes(wl.toLowerCase())))
: runnerLabelsMatchers.some((rl) => workflowJobLabels.some((wl) => rl.includes(wl.toLowerCase())));

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

0 comments on commit 9fcf33a

Please sign in to comment.