Compare commits
2 Commits
120aa062c4
...
029abb8fb6
| Author | SHA1 | Date | |
|---|---|---|---|
| 029abb8fb6 | |||
| 0dd6fdb4fb |
20
README.md
20
README.md
@ -26,6 +26,26 @@ Date: Fri Sep 1 09:57:54 2023 +0200
|
|||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Branch CI/CD prefix such as `feature/` will be handled correctly. If current branch is `feature/CLOUD-12345-some-important-branch` and we add commit:
|
||||||
|
|
||||||
|
```
|
||||||
|
git commit -m "some important message"
|
||||||
|
```
|
||||||
|
|
||||||
|
resulting commit message will be:
|
||||||
|
|
||||||
|
```
|
||||||
|
git log
|
||||||
|
commit 963dca96dd658a7df590c8b27b45d7f7536f9c1d (HEAD -> feature/CLOUD-12345-some-important-branch)
|
||||||
|
Author: Eden Kirin <eden@ekirin.com>
|
||||||
|
Date: Fri Sep 1 09:57:54 2023 +0200
|
||||||
|
|
||||||
|
CLOUD-12345: some important message
|
||||||
|
|
||||||
|
https://smartvending.atlassian.net/browse/CLOUD-12345
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
1. Clone repository
|
1. Clone repository
|
||||||
|
|||||||
@ -11,30 +11,39 @@ 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)
|
||||||
|
|
||||||
commit_file = sys.argv[1]
|
|
||||||
regex = re.compile("^([A-Z]+-[0-9]+)", re.IGNORECASE)
|
|
||||||
|
|
||||||
git_branch_name = subprocess.run(
|
def main():
|
||||||
["git", "branch", "--show-current"],
|
commit_file = sys.argv[1]
|
||||||
stdout=subprocess.PIPE,
|
|
||||||
encoding="utf-8",
|
|
||||||
)
|
|
||||||
|
|
||||||
match = regex.match(git_branch_name.stdout)
|
git_branch_name = subprocess.run(
|
||||||
|
["git", "branch", "--show-current"],
|
||||||
|
stdout=subprocess.PIPE,
|
||||||
|
encoding="utf-8",
|
||||||
|
)
|
||||||
|
|
||||||
if match:
|
match = REGEX.match(git_branch_name.stdout)
|
||||||
ticket = match.group()
|
|
||||||
ticket_url = f"{JIRA_ISSUE_URL}{ticket}"
|
|
||||||
|
|
||||||
with open(commit_file, "r+") as f:
|
if match:
|
||||||
contents = f.read().strip()
|
try:
|
||||||
|
ticket = match.group(2)
|
||||||
|
except IndexError:
|
||||||
|
return
|
||||||
|
ticket_url = f"{JIRA_ISSUE_URL}{ticket}"
|
||||||
|
|
||||||
if PREPEND_TICKET and not contents.startswith(ticket):
|
with open(commit_file, "r+") as f:
|
||||||
contents = f"{ticket}: {contents}"
|
contents = f.read().strip()
|
||||||
|
|
||||||
if APPEND_ISSUE_LINK:
|
if PREPEND_TICKET and not contents.startswith(ticket):
|
||||||
contents = f"{contents}\n\n{ticket_url}"
|
contents = f"{ticket}: {contents}"
|
||||||
|
|
||||||
f.seek(0)
|
if APPEND_ISSUE_LINK:
|
||||||
f.write(contents)
|
contents = f"{contents}\n\n{ticket_url}"
|
||||||
|
|
||||||
|
f.seek(0)
|
||||||
|
f.write(contents)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
|||||||
Reference in New Issue
Block a user