From 62c49fedf7daf6164fe2346109c96b40bcebb72f Mon Sep 17 00:00:00 2001 From: Tony Murray Date: Wed, 15 Feb 2017 14:48:56 -0600 Subject: [PATCH 1/6] Scripts to easily apply and remove github Pull Requests --- scripts/github-apply | 10 ++++++++++ scripts/github-remove | 28 ++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100755 scripts/github-apply create mode 100755 scripts/github-remove diff --git a/scripts/github-apply b/scripts/github-apply new file mode 100755 index 0000000000..16af1677ee --- /dev/null +++ b/scripts/github-apply @@ -0,0 +1,10 @@ +#!/bin/sh + +LIBRENMS_DIR=`dirname "$(readlink -f "$0/..")"` +cd $LIBRENMS_DIR + +if [ -z "$1" ]; then + echo "You must specify a PR number to apply a patch" +else + curl https://patch-diff.githubusercontent.com/raw/librenms/librenms/pull/${1}.patch | git apply -v ${2} +fi diff --git a/scripts/github-remove b/scripts/github-remove new file mode 100755 index 0000000000..7cfcd62da1 --- /dev/null +++ b/scripts/github-remove @@ -0,0 +1,28 @@ +#!/bin/sh + +LIBRENMS_DIR=`dirname "$(readlink -f "$0/..")"` +cd $LIBRENMS_DIR + +if [ "$1" == "-d" ]; then + # removing all uncommited changes + # git status + read -p "Are you sure you want to delete your changes? " -n 1 -r + echo + if [[ ! $REPLY =~ ^[Yy]$ ]]; then + exit 1 + fi + + git reset + git checkout --progress + git clean -d -f contrib/ doc/ html/ includes/ lib/ LibreNMS/ licenses/ mibs/ misc/ scripts/ sql-schema/ tests/ + if [ "$2" == "-v" ]; then + git clean -x -d -f vendor/ + fi +elif [ "$1" == "-h" ]; then + echo "Usage: $0 [-d [-v]]" + echo " Stashes changes by default. git stash list to see stashes" + echo " -d discard all uncommited changes" + echo " -v discard vendor directory changes too" +else + git stash +fi From bf32690abc01631cb1af933b05d6ecd7fdb0f4f4 Mon Sep 17 00:00:00 2001 From: Tony Murray Date: Fri, 17 Feb 2017 21:29:52 -0600 Subject: [PATCH 2/6] Port remove script to python --- scripts/github-remove | 82 ++++++++++++++++++++++++++++++------------- 1 file changed, 57 insertions(+), 25 deletions(-) diff --git a/scripts/github-remove b/scripts/github-remove index 7cfcd62da1..36643fc466 100755 --- a/scripts/github-remove +++ b/scripts/github-remove @@ -1,28 +1,60 @@ -#!/bin/sh +#! /usr/bin/env python +import argparse, datetime, sys +from subprocess import call, check_output +from os.path import dirname, abspath -LIBRENMS_DIR=`dirname "$(readlink -f "$0/..")"` -cd $LIBRENMS_DIR +raw_input = getattr(__builtins__, 'raw_input', input) -if [ "$1" == "-d" ]; then - # removing all uncommited changes - # git status - read -p "Are you sure you want to delete your changes? " -n 1 -r - echo - if [[ ! $REPLY =~ ^[Yy]$ ]]; then - exit 1 - fi +def confirm(question): + valid = {"yes":True, "y":True, "ye":True, "no":False, "n":False} + while 1: + sys.stdout.write(question + " [y/N] ") + choice = raw_input().lower() + if choice == '': + return False + elif choice in valid.keys(): + return valid[choice] + else: + sys.stdout.write("Please respond with 'yes' or 'no' (or 'y' or 'n').\n") - git reset - git checkout --progress - git clean -d -f contrib/ doc/ html/ includes/ lib/ LibreNMS/ licenses/ mibs/ misc/ scripts/ sql-schema/ tests/ - if [ "$2" == "-v" ]; then - git clean -x -d -f vendor/ - fi -elif [ "$1" == "-h" ]; then - echo "Usage: $0 [-d [-v]]" - echo " Stashes changes by default. git stash list to see stashes" - echo " -d discard all uncommited changes" - echo " -v discard vendor directory changes too" -else - git stash -fi + + +librenms_dir = dirname(dirname(abspath(__file__))) + +parser = argparse.ArgumentParser() +group = parser.add_mutually_exclusive_group() +group.add_argument("-d", "--discard", action="store_true", help="Discard all changes clean extra files") +group.add_argument("-s", "--save", action="store_true", help="Save and remove changes by stashing them. (git stash)") +group.add_argument("-r", "--restore", action="store_true", help="Attempt to restore saved changes (git stash pop)") +parser.add_argument("-v", "--vendor", action="store_true", help="Also Discard changes to the vendor directory (requires --discard)") + +args = parser.parse_args() + +if args.vendor and not args.discard: + print(__file__ + ": error: argument -v/--vendor requires -d/--discard") + exit(1) + + +if args.discard: + if confirm("Are you sure you want to delete all modified and untracked files?"): + dirs = ["contrib/", "doc/", "html/", "includes/", "lib/", "LibreNMS/", + "licenses/", "mibs/", "misc/", "scripts/", "sql-schema/", "tests/"] + call(["git", "reset", "-q"], cwd=librenms_dir) + call(["git", "checkout", "."], cwd=librenms_dir) + call(["git", "clean", "-d", "-f"] + dirs, cwd=librenms_dir) + + if args.vendor: + call(["git", "clean", "-x", "-d", "-f", "vendor/"], cwd=librenms_dir) + +elif args.save: + msg = "github-remove saved on "+str(datetime.datetime.now()) + call(["git", "stash", "save", msg], cwd=librenms_dir) + +elif args.restore: + list = check_output(["git", "stash", "list"]) + last = list.decode("utf-8") .split('\n', 1)[0] + + if "github-remove" in last: + call(["git", "stash", "pop"], cwd=librenms_dir) + else: + print("Last stash was not created by " + __file__ + ". Aborting.") From 3c22633cead35fd55c77a1cddda5af29d866e510 Mon Sep 17 00:00:00 2001 From: Tony Murray Date: Fri, 17 Feb 2017 21:29:52 -0600 Subject: [PATCH 3/6] Port remove script to python --- scripts/github-remove | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/github-remove b/scripts/github-remove index 36643fc466..34c162d1e7 100755 --- a/scripts/github-remove +++ b/scripts/github-remove @@ -39,6 +39,7 @@ if args.discard: if confirm("Are you sure you want to delete all modified and untracked files?"): dirs = ["contrib/", "doc/", "html/", "includes/", "lib/", "LibreNMS/", "licenses/", "mibs/", "misc/", "scripts/", "sql-schema/", "tests/"] + call(["git", "reset", "-q"], cwd=librenms_dir) call(["git", "checkout", "."], cwd=librenms_dir) call(["git", "clean", "-d", "-f"] + dirs, cwd=librenms_dir) From 6b33bdc949ca469c626f5ee985fd8dbceb0677a3 Mon Sep 17 00:00:00 2001 From: Tony Murray Date: Fri, 17 Feb 2017 21:38:54 -0600 Subject: [PATCH 4/6] require -d -s or -r --- scripts/github-remove | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/github-remove b/scripts/github-remove index 34c162d1e7..278745e37e 100755 --- a/scripts/github-remove +++ b/scripts/github-remove @@ -22,11 +22,11 @@ def confirm(question): librenms_dir = dirname(dirname(abspath(__file__))) parser = argparse.ArgumentParser() -group = parser.add_mutually_exclusive_group() +group = parser.add_mutually_exclusive_group(required=True) group.add_argument("-d", "--discard", action="store_true", help="Discard all changes clean extra files") group.add_argument("-s", "--save", action="store_true", help="Save and remove changes by stashing them. (git stash)") group.add_argument("-r", "--restore", action="store_true", help="Attempt to restore saved changes (git stash pop)") -parser.add_argument("-v", "--vendor", action="store_true", help="Also Discard changes to the vendor directory (requires --discard)") +parser.add_argument("-v", "--vendor", action="store_true", help="Also discard changes to ./vendor (requires --discard)") args = parser.parse_args() From 676e5563b9319f0db08908af618df02efa6fcf66 Mon Sep 17 00:00:00 2001 From: Tony Murray Date: Fri, 17 Feb 2017 21:49:29 -0600 Subject: [PATCH 5/6] Only allow integers for input to github-apply Remove some unneded code from github-remove --- scripts/github-apply | 9 ++++----- scripts/github-remove | 6 ------ 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/scripts/github-apply b/scripts/github-apply index 16af1677ee..2343ebe293 100755 --- a/scripts/github-apply +++ b/scripts/github-apply @@ -3,8 +3,7 @@ LIBRENMS_DIR=`dirname "$(readlink -f "$0/..")"` cd $LIBRENMS_DIR -if [ -z "$1" ]; then - echo "You must specify a PR number to apply a patch" -else - curl https://patch-diff.githubusercontent.com/raw/librenms/librenms/pull/${1}.patch | git apply -v ${2} -fi +case $1 in + ''|*[!0-9]*) echo "You must specify a PR number to apply a patch" ;; + *) curl -s https://patch-diff.githubusercontent.com/raw/librenms/librenms/pull/${1}.patch | git apply -v ${2} ;; +esac diff --git a/scripts/github-remove b/scripts/github-remove index 278745e37e..d05fa7a755 100755 --- a/scripts/github-remove +++ b/scripts/github-remove @@ -18,7 +18,6 @@ def confirm(question): sys.stdout.write("Please respond with 'yes' or 'no' (or 'y' or 'n').\n") - librenms_dir = dirname(dirname(abspath(__file__))) parser = argparse.ArgumentParser() @@ -27,13 +26,8 @@ group.add_argument("-d", "--discard", action="store_true", help="Discard all cha group.add_argument("-s", "--save", action="store_true", help="Save and remove changes by stashing them. (git stash)") group.add_argument("-r", "--restore", action="store_true", help="Attempt to restore saved changes (git stash pop)") parser.add_argument("-v", "--vendor", action="store_true", help="Also discard changes to ./vendor (requires --discard)") - args = parser.parse_args() -if args.vendor and not args.discard: - print(__file__ + ": error: argument -v/--vendor requires -d/--discard") - exit(1) - if args.discard: if confirm("Are you sure you want to delete all modified and untracked files?"): From 19a08a01fbd8eda05e33f9ece04f0e0e379a97b1 Mon Sep 17 00:00:00 2001 From: Neil Lathwood Date: Fri, 17 Feb 2017 16:57:47 +0000 Subject: [PATCH 6/6] added instructions on use to PULL_REQUEST_TEMPLATE.md --- .github/PULL_REQUEST_TEMPLATE.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index b7fc60bab2..8292a94ea6 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -6,3 +6,7 @@ DO NOT DELETE THIS TEXT - [ ] Have you signed the [Contributors agreement](http://docs.librenms.org/General/Contributing/) - please do NOT submit a pull request unless you have (signing the agreement in the same pull request is fine). Your commit message for signing the agreement must appear as per the docs. - [ ] Have you followed our [code guidelines?](http://docs.librenms.org/Developing/Code-Guidelines/) + +#### Testers + +If you would like to test this pull request then please run: `./scripts/github-apply `, i.e `./scripts/github-apply 5926`