From e075c94cf3c55ab655c689f5e10ec659eb2fec3b Mon Sep 17 00:00:00 2001 From: lhinds Date: Tue, 22 Aug 2017 15:13:27 +0100 Subject: Get Patch utils script A script to ease patchset file list creation neded to replicate the anteater checks that occur at gate. Usage is: get-patch.sh --project sandbox --patch 39741 Where `39741` would be the refSpec number of a patchset. This would then produce `/tmp/patchset_38275` A user can than peform: `anteater --project sandbox --patchset /tmp/patchset_38275` Change-Id: Id765133607cd4840c2a9a3a61cb9d297135356e6 Signed-off-by: lhinds --- utils/get-patch.sh | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100755 utils/get-patch.sh (limited to 'utils') diff --git a/utils/get-patch.sh b/utils/get-patch.sh new file mode 100755 index 0000000..76c5a7e --- /dev/null +++ b/utils/get-patch.sh @@ -0,0 +1,85 @@ +#!/bin/bash +############################################################################## +# Copyright (c) 2017 Luke Hinds , Red Hat +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## + +GERRITUSER="lukehinds" +REPO_DIR="/home/luke/repos/opnfv" +FORMATED_DIR=$(echo $REPO_DIR |sed 's./.\\/.g') + +help (){ +echo "" +echo -e "A script to generate a patchset file to allow local anteater tests" +echo -e "in the same manner as OPNFV security audit gate checks.\n" +echo -e "Please insure GERRITUSER and REPO_DIR are set within the script\n" +echo -e "You will also need to pass the following arguments.\n" +echo -e "--project \n" +echo -e "for example:" +echo -e "--project releng\n" +echo -e " * note that the project name has to be the same as the git" +echo -e " repository name for the project\n" +echo -e "--patch \n" +echo -e "for example:" +echo -e "--patch 39741\n" +echo -e " * note that the patchset can be retrieved from the URL," +echo -e " e.g https://gerrit.opnfv.org/gerrit/#/c/39741/\n" +echo -e "The above would create the patch set as /tmp/patchset_39741\n" +echo -e "You will then be able to run anteater as follows:" +echo -e "$ anteater --project sandbox --patchset /tmp/patchset_39741" +exit +} + +# GetOpts + +usage() { + echo "Usage: $0 [--project ] [--patch ] [--help>]" 1>&2; exit 1; +} + +for arg in "$@"; do + shift + case "$arg" in + "--project") set -- "$@" "-p" ;; + "--patch") set -- "$@" "-n" ;; + "--help") set -- "$@" "-h" ;; + *) set -- "$@" "$arg" + esac +done + + +while getopts ":p:n:h" arg; do + case "${arg}" in + p) + p=${OPTARG} + ;; + n) + n=${OPTARG} + ;; + h) + help + ;; + *) + usage + ;; + esac +done +shift $((OPTIND-1)) + + +if [ -z "${p}" ] || [ -z "${n}" ]; then + usage +fi + +ssh -p 29418 ${GERRITUSER}@gerrit.opnfv.org gerrit query \ + --current-patch-set ${n} \ + --files|grep file:|sed 's/file:\s\/COMMIT_MSG//;s/file://'| \ + sed '/^\s*$/d'| \ + sed -e "s/^/${FORMATED_DIR}\/${p}\//"| tr -d " \t\r" \ + > /tmp/patchset_${n} + +echo -e "Patchset created as /tmp/patchset_${n}" +echo -e "You can now run: $ anteater --project ${p} --patchset /tmp/patchset_${n}" \ No newline at end of file -- cgit 1.2.3-korg