- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommit-msg.py
More file actions
Latest commit
37 lines (30 loc) · 1.06 KB
/
Copy pathcommit-msg.py
File metadata and controls
37 lines (30 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env python3
importsys
importre
importplatform
importsubprocess
clear_screen_command='cls'ifplatform.system() =='Windows'else'clear'
# subprocess.call(clear_screen_command)
# Receive the filename with the temporary git commit msg.
msg_file=sys.argv[1]
msg_filehandle=open(msg_file)
withmsg_filehandleasf:
commit_msg_parts=f.readlines()
commit_msg=''.join(commit_msg_parts)
ifnotcommit_msg:
sys.exit(1)
else:
execute=subprocess.run(['git', 'branch'], stdout=subprocess.PIPE)
branch_list=execute.stdout \
.decode('utf-8') \
# Extract issue part from active branch for branch list
# * bugfix/APM-123456-test-branch-for-commit-msg
# ^^^^^^^^^^^^^^^^^
# master
regex=re.compile(r'(?<=\*\s).+APM-[0-9]*', re.MULTILINE)
issue_id=''.join(re.findall(regex, branch_list))
msg_filehandle=open(msg_file, 'w')
withmsg_filehandleasf:
complete_commit_msg='{} {}'.format(issue_id, commit_msg).strip()
f.write(complete_commit_msg)
sys.exit(0)