Don't forget the Jira tag in your git message

Posted by Marcus Folkesson on Thursday, January 9, 2025

Don't forget the Jira tag in your git message

I keep forgetting to add the Jira tag in my git messages. This is a problem as we use Jira for our project management and the Jira tag is used to link the commit to the issue. It is simply hard to get into my workflow for some reason.

Some time ago, I wrote about pre-commit [1], a framework for managing and maintaining pre-commit hooks for git. By running hooks before any commit, many small pitfalls could be avoided - such as a missing Jira: tag!

Add a hook for checking Jira tag

pygrep is a simple tool that can be used to check if a string is present. We can use this to check if the Jira tag is present in the commit message with the following configuration:

 1#.pre-commit-config.yaml
 2repos:
 3-   repo: local
 4    hooks:
 5    -   id: needs-jira
 6        name: commit message needs "Jira:"
 7        language: pygrep
 8        entry: '^Jira:'
 9        args: [--multiline, --negate]
10        stages: [commit-msg]

Then there is only to install the hook:

1pre-commit install --hook-type commit-msg

Now, if we try to commit without the Jira tag, we get an error message and the commit is aborted:

/media/needs-jira-tag.png

That will stop me from forgetting the Jira tag in the future.