Reputation: 532
I would like to find all pull requests for a Jira issue. Obviously, this is a possible task, as Jira itself shows the information:
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?
Upvotes: 6
Views: 7773
Reputation: 1457
My answer also uses the same dev-status
API, but let me provide the entire steps for this to work. I will provide cURLs for API so you can translate it to any preferred language.
Sadly, I couldn't find any other way to use this API without your actual JIRA password, the JIRA token didn't work for me. If you could make it work without the actual password, let me know too.
I assume you already have the ticket-id with you and it's a numeric ID corresponding to each textual id (eg. STACK-100
may have an id that's something like 301736
)
This is where we first need to login to JIRA via our actual username and password, from where we extract this session id from cookies:
curl --location 'https://YOUR_JIRA_URL/login.jsp' \
--data-urlencode 'os_username=YOUR_USERNAME' \
--data-urlencode 'os_password=YOUR_PASSWORD' \
--data-urlencode 'os_destination=' \
--data-urlencode 'user_role=' \
--data-urlencode 'atl_token=' \
--data-urlencode 'login=Log In'
Don't forget to replace: YOUR_JIRA_URL
, YOUR_USERNAME
and YOUR_PASSWORD
with the right values.
A successful request will result in an HTML response. Ignore it and look into the cookies of the response. There you'll find JSESSIONID and it's value. We use this to make our next request:
Execute this cURL:
curl --location 'https://YOUR_JIRA_URL/rest/dev-status/latest/issue/detail?issueId=ISSUE_ID&applicationType=stash&dataType=pullrequest' \
--header 'Cookie: JSESSIONID=EXTRACTED_JSESSIONID;'
This will give you the response that you need. Don't forget to replace:
YOUR_JIRA_URL
, ISSUE_ID
and EXTRACTED_JSESSIONID
with the correct values.
Note that I have used applicationType=stash
, but it could be bitbucket
or github
as well.
Upvotes: 0
Reputation: 1
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
Upvotes: 0
Reputation: 1185
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:
https://{jiraHost}/rest/dev-status/latest/issue/detail?issueId={jiraIssueNumericId}&applicationType=stash&dataType=pullrequest
https://{jiraHost}/rest/dev-status/latest/issue/detail?issueId={jiraIssueNumericId}&applicationType=stash&dataType=repository
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.
Upvotes: 11
Reputation: 77
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
Upvotes: 0