Repository navigation
Add field to retrieve linked PRs (closingPRsReferences) in gh issue view <number #10563
Description
Activity
GraphQL query:
query ($owner: String!, $repo: String!, $issue: Int!) { repository(owner: $owner, name: $repo) { issue(number: $issue) { closedByPullRequestsReferences(first: 100) { nodes { number } } } } }
Example with
gh apifor #10529:$ gh api graphql -F owner='cli' -F repo='cli' -F issue=10529 -f query=' query ($owner: String!, $repo: String!, $issue: Int!) { repository(owner: $owner, name: $repo) { issue(number: $issue) { closedByPullRequestsReferences(first: 100) { nodes { number } } } } }' --jq '.data.repository.issue.closedByPullRequestsReferences.nodes[].number' 10544
For consistency,
closedByPullRequestsReferencesmay be used for the JSON field:gh view issue <number> --json closedByPullRequestsReferences
Now that we have #10544 merged, thanks to @iamazeem, I think we can define the acceptance criteria for this one.
Acceptance Criteria
Given a PR references an issue to close
when I usegh issue view <number> --json closedByPullRequestsReferences
then I get a JSON object containingclosedByPullRequestsReferencesas an array of referenced issues with sufficient details to locate the PR(s):$ gh issue view 101 --json closedByPullRequestsReferences { "closedByPullRequestsReferences": [ { "number": 999, "id": "pr-id", "url": "https://github.com/...", "repository": { "id": "repo-id", "name": "repo-name", "owner": { "id": "owner-id", "login": "owner-login" } } } ] }Note that the nested structure (for
repositoryandownerfields) is mainly to keep the schema consistent withgh repo view --jsonoutput.The implementation should look like #10544, except it's for PRs. This is a non-paginated GQL query example (try in GQL Explorer):
query ($owner: String!, $repo: String!, $issue: Int!) { repository(owner: $owner, name: $repo) { issue(number: $issue) { closedByPullRequestsReferences(first: 100) { nodes { number id url repository { owner { login } name } } } } } }
With example variables:
{ "repo": "cli", "owner": "cli", "issue": 10529 }The response will be:
{ "data": { "repository": { "issue": { "closedByPullRequestsReferences": { "nodes": [ { "number": 10544, "id": "PR_kwDODKw3uc6Nbtk1", "url": "https://github.com/cli/cli/pull/10544", "repository": { "owner": { "login": "cli" }, "name": "cli" } } ] } } } } }- addedhelp wantedContributions welcomeContributions welcomegh-issuerelating to the gh issue commandrelating to the gh issue command
on May 6, 2025
Describe the feature or problem you’d like to solve
As per my comment in #10529,
gh issue view <number>should list the linked PRs that would close the issueProposed solution
Exposing
closingPRsReferencesas a field. E.g.gh view issue<number> --json closingPRsReferencesAdditional context
This is an improvement linked to my comment in #10529