fix(ci): use REST API to find PRs by branch in workflows

`gh pr view` queries with a hidden `first: 30` which fails to find PRs when the target PR falls outside the first page. The REST API filters by `head=owner:branch` server-side which avoid this limitation.
This commit is contained in:
Tony
2026-04-13 05:07:34 +08:00
parent 0f7808f345
commit 03be368c06
2 changed files with 9 additions and 6 deletions
+6 -4
View File
@@ -32,8 +32,9 @@ jobs:
}}
# Query the PR number by repo + branch, then assign to step output:
run: |
gh pr view --repo "${PR_TARGET_REPO}" "${PR_BRANCH}" \
--json 'number' --jq '"number=\(.number)"' \
gh api "repos/${PR_TARGET_REPO}/pulls" \
--method GET -f head="${PR_BRANCH}" -f state=open \
--jq '.[0] | "number=\(.number)"' \
>> "${GITHUB_OUTPUT}"
- name: Fetch PR data via GitHub API
@@ -180,8 +181,9 @@ jobs:
}}
# Query the PR number by repo + branch, then assign to step output:
run: |
gh pr view --repo "${PR_TARGET_REPO}" "${PR_BRANCH}" \
--json 'number' --jq '"number=\(.number)"' \
gh api "repos/${PR_TARGET_REPO}/pulls" \
--method GET -f head="${PR_BRANCH}" -f state=open \
--jq '.[0] | "number=\(.number)"' \
>> "${GITHUB_OUTPUT}"
- name: Pull Request Labeler
+3 -2
View File
@@ -38,8 +38,9 @@ jobs:
|| github.event.workflow_run.head_branch
}}
run: |
gh pr view --repo "${PR_TARGET_REPO}" "${PR_BRANCH}" \
--json 'number' --jq '"number=\(.number)"' \
gh api "repos/${PR_TARGET_REPO}/pulls" \
--method GET -f head="${PR_BRANCH}" -f state=open \
--jq '.[0] | "number=\(.number)"' \
>> "${GITHUB_OUTPUT}"
- name: Check PR author