Skip to content

Instantly share code, notes, and snippets.

@spudfkc
Last active August 3, 2017 10:21
Show Gist options
  • Save spudfkc/7345308 to your computer and use it in GitHub Desktop.
Save spudfkc/7345308 to your computer and use it in GitHub Desktop.
Uses Gerrit's REST API to add a reviewer to a change
#!/bin/bash
USERNAME="<HTTP-USERNAME>"
PASSWORD="<HTTP-PASSWORD>"
BASE_URL="<GERRIT-URL>"
REVIEWER="<DEFAULT-REVIEWER-EMAIL>"
CURL=$(which curl)
if [ -z "$CURL" ]
then
echo "could not find curl"
exit 1
fi
#parse args
if [ -z "$1" ]
then
echo "Usage: gerrit-add-reviewer CHANGEID [REVIEWEREMAIL]"
exit 1
fi
CHANGE="$1/reviewers"
URL="$BASE_URL/a/changes/$CHANGE"
if [ ! -z "$2" ]
then
REVIEWER="$2"
fi
HEADER="'Content-Type: application/json'"
JSON="'{\"reviewer\": \"$REVIEWER\"}'"
CMD="$CURL -s -k --digest -u $USERNAME:$PASSWORD -X POST -H $HEADER -d $JSON $URL"
eval $CMD
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment