Skip to content

Commit d63cef4

Browse files
author
Ricardo M
committed
bugfix/APM-123456 test commit
1 parent 0af9266 commit d63cef4

File tree

2 files changed

+27
-11
lines changed

2 files changed

+27
-11
lines changed

commit-msg.py

+27-11
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,37 @@
11
#!/usr/bin/env python3
22
import sys
3+
import re
34
import platform
45
import subprocess
56

67
clear_screen_command = 'cls' if platform.system() == 'Windows' else 'clear'
7-
subprocess.call(clear_screen_command)
8+
# subprocess.call(clear_screen_command)
89

9-
# Checking for not staged files, if there's files pending, exit the script
10-
git_command = ['git', '--no-pager', 'status', '-s']
11-
execute = subprocess.run(git_command, stdout=subprocess.PIPE)
12-
modified_files = execute.stdout \
13-
.decode('utf-8') \
14-
.split('\n')
15-
modified_files = [ file[3:] for file in modified_files if file ]
10+
# Receive the filename with the temporary git commit msg.
11+
msg_file = sys.argv[1]
1612

17-
print(modified_files)
13+
msg_filehandle = open(msg_file)
14+
with msg_filehandle as f:
15+
commit_msg_parts = f.readlines()
16+
commit_msg = ''.join(commit_msg_parts)
1817

19-
if len(modified_files):
20-
print('Files have been found in the work area, please stash or commit them first and run this command again.\n')
18+
if not commit_msg:
2119
sys.exit(1)
20+
else:
21+
execute = subprocess.run(['git', 'branch'], stdout=subprocess.PIPE)
22+
branch_list = execute.stdout \
23+
.decode('utf-8') \
24+
25+
# Extract issue part from active branch for branch list
26+
# * bugfix/APM-123456-test-branch-for-commit-msg
27+
# ^^^^^^^^^^^^^^^^^
28+
# master
29+
regex = re.compile(r'(?<=\*\s).+APM-[0-9]*', re.MULTILINE)
30+
issue_id = ''.join(re.findall(regex, branch_list))
31+
32+
msg_filehandle = open(msg_file, 'w')
33+
with msg_filehandle as f:
34+
complete_commit_msg = '{} {}'.format(issue_id, commit_msg).strip()
35+
f.write(complete_commit_msg)
36+
37+
sys.exit(0)

sample-file

Whitespace-only changes.

0 commit comments

Comments
 (0)