-
-
Save rjeczalik/10717182 to your computer and use it in GitHub Desktop.
A wrapper for Code Collabolator command line client, creating reviews for every local commit.
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/bash | |
die_usage() { | |
if [ ! -z "${*}" ]; then | |
echo "ccl: error: ${*}" 1>&2 | |
echo | |
fi | |
echo "usage: ccl <review id> <commit>" 1>&2 | |
echo " ccl <commit range>" 1>&2 | |
exit 1 | |
} | |
main() { | |
if [ ${#} == 0 ] || [ ${#} == 1 ]; then | |
COMMITS=() | |
if [ ${#} == 0 ]; then | |
local BRANCH=$(git rev-parse --abbrev-ref HEAD 2>/dev/null) | |
[ -z "${BRANCH}" ] && die_usage "unable to read current branch name" | |
local MERGEBASE= | |
for r in upstream origin; do | |
MERGEBASE=$(git log -1 --format=%H ${r}/${BRANCH} 2>/dev/null) | |
if [ ! -z "${MERGEBASE}" ]; then | |
break | |
fi | |
done | |
[ -z "${MERGEBASE}" ] && die_usage "unable to read merge base" | |
COMMITS=( $(git log --format=%H ${MERGEBASE}..HEAD 2>/dev/null) ) | |
[ ${#COMMITS[@]} -eq 0 ] && die_usage "unable to read commit list: did you try 'git fetch upstream'?" | |
elif [ ${#} == 1]; then | |
COMMITS=( $(git log --format=%H ${1} 2>/dev/null) ) | |
[ ${#COMMITS[@]} -eq 0 ] && die_usage "unable to read commit list" | |
echo "1: ${COMMITS[@]}" | |
fi | |
local MESSAGES=() | |
# local PATCHES=() | |
for i in ${!COMMITS[@]}; do | |
MESSAGES+=( "$(git log --format=%B ${COMMITS[i]}^..${COMMITS[i]} 2>/dev/null)" ) | |
# PATCHES+=( "$(git format-patch ${COMMITS[i]}^..${COMMITS[i]} 2>/dev/null)" ) | |
[ -z "${MESSAGES[i]}" ] && die_usage "unable to read message for commit ${COMMITS[i]}" | |
# [ -z "${PATCHES[i]}" ] && die_usage "unable to create patch for commit ${COMMITS[i]}" | |
done | |
for i in ${!COMMITS[@]}; do | |
local j=$(( ${#COMMITS[@]} - ${i} - 1 )) | |
ccollab addgitdiffs --upload-comment "[$(( ${i} + 1 ))/${#COMMITS[@]}] ${MESSAGES[j]}" new "${COMMITS[j]}^..${COMMITS[j]}" || die_usage | |
done | |
elif [ ${#} == 2 ]; then | |
local REVIEW_ID="$1" | |
local COMMIT_ID="$2" | |
[ -z "$REVIEW_ID" ] && die_usage "<review id> is empty" | |
[ -z "$COMMIT_ID" ] && die_usage "<commit> is empty" | |
ccollab addgitdiffs --upload-comment "$(git log -n 1 "$COMMIT_ID" --)" "$REVIEW_ID" "$COMMIT_ID^..$COMMIT_ID" | |
else | |
die_usage | |
fi | |
} | |
main $@ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment