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
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}}:
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:
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
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.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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!!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.