From 0981cb2f571459cbb6931fb69c914c149957b922 Mon Sep 17 00:00:00 2001 From: blam Date: Wed, 19 Jan 2022 09:56:52 +0100 Subject: [PATCH 1/3] chore: remove the label when it's closed Signed-off-by: blam --- .github/workflows/awaiting-review.yaml | 29 ++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/.github/workflows/awaiting-review.yaml b/.github/workflows/awaiting-review.yaml index 280511a980..12b19f3187 100644 --- a/.github/workflows/awaiting-review.yaml +++ b/.github/workflows/awaiting-review.yaml @@ -2,7 +2,11 @@ name: Set Awaiting Review on: - - pull_request_target + pull_request_target: + types: + - opened + - closed + - synchronize permissions: issues: write @@ -21,13 +25,26 @@ jobs: # TO THE WORKFLOW. THIS SCRIPT WILL AND SHOULD # RUN FROM THE BASE REPO ALL TIMES. script: | - // if it's the author, always add awaiting-review label - const isAuthor = context.payload.pull_request.user.login === context.actor - if (isAuthor) { - await github.rest.issues.addLabels({ + if (['opened', 'synchronize'].includes(${{ github.event.action }})) { + // if it's the author, always add awaiting-review label + const isAuthor = context.payload.pull_request.user.login === context.actor + if (isAuthor) { + await github.rest.issues.addLabels({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + labels: ['awaiting-review'] + }); + } + } + + if (${{ github.event.action}} === 'closed') { + await github.rest.issues.removeLabel({ issue_number: context.issue.number, owner: context.repo.owner, repo: context.repo.repo, - labels: ['awaiting-review'] + labels: 'awaiting-review' + }).catch((e) => { + console.log(e) }); } From 21d2908351526495bf11e16efc733588a38e0668 Mon Sep 17 00:00:00 2001 From: blam Date: Wed, 19 Jan 2022 10:35:46 +0100 Subject: [PATCH 2/3] chore: remove extra request - not needed as we already have the PR and only use it for the author. Signed-off-by: blam --- scripts/goalie-labels.js | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/scripts/goalie-labels.js b/scripts/goalie-labels.js index e2684dfd81..731bd7819a 100644 --- a/scripts/goalie-labels.js +++ b/scripts/goalie-labels.js @@ -91,7 +91,7 @@ module.exports = async ({ github, context, core }) => { // if all required reviewers have reviewed if (hasReviewed.size === expectedReviewers.size) { const recentEventsForPR = await github.paginate( - github.issues.listEvents, + github.rest.issues.listEvents, { issue_number: pullRequest.number, owner: context.repo.owner, @@ -99,16 +99,10 @@ module.exports = async ({ github, context, core }) => { }, ); - const { data: pr } = await github.pulls.get({ - issue_number: pullRequest.number, - owner: context.repo.owner, - repo: context.repo.repo, - }); - // if the last event for the issue is not by the author, remove the label if ( recentEventsForPR[recentEventsForPR.length - 1].actor.login !== - pr.author.login + pullRequest.author.login ) { await github.rest.issues .removeLabel({ From 1245434124bf8e7bf809c851a24442ad7dfb709f Mon Sep 17 00:00:00 2001 From: blam Date: Wed, 19 Jan 2022 10:38:33 +0100 Subject: [PATCH 3/3] chore: namespace the workflow name Signed-off-by: blam --- .github/workflows/awaiting-review.yaml | 2 +- .github/workflows/goalie.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/awaiting-review.yaml b/.github/workflows/awaiting-review.yaml index 12b19f3187..c8dd66d976 100644 --- a/.github/workflows/awaiting-review.yaml +++ b/.github/workflows/awaiting-review.yaml @@ -1,6 +1,6 @@ # When the target of the PR changes, open, re-open or sync, then re-add the label. -name: Set Awaiting Review +name: 'goalie: update awaiting-review label' on: pull_request_target: types: diff --git a/.github/workflows/goalie.yaml b/.github/workflows/goalie.yaml index 6aaaafc429..93ca4209fc 100644 --- a/.github/workflows/goalie.yaml +++ b/.github/workflows/goalie.yaml @@ -1,5 +1,5 @@ # on a review from someone in the reviewers group, remove the awaiting-review label and add the awaiting-author label -name: Goalie Workflow +name: 'goalie: run cron' on: schedule: - cron: '* * * * *'