How to get Jira ID link from Pull Request via Curl call to the API

Am trying to retrieve the JIRA ID referenced on the Stash Pull Request UI display (JIRA Issue). This Curl call: curl -k -D- -u <JiraUser> -X GET -H \'Content-Type: application/json\' \'https://localhost:8443/rest/api/1.0/projects/<project>/repos/<repository>/pull-requests/4379/activities?limit=1000' can return "attributes:{"jira-key": but does not appear to actually return the JIRA Issue linked to on the Pull Request page.

3 answers

1 vote

Hi @Danny Powell,

I believe what you are looking for is the bitbucket-JIRA REST API. (The docs I've linked are Stash docs, as the Bitbucket Server docs are currently broken. I'm working on fixing that right now!) 

Basically you can call:

/rest/jira/1.0/projects/{projectKey}/repos/{repositorySlug}/pull-requests/{pullRequestId}/issues

and will receive a response similar to:

[
    {
        "key": "JRA-11",
        "url": "https://jira.atlassian.com/browse/JRA-11"
    },
    {
        "key": "JRA-9",
        "url": "https://jira.atlassian.com/browse/JRA-9"
    }
]

 

I hope that helps, 

Felix Haehnel
Graduate Developer
Bitbucket Server 

Hi,

Is there any Java Method to get all the JIRA issues associated with the PR? Pls help.

@Senthil Jothi, 

there sure is: 

com.atlassian.bitbucket.integration.jira.JiraIssueService exposes the method getIssuesForPullRequest(int, long).

You will also need to add the following dependency to your pom.xml:

&lt;dependency&gt;
	&lt;groupId&gt;com.atlassian.bitbucket.server&lt;/groupId&gt;
	&lt;artifactId&gt;bitbucket-jira-api&lt;/artifactId&gt;
	&lt;scope&gt;provided&lt;/scope&gt;
&lt;/dependency&gt;

Thank you soo much. smile

Last question,

Is there any method to add more issues to the same list ? 

Hi @Felix Haehnel

I am still using stash 3.11.4. Will this dependency work ? 

Is there a way to increase the default # of commits that it will check? Looks like it's limited to 100, but I need to get to about 400 commits. the "?limit=1000" doesn't work anymore

This does not appear to work in JIRA Server 7.2.1 with Bitbucket Server 4.9.1. I can't see to find anyway to link either Issues to Pull-requests or vice versa.

That did it! Thank you for the help. That was exactly what I needed.

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Posted Jun 12, 2018 in Bitbucket

Do you use any Atlassian products for your personal projects?

After spinning my wheels trying to get organized enough to write a book for National Novel Writing Month (NaNoWriMo) I took my affinity for Atlassian products from my work life and decided to tr...

22,153 views 26 11
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you