mirror of
https://github.com/armbian/build
synced 2025-09-24 19:47:06 +07:00
PR review labeler: extract PR number from commit ID (#8627)
This commit is contained in:
33
.github/workflows/pr-label-on-approved.yml
vendored
33
.github/workflows/pr-label-on-approved.yml
vendored
@@ -1,25 +1,43 @@
|
||||
name: PR review labeler
|
||||
on:
|
||||
workflow_run:
|
||||
workflows: ["PR review listener"]
|
||||
workflows: ["PR review listener"] # must match the other workflow's name
|
||||
types: [completed]
|
||||
|
||||
jobs:
|
||||
label:
|
||||
if: ${{ github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.pull_requests[0] }}
|
||||
name: "Set label"
|
||||
if: ${{ github.event.workflow_run.conclusion == 'success' }}
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: read
|
||||
issues: write
|
||||
pull-requests: write
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Extract PR number
|
||||
- name: Resolve PR number from head_sha
|
||||
id: pr
|
||||
run: |
|
||||
echo "number=${{ github.event.workflow_run.pull_requests[0].number }}" >> "$GITHUB_OUTPUT"
|
||||
uses: actions/github-script@v7
|
||||
with:
|
||||
script: |
|
||||
const { owner, repo } = context.repo;
|
||||
const sha = context.payload.workflow_run.head_sha;
|
||||
|
||||
const { data: prs } = await github.rest.repos.listPullRequestsAssociatedWithCommit({
|
||||
owner, repo, commit_sha: sha
|
||||
});
|
||||
|
||||
if (!prs.length) {
|
||||
core.setFailed(`❌ No PR found for commit ${sha}`);
|
||||
return;
|
||||
}
|
||||
|
||||
// Pick an open PR if possible
|
||||
const pr = prs.find(p => p.state === 'open') || prs[0];
|
||||
core.info(`Using PR #${pr.number}`);
|
||||
core.setOutput('number', String(pr.number));
|
||||
|
||||
- name: Label when approved
|
||||
if: ${{ success() }}
|
||||
uses: j-fulbright/label-when-approved-action@v1.2
|
||||
with:
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
@@ -27,5 +45,4 @@ jobs:
|
||||
require_committers_approval: 'true'
|
||||
remove_label_when_approval_missing: 'true'
|
||||
comment: '✅ This PR has been reviewed and approved — all set for merge!'
|
||||
# action runs on workflow_run, so pass PR number explicitly
|
||||
pullRequestNumber: ${{ steps.pr.outputs.number }}
|
||||
|
||||
Reference in New Issue
Block a user