Last active
August 29, 2015 14:14
-
-
Save pawellenart/588f0152ad1b6b35e4b5 to your computer and use it in GitHub Desktop.
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 | |
usage() | |
{ | |
cat <<'USAGE' | |
Name | |
review - Gerrit review posting tool | |
Description | |
Tool for automatic posting reviews to Xstream Gerrit. It allows to add reviewers straight from | |
the command line instead of opening the review and adding them manually. | |
Synopsis | |
review [options] | |
Options | |
-b|--branch <branch> | |
Name of the branch where changes will be pushed. This option is mandatory. | |
-r|--reviewer <reviewer> | |
Name of the reviewer group or a single reviewer in an e-mail form (e.g. "john.doe@example.com"). | |
NOTE: This option can be used multiple times. | |
-h|--help | |
Print this help. | |
Authors | |
Pawel Lenart <pawel.lenart@xstream.net> | |
USAGE | |
} | |
__review_parseopts() | |
{ | |
while | |
(( $# > 0 )) | |
do | |
opt="$1" | |
shift | |
case "$opt" in | |
-b|--branch) | |
_branch="$1" | |
shift | |
;; | |
-r|--reviewer) | |
_reviewers+=("$1") | |
shift | |
;; | |
-h|--help) | |
usage | |
exit 0 | |
;; | |
*) | |
# unknown option - pass | |
;; | |
esac | |
done | |
} | |
__review() | |
{ | |
git push origin HEAD:refs/for/${_branch} 2>&1 | tee .tmpgerrit | |
if [[ $(grep http .tmpgerrit | wc -l | tr -d ' ') -ge 1 && ! -z ${_reviewers[@]} ]]; then | |
echo | |
_revstring="" | |
for _rev in "${_reviewers[@]}"; do | |
_revstring+="--add \"${_rev}\" " | |
done | |
_gerrit_port=$(git remote -v | head -1 | perl -ne 'print /(\d+)/') | |
_gerrit_host=$(git remote -v | head -1 | perl -ne 'print /\/\/(.*):/') | |
_gerrit_rev_no=$(grep http .tmpgerrit | perl -ne 'print /(\d+)/; print "\n"') | |
for rev_no in ${_gerrit_rev_no}; do | |
echo -n "Setting reviewers for review ${rev_no}... " | |
ssh -p ${_gerrit_port} ${_gerrit_host} \ | |
gerrit set-reviewers ${_revstring} ${rev_no} && echo "done" | |
done | |
fi | |
rm -f .tmpgerrit | |
} | |
__review_parseopts "$@" | |
if [[ -z ${_branch} ]]; then | |
usage | |
else | |
__review | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment