|
1 | | -on: pull_request_review |
2 | | -name: Label approved pull requests |
3 | | - |
4 | | -permissions: |
5 | | - contents: read # Required for checking changed files |
6 | | - pull-requests: write # Required for labeling PRs |
7 | | - issues: write # Required for adding/removing labels |
| 1 | +name: PR review labeler |
| 2 | +on: |
| 3 | + workflow_run: |
| 4 | + workflows: ["PR review listener"] |
| 5 | + types: [completed] |
8 | 6 |
|
9 | 7 | jobs: |
10 | | - labelWhenApproved: |
11 | | - if: ${{ github.repository_owner == 'armbian' }} |
12 | | - name: Label when approved |
| 8 | + label: |
| 9 | + if: ${{ github.event.workflow_run.conclusion == 'success' }} |
13 | 10 | runs-on: ubuntu-latest |
| 11 | + permissions: |
| 12 | + contents: read |
| 13 | + issues: write |
| 14 | + pull-requests: write |
| 15 | + |
14 | 16 | steps: |
15 | | - - name: Label when approved |
16 | | - uses: pullreminders/label-when-approved-action@master |
17 | | - env: |
18 | | - APPROVALS: "1" |
19 | | - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
20 | | - ADD_LABEL: "Ready to merge" |
21 | | - REMOVE_LABEL: "Needs%20review" |
| 17 | + - name: Download PR number artifact from upstream run |
| 18 | + uses: actions/download-artifact@v6 |
| 19 | + with: |
| 20 | + name: pr-number-${{ github.event.workflow_run.id }} # same unique name |
| 21 | + path: . |
| 22 | + run-id: ${{ github.event.workflow_run.id }} # ← CRITICAL: fetch from the upstream run |
| 23 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 24 | + |
| 25 | + - id: pr |
| 26 | + run: echo "number=$(cat pr.txt)" >> $GITHUB_OUTPUT |
| 27 | + |
| 28 | + - name: Label when approved |
| 29 | + uses: j-fulbright/[email protected] |
| 30 | + with: |
| 31 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 32 | + label: 'Ready to merge' |
| 33 | + require_committers_approval: 'true' |
| 34 | + remove_label_when_approval_missing: 'true' |
| 35 | + comment: '✅ This PR has been reviewed and approved — all set for merge!' |
| 36 | + pullRequestNumber: ${{ steps.pr.outputs.number }} |
| 37 | + |
| 38 | + - name: Remove review-related labels |
| 39 | + if: ${{ success() }} |
| 40 | + uses: actions/github-script@v8 |
| 41 | + with: |
| 42 | + script: | |
| 43 | + const { owner, repo } = context.repo; |
| 44 | + const issue_number = ${{ steps.pr.outputs.number }}; |
| 45 | + const labelsToRemove = ["Needs review", "Work in progress", "Backlog", "Can be closed?", "Help needed", "Needs Documentation"]; |
| 46 | +
|
| 47 | + for (const name of labelsToRemove) { |
| 48 | + try { |
| 49 | + await github.rest.issues.removeLabel({ owner, repo, issue_number, name }); |
| 50 | + core.info(`Removed label "${name}"`); |
| 51 | + } catch (e) { |
| 52 | + core.warning(`Could not remove label "${name}": ${e.message}`); |
| 53 | + } |
| 54 | + } |
0 commit comments