Skip to content

Add field to retrieve linked PRs (closingPRsReferences) in gh issue view <number #10563

Description

@EdouardF

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 issue

Proposed solution

Exposing closingPRsReferences as a field. E.g. gh view issue<number> --json closingPRsReferences

Additional context

This is an improvement linked to my comment in #10529

Activity

  1. iamazeem commented on Mar 10, 2025

    @iamazeem
    Contributor

    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 api for #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, closedByPullRequestsReferences may be used for the JSON field:

    gh view issue <number> --json closedByPullRequestsReferences
  2. babakks commented on May 6, 2025

    @babakks
    Member

    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 use gh issue view <number> --json closedByPullRequestsReferences
    then I get a JSON object containing closedByPullRequestsReferences as 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 repository and owner fields) is mainly to keep the schema consistent with gh repo view --json output.

  3. babakks commented on May 6, 2025

    @babakks
    Member

    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"
                  }
                }
              ]
            }
          }
        }
      }
    }
  4. babakks commented on May 6, 2025

    @babakks
    Member

    We discussed about this issue in the team and decided to mark it as help-wanted.

    @iamazeem, since you did the pr view part in #10544, would you like to take this one as well?

  5. iamazeem commented on May 6, 2025

    @iamazeem
    Contributor

    We discussed about this issue in the team and decided to mark it as help-wanted.

    @iamazeem, since you did the pr view part in #10544, would you like to take this one as well?

    Sure, I'd like to take this one too. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementa request to improve CLIgh-issuerelating to the gh issue commandhelp wantedContributions welcome

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions