Skip to content

Instantly share code, notes, and snippets.

@ianlewis
Last active August 29, 2015 13:57
Show Gist options
  • Save ianlewis/9883387 to your computer and use it in GitHub Desktop.
Save ianlewis/9883387 to your computer and use it in GitHub Desktop.
A script for recommending a reviewer for a diff.
#!/bin/bash
# A script for recommending a reviewer for a particular diff.
# Currently only supports mercurial repositories.
if [ "$1" = "" ]; then
echo "Usage: recommend_reviewer REV1 REV2"
exit 0
fi
gitdir ()
{
# Note: this function is duplicated in git-completion.bash
# When updating it, make sure you update the other one to match.
if [ -z "${1-}" ]; then
if [ -n "${__git_dir-}" ]; then
echo "$__git_dir"
elif [ -n "${GIT_DIR-}" ]; then
test -d "${GIT_DIR-}" || return 1
echo "$GIT_DIR"
elif [ -d .git ]; then
echo .git
else
git rev-parse --git-dir 2>/dev/null
fi
elif [ -d "$1/.git" ]; then
echo "$1/.git"
else
echo "$1"
fi
}
GIT_ROOT="$(gitdir)"
if [ "$GIT_ROOT" = "" ]; then
HG_ROOT=`hg root 2>/dev/null`
# Try HG
if [ "$HG_ROOT" = "" ]; then
echo "No git or mercurial repository found."
exit 1
else
# echo "Found hg repo: $HG_ROOT"
# TODO: make max recommendations an option.
hg diff -r "$1:$2" --stat | awk '{ print $1; }' | head -n -1 | xargs hg annotate -r $2 -u | awk 'BEGIN { FS=":" } { print $1; }' | tr -d ' '| sort | uniq -c | sort -nr | head -n 10
fi
else
# echo "Found git repo: $GIT_ROOT"
git diff --name-only $1 $2 | xargs -L1 git annotate $2 | awk 'BEGIN { FS="\t" } { print $2 }' | cut -c 2- | sort | uniq -c | sort -nr | head -n 10
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment