From 471c387b744c677941bae783225ebdcfa6d1cefb Mon Sep 17 00:00:00 2001 From: Zakk Date: Fri, 9 Oct 2026 10:45:20 +1100 Subject: [PATCH] scripts: stop the pkgcheck report from passing unfinished or hidden findings A failed `pmaint sync` or `pmaint regen` left empty report files, and the comment counted zero new findings and posted good. The scan now leaves a complete marker and the comment reports a scan that did not finish. New findings were keyed by package, keyword and version, so a second finding of the same keyword in an existing version was taken for the old one. They are now compared by their message without line numbers, counted as a multiset. The marker lookup only takes comments written by a bot, so a user comment that quotes the marker is not edited. Signed-off-by: Zakk --- scripts/pkgcheck-comment.sh | 4 +++- scripts/pkgcheck-new-findings.py | 28 ++++++++++++++++++---------- scripts/pkgcheck-report.sh | 2 ++ scripts/upsert-comment.sh | 2 +- 4 files changed, 24 insertions(+), 12 deletions(-) diff --git a/scripts/pkgcheck-comment.sh b/scripts/pkgcheck-comment.sh index 4f9099bfd8..111f71e695 100755 --- a/scripts/pkgcheck-comment.sh +++ b/scripts/pkgcheck-comment.sh @@ -46,7 +46,9 @@ fi else echo "*Packages scanned*: ${count}" fi - if [ "${new}" -eq 0 ]; then + if [ ! -f "$report_dir"/complete ]; then + echo "*Status*: :x: the scan did not finish, see the [run](${RUN_URL})" + elif [ "${new}" -eq 0 ]; then echo '*Status*: :white_check_mark: good' else echo '*Status*: :warning: **new issues**' diff --git a/scripts/pkgcheck-new-findings.py b/scripts/pkgcheck-new-findings.py index 6c65c6dc63..8ddcb91b42 100755 --- a/scripts/pkgcheck-new-findings.py +++ b/scripts/pkgcheck-new-findings.py @@ -2,18 +2,23 @@ """Print the pkgcheck findings a pull request adds, dropping the ones already there. pkgcheck plain output puts a package on its own line and indents its findings under -it. Findings are matched by package, keyword and version rather than by the whole -message, so one that merely moved to another line does not count as new. +it. Findings are compared without their line numbers, so one that merely moved to +another line does not count as new; a finding printed more often than in the base +report counts as new that many times. Usage: pkgcheck-new-findings.py BASE_REPORT HEAD_REPORT """ +from collections import Counter +import re import sys +LINE_NUMBERS = re.compile(r"\blines?:? \d+(?:, \d+)*") + def parse(path): - """Map (package, keyword, version) to the finding as pkgcheck printed it.""" - findings = {} + """(package, finding without line numbers, finding as pkgcheck printed it) for each finding.""" + findings = [] package = None with open(path) as report: for line in report: @@ -23,20 +28,23 @@ def parse(path): if not line.startswith(" "): package = line continue - keyword, _, rest = line.strip().partition(": ") - version = rest.split(":")[0] if rest.startswith("version ") else "" - findings[(package, keyword, version)] = line + findings.append((package, LINE_NUMBERS.sub("line", line.strip()), line)) return findings def main(): if len(sys.argv) != 3: sys.exit(__doc__) - existing = parse(sys.argv[1]) - added = {key: line for key, line in parse(sys.argv[2]).items() if key not in existing} + existing = Counter((package, finding) for package, finding, _ in parse(sys.argv[1])) + added = [] + for package, finding, line in parse(sys.argv[2]): + if existing[(package, finding)]: + existing[(package, finding)] -= 1 + else: + added.append((package, line)) package = None - for (pkg, _, _), line in added.items(): + for pkg, line in added: if pkg != package: if package is not None: print() diff --git a/scripts/pkgcheck-report.sh b/scripts/pkgcheck-report.sh index 186b8f792c..89cc3eab6f 100755 --- a/scripts/pkgcheck-report.sh +++ b/scripts/pkgcheck-report.sh @@ -44,6 +44,7 @@ case "${1:?packages, scan or stage}" in python3 scripts/pkgcheck-new-findings.py base-report.txt report.txt > new.txt echo '--- new ---'; cat new.txt echo '--- all ---'; cat report.txt + : > scan-complete ;; stage) mkdir -p pkgcheck-report @@ -51,5 +52,6 @@ case "${1:?packages, scan or stage}" in cp packages.txt pkgcheck-report/packages 2>/dev/null || : > pkgcheck-report/packages cp report.txt pkgcheck-report/report.txt 2>/dev/null || : > pkgcheck-report/report.txt cp new.txt pkgcheck-report/new.txt 2>/dev/null || : > pkgcheck-report/new.txt + [ ! -f scan-complete ] || : > pkgcheck-report/complete ;; esac diff --git a/scripts/upsert-comment.sh b/scripts/upsert-comment.sh index cf72446139..71a1d1c60e 100755 --- a/scripts/upsert-comment.sh +++ b/scripts/upsert-comment.sh @@ -9,7 +9,7 @@ body_file=${4:?body-file} comments=$(gh api "repos/$repository/issues/$issue/comments" --paginate --slurp) comment_id=$(jq -r --arg marker "$marker" ' - [.[][] | select(.body | contains($marker))][0].id // empty + [.[][] | select(.user.type == "Bot" and (.body | contains($marker)))][0].id // empty ' <<< "$comments") if [ -n "$comment_id" ]; then