|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# POST-COMMIT HOOK |
| 4 | +# |
| 5 | +# The post-commit hook is invoked after a commit. Subversion runs |
| 6 | +# this hook by invoking a program (script, executable, binary, etc.) |
| 7 | +# named 'post-commit' (for which this file is a template) with the |
| 8 | +# following ordered arguments: |
| 9 | +# |
| 10 | +# [1] REPOS-PATH (the path to this repository) |
| 11 | +# [2] REV (the number of the revision just committed) |
| 12 | +# |
| 13 | +# The default working directory for the invocation is undefined, so |
| 14 | +# the program should set one explicitly if it cares. |
| 15 | +# |
| 16 | +# Because the commit has already completed and cannot be undone, |
| 17 | +# the exit code of the hook program is ignored. The hook program |
| 18 | +# can use the 'svnlook' utility to help it examine the |
| 19 | +# newly-committed tree. |
| 20 | +# |
| 21 | +# On a Unix system, the normal procedure is to have 'post-commit' |
| 22 | +# invoke other programs to do the real work, though it may do the |
| 23 | +# work itself too. |
| 24 | +# |
| 25 | +# Note that 'post-commit' must be executable by the user(s) who will |
| 26 | +# invoke it (typically the user httpd runs as), and that user must |
| 27 | +# have filesystem-level permission to access the repository. |
| 28 | +# |
| 29 | +# On a Windows system, you should name the hook program |
| 30 | +# 'post-commit.bat' or 'post-commit.exe', |
| 31 | +# but the basic idea is the same. |
| 32 | +# |
| 33 | +# The hook program typically does not inherit the environment of |
| 34 | +# its parent process. For example, a common problem is for the |
| 35 | +# PATH environment variable to not be set to its usual value, so |
| 36 | +# that subprograms fail to launch unless invoked via absolute path. |
| 37 | +# If you're having unexpected problems with a hook program, the |
| 38 | +# culprit may be unusual (or missing) environment variables. |
| 39 | +# |
| 40 | +# Here is an example hook script, for a Unix /bin/sh interpreter. |
| 41 | +# For more examples and pre-written hooks, see those in |
| 42 | +# the Subversion repository at |
| 43 | +# http://svn.collab.net/repos/svn/trunk/tools/hook-scripts/ and |
| 44 | +# http://svn.collab.net/repos/svn/trunk/contrib/hook-scripts/ |
| 45 | + |
| 46 | +# Log everything for debug, otherwise use explicit logging (further down) |
| 47 | +#[ "$LOGGING" ] || LOGGING=1 { exec $0 "$@" 2>&1 | logger -p local0.info -t "commit"; } |
| 48 | + |
| 49 | +logger -p local0.info -t "hook" "${0##*/} $*" |
| 50 | + |
| 51 | +repo="$1" |
| 52 | +rev="$2" |
| 53 | + |
| 54 | +# Settings |
| 55 | +program=${0##*/} |
| 56 | +progdir=${0%/*} |
| 57 | +thishost="$(/bin/hostname)" |
| 58 | +thishost="${thishost%%.*}" |
| 59 | +svnpath="/home/svn" |
| 60 | +trac="/www/tools.ietf.org/tools/ietfdb/" |
| 61 | +svn_url="https://svn.tools.ietf.org/svn/tools/ietfdb" |
| 62 | +trac_url="https://trac.tools.ietf.org/tools/ietfdb" |
| 63 | + |
| 64 | +# Do a local backup |
| 65 | +relpath=${repo#$svnpath/} |
| 66 | +bckpath="$svnpath/.backup/$thishost/$relpath" |
| 67 | +[ -d $bckpath ] || mkdir -p $bckpath |
| 68 | +/usr/bin/svn-fast-backup -q $repo $bckpath |
| 69 | + |
| 70 | +# Inform trac about a new changeset |
| 71 | +trac-admin $trac changeset added ietfdb $rev |
| 72 | + |
| 73 | +committer=$(/usr/bin/svnlook author $repo -r $rev) |
| 74 | +comments=$(/usr/bin/svnlook log $repo -r $rev) |
| 75 | +files=$(/usr/bin/svnlook changed $repo -r $rev) |
| 76 | + |
| 77 | +dirs=$(/usr/bin/svnlook dirs-changed -r$rev $repo) |
| 78 | +logger -p local0.info -t "commit" "dirs '$dirs'" |
| 79 | + |
| 80 | +# Look for 'requirements.txt' above the committed change. Looking only for |
| 81 | +# filechanges, not for dirchanges, filters out commits which are just tree |
| 82 | +# copies, such as when creating new dev branches for the code sprint. |
| 83 | +branch=$($progdir/svnfind --filechange --dirpath $repo $rev "requirements.txt") |
| 84 | + |
| 85 | +if [ -n "$branch" ]; then |
| 86 | + # Update trac tickets |
| 87 | + /usr/bin/python $progdir/trac-post-commit-hook -p "$trac" -r "$rev" 2>&1 | logger -t "svn post-commit" -p "user.error" -i |
| 88 | + |
| 89 | + # Notify buildbot |
| 90 | + filenames=$(/usr/bin/svnlook changed $repo -r $rev | sed -r -e 's/^ *[^ ]+ +//' -e "s|$branch/||") |
| 91 | + /usr/local/bin/buildbot sendchange \ |
| 92 | + --master="zinfandel.tools.ietf.org:9989" --auth="ietfdb:BRiR6XcT7x3$" \ |
| 93 | + --who="$committer" --repository="https://svn.tools.ietf.org/svn/tools/ietfdb/" \ |
| 94 | + --vc=svn --branch="$branch" --revision=$rev --property=xproperty:xvalue \ |
| 95 | + --revlink="https://trac.tools.ietf.org/tools/ietfdb/changeset/$rev" \ |
| 96 | + --comments="$comments" $filenames > /dev/null |
| 97 | + |
| 98 | +fi |
| 99 | + |
| 100 | + |
| 101 | +# Log the commit |
| 102 | +logger -p local0.info -t "commit" "$relpath r$rev $committer" |
| 103 | +logger -p local0.info -t "commit" "branch: $branch" |
| 104 | + |
| 105 | +# Notify committers |
| 106 | + |
| 107 | +if [[ $comments =~ ready.(for|to).merge ]]; then |
| 108 | + mail $(< $progdir/notify-email.txt) -s "[svnhook] Svn commit ready for merge: $relpath | $committer: ${comments:0:42}..." <<-EOF | logger -p local0.info -t "ready for merge email" |
| 109 | +
|
| 110 | + $committer has a commit ready for merge: |
| 111 | + $relpath/$branch [$rev]: |
| 112 | +
|
| 113 | + $comments |
| 114 | +
|
| 115 | + Svn: $svn_url/$branch |
| 116 | + Trac: $trac_url/changeset/$rev/$branch |
| 117 | +
|
| 118 | + Files: |
| 119 | +
|
| 120 | + $files |
| 121 | +
|
| 122 | + EOF |
| 123 | + |
| 124 | +else |
| 125 | + |
| 126 | + mail $(< $progdir/notify-email.txt) -s "[svnhook] Svn commit to $relpath | $committer: ${comments:0:42}..." <<-EOF | logger -p local0.info -t "commit email" |
| 127 | +
|
| 128 | + $committer has made a new SVN commit in |
| 129 | + $relpath/$branch [$rev]: |
| 130 | +
|
| 131 | + $comments |
| 132 | +
|
| 133 | + Svn: $svn_url/$branch |
| 134 | + Trac: $trac_url/changeset/$rev/$branch |
| 135 | +
|
| 136 | + Files: |
| 137 | +
|
| 138 | + $files |
| 139 | +
|
| 140 | + EOF |
| 141 | + |
| 142 | +fi |
0 commit comments