From 1b8e982332b81644c3dc90d0fa3367dd4ff6f53c Mon Sep 17 00:00:00 2001 From: "Bala.FA" Date: Sat, 15 Mar 2014 10:58:49 +0530 Subject: rfc: refactor to make more usable and friendly Usage: rfc.sh [OPTION]... [ ]... Options: -a ask for Bug ID addition. This option is set by default for non 'master' branches. -b BRANCH use BRANCH to submitting patch. Default branch is 'master'. -d dry run. Show what command to run. -n do not fetch origin. -t TOPIC use TOPIC to submitting patch. -h display this help text and exit. By default, BUGID is used as topic in patch submission. If TOPIC and BUGID are used together, TOPIC gets used. Examples: # submit patch to master branch without reviewer $ rfc.sh # submit patch to master branch with reviewer $ rfc.sh charlie@example.com # submit patch to release-3.0 branch with topic "awesome feature" and # reviewers charlie@example.com alice@example.com $ rfc.sh -b release-3.0 -t "awesome feature" charlie@example.com alice@example.com Change-Id: I6ca6f4ad70ea3a902c3415a12a12c3e46e79adef Signed-off-by: Bala.FA Reviewed-on: https://cuckoo.blr.redhat.com:8443/12 --- README | 13 ++-- rfc.sh | 233 +++++++++++++++++++++++++++++++++++++++++++++++++---------------- 2 files changed, 182 insertions(+), 64 deletions(-) diff --git a/README b/README index 6d391bb..a4e1e4b 100644 --- a/README +++ b/README @@ -1,14 +1,13 @@ -Nagios Gluster Add-ons: +Nagios Gluster Common: ======================= -Nagios plugin, scripts, configuration files etc for gluster nodes. - +Common libraries, tools, configurations for Gluster node and Nagios +server add-ons Installation ============ -The Nagios Gluster Add-ons can be used by following the standard -autotools installation process, documented in the INSTALL file. As a -quick start you can do +This can be used by following the standard autotools installation +process, documented in the INSTALL file. As a quick start you can do ./configure --prefix=/usr --sysconfdir=/etc \ --localstatedir=/var --libdir=/usr/lib @@ -18,7 +17,7 @@ quick start you can do Packaging ========= -The 'nagios-gluster-addons.spec' file demonstrates how to distribute +The 'nagios-gluster-common.spec' file demonstrates how to distribute this as an RPM package. diff --git a/rfc.sh b/rfc.sh index fdb22ef..dfbfde0 100755 --- a/rfc.sh +++ b/rfc.sh @@ -1,113 +1,232 @@ -#!/bin/sh -e +#!/bin/bash +ME=$(basename $0) -branch="master"; +editormode=0 +askbugid=0 +branch="master" +dryrun=0 +fetch=1 +topic="" -set_hooks_commit_msg() +show_help() { - f=".git/hooks/commit-msg"; - u="https://10.70.35.186:8443/tools/hooks/commit-msg"; + cat 1>&2 < ]... - if [ -x "$f" ]; then - return; - fi +Options: + -a ask for Bug ID addition. This option is set by default for + non 'master' branches. + -b BRANCH use BRANCH to submitting patch. Default branch is 'master'. + -d dry run. Show what command to run. + -n do not fetch origin. + -t TOPIC use TOPIC to submitting patch. + -h display this help text and exit. - curl -k -o $f $u || wget --no-check-certificate -O $f $u; - chmod +x .git/hooks/commit-msg; +By default, BUGID is used as topic in patch submission. If TOPIC and +BUGID are used together, TOPIC gets used. - # Let the 'Change-Id: ' header get assigned on first run of rfc.sh - GIT_EDITOR=true git commit --amend; -} +Examples: +# submit patch to master branch without reviewer +$ $ME -is_num() -{ - local num; +# submit patch to master branch with reviewer +$ $ME charlie@example.com - num="$1"; +# submit patch to release-3.0 branch with topic "awesome feature" and +# reviewers charlie@example.com alice@example.com +$ $ME -b release-3.0 -t "awesome feature" charlie@example.com alice@example.com - [ -z "$(echo $num | sed -e 's/[0-9]//g')" ] +EOF } -rebase_changes() +is_num() { - git fetch origin; - - GIT_EDITOR=$0 git rebase -i origin/$branch; + test "$1" -eq "$1" 2>/dev/null } -editor_mode() +exit_editor_mode() { - if [ $(basename "$1") = "git-rebase-todo" ]; then - sed 's/^pick /reword /g' "$1" > $1.new && mv $1.new $1; - return; + if [[ "$1" =~ /git-rebase-todo$ ]]; then + sed -i 's/^pick /reword /' "$1" + exit 0 fi - if [ $(basename "$1") = "COMMIT_EDITMSG" ]; then - if grep -qi '^BUG: ' $1; then - return; + if [[ "$1" =~ /COMMIT_EDITMSG$ ]]; then + if grep -qi '^BUG:' "$1"; then + exit 0 fi + + if [ "$askbugid" -eq 0 ]; then + #echo "warning: no Bug ID found" 1>&2 + exit 0 + fi + while true; do - echo Commit: "\"$(head -n 1 $1)\"" + echo "Commit: $(head -n 1 $1)" echo -n "Enter Bug ID: " read bug + if [ -z "$bug" ]; then - return; + echo -e "ignored adding Bug ID\n" 1>&2 + exit 0 fi + if ! is_num "$bug"; then - echo "Invalid Bug ID ($bug)!!!"; - continue; + echo "invalid Bug ID '$bug'" 1>&2 + continue fi - sed "/^Change-Id:/{p; s/^.*$/BUG: $bug/;}" $1 > $1.new && \ - mv $1.new $1; - return; + echo + sed "/^Change-Id:/i BUG: $bug" "$1" + exit 0 done fi - cat </dev/null | grep -e '\.py$' -e '\.py\.in$') + if [ -z "$pyfiles" ]; then + return + fi + if ! pyflakes $pyfiles; then + echo -e "\nPlease clear pyflakes error(s) before submission" 1>&2 + exit 1 + fi + if ! pep8 -r --show-pep8 $pyfiles; then + echo -e "\nPlease clear pep8 error(s) before submission" 1>&2 + exit 1 + fi +} - if [ -e "$1" ]; then - editor_mode "$@"; - return; + +assert_rebase() +{ + if [ "$askbugid" -eq 1 -o "$branch" != "master" ]; then + GIT_EDITOR="$0 -E -a" git -c 'commit.status=false' -c 'commit.cleanup=whitespace' rebase -i origin/$branch || exit 2 + else + GIT_EDITOR="$0 -E" git -c 'commit.status=false' -c 'commit.cleanup=whitespace' rebase -i origin/$branch || exit 2 fi +} - rebase_changes; - assert_diverge; +assert_nochange() +{ + if ! git diff origin/$branch..HEAD 2>/dev/null | grep -q .; then + echo "No change to submit" 1>&2 + exit 3 + fi +} - bug=$(git show --format='%b' | grep -i '^BUG: ' | awk '{print $2}'); - if [ "$DRY_RUN" = 1 ]; then - drier='echo -e Please use the following command to send your commits to review:\n\n' +main() +{ + # A POSIX variable + OPTIND=1 # Reset in case getopts has been used previously in the shell. + + while getopts "Eab:dnt:h" opt; do + case "$opt" in + E) + editormode=1 + ;; + a) + askbugid=1 + ;; + b) + branch=$OPTARG + ;; + d) + dryrun=1 + ;; + n) + fetch=0 + ;; + t) + topic="$OPTARG" + ;; + h) + show_help + exit 0 + ;; + \?) + show_help + exit -1 + ;; + esac + done + + shift $((OPTIND-1)) + + [ "$1" = "--" ] && shift + + if [ $editormode -eq 1 ]; then + exit_editor_mode "$@" + fi + + for i; do + if [[ ! "$i" =~ .*@.*\..*$ ]]; then + echo "invalid email id: $i" 1>&2 + show_help + exit -1 + fi + done + + ref="HEAD:refs/for/${branch}%" + + if [ $dryrun -eq 1 ]; then + drier='echo command: ' else drier= fi - if [ -z "$bug" ]; then - $drier git push origin HEAD:refs/for/$branch/rfc; - else - $drier git push origin HEAD:refs/for/$branch/bug-$bug; + if [ -n "$topic" ]; then + topic=$(echo $topic | sed 's| |/|g') + ref="${ref}topic=$topic," + elif [ -n "$bugid" ]; then + ref="${ref}topic=bug-$bugid," + fi + + reviewers=( "$@" ) + reviewers=$(IFS=,; echo "${reviewers[*]/#/r=}") + [ -n "$reviewers" ] && ref="$ref$reviewers" + + add_hook_commit_msg + assert_python_check + [ $fetch -eq 1 ] && git fetch origin + assert_rebase + assert_nochange + + $drier git push origin $ref + + if [ -z "$reviewers" ]; then + echo -e "\nPatch is submitted without any reviewer. Please add manually" fi } -- cgit