-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate
65 lines (55 loc) · 1.49 KB
/
update
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/bin/bash
refname="$1"
oldrev="$2"
newrev="$3"
regex="^(refs|fixes) #[0-9]+: [A-Z0-9].+"
merge_message="Merge branch 'master' of"
redmine_host=""
redmine_apikey=""
function info {
echo >&2 $1
}
function debug {
debug=false
if $debug
then
echo >&2 $1
fi
}
function get_json {
python -c "import sys;import json;j=json.loads(sys.stdin.read());print str(j$1);"
}
function redmine_json {
curl --silent -k -H "Content-Type: application/json" -X GET -H "X-Redmine-API-Key: $redmine_apikey" "$redmine_host/$1"
}
# Make sure we handle the situation when the branch does not exist yet
if ! [ "$oldrev" = "0000000000000000000000000000000000000000" ] ; then
excludes=( ^$oldrev )
else
excludes=( $(git for-each-ref --format '^%(refname:short)' refs/heads/) )
fi
# Get the list of incomming commits
commits=`git rev-list $newrev "${excludes[@]}"`
# For every commit in the list
for commit in $commits
do
# Check the log message for ticket number
message=`git log --format=%s -1 $commit`
if [[ "$message" =~ $regex ]] || [[ "$message" == $merge_message* ]] ;
then
debug "Commit message: OK"
else
# Define format message for first line in commit message
info "Commit needs to be \"[refs|fix] #ID: Message, but was $message\""
exit 1
fi
issue_id=`echo $var | sed 's/\(refs\|fix\)\ \#\([0-9]*\).*/\2/'`
issue=`redmine_json "issues/$issue_id\.json"`
if [[ "$issue" != " " ]]
then
debug "Issue exist: OK"
else
info "Issue $issue_id don't exist"
exit 2;
fi
done