Created
December 19, 2012 20:33
-
-
Save axelson/4340197 to your computer and use it in GitHub Desktop.
Ref-updated gerrit script to send emails via the mail command when commits are pushed directly to gerrit. Install into the gerrit/hooks directory and make sure it is executable. You may want to change the "gitblit.rams" url to point to your own source code viewing website (such as a gitblit server). This has been tested on Gerrit 2.5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#ref-updated --oldrev <old rev> --newrev <new rev> --refname <ref name> --project <project name> --submitter <submitter> | |
OLD_REV="$2" | |
NEW_REV="$4" | |
REF_NAME="$6" | |
PROJECT_NAME="$8" | |
SUBMITTER="${10}" | |
LOG="/tmp/log.txt" | |
date >> $LOG | |
echo "args: $@" >> $LOG | |
echo "old rev $OLD_REV" >> $LOG | |
echo "new rev $NEW_REV" >> $LOG | |
echo "ref name $REF_NAME" >> $LOG | |
echo "project name $PROJECT_NAME" >> $LOG | |
echo "submitter $SUBMITTER" >> $LOG | |
NAME="$SUBMITTER" | |
BRANCH="$REF_NAME" | |
NUM_COMMITS=$(git log $OLD_REV..$NEW_REV --oneline|wc -l) | |
SUBJECT="$NAME pushed $NUM_COMMITS commit(s) to $BRANCH on project $PROJECT_NAME" | |
BODY="Insert summary of commits" | |
TEAM1_EMAILS="[email protected]" | |
TEAM2_EMAILS="[email protected] [email protected]" | |
ADMIN_EMAILS="[email protected]" | |
case $PROJECT_NAME in | |
project1*) | |
EMAIL_LIST="$TEAM1_EMAILS" | |
;; | |
project2*) | |
EMAIL_LIST="$TEAM2_EMAILS" | |
;; | |
*) | |
EMAIL_LIST="$ADMIN_EMAILS" | |
;; | |
esac | |
echo "Subject is $SUBJECT" >> $LOG | |
#for commit in $(git rev-list $OLD_REV..$NEW_REV); do | |
# echo "on commit sha1 $commit" >>$LOG | |
#done | |
# Example gitblit URL: | |
# http://gitblit.rams/commit/hello-world.git/87926995aa1c64225520f0620972df92f6df6879 | |
BODY=$(git shortlog $OLD_REV..$NEW_REV --format="%s - http://gitblit.rams/commit/$PROJECT_NAME.git/%h") | |
echo "Body is $BODY" >> $LOG | |
# Send the email! | |
echo "$BODY" | mail -s "$SUBJECT" $EMAIL_LIST | |
echo >> $LOG |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, have you wrote ref-update hook for gerrit in windows?
I have a ref-update.bat hook, and in ref-update.bak I call/run the python script, then it disappears an error when I push changes to gerrit.
the python script can be run, because I can get the log from the python script.
If I don't call/run python script or others scripts, the ref-update.bak works. why?
Tips: the gerrit version is 2.13
Do you have any idea? thanks.