- Make the script executable:
chmod +x jira-prepare-commit-msg.py
- Copy or symlink it to the repository hooks directory:
cp jira-prepare-commit-msg.py /path/to/repo/.git/hooks/prepare-commit-msg
or to the global hooks directory:cp jira-prepare-commit-msg.py ~/.config/git/hooks/prepare-commit-msg
. - Specify the URL of your Jira server, your username and API token. Make sure HTTPS is used when possible, since the username and the token are sent unencrypted by means of Basic HTTP authentication.
In order to be correctly processed, the git branch should have the same name as the Jira issue number (e.g. JPA-71). The branches which have different name format are ignored.
Just type git commit
, and automatically generated message will appear in the text editor of your choise:
morozov@viola:~/Projects/test (JPA-71)
↪ git commit
Retrieving JPA-71 summary from Jira...
---------------------------------------8<---------------------------------------
JPA-71: Criteria query: casting joined polymorphic entity
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
# On branch JPA-71
# Your branch is ahead of 'origin/JPA-71' by 1 commit.
# (use "git push" to publish your local commits)
#
# Changes to be committed:
# new file: test.txt
#
"~/Projects/test/.git/COMMIT_EDITMSG" 11L, 353C 1,1 All