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 <zakk@gentoozh.org>
This commit is contained in:
1 parent
2870a83aa4
commit
471c387b74
4 files changed
+24
-12
No files matched your search
@@ -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**'
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user