From 03be368c06cecc6e49bafabed620b97dd9477a3e Mon Sep 17 00:00:00 2001 From: Tony Date: Mon, 13 Apr 2026 05:07:34 +0800 Subject: [PATCH] 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. --- .github/workflows/docker-test-cont.yml | 10 ++++++---- .github/workflows/pr-review.yml | 5 +++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/.github/workflows/docker-test-cont.yml b/.github/workflows/docker-test-cont.yml index 84b324214..1f00ab0d3 100644 --- a/.github/workflows/docker-test-cont.yml +++ b/.github/workflows/docker-test-cont.yml @@ -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 diff --git a/.github/workflows/pr-review.yml b/.github/workflows/pr-review.yml index 39db57eb3..57fd48e25 100644 --- a/.github/workflows/pr-review.yml +++ b/.github/workflows/pr-review.yml @@ -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