How can I get "Linked issues" information from REST API?

For example, this pull request has a linked issue.

But when I use the API

https://api.github.com/repos/pingcap/tidb/pulls?state=open&per_page=100&page=1

iterates pull requests, the response body doesn’t contain this information.

Hi there @tisonkun :wave:

I think I see the problem. If we look only at the specific PR you’re wanting to inspect:

https://api.github.com/repos/pingcap/tidb/pulls/24641

…we can see that the links values do show an association with github.com/pingcap/tidb/issues/24641 that suggests it closes the specific issue you’re expecting to see:

Issue Number: close #24580

This is the response I was looking at:

Linked references return
"_links": {
    "self": {
      "href": "https://api.github.com/repos/pingcap/tidb/pulls/24641"
    },
    "html": {
      "href": "https://github.com/pingcap/tidb/pull/24641"
    },
    "issue": {
      "href": "https://api.github.com/repos/pingcap/tidb/issues/24641"
    },
    "comments": {
      "href": "https://api.github.com/repos/pingcap/tidb/issues/24641/comments"
    },
    "review_comments": {
      "href": "https://api.github.com/repos/pingcap/tidb/pulls/24641/comments"
    },
    "review_comment": {
      "href": "https://api.github.com/repos/pingcap/tidb/pulls/comments{/number}"
    },
    "commits": {
      "href": "https://api.github.com/repos/pingcap/tidb/pulls/24641/commits"
    },
    "statuses": {
      "href": "https://api.github.com/repos/pingcap/tidb/statuses/b28c38ba3ef7313e4bc4002a9361e6fe5b4f5026"

So we can see the reference to the PR which suggests closure of the issue you had expected to see as being linked in the PR you were hoping to query against.

Certainly confusing at first glance!

Let us know if you have any followup questions.

No. It is the description of that PR. Not something provided by GitHub.

1 Like

I wouldn’t just go with confusing. I’d go with “unhelpful”.

GitHub somehow “knows” at a “right now” that if a given PR were merged, it would choose to close the associated issue(s) (and it can be more than one).

Forcing each dev to trawl through the PR description and all of the commits in the PR and not incorrectly reimplement GitHub’s parsing Linking a pull request to an issue - GitHub Docs
is really a bad idea.

Given that the docs describe this as:

Linking a pull request to an issue

About linked issues and pull requests

And given that one can apparently Manually linking a pull request to an issue

It seems perfectly reasonable to expect there be an API to ask about them.

The fact that Link Relations do not cover Linked issues seems really misleading.

There is a connected event.

There’s also a ConnectedEvent in GraphQL.

I can’t find anything useful in Interfaces - GitHub Docs

There isn’t anything particularly obvious in: Objects - GitHub Docs
or
Objects - GitHub Docs

There is also:

But, it isn’t relevant, it’s just glue:

Afaict, there is in fact, no API for this. And, given that it’s possible for users to manually PRs to Issues, it doesn’t appear that there’s a public API for code to do this either.

OTOH, it’s certainly possible I’m bad at searching.

1 Like

Using the

It’s possible to see which PRs/Issues have links:
https://github.com/pingcap/tidb/pulls?q=is%3Apr+is%3Aopen+linked%3Aissue+

But, it doesn’t appear to report what they are. And even this doesn’t appear to be exposed via the API. (The web app is receiving html which it’s merging into the page.) For any repository that actively uses this feature, it’s unlikely that this feature alone would be useful. Also unhelpful is the inability to filter by PR#/Issue#/base branch/head branch.

Hey there :wave:

I genuinely appreciate the time that you’ve taken here @jsoref to express your experience and to more holistically look at what info is available for linked issues from the API. My first response was mostly just focusing on the /pulls endpoint, and what information is gathered there when it comes to link relations.

There is an existing thread:

…which has made its way to our internal tracking issue for functionality that would provide some value here as well, I think.

But obviously there is a gap of functionality that would benefit you both and I request that you submit your feedback via this form:

These submissions go directly to our Product Management teams for review and consideration. I would say individual submissions for both the frustration of the current experience with /pulls, and for the improvements you would like to see with a unique endpoint.

Auto link is a different feature. I know that Apache was specifically frustrated at the lack of an endpoint for configuring it.

This as far as I know was specifically about linking internal GitHub objects.

That said, neither of these are problems I’m particularly concerned with today. I was browsing through the community in search of some other stuff in case my actual needs were already addressed (they aren’t).

I file quite a few tickets via the support portal.

1 Like

I’m sadden to find that this issue doesn’t have an accepted solution, as I was looking to do something related to PR linked issues. Parsing the PR body is something that GitHub already has to do to link issues, we shouldn’t have to do it ourselves to get the same information from the API :frowning: