akaros/scripts/ak-scripts/ak-code-review.sh
<<
>>
Prefs
   1#!/usr/bin/env bash
   2#
   3# Copyright (c) 2015 Google Inc.
   4# Kevin Klues <klueska@cs.berkeley.edu>
   5# See LICENSE for details.
   6
   7# Some global variables
   8origin="brho"
   9
  10function short_description() {
  11        echo "Prepare the message body for an akaros code review"
  12}
  13
  14function usage() {
  15        echo "Usage:"
  16        echo "    ${cmd} [ -h | --help ]"
  17        echo "    ${cmd} [ -p ] <base> <remote> [ <head> ]"
  18        echo ""
  19        echo "Options:"
  20        echo "    -h --help  Display this screen and exit"
  21        echo "    -p         Show patch text as well"
  22        echo ""
  23        echo "Description:"
  24        echo "    This tool takes the same parameters as the standard"
  25        echo "    git request-pull command but formats the output"
  26        echo "    in a more convenient format for akaros code-reviews"
  27        echo "    Please copy the contents of the output into an email"
  28        echo "    and send it to akaros@googlegroups.com for review"
  29}
  30
  31function gen_request()
  32{
  33        # Set some local variables
  34        local base_sha1=$(git rev-parse ${base})
  35        local head_sha1=${remote}:${head}
  36        base_sha1=${base_sha1:0:7}
  37
  38        # Get the text from a git request-pull
  39        request=$(git request-pull ${patch} ${base} ${remote} ${head});
  40        ret=${?};
  41        if [ "${ret}" != "0" ]; then
  42                kill -s TERM $TOP_PID
  43        else
  44                echo "The changes in this request can be viewed online at:"
  45                echo ""
  46                echo "    https://github.com/brho/akaros/compare/${base_sha1}...${head_sha1}"
  47                echo ""
  48                echo "${request}"
  49
  50        fi
  51}
  52
  53function main() {
  54        # Set so functions can exit from entire program if desired
  55        trap "exit 1" TERM
  56        export TOP_PID=$$
  57
  58        # Verify cmd-line options
  59        if [ "${head}" = "" ]; then
  60                head=$(git rev-parse --abbrev-ref HEAD)
  61        fi
  62        if [ "${_p}" = "true" ]; then
  63                local patch="-p"
  64        fi
  65
  66        gen_request
  67}
  68