Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to get issue ID by commit hash?

Orkhan Mamedov
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 24, 2021

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?

1 answer

1 accepted

2 votes
Answer accepted
Andy Heinzer
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 25, 2021

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:

Screen Shot 2021-08-25 at 2.31.39 PM.png

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

Orkhan Mamedov
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 26, 2021

Thanks! I've already did it by automation rules, but thanks for confirming.

Suggest an answer

Log in or Sign up to answer