forked from hankman2k/HipChat-SVN-post-commit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
post-commit
executable file
·99 lines (82 loc) · 2.81 KB
/
post-commit
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/bin/bash
# post-commit: Hook used for Visual SVN Server post commits
#
# Kirk Gleason
# This script is set to publish information to HipChat after SVN commits are made.
#
# Set hipchat_cli info
#
HCCLI="$(which hipchat_cli)"
TOKEN=""
ROOM=""
USER="Subversion"
SVNUSER="<replace me with the name of your SVN reader account>"
SVNPASS="<replace me with the password of your SVN reader account>"
SVNCMD="$(which svn)"
#The base address of your Subversion server. The repository name will be appended to the end.
SVNROOT="https://<replace me with the name of your SVN server>/svn"
#This should reflect the path of your Visual SVNReporistories on the Windows Filesystem
#with all of the \ removed.
#Visual SVN passes a physcial path, and the \ are lost as escapes when the values are
#passed via ssh. The variable below is used to clean this our of the REPO variable.
REPOPATH="D:SubVersionRepositories"
# Sub-Repository - USE "" if no sub-repo is needed
SUB=""
# Temp file location and name
HCTMP="/tmp/svn_hc.$$"
##############################################################
##############################################################
############ Edit below at your own risk #####################
##############################################################
##############################################################
# Check that we are using the scipt correctly
# Shouldn't be an issue unless you're running this by hand
usage(){
echo ""
echo "Usage: $0 REPO REVISION"
echo ""
}
# Check the command line args
# Shouldn't be an issue unless you're running this by hand
if [ $# -ne 2 ]
then
usage
exit 1
fi
# Setup the actual post-commit process
post(){
#Create the tmp file to hold our message.
echo | cat > ${HCTMP} << ENDEND
${WHO} updated ${REPO} to Rev: ${REV}
Comments: ${CMT}
The following list of files were changed:
${FILES}
ENDEND
# Added test to look for specific sub-repositories
if [ -n "$SUB" ]
then
CHKSUB=`grep ${SUB} ${HCTMP} | wc -l`
if [ $CHKSUB -gt 0 ]
then
cat ${HCTMP} | ${HCCTL}
rm -f ${HCTMP}
else
rm -f ${HCTMP}
fi
else
cat ${HCTMP} | ${HCCTL}
rm -f ${HCTMP}
fi
}
# Make things tight
# $1 and $2 are passed by the "svn commit" process
# CMT, WHO and FILES are set to keep the "post" process tight and easy
# HCCTL is the call to the hipchat_cli
REPO="$(echo $1 | sed \"s/${REPOPATH}//g\")"
REV="$2"
CMT="$(svn log --username ${SVNUSER} --password ${SVNPASS} ${SVNROOT}/${REPO} -r ${REV} | grep -v ${REV} | grep -v -e --- | grep -v ^$)"
WHO="$(svn info --username ${SVNUSER} --password ${SVNPASS} ${SVNROOT}/${REPO} -r ${REV} | grep Author | awk '{ print $4 }')"
FILES="$(svn log --username ${SVNUSER} --password ${SVNPASS} --verbose ${SVNROOT}/${REPO} -r ${REV} | grep /)"
HCCTL="${HCCLI} -t ${TOKEN} -r ${ROOM} -f ${USER}"
# Finally, let's do what needs to be done.
post