Skip to content

Instantly share code, notes, and snippets.

@Kludex
Created March 10, 2022 08:43
Show Gist options
  • Save Kludex/b4a93523ea067ed72e24c740f3ac2527 to your computer and use it in GitHub Desktop.
Save Kludex/b4a93523ea067ed72e24c740f3ac2527 to your computer and use it in GitHub Desktop.
Script that adds "[A-B] " as prefix, considering a branch called "A-B-other-stuff"
#!/usr/bin/env python3
import subprocess
import sys
branch_name = subprocess.check_output("git rev-parse --abbrev-ref HEAD".split()).decode().strip()
jira_ticket = "-".join(branch_name.split("-")[:2])
commit_msg = f"[{jira_ticket}] {sys.argv[1]}"
sys.argv[1] = commit_msg
gcmsg_args = sys.argv[1:]
subprocess.run(["git", "commit", "-m", *gcmsg_args])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment