Skip to content

H-Rusch/JiraIssueCommitHook

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Jira Issue Commit Hook

Integration Tests

This script can be used as a Git Hook to automatically prefix commit messages with the branches associated Jira issue.

Examples

Branch Name Commit Message Result Description
feature/ABC-123-branchname Message ABC-123: Message Prefix the commit message with the Jira issue key based on the branch name
feature/ABC-123/branchname ABC-234: Message ABC-234: Message Commit message will not be prefixed if a issue key is found
@1c50bb7f rebase-i 2/3 Message Message No action will be taken when not on a valid branch (i.e. while rebasing)
branchname Message Message No action will be taken when no Jira issue key is found

Configuration

By default the commit messages are prefixed with the Jira key followed by a hyphen ABC-123: ... as shown in the examples above.

This format can be specified by providing the environment variable COMMIT_MESSAGE_FORMAT by giving a formatting string using {{key}} and {{message}} as placeholders for the key and message respectively.

Example:

for Branch feauture/ABC-123-branch and message Message

export COMMIT_MESSAGE_FORMAT="[{{key}}] -> {{message}}"

Results in:

[ABC-123] -> Some Message

Prerequisites

  • Python 3.x: Make sure Python 3 is installed on your machine.
  • Git: You need Git installed and configured.

Installation

  1. Download the Script: Place the commit-msg script into the .git/hooks/ directory of your local repository.

    • Alternatively, if you want to automatically apply this hook to all newly cloned repositories, you can set up a Git template directory and place the commit-msg script in the hooks folder of your template. This will ensure the hook is included in all new repositories initialized with git init.
  2. Make the Script Executable:

    chmod +x .git/hooks/commit-msg
  3. Ensure Correct Python Path: Verify that the first line of the commit-msg script points to a valid Python 3 installation.

Usage

Once installed, the hook will automatically run each time you create a commit. The script scans the branch name for a Jira issue key (e.g., ABC-123) and prefixes it to the commit message, if not already present.

Uninstallation

To uninstall the commit hook:

rm .git/hooks/commit-msg

Tests

Integration tests are implemented to verify the behavior of this script using cucumber-rs. Tests are written inside the integration-tests directory.

License

This project is licensed under the MIT License.

About

commit-msg Git Hook to prefix the commit messages with the Jira key automatically

Topics

Resources

License

Stars

Watchers

Forks

Contributors