Accept XXXX-nnn and yyyy/XXXX-nnn branch names
This commit is contained in:
@ -11,9 +11,11 @@ import re, subprocess, sys
|
|||||||
JIRA_ISSUE_URL = "https://smartvending.atlassian.net/browse/"
|
JIRA_ISSUE_URL = "https://smartvending.atlassian.net/browse/"
|
||||||
PREPEND_TICKET = True
|
PREPEND_TICKET = True
|
||||||
APPEND_ISSUE_LINK = True
|
APPEND_ISSUE_LINK = True
|
||||||
|
REGEX = re.compile("^(.*/)?([A-Z]+-[0-9]+)", re.IGNORECASE)
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
commit_file = sys.argv[1]
|
commit_file = sys.argv[1]
|
||||||
regex = re.compile("^([A-Z]+-[0-9]+)", re.IGNORECASE)
|
|
||||||
|
|
||||||
git_branch_name = subprocess.run(
|
git_branch_name = subprocess.run(
|
||||||
["git", "branch", "--show-current"],
|
["git", "branch", "--show-current"],
|
||||||
@ -21,10 +23,13 @@ git_branch_name = subprocess.run(
|
|||||||
encoding="utf-8",
|
encoding="utf-8",
|
||||||
)
|
)
|
||||||
|
|
||||||
match = regex.match(git_branch_name.stdout)
|
match = REGEX.match(git_branch_name.stdout)
|
||||||
|
|
||||||
if match:
|
if match:
|
||||||
ticket = match.group()
|
try:
|
||||||
|
ticket = match.group(2)
|
||||||
|
except IndexError:
|
||||||
|
return
|
||||||
ticket_url = f"{JIRA_ISSUE_URL}{ticket}"
|
ticket_url = f"{JIRA_ISSUE_URL}{ticket}"
|
||||||
|
|
||||||
with open(commit_file, "r+") as f:
|
with open(commit_file, "r+") as f:
|
||||||
@ -38,3 +43,7 @@ if match:
|
|||||||
|
|
||||||
f.seek(0)
|
f.seek(0)
|
||||||
f.write(contents)
|
f.write(contents)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
|||||||
Reference in New Issue
Block a user