Files
gentoo-zh/scripts/pkgcheck-new-findings.py
T
Zakk ed5071f22d .github/workflows: pkgcheck: comment scan results for changed packages
因为仓库级扫描只在 NonexistentDeps 上失败,所以改动的 ebuild 上 warning 级别的问题
不会让 CI 变红。

因为 pkgcheck 会 source 它扫描的 ebuild,等于执行 PR 里的代码,所以扫描只拿只读
token,评论由 workflow_run 另起一个不检出该代码的任务发出。

因为包里原有的问题会淹没 PR 引入的那几条,所以基线分支也扫一遍,评论只列新增的。
2026-07-29 22:40:59 +10:00

50 lines
1.4 KiB
Python
Executable File

#!/usr/bin/env python3
"""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.
Usage: pkgcheck-new-findings.py BASE_REPORT HEAD_REPORT
"""
import sys
def parse(path):
"""Map (package, keyword, version) to the finding as pkgcheck printed it."""
findings = {}
package = None
with open(path) as report:
for line in report:
line = line.rstrip("\n")
if not line:
continue
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
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}
package = None
for (pkg, _, _), line in added.items():
if pkg != package:
if package is not None:
print()
print(pkg)
package = pkg
print(line)
if __name__ == "__main__":
main()