Last active
June 12, 2017 08:40
-
-
Save andersonvom/924fdc5f92aefa5eca9c 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 | |
# This script will submit all pending commits to gerrit and will automatically | |
# add reviewers to the associated change. Reviewers can be added by simply | |
# listing them after greview. You can either enter their full email addresses | |
# or just partially enter a unique combination of letters that will be | |
# fuzy-matched to either the email or the name of the commiters. | |
# | |
# Usage: greview <reviewer-1> <reviewer-2> ... | |
reviewers=${*:1} | |
function list_reviewers { | |
git log --format="%aE %aN" -n 1000 | sort | uniq | |
} | |
default_branch=$(cat .gitreview | grep -e 'defaultbranch' | cut -d '=' -f2) | |
default_branch=${default_branch:-"master"} | |
topic_branch=$(git rev-parse --abbrev-ref HEAD) | |
push_ref="HEAD:refs/for/$default_branch" | |
if [ "$topic_branch" != "$default_branch" ]; then | |
push_ref="$push_ref/$topic_branch" | |
fi | |
url=$(git remote show -n gerrit | | |
grep Fetch | | |
cut -d ':' -f2- | | |
sed -e 's/ //g') | |
for rev in $reviewers | |
do | |
pattern="$(echo "$rev" | sed 's/\(.\)/[^ ]*\1/g')" | |
matches="$(list_reviewers | grep "$pattern" | cut -d ' ' -f1)" | |
all_reviewers=$(echo $matches | sed -e "s/ .*//g") | |
if [ "$all_reviewers" = "" ]; then | |
all_reviewers="$rev" | |
fi | |
reviewer_opts="$reviewer_opts --reviewer $all_reviewers" | |
done | |
git push --receive-pack="git-receive-pack $reviewer_opts" "$url" "$push_ref" |
Thanks for the tips! The sed
expression needed a bit of change to work properly, but it's working great now. I'm also limiting the number of commits to 1000 so that there's no performance hit in large repos. =D
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think that the last lines (
git config
andgit push
) can be simplified to avoid a new remote:Simplification of
matches
that is also case sensitive now:... now I also see that this script retrieves all authors from the commit log as reviewers which could a bit slow for large repos.