-
-
Save fangj99/cd980ff5a49d2f58cfa5d01be9025c92 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 hidden or 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