4

I would like to find all pull requests for a Jira issue. Obviously, this is a possible task, as Jira itself shows the information:

Screenshot Jira/Bitbucket integration

Currently, I retrieve a list of all merged and open pull requests via the Bitbucket API, and pattern match these to my issue number. This is time consuming, even more so as I have to load the pull requests in batches of 100 (Max limit in Bitbucket), and we have our code spread in several repositories.

There is an integration api call to bitbucket: /rest/jira/1.0/issues//commits, which will show all commits to this issue, but .../pullrequests is not available.

Does anyone know, how Jira retrieves this information?

Alexander Reifinger
  • 512
  • 1
  • 4
  • 18

3 Answers3

10

https://github.com/jira-node/node-jira-client/issues/142

JIRA has an undocumented "dev-status" API that is usual when JIRA is integrated with other tools like Stash (Bitbucket Server)

At first you have to get jiraIssueNumericId. For example you can get it by getting issue info via Jira API that is well documented. The field you are looking for is "id". https://docs.atlassian.com/software/jira/docs/api/REST/7.6.1/?_ga=2.203378385.1940451621.1522669776-298439511.1476796418#api/2/issue-getIssue)

About methods of this Jira dev-status API:

  1. To get info about branches and pull requests related to an issue: https://{jiraHost}/rest/dev-status/latest/issue/detail?issueId={jiraIssueNumericId}&applicationType=stash&dataType=pullrequest
  2. To get info about commits related to an issue: https://{jiraHost}/rest/dev-status/latest/issue/detail?issueId={jiraIssueNumericId}&applicationType=stash&dataType=repository
  3. To get summary: https://{jiraHost}/rest/dev-status/latest/issue/summary?issueId={jiraIssueNumericId}

P.S. This API is actually used on issue page in Jira. Try clicking on pull-requests link to open popup window with a list of them. In development panel of your browser in Network tab you will find XHR-calls or these urls.

P.P.S. And yes, I've also struggled to find this info and I have no idea why it is undocumented.

Pigalev Pavel
  • 1,155
  • 1
  • 15
  • 29
  • Tried to get the prs for an issue. This is what I got: https://imgur.com/a/Uqcep. Apart from prs being an empty array and the info being under "_instance", how do I get the pr with this id? – Alexander Reifinger Apr 05 '18 at 07:52
  • 1
    @AlexanderReifinger I think issue you are trying it with doesn't have any pullRequests connected with it. I suggest you trying to look in Network tab as I wrote in "p.s.". Just open development panel of you browser, choose Network tab, choose "XHR" and then click on "N pull-requests" you will see pop-up window with a list of pull-requests and you will also see xhr-call in network-tab like this one: https://imgur.com/a/oaH9I – Pigalev Pavel Apr 09 '18 at 19:07
0

It looks like this endpoint used to be documented in the API https://developer.atlassian.com/static/rest/stash/2.6.0/stash-jira-integration-rest.html#idp21856

But I'm pretty sure its an internal API so you shouldn't rely on it being stable. The current documentation doesn't list it https://developer.atlassian.com/static/rest/bitbucket-server/4.13.0/bitbucket-rest.html

Ben
  • 79
  • 2
0

The correct API:

https://{jiraHost}/rest/dev-status/latest/issue/details?issueId={jiraIssueNumericId}&applicationType=<scm>&dataType=<option>

where <scm> could be bitbucket, stash or github
and dataType could be branch or pullrequest

Reza Rahemtola
  • 1,182
  • 7
  • 16
  • 30