Jira automation: get linked PR information

Nick de Palézieux
Contributor
March 27, 2023

I'm trying to implement a Jira automation that triggers on an issue state change that then performs actions based on the linked pull requests.

For this, I need to be able to access the pull request URL etc. I have access to this information in automation rules that trigger on "Pull request created", but I don't know how to get to this information when using another trigger.

I tried looking at {{issue.development}} but there doesn't seem to be any relevant information (just a count, really).

Is there a smart value that gives me the info I need?

Is there some REST API call or GraphQL call I can make to get that information?

 

Thanks

1 answer

0 votes
Mitch Talmadge September 23, 2024

I don't know if you're still working on this, but I found it via Google search, so I figured I'd share what I found. Looks like you can get PRs from this hidden API, which I discovered here: https://community.atlassian.com/t5/Jira-questions/Re-JIRA-REST-API-to-get-list-of-branches-related-to-a-issue/qaq-p/800424/comment-id/258033#M258033

https://YOURSITE.atlassian.net/rest/dev-status/1.0/issue/details?issueId=YOURISSUEID&applicationType=github&dataType=pullrequest

Note that the issue ID is not the same as the issue key. It's an internal number like 12345, not like AB-123. 

In an automation you can get the ID with {{issue.id}}:

image.png

So then you can use the automation's "send web request" action, and smart branching, to emit the PR URLs.

Here's how I did it successfully:

image.png

 

Some things to consider:

1. That API is unsupported and may change randomly

2. The API seems to return multiple GitHub data sources in the "detail" array. In my case, 4 sources are returned and only 2 of them have links to the PRs. I don't know why there are 4 sources. For me the first data source always seems to have the PRs, but if another source came first in the array, it's possible this automation would break. I wonder if there are more query parameters that could be used to filter the data sources.

3. The "send web request" action will require authentication. I made an API key in my user profile under the Security tab. Then I mashed it together with my email like follows:

my@email.com:APIKEYHERE

Then I used a base64 encoder to turn that into one base64 encoded string. In the web request, I made an "Authorization" header with this value:

Basic BASE64STRINGHERE

 

Nick de Palézieux
Contributor
September 25, 2024

Thanks for your answer!

I actually successfully implemented a set of automations that trigger on Jira issue changes and on PR created that then use various web request actions to fetch PR info and "Request changes" on PRs as a bot account.

I wasn't aware of the API you are referring to. Instead I use the GraphQL API that the Development panel on the Jira issue uses to list the PRs related to the issue.

Screenshot 2024-09-25 at 16.38.36.png

The system works ok for what it's supposed to do at the moment but it's hard to maintain since it involves several interconnected code-heavy (graphql queries in a web request action, request response string parsing etc) automations in a "no-code tool".

So I'm looking for a solution that would make this a) more maintainable and readable and b) more extensible (i.e. to add further conditions on when a PR can be merged), I have a related question here.

Like Mitch Talmadge likes this
Mitch Talmadge September 25, 2024

Oh wow I didn't realize that the internal development panel used GraphQL! What you've done there is very cool. I bet it was hard; I often wish Atlassian provided some kind of JavaScript or Python automation environment for power users, but I understand why they don't.

Thank you for the update!!

Nick de Palézieux
Contributor
September 26, 2024

Yes, it was rather painful to implement.

I guess forge is the power user tool that they provide. I have not been able to spend too much time on learning that. The given examples are quite simple but if you want to do stuff across Jira and Bitbucket, I haven't found any examples.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events