From 2c2695cc1a0340620963834b45ad61bf5b193643 Mon Sep 17 00:00:00 2001 From: blam Date: Tue, 18 Jan 2022 21:42:16 +0100 Subject: [PATCH 1/3] chore: some small changes to try and get the workflow running properly Signed-off-by: blam --- .github/workflows/awaiting-review.yaml | 7 +------ scripts/goalie-labels.js | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/.github/workflows/awaiting-review.yaml b/.github/workflows/awaiting-review.yaml index 06a85921d8..64fd18d75a 100644 --- a/.github/workflows/awaiting-review.yaml +++ b/.github/workflows/awaiting-review.yaml @@ -1,11 +1,7 @@ # on a PR open on PR review or comment, assign the awaiting-review label if the actor is the author name: Set Awaiting Review on: - pull_request_review: - types: [submitted] - pull_request_review_comment: - types: [created] - pull_request: + pull_request_target: types: [opened, reopened, synchronize] permissions: @@ -19,7 +15,6 @@ jobs: - uses: actions/github-script@v5 id: fix-labels with: - github-token: ${{ secrets.GITHUB_TOKEN }} script: | // if it's the author, always add awaiting-review label const isAuthor = context.payload.pull_request.user.login === context.actor diff --git a/scripts/goalie-labels.js b/scripts/goalie-labels.js index e9765aebb8..adedc35d42 100644 --- a/scripts/goalie-labels.js +++ b/scripts/goalie-labels.js @@ -91,12 +91,25 @@ module.exports = async ({ github, context, core }) => { if (hasReviewed.size === expectedReviewers.size) { await github.rest.issues .removeLabel({ - issue_number: context.issue.number, + issue_number: pullRequest.number, owner: context.repo.owner, repo: context.repo.repo, name: 'awaiting-review', }) - .catch(() => {}); + .catch(e => { + console.error(e); + }); + } else { + await github.rest.issues + .addLabels({ + issue_number: pullRequest.number, + owner: context.repo.owner, + repo: context.repo.repo, + labels: ['awaiting-review'], + }) + .catch(e => { + console.error(e); + }); } } }; From e2a8331c600207584dc4ec6bfacfff90f09c5710 Mon Sep 17 00:00:00 2001 From: blam Date: Tue, 18 Jan 2022 21:46:43 +0100 Subject: [PATCH 2/3] chore: use GITHUB_TOKEN Signed-off-by: blam --- .github/workflows/awaiting-review.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/awaiting-review.yaml b/.github/workflows/awaiting-review.yaml index 64fd18d75a..b5c1e6a1ff 100644 --- a/.github/workflows/awaiting-review.yaml +++ b/.github/workflows/awaiting-review.yaml @@ -1,9 +1,8 @@ # on a PR open on PR review or comment, assign the awaiting-review label if the actor is the author name: Set Awaiting Review on: - pull_request_target: - types: [opened, reopened, synchronize] - + - pull_request_target + permissions: issues: write pull-requests: write @@ -15,6 +14,7 @@ jobs: - uses: actions/github-script@v5 id: fix-labels with: + github-token: ${{ secrets.GITHUB_TOKEN }} script: | // if it's the author, always add awaiting-review label const isAuthor = context.payload.pull_request.user.login === context.actor From 0c3641fc84210e70b0c35998055aa9ee927fb169 Mon Sep 17 00:00:00 2001 From: blam Date: Tue, 18 Jan 2022 22:08:20 +0100 Subject: [PATCH 3/3] chore: added a noite around the repo token Signed-off-by: blam --- .github/workflows/awaiting-review.yaml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/awaiting-review.yaml b/.github/workflows/awaiting-review.yaml index b5c1e6a1ff..280511a980 100644 --- a/.github/workflows/awaiting-review.yaml +++ b/.github/workflows/awaiting-review.yaml @@ -1,8 +1,9 @@ -# on a PR open on PR review or comment, assign the awaiting-review label if the actor is the author +# When the target of the PR changes, open, re-open or sync, then re-add the label. + name: Set Awaiting Review on: - pull_request_target - + permissions: issues: write pull-requests: write @@ -15,6 +16,10 @@ jobs: id: fix-labels with: github-token: ${{ secrets.GITHUB_TOKEN }} + # THIS SCRIPT SHOULD BE INLINED AND NOT IN REPO + # DUE TO THE TOKEN PERMISSIONS THAT ARE GIVEN + # 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