Skip to content
This repository was archived by the owner on Mar 18, 2021. It is now read-only.

Commit 2b189d9

Browse files
qboileaumsidhoum
authored and
msidhoum
committedNov 16, 2015
chore(*): embed constellation git hooks to project source
1 parent 0263e9d commit 2b189d9

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed
 

‎README.md

+10
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,13 @@ SMTP server configuration (used to re-initialized user password) :
103103
* **cstl.mail.smtp.username** : Default value `no-reply@localhost`
104104
* **cstl.mail.smtp.password** : Default value `mypassword`
105105
* **cstl.mail.smtp.ssl** : Default value `false`
106+
107+
## Contribute
108+
109+
### Activate Git hooks
110+
Constellation use Git hooks to standardize commits message format.
111+
112+
```shell
113+
rm .git/hooks/commit-msg
114+
ln -s githook/* .git/hooks/
115+
```

‎githook/commit-msg

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/usr/bin/env python
2+
"""
3+
Git commit hook:
4+
.git/hooks/commit-msg
5+
6+
Check commit message according to angularjs guidelines:
7+
* https://docs.google.com/document/d/1QrDFcIiPjSLDn3EL15IJygNPiHORgU1_OOAqWjiDU5Y/edit#
8+
9+
Check commit scope according to geomatys internal guidelines:
10+
* https://docs.google.com/a/geomatys.com/spreadsheets/d/1hGwogTSwlmMmIgDsDbAFyBDC9G5xixcMAIRbn9A9TtM/edit#
11+
12+
"""
13+
14+
import sys
15+
import re
16+
17+
valid_commit_types = ['feat', 'fix', 'docs', 'style', 'refactor', 'perf', 'test', 'chore']
18+
valid_scope_types = ['Admin', 'Client', 'SDI', 'Services', 'Database', 'Token', 'Engine', 'Gui Swing', 'JSON Binding', 'Library', 'Storage', 'Testing', 'WS', 'XML Binding', 'Docker', '*']
19+
commit_file = sys.argv[1]
20+
help_address = 'https://docs.google.com/document/d/1QrDFcIiPjSLDn3EL15IJygNPiHORgU1_OOAqWjiDU5Y/edit#'
21+
help_scopes = 'https://docs.google.com/a/geomatys.com/spreadsheets/d/1hGwogTSwlmMmIgDsDbAFyBDC9G5xixcMAIRbn9A9TtM/edit#'
22+
23+
with open(commit_file) as commit:
24+
lines = commit.readlines()
25+
if len(lines) == 0:
26+
sys.stderr.write("\nEmpty commit message\n")
27+
sys.stderr.write("\n - Refer commit guide: %s\n\n" % help_address)
28+
sys.exit(1)
29+
30+
# first line
31+
line = lines[0]
32+
m = re.search('^(.*)\((.*)\): (.*)$', line)
33+
34+
if not m or len(m.groups()) != 3:
35+
sys.stderr.write("\nFirst commit message line (header) does not follow format: type(scope): message\n")
36+
sys.stderr.write("\n - Refer commit guide: %s\n\n" % help_address)
37+
sys.exit(1)
38+
commit_type, commit_scope, commit_message = m.groups()
39+
if commit_type not in valid_commit_types:
40+
sys.stderr.write("\nCommit type not in valid ones: %s\n" % ", ".join(valid_commit_types))
41+
sys.stderr.write("\n - Refer commit guide: %s\n\n" % help_address)
42+
sys.exit(1)
43+
if commit_scope not in valid_scope_types:
44+
sys.stderr.write("\nCommit scope not in valid ones: %s\n" % ", ".join(valid_scope_types))
45+
sys.stderr.write("\n - Refer scope guide: %s\n\n" % help_scopes)
46+
sys.exit(1)
47+
48+
49+
if len(lines) > 1 and lines[1].strip():
50+
sys.stderr.write("\nSecond commit message line must be empty\n")
51+
sys.stderr.write("\n - Refer commit guide: %s\n\n" % help_address)
52+
sys.exit(1)
53+
54+
if len(lines) > 2 and not lines[2].strip():
55+
sys.stderr.write("\nThird commit message line (body) must not be empty\n")
56+
sys.stderr.write("\n - Refer commit guide: %s\n\n" % help_address)
57+
sys.exit(1)
58+
59+
sys.exit(0)

0 commit comments

Comments
 (0)