yetus-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a.@apache.org
Subject [yetus] branch master updated: YETUS-751. line comments generate too many messages; not obvious how to disable
Date Fri, 04 Jan 2019 06:21:25 GMT
This is an automated email from the ASF dual-hosted git repository.

aw pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/yetus.git


The following commit(s) were added to refs/heads/master by this push:
     new 16e34af  YETUS-751. line comments generate too many messages; not obvious how to
disable
16e34af is described below

commit 16e34afcc65a0ea7e42300b1cb212d9ec6a1105c
Author: Allen Wittenauer <aw@apache.org>
AuthorDate: Mon Dec 31 09:58:23 2018 -0800

    YETUS-751. line comments generate too many messages; not obvious how to disable
    
    Signed-off-by: Allen Wittenauer <aw@apache.org>
---
 precommit/src/main/shell/test-patch.d/github.sh    |  19 ++--
 precommit/src/main/shell/test-patch.d/hadolint.sh  |   2 +-
 precommit/src/main/shell/test-patch.d/jshint.sh    |   2 +-
 .../src/main/shell/test-patch.d/shellcheck.sh      |   2 +-
 precommit/src/main/shell/test-patch.d/shelldocs.sh |   2 +-
 .../src/main/shell/test-patch.d/whitespace.sh      |   2 +-
 precommit/src/main/shell/test-patch.d/yamllint.sh  |   2 +-
 precommit/src/main/shell/test-patch.sh             | 123 ++++++++++++++++++---
 8 files changed, 122 insertions(+), 32 deletions(-)

