Skip to content
Open
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
61 changes: 59 additions & 2 deletions .github/workflows/label-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,73 @@ name: Label PRs
on:
pull_request_target:
types: [opened]
workflow_run:
workflows: [PR Reviewed]
types: [completed]

permissions:
contents: read
permissions: {}

jobs:
label:
runs-on: ubuntu-slim
if: github.event_name != 'workflow_run'

steps:
- uses: nodejs/node-pr-labeler@d4cf1b8b9f23189c37917000e5e17e796c770a6b # v1
with:
repo-token: ${{ secrets.GH_USER_TOKEN }}
configuration-path: .github/label-pr-config.yml

count_approvals:
runs-on: ubuntu-latest
if: github.event_name == 'workflow_run'
permissions:
pull-requests: read
steps:
- name: Download PR number
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: pr-number
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ secrets.GH_USER_TOKEN }}
- name: Fetch PR data
id: pr-data
run: |
set -x
PR_NUMBER="$(grep -E '^[0-9]+$' pr_number.txt)"

[ -n "$PR_NUMBER" ] && {
echo "NUMBER=$PR_NUMBER"
echo "DATA=$(
gh --repo "$GITHUB_REPOSITORY" pr view "$PR_NUMBER" \
--json reviewDecision,headRefOid,reviews,labels \
--jq 'if .reviewDecision != "APPROVED" then .reviewDecision | halt_error end' \
|| true
)"
} >> "$GITHUB_OUTPUT"
env:
GH_TOKEN: ${{ github.token }}
- name: 'Add/remove "Approvals: 2+" label'
run: |
set -x
[ -n "$PR_DATA" ] && {
TEAM_NAME=$(echo "$PR_DATA" | jq -r 'if (.labels | any(.name == "semver-major")) then "tsc" else "collaborators" end')
TEAM_MEMBERS=$(gh api "orgs/nodejs/teams/$TEAM_NAME/members" --paginate --jq 'map(.login)')

echo "$PR_DATA" | jq --argjson team "$TEAM_MEMBERS" -r '
.headRefOid as $head
| .reviews
| map(select(
.state == "APPROVED"
and .commit.oid == $head
and (.author.login as $login | $team | any(. == $login))
))
| unique_by(.author.login)
| if length < 2 then halt_error end' \
&& gh --repo "$GITHUB_REPOSITORY" pr edit "$PR_NUMBER" --add-label 'Approvals: 2+'
} \
|| gh --repo "$GITHUB_REPOSITORY" pr edit "$PR_NUMBER" --remove-label 'Approvals: 2+'
env:
GH_TOKEN: ${{ secrets.GH_USER_TOKEN }}
PR_NUMBER: ${{ steps.pr-data.outputs.NUMBER }}
PR_DATA: ${{ steps.pr-data.outputs.DATA }}
19 changes: 19 additions & 0 deletions .github/workflows/pr-revieweed.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: PR Reviewed

on:
pull_request_review:
types: [submitted, dismissed]

permissions: {}

jobs:
store-pr-number:
runs-on: ubuntu-slim
steps:
- name: Store PR number
run: echo "${{ github.event.pull_request.number }}" > pr_number.txt
- name: Upload PR number
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: pr-number
path: pr_number.txt
Loading
Loading