forked from mbmccormick/gitosis-webhook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
post-receive
78 lines (66 loc) · 2.03 KB
/
post-receive
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
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/bin/sh
# webhook post_url: this URL is hit with a POST request when you push
post_url="http://www.postbin.org/q3dil8"
repo_url="http://server"
commit_url="http://server/commit/"
repo_name="reponame"
repo_owner_name="Owner name"
repo_owner_email="name@domain.com"
repo_desc="Description of the repo"
read oldrev newrev refname
refname=${refname##refs/heads/}
gitver=$(git --version)
gitver=${gitver##* }
rev=$(git describe ${newrev} 2>/dev/null)
[[ -z ${rev} ]] && rev=${newrev:0:12}
rawcommit=$(git cat-file commit ${newrev})
author=$(sed -n -e '/^author \([^<]*\).*$/s--\1-p' \
<<< "${rawcommit}")
author=$(echo ${author} | sed -e 's/[ ]*$//')
email=$(sed -n -e '/^author .*<\([^>]*\).*$/s--\1-p' \
<<< "${rawcommit}")
logmessage=$(sed -e '1,/^$/d' <<< "${rawcommit}")
logmessage=${logmessage//&/&}
logmessage=${logmessage//</<}
logmessage=${logmessage//>/>}
ts=$(sed -n -e '/^author .*> \([0-9]\+\).*$/s--\1-p' \
<<< "${rawcommit}")
out="
{
\"after\": \"${newrev}\",
\"before\": \"${oldrev}\",
\"commits\": [
{
\"added\": [
$(git diff-tree -r --name-only --diff-filter=A ${newrev} | sed -e '1d' -e 's-.*- \"&\",-' | sed -e '$s/,//')
],
\"author\": {
\"email\": \"${email}\",
\"name\": \"${author}\"
},
\"id\": \"${rev}\",
\"message\": \"${logmessage}\",
\"modified\": [
$(git diff-tree -r --name-only --diff-filter=M ${newrev} | sed -e '1d' -e 's-.*- \"&\",-' | sed -e '$s/,//')
],
\"removed\": [
$(git diff-tree -r --name-only --diff-filter=D ${newrev} | sed -e '1d' -e 's-.*- \"&\",-' | sed -e '$s/,//')
],
\"timestamp\": \"${ts}\",
\"url\": \"${commit_url}${newrev}\"
}
],
\"ref\": \"${refname}\",
\"repository\":
{
\"url\": \"${repo_url}\",
\"name\": \"${repo_name}\",
\"description\": \"${repo_desc}\",
\"owner\":
{
\"name\": \"${repo_owner_name}\",
\"email\": \"${repo_owner_email}\"
}
}
}"
wget --post-data "payload=${out}" ${post_url} --quiet -o /dev/null