File tree Expand file tree Collapse file tree 1 file changed +16
-26
lines changed Expand file tree Collapse file tree 1 file changed +16
-26
lines changed Original file line number Diff line number Diff line change 1
- #! /usr/bin/env bash
1
+ #! /bin/bash
2
+ #
3
+ # check commit messages for JIRA issue numbers formatted as [JIRA-<issue number>]
2
4
3
- zero_commit= " 0000000000000000000000000000000000000000 "
5
+ REGEX= " \[JIRA\-[0-9]*\] "
4
6
5
- read oldrev newrev refname
6
- echo $oldrev $newrev $refname
7
+ ERROR_MSG=" [POLICY] The commit doesn't reference a JIRA issue"
7
8
8
- check_message_format ()
9
- # enforced custom commit message format
10
- {
11
- message=` git cat-file commit $newrev | sed ' 1,/^$/d' `
12
- regex=" /*\[jira-.*\]"
13
- echo " [COMMIT MESSAGE]:" $message
14
- if [[ $message =~ $regex ]];
15
- then
16
- echo " Commit message looks good!"
17
- exit 0
18
- else
19
- echo " [POLICY] Commit message does not contain a JIRA ticket #"
20
- exit 1
21
-
22
- fi
23
- }
24
-
25
- if [ " $newrev " = " $zero_commit " ]; then
26
- continue
27
- else
28
- check_message_format
29
- fi
9
+ while read OLDREV NEWREV REFNAME ; do
10
+ for COMMIT in ` git rev-list $OLDREV ..$NEWREV ` ;
11
+ do
12
+ MESSAGE=` git cat-file commit $COMMIT | sed ' 1,/^$/d' `
13
+ if ! echo $MESSAGE | grep -iqE " $REGEX " ; then
14
+ echo " $ERROR_MSG : $MESSAGE " >&2
15
+ exit 1
16
+ fi
17
+ done
18
+ done
19
+ exit 0
You can’t perform that action at this time.
0 commit comments