diff --git a/precommit/src/main/shell/test-patch.d/github.sh b/precommit/src/main/shell/test-patch.d/github.sh
index 17df408..be1893d 100755
--- a/precommit/src/main/shell/test-patch.d/github.sh
+++ b/precommit/src/main/shell/test-patch.d/github.sh
@@ -421,19 +421,16 @@ function github_locate_patch
 
 function github_linecomments
 {
-  declare plugin=$1
-  declare file=$2
+  declare file=$1
   # shellcheck disable=SC2034
-  declare realline=$3
-  declare uniline=$4
-  declare text=$5
+  declare linenum=$2
+  declare uniline=$3
+  shift 3
+  declare -a text
+  text=("$@")
   declare tempfile="${PATCH_DIR}/ghcomment.$$.${RANDOM}"
   declare githubauth
 
-  if [[ "${file}" =~ ^./ ]]; then
-    file=${file##./}
-  fi
-
   if [[ -z "${GITHUB_COMMITSHA}" ]]; then
     GITHUB_COMMITSHA=$("${GREP}" \"sha\" "${PATCH_DIR}/github-pull.json" 2>/dev/null \
       | head -1 \
@@ -447,11 +444,13 @@ function github_linecomments
   # build our REST post
   {
     printf "{\"body\":\""
-    echo "${plugin}: ${text}" \
+    for line in "${text[@]}"; do
+      echo "${line}" \
       | "${SED}" -e 's,\\,\\\\,g' \
         -e 's,\",\\\",g' \
         -e 's,$,\\r\\n,g' \
       | tr -d '\n'
+    done
     echo "\","
     echo "\"commit_id\":\"${GITHUB_COMMITSHA}\","
     echo "\"path\":\"${file}\","
diff --git a/precommit/src/main/shell/test-patch.d/hadolint.sh b/precommit/src/main/shell/test-patch.d/hadolint.sh
index b5e068b..9e1ce93 100755
--- a/precommit/src/main/shell/test-patch.d/hadolint.sh
+++ b/precommit/src/main/shell/test-patch.d/hadolint.sh
@@ -179,7 +179,7 @@ function hadolint_postapply
   if [[ ${diffPostpatch} -gt 0 ]] ; then
     add_vote_table -1 hadolint "${BUILDMODEMSG} ${statstring}"
     add_footer_table hadolint "@@BASE@@/diff-patch-hadolint.txt"
-    bugsystem_linecomments "hadolint" "${PATCH_DIR}/diff-patch-hadolint.txt"
+    bugsystem_linecomments_queue "hadolint" "${PATCH_DIR}/diff-patch-hadolint.txt"
     return 1
   elif [[ ${fixedpatch} -gt 0 ]]; then
     add_vote_table +1 hadolint "${BUILDMODEMSG} ${statstring}"
diff --git a/precommit/src/main/shell/test-patch.d/jshint.sh b/precommit/src/main/shell/test-patch.d/jshint.sh
index 0fcf0de..0646a30 100755
--- a/precommit/src/main/shell/test-patch.d/jshint.sh
+++ b/precommit/src/main/shell/test-patch.d/jshint.sh
@@ -184,7 +184,7 @@ function jshint_postapply
   if [[ ${diffPostpatch} -gt 0 ]] ; then
     add_vote_table -1 jshint "${BUILDMODEMSG} ${statstring}"
     add_footer_table jshint "@@BASE@@/diff-patch-jshint.txt"
-    bugsystem_linecomments "jshint" "${PATCH_DIR}/diff-patch-jshint.txt"
+    bugsystem_linecomments_queue "jshint" "${PATCH_DIR}/diff-patch-jshint.txt"
     return 1
   elif [[ ${fixedpatch} -gt 0 ]]; then
     add_vote_table +1 jshint "${BUILDMODEMSG} ${statstring}"
diff --git a/precommit/src/main/shell/test-patch.d/shellcheck.sh b/precommit/src/main/shell/test-patch.d/shellcheck.sh
index 59ef98b..795466a 100755
--- a/precommit/src/main/shell/test-patch.d/shellcheck.sh
+++ b/precommit/src/main/shell/test-patch.d/shellcheck.sh
@@ -240,7 +240,7 @@ function shellcheck_postapply
   if [[ ${diffPostpatch} -gt 0 ]] ; then
     add_vote_table -1 shellcheck "${BUILDMODEMSG} ${statstring}"
     add_footer_table shellcheck "@@BASE@@/diff-patch-shellcheck.txt"
-    bugsystem_linecomments "shellcheck" "${PATCH_DIR}/diff-patch-shellcheck.txt"
+    bugsystem_linecomments_queue "shellcheck" "${PATCH_DIR}/diff-patch-shellcheck.txt"
     return 1
   elif [[ ${fixedpatch} -gt 0 ]]; then
     add_vote_table +1 shellcheck "${BUILDMODEMSG} ${statstring}"
diff --git a/precommit/src/main/shell/test-patch.d/shelldocs.sh b/precommit/src/main/shell/test-patch.d/shelldocs.sh
index 67f94d9..ce998dd 100755
--- a/precommit/src/main/shell/test-patch.d/shelldocs.sh
+++ b/precommit/src/main/shell/test-patch.d/shelldocs.sh
@@ -177,7 +177,7 @@ function shelldocs_postapply
   if [[ ${diffPostpatch} -gt 0 ]] ; then
     add_vote_table -1 shelldocs "${BUILDMODEMSG} ${statstring}"
     add_footer_table shelldocs "@@BASE@@/diff-patch-shelldocs.txt"
-    bugsystem_linecomments "shelldocs" "${PATCH_DIR}/diff-patch-shelldocs.txt"
+    bugsystem_linecomments_queue "shelldocs" "${PATCH_DIR}/diff-patch-shelldocs.txt"
     return 1
   elif [[ ${fixedpatch} -gt 0 ]]; then
     add_vote_table +1 shelldocs "${BUILDMODEMSG} ${statstring}"
diff --git a/precommit/src/main/shell/test-patch.d/whitespace.sh b/precommit/src/main/shell/test-patch.d/whitespace.sh
index fb4e923..492f723 100755
--- a/precommit/src/main/shell/test-patch.d/whitespace.sh
+++ b/precommit/src/main/shell/test-patch.d/whitespace.sh
@@ -64,7 +64,7 @@ function whitespace_linecomment_reporter
     "${file}" \
     > "${tmpfile}"
 
-  bugsystem_linecomments "whitespace:" "${tmpfile}"
+  bugsystem_linecomments_queue "whitespace" "${tmpfile}"
   rm "${tmpfile}"
 }
 
diff --git a/precommit/src/main/shell/test-patch.d/yamllint.sh b/precommit/src/main/shell/test-patch.d/yamllint.sh
index b3c4a5b..3d852d8 100755
--- a/precommit/src/main/shell/test-patch.d/yamllint.sh
+++ b/precommit/src/main/shell/test-patch.d/yamllint.sh
@@ -141,7 +141,7 @@ function yamllint_postapply
   if [[ ${diffPostpatch} -gt 0 ]] ; then
     add_vote_table -1 yamllint "${BUILDMODEMSG} ${statstring}"
     add_footer_table yamllint "@@BASE@@/diff-patch-yamllint.txt"
-    bugsystem_linecomments "yamllint" "${PATCH_DIR}/diff-patch-yamllint.txt"
+    bugsystem_linecomments_queue "yamllint" "${PATCH_DIR}/diff-patch-yamllint.txt"
     return 1
   elif [[ ${fixedpatch} -gt 0 ]]; then
     add_vote_table +1 yamllint "${BUILDMODEMSG} ${statstring}"
diff --git a/precommit/src/main/shell/test-patch.sh b/precommit/src/main/shell/test-patch.sh
index 8e62afa..4ea5cb1 100755
--- a/precommit/src/main/shell/test-patch.sh
+++ b/precommit/src/main/shell/test-patch.sh
@@ -860,6 +860,9 @@ function parse_args
       --linecomments=*)
         BUGLINECOMMENTS=${i#*=}
         BUGLINECOMMENTS=${BUGLINECOMMENTS//,/ }
+        if [[ -z "${BUGLINECOMMENTS}" ]]; then
+          BUGLINECOMMENTS=" "
+        fi
       ;;
       --modulelist=*)
         yetus_comma_to_array USER_MODULE_LIST "${i#*=}"
@@ -2292,40 +2295,121 @@ function check_unittests
   return 0
 }
 
-## @description  Write comments onto bug systems that have code review support.
+## @description  Queue up comments to write into bug systems
+## @description  that have code review support, if such support
+## @description  enabled/available.
 ## @description  File should be in the form of "file:line:comment"
 ## @audience     public
 ## @stability    evolving
 ## @replaceable  no
+## @param        plugin
 ## @param        filename
-function bugsystem_linecomments
+function bugsystem_linecomments_queue
 {
-  declare title=$1
+  declare plugin=$1
   declare fn=$2
   declare line
-  declare bugs
-  declare realline
+  declare linenum
   declare text
+
+  if [[ ! -f "${GITUNIDIFFLINES}" ]]; then
+    return
+  fi
+
+  while read -r line; do
+    file=$(echo "${line}" | cut -f1 -d:)
+    if [[ "${file}" =~ ^\./ ]]; then
+      file=${file:2}
+    fi
+    linenum=$(echo "${line}" | cut -f2 -d:)
+    text=$(echo "${line}" | cut -f3- -d:)
+
+    echo "${file}:${linenum}:${plugin}:${text}" >> "${PATCH_DIR}/linecomments-in.txt"
+
+  done < "${fn}"
+}
+
+## @description  Call relevant bug systems to write comments
+## @audience     private
+## @stability    evolving
+## @replaceable  no
+function bugsystem_linecomments_writer
+{
+  declare fn=$1
+  declare linenum=$2
+  shift 2
+  declare -a text
+  text=("$@")
   declare idxline
   declare uniline
 
+  if [[ -z "${fn}" ]]; then
+    return
+  fi
+
+  idxline="${fn}:${linenum}:"
+  uniline=$("${GREP}" "${idxline}" "${GITUNIDIFFLINES}" | cut -f3 -d: )
+
+  for bugs in ${BUGLINECOMMENTS}; do
+    if declare -f "${bugs}_linecomments" >/dev/null;then
+      "${bugs}_linecomments" "${fn}" "${linenum}" "${uniline}" "${linetext[@]}"
+    fi
+  done
+}
+
+## @description  Write all of the bugsystem linecomments
+## @audience     public
+## @stability    evolving
+## @replaceable  no
+function bugsystem_linecomments_trigger
+{
+  declare line
+  declare fn
+  declare linenum
+  declare text
+  declare -a linetext
+  declare prevnum
+  declare prevfn
+  declare plugin
+
   if [[ ! -f "${GITUNIDIFFLINES}" ]]; then
     return
   fi
 
+  # sort the file such that all files and lines are now next to each other
+  sort "${PATCH_DIR}/linecomments-in.txt" > "${PATCH_DIR}/linecomments-sorted.txt"
+
   while read -r line;do
-    file=$(echo "${line}" | cut -f1 -d:)
-    realline=$(echo "${line}" | cut -f2 -d:)
+    fn=$(echo "${line}" | cut -f1 -d:)
+    if [[ -z "${prevfn}" ]]; then
+      prevfn=${fn}
+    fi
+
+    linenum=$(echo "${line}" | cut -f2 -d:)
+    if [[ -z "${prevnum}" ]]; then
+      prevnum=${linenum}
+    fi
+
     text=$(echo "${line}" | cut -f3- -d:)
-    idxline="${file}:${realline}:"
-    uniline=$(${GREP} "${idxline}" "${GITUNIDIFFLINES}" | cut -f3 -d: )
 
-    for bugs in ${BUGLINECOMMENTS}; do
-      if declare -f "${bugs}_linecomments" >/dev/null;then
-        "${bugs}_linecomments" "${title}" "${file}" "${realline}" "${uniline}" "${text}"
-      fi
-    done
-  done < "${fn}"
+    if [[ "${prevfn}" == "${fn}" ]] &&
+       [[ ${prevnum} -eq ${linenum} ]]; then
+      linetext+=("${text}")
+      continue
+    fi
+
+    bugsystem_linecomments_writer "${prevfn}" "${prevnum}" "${linetext[@]}"
+    prevfn=${fn}
+    prevnum=${linenum}
+    linetext=("${text}")
+  done < "${PATCH_DIR}/linecomments-sorted.txt"
+
+  bugsystem_linecomments_writer "${prevfn}" "${prevnum}" "${linetext[@]}"
+  if [[ "${YETUS_SHELL_SCRIPT_DEBUG}" = true ]]; then
+    yetus_debug "Keeping linecomments files for debugging"
+  else
+    rm "${PATCH_DIR}/linecomments-in.txt" "${PATCH_DIR}/linecomments-sorted.txt"
+  fi
 }
 
 ## @description  Write the final output to the selected bug system
@@ -2344,6 +2428,8 @@ function bugsystem_finalreport
   fi
   add_footer_table "Powered by" "Apache Yetus ${VERSION} http://yetus.apache.org"
 
+  bugsystem_linecomments_trigger
+
   for bugs in ${BUGCOMMENTS}; do
     if declare -f "${bugs}_finalreport" >/dev/null;then
       "${bugs}_finalreport" "${@}"
@@ -3108,7 +3194,12 @@ function initialize
     BUGCOMMENTS="${BUGCOMMENTS} console"
   fi
 
-  BUGLINECOMMENTS=${BUGLINECOMMENTS:-${BUGCOMMENTS}}
+
+  if [[ "${BUGLINECOMMENTS}" == " " ]]; then
+    BUGLINECOMMENTS=""
+  else
+    BUGLINECOMMENTS=${BUGLINECOMMENTS:-${BUGCOMMENTS}}
+  fi
 
   # we need to do this BEFORE plugins initialize
   # because they may change what they do based upon


Mime
View raw message