From 300311578e0645342a80dd671302fe864a6d4385 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20S=C3=B8rensen?= Date: Tue, 3 Oct 2023 13:27:50 +0200 Subject: [PATCH] When CLA is failing create a review with requested changes (#207) --- .../github-webhook/handlers/validate-cla.ts | 34 +++++++++++-------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/services/bots/src/github-webhook/handlers/validate-cla.ts b/services/bots/src/github-webhook/handlers/validate-cla.ts index 2f46c0f..2126357 100644 --- a/services/bots/src/github-webhook/handlers/validate-cla.ts +++ b/services/bots/src/github-webhook/handlers/validate-cla.ts @@ -112,14 +112,16 @@ export class ValidateCla extends BaseWebhookHandler { } if (commitsWithoutLogins.length) { - context.scheduleIssueComment({ - handler: botContextName, - comment: noLoginOnShaComment( - commitsWithoutLogins, - context.payload.pull_request.user.login, - `https://github.com/${context.payload.repository.full_name}/pull/${context.payload.number}/commits/`, - ), - }); + await context.github.pulls.createReview( + context.pullRequest({ + body: noLoginOnShaComment( + commitsWithoutLogins, + context.payload.pull_request.user.login, + `https://github.com/${context.payload.repository.full_name}/pull/${context.payload.number}/commits/`, + ), + event: 'REQUEST_CHANGES', + }), + ); context.scheduleIssueLabel(ClaIssueLabel.CLA_ERROR); @@ -137,13 +139,15 @@ export class ValidateCla extends BaseWebhookHandler { } if (authorsNeedingCLA.length) { - context.scheduleIssueComment({ - handler: botContextName, - comment: pullRequestComment( - uniqueEntries(authorsNeedingCLA.map((entry) => `@${entry.login}`)), - `${context.payload.repository.full_name}#${context.payload.number}`, - ), - }); + await context.github.pulls.createReview( + context.pullRequest({ + body: pullRequestComment( + uniqueEntries(authorsNeedingCLA.map((entry) => `@${entry.login}`)), + `${context.payload.repository.full_name}#${context.payload.number}`, + ), + event: 'REQUEST_CHANGES', + }), + ); context.scheduleIssueLabel(ClaIssueLabel.CLA_NEEDED); authorsNeedingCLA.forEach((entry) =>