Last active
September 21, 2025 22:36
-
-
Save Fawers/f238690fa7e6aea9b2401eece4e96e8c to your computer and use it in GitHub Desktop.
include jira ticket in commit message
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/python | |
| import re | |
| import subprocess | |
| import sys | |
| jira_pattern = re.compile(r"[A-Z0-9]+-\d+") | |
| commit_msg_filename = sys.argv[1] | |
| with open(commit_msg_filename) as f: | |
| commit_msg = f.read() | |
| if commit_msg.startswith('Merge branch'): | |
| print("commit-msg: ignoring merge commit", file=sys.stderr) | |
| exit() | |
| current_branch = subprocess.getoutput("git branch --show-current") | |
| jira_branch = (jira_match := jira_pattern.match(current_branch)) and jira_match[0] | |
| if jira_branch and not commit_msg.startswith(jira_branch): | |
| if jira_match := jira_pattern.match(commit_msg): | |
| print(f"commit-msg: ignoring message matching {jira_match[0]}", file=sys.stderr) | |
| exit() | |
| commit_msg = f"{jira_branch}: {commit_msg}" | |
| with open(commit_msg_filename, 'w') as f: | |
| f.write(commit_msg) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment