How to get the issue key into the commit message automatically?
Asked by Intel CHD Jira Admin:

We're using the feature branch workflow with JIRA and Stash. Creating the branch from JIRA works perfectly, but when I commit on the branch I expect the commit message to be prefilled with the issue key automatically. If I commit without the key in the message the changeset won't show up Jira. But the commit message is empty, forcing me to go back to JIRA and copy and paste the key before committing - a waste of time. What am I doing wrong?

-David


Answers:
author: Jobin Kuruvilla [Adaptavist]
body: The commit message is entered on the client side and there is no way to populate it from Stash, unless you do some scripting on your git client.

At best, you can prevent pushes to Stash without having a proper issue key in the commit message. [Yet Another Commit Checker](https://marketplace.atlassian.com/plugins/com.isroot.stash.plugin.yacc) worked well for me to validate the issue keys.

comments: author: Intel CHD Jira Admin
body: Thanks for the tip! I have to say I do find it disappointing that ST can't figure out that the user is working on a feature and extract the issue key and prefill it in the commit message. It's not rocket science, and after all Atlassian controls every part of the solution: Jira, Stash and SourceTree;). Atlassian goes to so much trouble to connect things and save the developer time and then they ignore this low hanging fruit and force him to switch tools just to get the issue key into the commit message. Doesn't make sense.Another more general approach would be a configuration option that uses a regular expression and whatever matches that expression in the current branch name is extracted and placed in the commit message. -David


author: Jobin Kuruvilla [Adaptavist]
body: I like the regular expression check on ST. For now, ST is developed as a generic tool for any git solutions, not just for Stash, and that is probably why they do not have any hard coded rules. Any solution, should be a configurable one so that it can continue to work with other git servers like GitHub.


author: Intel CHD Jira Admin
body: So I have made a feature request: <https://jira.atlassian.com/browse/SRCTREEWIN-3261>.


author: Intel CHD Jira Admin
body: Hey Jobin, the solution is independent of the repo hosting solution and in fact all the information is present on the client side in a generic way. The branch name contains the Jira issue key, or more generally, some string matching a regular expression. That doesn't depend on Stash, Github, Foohub or Barhub. The rule is extract whatever matches that and put it in the commit message, as the default content. The solution that is hardcoded to a Jira issue key is also independent of the repo hosting solution, though it is of course hardcoded to the syntax of Jira issue keys.-David


author: Intel CHD Jira Admin
body: Jobin, I have reworked the ST issue to specify the generic solution. Feel free to comment or vote: <https://jira.atlassian.com/browse/SRCTREEWIN-3261>.-David


author: Timothy
body: > But the commit message is empty

You mean that after **committing with a commit message** **and pushing to Stash**, the message is not there?

comments: author: Intel CHD Jira Admin
body: No. I mean when I am making the commit in ST, the commit message is not prefilled with the issue key. I have to manually go back to Jira and copy and paste it, or manually type it. A waste of time. ST can see I am working on a branch with an issue key. To make the workflow easily to execute it could just stick that into the commit message (before I commit of course - I might want to delete it - that should be up to the user). ST already knows about pull requests in Stash, so it's no big leap to say it should know about the feature branch workflow and provide some help.


Tags: bitbucket

jira