From commits-return-1439-apmail-knox-commits-archive=knox.apache.org@knox.apache.org Thu Jan 21 20:36:21 2016 Return-Path: X-Original-To: apmail-knox-commits-archive@minotaur.apache.org Delivered-To: apmail-knox-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 15CD118A0F for ; Thu, 21 Jan 2016 20:36:21 +0000 (UTC) Received: (qmail 1450 invoked by uid 500); 21 Jan 2016 20:36:20 -0000 Delivered-To: apmail-knox-commits-archive@knox.apache.org Received: (qmail 1426 invoked by uid 500); 21 Jan 2016 20:36:20 -0000 Mailing-List: contact commits-help@knox.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@knox.apache.org Delivered-To: mailing list commits@knox.apache.org Received: (qmail 1417 invoked by uid 99); 21 Jan 2016 20:36:20 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 21 Jan 2016 20:36:20 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id ACBBFDFF94; Thu, 21 Jan 2016 20:36:20 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: kminder@apache.org To: commits@knox.apache.org Message-Id: <0155950fed244c9684cac0e9aa5bef03@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: knox git commit: Add script used by PreCommit-KNOX-Scan jenkins job. Date: Thu, 21 Jan 2016 20:36:20 +0000 (UTC) Repository: knox Updated Branches: refs/heads/master fd0d5197b -> 30a5f7ece Add script used by PreCommit-KNOX-Scan jenkins job. Project: http://git-wip-us.apache.org/repos/asf/knox/repo Commit: http://git-wip-us.apache.org/repos/asf/knox/commit/30a5f7ec Tree: http://git-wip-us.apache.org/repos/asf/knox/tree/30a5f7ec Diff: http://git-wip-us.apache.org/repos/asf/knox/diff/30a5f7ec Branch: refs/heads/master Commit: 30a5f7eceba22bdf8723f49e532b4671a2cdf1b3 Parents: fd0d519 Author: Kevin Minder Authored: Thu Jan 21 15:36:08 2016 -0500 Committer: Kevin Minder Committed: Thu Jan 21 15:36:16 2016 -0500 ---------------------------------------------------------------------- ...test-patch-find-new-patch-available-jiras.sh | 125 +++++++++++++++++++ 1 file changed, 125 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/knox/blob/30a5f7ec/dev-support/test-patch-find-new-patch-available-jiras.sh ---------------------------------------------------------------------- diff --git a/dev-support/test-patch-find-new-patch-available-jiras.sh b/dev-support/test-patch-find-new-patch-available-jiras.sh new file mode 100755 index 0000000..3a3b639 --- /dev/null +++ b/dev-support/test-patch-find-new-patch-available-jiras.sh @@ -0,0 +1,125 @@ +#!/bin/bash +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +if [ "${TESTPATCHDEBUG}" == "true" ] ; then + set -x +fi + +BASEDIR=$(pwd) +TEMPDIR=${BASEDIR}/tmp + +JIRAAVAILPATCHQUERY="https://issues.apache.org/jira/sr/jira.issueviews:searchrequest-xml/temp/SearchRequest.xml?jqlQuery=project+in+%28KNOX%29+AND+status+%3D+%22Patch+Available%22+ORDER+BY+updated+DESC&tempMax=1000" +TESTPATCHJOBURL="https://builds.apache.org/job/PreCommit-Knox-Build" +TOKEN="" +SUBMIT="false" +DELETEHISTORYFILE="false" + +RUNTESTSFILE=${BASEDIR}/TESTED_PATCHES.txt + +printUsage() { + echo "Usage: $0 " + echo " --submit --token=" + echo " [--delete-history-file]" + echo " [--script-debug]" + echo +} +############################################################################### +parseArgs() { + for i in $* + do + case $i in + --submit) + SUBMIT="true" + ;; + --token=*) + TOKEN=${i#*=} + ;; + --script-debug) + DEBUG="-x" + ;; + --delete-history-file) + DELETEHISTORYFILE="true" + ;; + *) + echo "Invalid option" + echo + printUsage + exit 1 + ;; + esac + done + if [[ "$SUBMIT" == "true" && "${TOKEN}" == "" ]] ; then + echo "Token has not been specified" + echo + printUsage + exit 1 + fi +} +############################################################################### +findAndSubmitAvailablePatches() { + +## Grab all the key (issue numbers) and largest attachment id for each item in the XML +curl --fail --location --retry 3 "${JIRAAVAILPATCHQUERY}" > ${TEMPDIR}/patch-availables.xml +if [ "$?" != "0" ] ; then + echo "Could not retrieve available patches from JIRA" + exit 1 +fi +xpath -q -e "//item/key/text() | //item/attachments/attachment[not(../attachment/@id > @id)]/@id" ${TEMPDIR}/patch-availables.xml > ${TEMPDIR}/patch-attachments.element + +### Replace newlines with nothing, then replace id=" with =, then replace " with newline +### to yield lines with pairs (issueNumber,largestAttachmentId). Example: KNOX-123,456984 +cat ${TEMPDIR}/patch-attachments.element | awk '{ if ( $1 ~ /^KNOX\-/) {JIRA=$1 }; if ($1 ~ /id=/) { print JIRA","$1} }' | sed 's/id\="//' | sed 's/"//' > ${TEMPDIR}/patch-availables.pair + +### Iterate through issue list and find the (issueNumber,largestAttachmentId) pairs that have +### not been tested (ie don't already exist in the patch_tested.txt file +touch ${RUNTESTSFILE} +cat ${TEMPDIR}/patch-availables.pair | while read PAIR ; do + set +e + COUNT=`grep -c "$PAIR" ${RUNTESTSFILE}` + set -e + if [ "$COUNT" -lt "1" ] ; then + ### Parse $PAIR into project, issue number, and attachment id + ISSUE=`echo $PAIR | sed -e "s/,.*$//"` + echo "Found new patch for issue $ISSUE" + if [ "$SUBMIT" == "true" ]; then + ### Kick off job + echo "Submitting job for issue $ISSUE" + curl --fail --location --retry 3 "${TESTPATCHJOBURL}/buildWithParameters?token=${TOKEN}&JIRA_NUMBER=${ISSUE}" > /dev/null + if [ "$?" != "0" ] ; then + echo "Could not submit precommit job for $ISSUE" + exit 1 + fi + fi + ### Mark this pair as tested by appending to file + echo "$PAIR" >> ${RUNTESTSFILE} + fi +done +} +############################################################################### + +mkdir ${TEMPDIR} 2>&1 $STDOUT + +parseArgs "$@" + +if [ -n "${DEBUG}" ] ; then + set -x +fi + +if [ "${DELETEHISTORYFILE}" == "true" ] ; then + rm ${RUNTESTSFILE} +fi + +findAndSubmitAvailablePatches + +exit 0