forked from eirc/git-hipchat-hook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hipchat-post-receive
executable file
·77 lines (70 loc) · 2.58 KB
/
hipchat-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
#!/bin/sh
# Read variables passed on by GIT
read OLDREV NEWREV REFNAME
# Find out basic variables
GIT_EXEC=${GIT_EXEC:-`which git`}
REPO=${REPO:-`basename $PWD`}
HIPCHAT_COLOR=${HIPCHAT_COLOR:-"yellow"}
# User is commiter of either last or first commit
NULLREV="0000000000000000000000000000000000000000"
[ "$NEWREV" = "$NULLREV" ] && USER_REV="$OLDREV" || USER_REV="$NEWREV"
USER=`$GIT_EXEC log -1 $USER_REV --format="%aN"`
BRANCH=${REFNAME#refs/heads/}
# Setup gitweb links
if [ -n "$GITWEB" ]
then
USER_LINK="<a href=\"http://$GITWEB/?p=$REPO;a=search;s=$USER;st=author\">$USER</a>"
BRANCH_LINK="<a href=\"http://$GITWEB/?p=$REPO;a=shortlog;h=$REFNAME\">$BRANCH</a>"
REPO_LINK="<a href=\"http://$GITWEB/?p=$REPO;a=summary\">$REPO</a>"
elif [ -n "$CGIT" ]
then
USER_LINK=$USER
BRANCH_LINK="<a href=\"http://$CGIT/$REPO/log/?h=$REFNAME\">$BRANCH</a>"
REPO_LINK="<a href=\"http://$CGIT/$REPO/\">$REPO</a>"
else
USER_LINK=$USER
BRANCH_LINK=$BRANCH
REPO_LINK=$REPO
fi
# Construct gitorious links
if [ -n "$GITORIOUS" ]
then
REPO_NO_GIT=`echo -e $REPO|sed "s/.git//g"`
USER_LINK="<a href=\"https://$GITORIOUS/~$USER\">$USER</a>"
REPO_LINK="<a href=\"https://$GITORIOUS/$GIT_PROJECT/$REPO_NO_GIT\">$REPO</a>"
BRANCH_LINK="<a href=\"https://$GITORIOUS/$GIT_PROJECT/$REPO_NO_GIT/commits/$BRANCH\">$BRANCH</a>"
fi
# Construct message
if [ "$OLDREV" = "$NULLREV" ]
then
MSG="$USER_LINK created branch $BRANCH_LINK of $REPO_LINK"
HIPCHAT_COLOR="green"
elif [ "$NEWREV" = "$NULLREV" ]
then
MSG="$USER_LINK deleted branch $BRANCH of $REPO_LINK"
HIPCHAT_COLOR="red"
else
TITLE="$USER_LINK pushed to branch $BRANCH_LINK of $REPO_LINK"
if [ -n "$GITWEB" ]
then
LOG=`$GIT_EXEC log $OLDREV..$NEWREV --format="- %s (<a href=\"http://$GITWEB/?p=$REPO;a=commitdiff;h=%H\">%h</a>)"`
elif [ -n "$CGIT" ]
then
LOG=`$GIT_EXEC log $OLDREV..$NEWREV --format="- %s (<a href=\"http://$CGIT/$REPO/commit/?id=%H\">%h</a>)"`
elif [ -n "$GITORIOUS" ]
then
LOG=`$GIT_EXEC log $OLDREV..$NEWREV --format="- %s (<a href=\"https://$GITORIOUS/$GIT_PROJECT/$REPO_NO_GIT/commit/%H\">%h</a>)"`
else
LOG=`$GIT_EXEC log $OLDREV..$NEWREV --format="- %s (%h)"`
fi
if [ -n "$REDMINE" ]
then
LOG=`echo -e "$LOG" | sed "s/#\([0-9]*\)/#<a href=\"http:\/\/$REDMINE\/issues\/\1\">\1<\/a>/g"`
elif [ -n "$JIRA" ]
then
LOG=`echo -e "$LOG" | sed "s/\([A-Z]\{2,\}\-[0-9]\{1,\}\)/<a href=\"http:\/\/$JIRA\/browse\/\1\">\1<\/a>/g"`
fi
MSG="$TITLE</br>$LOG"
fi
# Send it to HipChat
echo -e "$MSG" | $HIPCHAT_SCRIPT -c "$HIPCHAT_COLOR" -t "$HIPCHAT_TOKEN" -r "$HIPCHAT_ROOM" -f "$HIPCHAT_FROM" > /dev/null