Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Copilot Lvl 2
Message 1 of 4

Get referenced pull request from issue

Solved! Go to Solution.

Hey Community,

 

Github allows to see if pull requests reference an issue (or vice versa), e.g. see the following example (randomly picked):

issue with referenced pull request

 

This is great and I'm wondering if I can achieve the same via the API. While the API (v3) allows to see if commits are referenced in the issue (via its events) I wasn't able to find a way to get referenced pull requests. I went through a couple of sources (e.g. here).

 

Is this even possible?

3 Replies
Solution
Community Manager
Message 2 of 4

Re: Get referenced pull request from issue

You're correct. I wasn't able to find a way to do what you're asking via the REST API. But here's a query that works for the GraphQL API:

 

query {
  repository(owner: "bigdatagenomics", name: "adam") {
    issue(number: 479) {
      timelineItems(first: 100) {
        nodes {
          ... on ClosedEvent {
            closer {
              ... on PullRequest {
                number
                title
              }
            }
          }
        }
      }
    }
  }
}

which results in:

 

{
  "data": {
    "repository": {
      "issue": {
        "timelineItems": {
          "nodes": [
            {},
            {},
            {},
            {
              "closer": {
                "number": 570,
                "title": "A few small conversion fixes"
              }
            }
          ]
        }
      }
    }
  }
}

I hope that helps!

Copilot Lvl 2
Message 3 of 4

Re: Get referenced pull request from issue

Thanks for your answer! Based on your query I played around with the v4 API and came up with something different which suits me better:

 

 

query {
  repository(owner: "bigdatagenomics", name: "adam") {
    issue(number: 479) {
      timelineItems(first: 100) {
        nodes {
          ... on CrossReferencedEvent {
            source {
              ... on PullRequest {
                number
                title
              }
            }
          }
        }
      }
    }
  }
}

In this case I get every referenced Pull Requests and not only those which closed the issue.

 

Thanks again!

 

Community Manager
Message 4 of 4

Re: Get referenced pull request from issue

Awesome! Thanks for sharing your ultimate solution back 😀