Skip to content

Maintenance: Label PR on approval #2315

Maintenance: Label PR on approval

Maintenance: Label PR on approval #2315

name: "Maintenance: Label PR on approval"
on:
workflow_run:
workflows: ["Maintenance: Listen PR review"]
types: [completed]
permissions:
contents: read
jobs:
label:
if: ${{ github.event.workflow_run.conclusion == 'success' }}
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
issues: write
pull-requests: write
steps:
- name: Download PR number artifact from upstream run
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: pr-number-${{ github.event.workflow_run.id }} # same unique name
path: .
run-id: ${{ github.event.workflow_run.id }} # ← CRITICAL: fetch from the upstream run
github-token: ${{ secrets.GITHUB_TOKEN }}
- id: pr
run: echo "number=$(cat pr.txt)" >> $GITHUB_OUTPUT
- name: Label when approved
uses: j-fulbright/label-when-approved-action@911c622c75f8ea99ee00cdd66e2cd888bac530c6 # v1.2
with:
token: ${{ secrets.GITHUB_TOKEN }}
label: 'Ready to merge'
require_committers_approval: 'true'
remove_label_when_approval_missing: 'true'
comment: '✅ This PR has been reviewed and approved — all set for merge!'
pullRequestNumber: ${{ steps.pr.outputs.number }}
- name: Remove review-related labels
if: ${{ success() }}
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
env:
PR_NUMBER: ${{ steps.pr.outputs.number }}
with:
script: |
const { owner, repo } = context.repo;
const issue_number = Number.parseInt(process.env.PR_NUMBER || "", 10);
if (!Number.isInteger(issue_number) || issue_number <= 0) {
core.setFailed("Invalid PR number in PR_NUMBER");
return;
}
const labelsToRemove = ["Needs review", "Work in progress", "Backlog", "Can be closed?", "Help needed", "Needs Documentation"];
for (const name of labelsToRemove) {
try {
await github.rest.issues.removeLabel({ owner, repo, issue_number, name });
core.info(`Removed label "${name}"`);
} catch (e) {
core.warning(`Could not remove label "${name}": ${e.message}`);
}
}