yetus-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a.@apache.org
Subject yetus git commit: YETUS-298. precommit jira plugin will try to download deleted attachments
Date Thu, 11 Feb 2016 02:13:07 GMT
Repository: yetus
Updated Branches:
  refs/heads/master 83342e013 -> 76a6a971f


YETUS-298. precommit jira plugin will try to download deleted attachments

Signed-off-by: Sean Busbey <busbey@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/yetus/repo
Commit: http://git-wip-us.apache.org/repos/asf/yetus/commit/76a6a971
Tree: http://git-wip-us.apache.org/repos/asf/yetus/tree/76a6a971
Diff: http://git-wip-us.apache.org/repos/asf/yetus/diff/76a6a971

Branch: refs/heads/master
Commit: 76a6a971fe61d4942bcdd782e5019cd70973dd87
Parents: 83342e0
Author: Allen Wittenauer <aw@apache.org>
Authored: Wed Feb 10 14:17:32 2016 -0800
Committer: Allen Wittenauer <aw@apache.org>
Committed: Wed Feb 10 18:12:15 2016 -0800

----------------------------------------------------------------------
 precommit/test-patch.d/jira.sh | 41 +++++++++++++++++++++++++++++--------
 1 file changed, 33 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/yetus/blob/76a6a971/precommit/test-patch.d/jira.sh
----------------------------------------------------------------------
diff --git a/precommit/test-patch.d/jira.sh b/precommit/test-patch.d/jira.sh
index bf6a598..a2920b9 100755
--- a/precommit/test-patch.d/jira.sh
+++ b/precommit/test-patch.d/jira.sh
@@ -95,6 +95,7 @@ function jira_http_fetch
   declare input=$1
   declare output=$2
 
+  yetus_debug "jira_http_fetch: ${JIRA_URL}/${input}"
   if [[ -n "${JIRA_USER}"
      && -n "${JIRA_PASSWD}" ]]; then
     ${CURL} --silent --fail \
@@ -115,6 +116,8 @@ function jira_locate_patch
   declare input=$1
   declare fileloc=$2
   declare relativeurl
+  declare retval
+  declare found=false
 
   yetus_debug "jira_locate_patch: trying ${JIRA_URL}/browse/${input}"
 
@@ -124,7 +127,6 @@ function jira_locate_patch
   fi
 
   jira_http_fetch "browse/${input}" "${PATCH_DIR}/jira"
-
   if [[ $? != 0 ]]; then
     yetus_debug "jira_locate_patch: not a JIRA."
     return 1
@@ -147,16 +149,38 @@ function jira_locate_patch
     fi
   fi
 
+  # See https://jira.atlassian.com/browse/JRA-27637 as why we can't use
+  # the REST interface here. :(
+  # the assumption here is that attachment id's are given in an
+  # ascending order. so bigger # == newer file
   #shellcheck disable=SC2016
-  relativeurl=$(${AWK} 'match($0,"/secure/attachment/[0-9]*/[^\"]*"){print substr($0,RSTART,RLENGTH)}'
"${PATCH_DIR}/jira" |
-    ${GREP} -v -e 'htm[l]*$' | sort | tail -1 | ${SED} -e 's,[ ]*$,,g')
-  PATCHURL="${JIRA_URL}${relativeurl}"
+  ${AWK} 'match($0,"/secure/attachment/[0-9]*/[^\"]*"){print substr($0,RSTART,RLENGTH)}'
"${PATCH_DIR}/jira" \
+    | ${GREP} -v -e 'htm[l]*$' \
+    | ${SED} -e 's,[ ]*$,,g' \
+    | sort -n -r -k4 -t/ \
+    | uniq \
+      > "${PATCH_DIR}/jira-attachments.txt"
 
   echo "${input} patch is being downloaded at $(date) from"
-  echo "${PATCHURL}"
-  jira_http_fetch "${relativeurl}" "${fileloc}"
-  if [[ $? != 0 ]];then
-    yetus_error "ERROR: ${input}/${PATCHURL} could not be downloaded."
+  while read -r relativeurl && [[ ${found} = false ]]; do
+    PATCHURL="${JIRA_URL}${relativeurl}"
+
+    printf "  %s -> " "${PATCHURL}"
+
+    jira_http_fetch "${relativeurl}" "${fileloc}"
+    retval=$?
+    if [[ ${retval} == 0 ]]; then
+      found=true
+      echo "Downloaded"
+    elif [[ ${retval} == 22 ]]; then
+      echo "404"
+    else
+      echo "Error (curl returned ${retval})"
+    fi
+  done < <(cat "${PATCH_DIR}/jira-attachments.txt")
+
+  if [[ "${found}" = false ]]; then
+    yetus_error "ERROR: ${input} could not be downloaded."
     cleanup_and_exit 1
   fi
 
@@ -171,6 +195,7 @@ function jira_locate_patch
     fi
   fi
   add_footer_table "JIRA Patch URL" "${PATCHURL}"
+
   return 0
 }
 


Mime
View raw message