Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Webhook accept jobs where not all labels are provided in job. #2209

Merged
merged 1 commit into from
Aug 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions modules/webhook/lambdas/webhook/src/webhook/handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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 () => {
Expand Down
13 changes: 3 additions & 10 deletions modules/webhook/lambdas/webhook/src/webhook/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,16 +178,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 ${
Expand Down