Skip to content

Commit 4b64c1f

Browse files
committed
tools: add workflow to add label when there are 2+ approvals
Signed-off-by: Antoine du Hamel <duhamelantoine1995@gmail.com> PR-URL: nodejs/node#60554
1 parent 8410a91 commit 4b64c1f

1 file changed

Lines changed: 27 additions & 2 deletions

File tree

.github/workflows/label-pr.yml

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,41 @@ name: Label PRs
33
on:
44
pull_request_target:
55
types: [opened]
6+
pull_request_review:
7+
types: [submitted, dismissed]
68

7-
permissions:
8-
contents: read
9+
permissions: {}
910

1011
jobs:
1112
label:
1213
runs-on: ubuntu-slim
14+
if: github.event_name != 'pull_request_review'
1315

1416
steps:
1517
- uses: nodejs/node-pr-labeler@d4cf1b8b9f23189c37917000e5e17e796c770a6b # v1
1618
with:
1719
repo-token: ${{ secrets.GH_USER_TOKEN }}
1820
configuration-path: .github/label-pr-config.yml
21+
22+
count_approvals:
23+
runs-on: ubuntu-latest
24+
if: github.event_name == 'pull_request_review'
25+
permissions:
26+
issues: write
27+
steps:
28+
- name: 'Add/remove "Approvals: 2+" label'
29+
run: |
30+
set -x
31+
PR_DATA=$(gh pr view "$PR_URL" --json reviewDecision,reviews,labels --jq 'if .reviewDecision != "APPROVED" then .reviewDecision | halt_error end' || true)
32+
33+
[ -n "$PR_DATA" ] && {
34+
TEAM_NAME=$(echo "$PR_DATA" | jq -r 'if (.labels | any(.name == "semver-major")) then "tsc" else "collaborators" end')
35+
TEAM_MEMBERS=$(gh api "orgs/nodejs/teams/$TEAM_NAME/members" --paginate --jq 'map(.login)')
36+
37+
echo "$PR_DATA" | jq --argjson team "$TEAM_MEMBERS" -r '.reviews | map(select(.state == "APPROVED" and (.author.login as $login | $team | any(. == $login)))) | if length < 2 then halt_error end' \
38+
&& gh pr edit "$PR_URL" --add-label 'Approvals: 2+'
39+
} \
40+
|| gh pr edit "$PR_URL" --remove-label 'Approvals: 2+'
41+
env:
42+
GH_TOKEN: ${{ secrets.GH_USER_TOKEN }}
43+
PR_URL: ${{ github.event.pull_request.html_url }}

0 commit comments

Comments
 (0)