I have connected github & jira, so when I push my commit with a prefix in a style "ISSUEID-ISSUENYMBER any text after" I can see that commits / branches / PR's at the issue page.
But I have a small application, which gathers information about released deployments which gives a notification in a slack channel about that. And that app gathers information about commit's author, repo, and jira related issue.
I have not much input data which are workflow_run_id, commit sha and workflow run url, so I'm looking for an option
> to retrieve jira issue by jira api using only commit sha
Is there such option?
Hi Orkhan,
If I understand correctly, you have a commit hash from github that you want to be able to use in order to find the issuekey of a Jira issue referenced inside that commit. While Jira can be integrated with github, Jira Cloud's documented REST API endpoints do not provide an endpoint that can search by a commit hash at all.
There was a past feature request seeking this information over in https://jira.atlassian.com/browse/JSWCLOUD-14496 but this was closed as a "Won't do".
That said, I think I found way that you could configure Jira Cloud to keep and track that information in a way that is searchable from the REST API in Jira going forward. You can create a new automation rule that captures that commit hash into a custom field or labels field on that Jira issue.
In my example, my automation rule looks like this:
With a trigger of "Commit created" and then an action of "Edit issue", you can configure edit issue to set the Labels field to add the smart value of {{commit.hash}}. I choose the labels field because it can contain multiple values. And I had to configure this rule to use the Add/Remove. By default if you just use the Set action, it would overwrite any existing labels, which we probably don't want to do that here.
But with that automation rule set, any new commits that are created to reference that Jira issuekey will now include that commit hash into the labels field. Once that is done you can then do a JQL search for that label to return any issues that have it.
For example, I tested this and I found it did work to create a label of that hash of
labels = "423ce64eafbf8b5aea2a98b1aa12970e420e2522"
You could then make a REST API search on the endpoint of GET /rest/api/3/search and specifically search for that label. This of course could potentially return more than one issue, but I'd expect that it at least will give you the Jira issue details you are looking for here.
This kind of configuration might help, but it does have some caveats. For example, this won't help you for past commits, only for commits created after the automation rule exists. Also when you create an automation rule in Jira, there is a matter of deciding if this should be a project rule or a global rule. Certainly creating a global rule could be more useful if you need this to happen across projects, but global rules have monthly execution limits, whereas project level rules do not.
Try this, and let me know if you have any questions or concerns about this approach.
Andy
Thanks! I've already did it by automation rules, but thanks for confirming.
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.