From 451007f6dfef5b4d68e9a047c5cf27d7b52103f3 Mon Sep 17 00:00:00 2001 From: Dan Brown Date: Tue, 26 Nov 2013 22:50:46 -0500 Subject: [PATCH 1/2] Distinguish tag create/delete from branch create/delete --- hipchat-post-receive | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/hipchat-post-receive b/hipchat-post-receive index 209f2e6..bd6a5e0 100755 --- a/hipchat-post-receive +++ b/hipchat-post-receive @@ -12,7 +12,16 @@ HIPCHAT_COLOR=${HIPCHAT_COLOR:-"yellow"} NULLREV="0000000000000000000000000000000000000000" [ "$NEWREV" = "$NULLREV" ] && USER_REV="$OLDREV" || USER_REV="$NEWREV" USER=`$GIT_EXEC log -1 $USER_REV --format="%aN"` -BRANCH=${REFNAME#refs/heads/} + +# Record whether this is a tag or normal commit/branch +if [ `$GIT_EXEC cat-file -t $USER_REV` != 'tag' ] +then + TAG_OR_BRANCH='branch' + BRANCH=${REFNAME#refs/heads/} +else + TAG_OR_BRANCH='tag' + BRANCH=${REFNAME#refs/tags/} +fi # Setup gitweb links if [ -n "$GITWEB" ] @@ -43,11 +52,11 @@ fi # Construct message if [ "$OLDREV" = "$NULLREV" ] then - MSG="$USER_LINK created branch $BRANCH_LINK of $REPO_LINK" + MSG="$USER_LINK created $TAG_OR_BRANCH $BRANCH_LINK of $REPO_LINK" HIPCHAT_COLOR="green" elif [ "$NEWREV" = "$NULLREV" ] then - MSG="$USER_LINK deleted branch $BRANCH of $REPO_LINK" + MSG="$USER_LINK deleted $TAG_OR_BRANCH $BRANCH of $REPO_LINK" HIPCHAT_COLOR="red" else TITLE="$USER_LINK pushed to branch $BRANCH_LINK of $REPO_LINK" From 80d84b6beb68dab4b1748282fa2a478801e8926e Mon Sep 17 00:00:00 2001 From: Dan Brown Date: Tue, 26 Nov 2013 22:51:10 -0500 Subject: [PATCH 2/2] For tag create/delete, report tag tagger instead of commit author --- hipchat-post-receive | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/hipchat-post-receive b/hipchat-post-receive index bd6a5e0..8b52f0b 100755 --- a/hipchat-post-receive +++ b/hipchat-post-receive @@ -8,10 +8,12 @@ GIT_EXEC=${GIT_EXEC:-`which git`} REPO=${REPO:-`basename $PWD`} HIPCHAT_COLOR=${HIPCHAT_COLOR:-"yellow"} -# User is commiter of either last or first commit +# First or last commit might be 0, in case of branch/tag create or delete NULLREV="0000000000000000000000000000000000000000" [ "$NEWREV" = "$NULLREV" ] && USER_REV="$OLDREV" || USER_REV="$NEWREV" -USER=`$GIT_EXEC log -1 $USER_REV --format="%aN"` + +# User is either tag tagger or commit author +USER=`git cat-file -p $USER_REV | grep -E '^tagger|^author' | sed -E 's/^(tagger|author) (.*) <.*$/\2/g'` # Record whether this is a tag or normal commit/branch if [ `$GIT_EXEC cat-file -t $USER_REV` != 'tag' ]