Skip to content

Instantly share code, notes, and snippets.

@chmouel
Last active December 23, 2015 19:19
Show Gist options
  • Save chmouel/6682049 to your computer and use it in GitHub Desktop.
Save chmouel/6682049 to your computer and use it in GitHub Desktop.
Browse current review in browser
#!/bin/bash
# Browse current review in browser
# Chmouel Boudjnah <[email protected]>
set -e
function readlinkf() {
python -c 'import os,sys;print os.path.realpath(sys.argv[1])' $1
}
function get-gitreview () {
oldpwd=$PWD
curdir="./"
while [[ ${curdir} != "/" ]];do
if [[ -e .gitreview ]];then
echo $(readlinkf .gitreview)
break
fi
cd ../
curdir=$(readlinkf ./)
done
cd ${OLDPWD}
}
GIT_REVIEW_FILE=$(get-gitreview)
if [[ -z ${GIT_REVIEW_FILE} ]];then
echo "Cannot find git-review"
exit 1
fi
while read -a line;do
if [[ ${line} == host* ]];then
host=${line#*=}
elif [[ ${line} == port* ]];then
port=${line#*=}
elif [[ ${line} == project* ]];then
project=${line#*=}
project=${project/.git/}
fi
done < ${GIT_REVIEW_FILE}
if [[ -z ${host} || -z ${port} || -z ${project} ]];then
echo "Could not parse properly ${GIT_REVIEW_FILE}"
exit 1
fi
change_id=$(git log -n1|grep Change-Id|sed 's/.* I/I/')
if [[ -z ${change_id} ]];then
echo "Could not parse ChangeID"
exit 1
fi
review_url=$(ssh -x -p ${port} ${host} "gerrit query --format=JSON project:${project} change:${change_id}" | grep -v '"type":"stats"' | sed 's/.*url...\([^"]*\).*/\1/')
if [[ -z ${review_url} ]];then
echo "Could not find the review URL"
exit 1
fi
if type -p open >/dev/null;then
open ${review_url}
elif type -p gnome-open >/dev/null;then
gnome-open ${review_url}
else
echo ${review_url}
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment