Skip to content

Commit dd51687

Browse files
committed
Fix: Extract owner/repo from URL instead of head repository fields
The script was extracting owner and repo from headRepositoryOwner and headRepository, which refer to the fork (source) repository. For fork PRs, this caused all API calls to target the wrong repository since PRs live on the base (target) repository. Fixed by parsing owner and repo from the URL field, which always points to the base repository where the PR actually exists.
1 parent 15971ba commit dd51687

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

.cursor/skills/gh-review/scripts/gh-review.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,15 @@ cmd_start() {
2525
local pr="${1:?PR number required}"
2626

2727
local pr_json
28-
pr_json=$(gh pr view "$pr" --json number,headRefOid,headRepository,headRepositoryOwner,url)
28+
pr_json=$(gh pr view "$pr" --json number,headRefOid,url)
2929

3030
local number head_sha owner repo url
3131
number=$(echo "$pr_json" | jq -r '.number')
3232
head_sha=$(echo "$pr_json" | jq -r '.headRefOid')
33-
owner=$(echo "$pr_json" | jq -r '.headRepositoryOwner.login')
34-
repo=$(echo "$pr_json" | jq -r '.headRepository.name')
3533
url=$(echo "$pr_json" | jq -r '.url')
34+
# Parse owner and repo from URL which always points to the base repository
35+
owner=$(echo "$url" | sed -E 's|https://github.com/([^/]+)/([^/]+)/pull/[0-9]+.*|\1|')
36+
repo=$(echo "$url" | sed -E 's|https://github.com/([^/]+)/([^/]+)/pull/[0-9]+.*|\2|')
3637

3738
local pending
3839
pending=$(gh api graphql -f query='

0 commit comments

Comments
 (0)