-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsvn-commit-notify
executable file
·99 lines (89 loc) · 1.85 KB
/
svn-commit-notify
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
#!/usr/bin/env bash
#
# Synopsis:
# Notify users of an svn commit
# Usage:
# # typical called by the script <repo>/repos/hooks/post-commit
#
# PATH=/usr/local/bin:/usr/bin:/bin
# svn-commit-notify repo rev [--notify [email protected]]+
# svn-commit-notify repo rev \
# --notify [email protected] \
# --notify [email protected]
# See:
# https://github.com/jmscott/work/svn-commit-notify
# Note:
# Unfortunatly, the option --notify only accepts fully qualified email
# SMTP addresses. Local address are not allowed (like root).
#
PROG=$(basename $0)
USAGE="usage: $PROG repo rev [--notify [email protected]]+"
LOOK_OUT=${TMPDIR:=/tmp}/$PROG.$$
trap "rm -f $LOOK_OUT" EXIT
die()
{
echo "$PROG: ERROR: $@" >&2
echo $USAGE
exit 1
}
case $# in
0|1|2|*[13579]) # only even number args > 2
die 'wrong number of arguments'
;;
esac
REPOS="$1";
REV="$2";
shift; shift
while [ "$1" ]; do
ARG="$1"; shift
case "$ARG" in
--notify)
N=$1
shift
case "$N" in
'')
die 'option --notify: missing email address'
;;
*@*)
NOTIFY="$NOTIFY $N"
;;
*)
die "option --notify; unexpected email address: $N"
;;
esac
;;
--*)
die "unknown option: $ARG"
;;
*)
die "unknown command line argument: $ARG"
;;
esac
done
R=$(basename $REPOS)
svnlook info $REPOS -r $REV >$LOOK_OUT 2>&1
STATUS=$?
if [ $STATUS != 0 ]; then
(
echo "svnlook $REPOS/$REV failed: exit status: $STATUS"
echo
echo "svnlook output follows:"
cat $LOOK_OUT
) | mail -x "ERROR: $REPOS/$REV: svnlook failed"
die "$REPOS/$REV: svnlook failed"
fi
#
# Fourth line has comment
#
SUBJECT="COMMIT: $R: $(awk 'NR == 4' $LOOK_OUT)"
(
cat <<END
SVN Host: $(hostname)
SVN Repo Path: $REPOS
SVN User Id: $(id)
PATH: $PATH
SVN Commit Hook: $(which $0)
SVN Look Output:
END
cat $LOOK_OUT
) | mail -s "$SUBJECT" $NOTIFY <$LOOK_OUT