-
Notifications
You must be signed in to change notification settings - Fork 20
/
check_commit_msg.py
45 lines (36 loc) · 1.47 KB
/
check_commit_msg.py
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
38
39
40
41
42
43
44
45
#!/bin/python
import os
import requests
commit_msg = str(os.environ['TRAVIS_COMMIT_MSG'])
tendrl_bug_id = None
tendrl_spec = None
github_base_url = "http://github.com"
# Extract "tendrl-bug-id" and "tendrl-spec" name from the commit message
for line in commit_msg.split("\n"):
if "tendrl-bug-id" in line:
try:
tendrl_bug_id = line.split("tendrl-bug-id:")[-1].strip()
except Exception as ex:
print(ex)
if "tendrl-spec" in line:
try:
tendrl_spec = line.split("tendrl-spec:")[-1].strip()
except Exception as ex:
print(ex)
if tendrl_bug_id is None:
raise Exception("Please add 'tendrl-bug-id:Tendrl/<tendrl_repo>#issue_id'"
" to your commit msg")
if tendrl_bug_id:
issue = "%s/%s" % (github_base_url, tendrl_bug_id.replace("#", "/issues/"))
if requests.get(issue).status_code != 200:
raise Exception("Tendrl Bug specified in git commit msg not "
"found!!\n"
"%s" % issue)
print("Tendrl Bug specified in git commit msg found!!\n%s" % issue)
if tendrl_spec:
spec = "%s/%s.adoc" % ("https://github.com/Tendrl/specifications/tree"
"/master/specs", tendrl_spec)
if requests.get(spec).status_code != 200:
raise Exception("Tendrl Spec specified in git commit msg not found\n"
"%s" % spec)
print("Tendrl Spec specified in git commit msg found!!\n%s" % spec)