Last active
December 22, 2015 17:39
-
-
Save agateau/6507885 to your computer and use it in GitHub Desktop.
Wrapper around post-review to create reviews on http://git.reviewboard.kde.org
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/sh | |
set -e | |
REVIEWBOARD_URL="https://git.reviewboard.kde.org" | |
err() { | |
echo "$*" 1>&2 | |
} | |
usage() { | |
if [ -n "$*" ] ; then | |
err "ERROR: $*" | |
err "" | |
fi | |
cat 1>&2 <<EOF | |
Usage: kde-post-review [options] | |
Where [options] is one of: | |
-h, --help This screen | |
-r ID Update existing review request ID | |
--find-copies-harder Passed to "git diff" | |
--username USER Use USER to authenticate. You will be prompted for the | |
password. If not specified, relies on finding an existing | |
browser cookie for password-less authentication. See | |
post-review documentation for more details. | |
EOF | |
exit 1 | |
} | |
# Change PWD to base dir of repository | |
cd_repo_base_dir() { | |
while [ ! -d ".git" ] ; do | |
cd .. | |
if [ "$PWD" = "/" ] ; then | |
err "Not a git repository" | |
exit 1 | |
fi | |
done | |
} | |
git_diff_args="" | |
post_review_args="" | |
updating=false | |
while [ -n "$*" ] ; do | |
x=$1 | |
shift | |
case "$x" in | |
-r) | |
updating=true | |
rev_id=$1 | |
shift | |
;; | |
-h|--help) | |
usage | |
;; | |
--find-copies-harder) | |
git_diff_args="$git_diff_args $x" | |
;; | |
--username) | |
post_review_args="$post_review_args --username=$1" | |
shift | |
;; | |
*) | |
usage "Invalid argument \`$x\`" | |
;; | |
esac | |
done | |
cd_repo_base_dir | |
if [ ! -e ".reviewboardrc" ]; then | |
err "No .reviewboardrc file in $PWD. Please create one or ask the project adminstrator to create one." | |
err "Here is a template:" | |
cat 1>&2 <<EOF | |
REVIEWBOARD_URL = '$REVIEWBOARD_URL' | |
REPOSITORY = 'git://anongit.kde.org/<project-name>' | |
# Optional: which branch the changes should be merged in. Defaults to 'master'. | |
# BRANCH = 'master' | |
# Optional: which group(s) should be notified. There is often a group with the | |
# same name as the project | |
# TARGET_GROUPS = '<group1>, <group2>' | |
EOF | |
exit 1 | |
fi | |
# .reviewboardrc is supposed to be Python-readable, so use Python to read it | |
default_parent=$(python -c 'exec(open(".reviewboardrc").read()) ; print(locals().get("BRANCH", "master"))') | |
echo -n "Parent branch or commit-id ($default_parent): " | |
read parent | |
if [ -z "$parent" ] ; then | |
parent=$default_parent | |
fi | |
commit_range="$parent...HEAD" | |
echo | |
echo "List of changes to post:" | |
echo | |
git log $commit_range | |
echo | |
echo -n "OK [Yn]? " | |
read ok | |
case "$ok" in | |
Y|y|"") | |
;; | |
*) | |
exit 1 | |
;; | |
esac | |
if [ "$updating" = true ] ; then | |
echo "Updating review..." | |
post_review_args="$post_review_args -r $rev_id" | |
else | |
echo "Posting review..." | |
description=/tmp/description | |
git log --pretty=format:%B%n%n $commit_range > $description | |
post_review_args="$post_review_args --description-file=$description" | |
fi | |
tmpfile=/tmp/kde-post-review-$UID-$PID | |
clean_up() | |
{ | |
rm -f $tmpfile | |
} | |
trap 'clean_up; exit 0' 1 2 3 15 | |
git diff $git_diff_args $commit_range > $tmpfile | |
post-review \ | |
--diff-filename=$tmpfile \ | |
--open \ | |
$post_review_args |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment