2026-11-24 00:09:38 -06:00
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
"""Pull request checks computed from data only. PR code is never fetched or run."""
|
|
|
|
|
from . import config as cfgmod
|
|
|
|
|
from . import lease as L
|
|
|
|
|
from .patterns import path_matches, patterns_overlap
|
2026-11-24 01:05:28 -06:00
|
|
|
from .decide import task_index, verified_sha
|
2026-11-24 00:09:38 -06:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def verified_by(pr, comments, tasks, cfg):
|
|
|
|
|
"""Eligible verifier logins whose /verified comment names the current head SHA."""
|
|
|
|
|
head, out = pr.get("head_sha", ""), []
|
|
|
|
|
holders = {tasks[i]["holder"] for i in L.linked_issues(pr.get("body")) if i in tasks}
|
|
|
|
|
for c in comments:
|
2026-11-24 01:05:28 -06:00
|
|
|
sha, who = verified_sha(c["body"]), c["user"]
|
|
|
|
|
if (sha and sha == head and who != pr.get("author") and who not in holders
|
2026-11-24 00:09:38 -06:00
|
|
|
and cfgmod.is_verifier(cfg, who) and who not in out):
|
|
|
|
|
out.append(who)
|
|
|
|
|
return out
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def check_pr(state, cfg, now):
|
|
|
|
|
pr, comments = state["pr"], state.get("pr_comments", [])
|
|
|
|
|
tasks = task_index(state)
|
|
|
|
|
problems = []
|
|
|
|
|
links = [i for i in L.linked_issues(pr.get("body")) if i in tasks]
|
|
|
|
|
if not links:
|
|
|
|
|
problems.append("no linked task: the pull request body must contain `Closes #N` for a claimed task")
|
|
|
|
|
for n in links:
|
|
|
|
|
t = tasks[n]
|
|
|
|
|
if "agent:claimed" not in t["labels"]:
|
|
|
|
|
problems.append("task #%d is not claimed" % n)
|
|
|
|
|
continue
|
|
|
|
|
if t["holder"] != pr["author"]:
|
|
|
|
|
problems.append("task #%d is held by %s, not the pull request author" % (n, t["holder"] or "nobody"))
|
|
|
|
|
outside = [f for f in pr.get("files", []) if not any(path_matches(f, p) for p in t["files"])]
|
|
|
|
|
if outside:
|
|
|
|
|
problems.append("files outside task #%d ownership: %s" % (n, ", ".join(outside[:10])))
|
|
|
|
|
if L.lapsed(t, state.get("task_comments", {}).get(str(n), []), [pr], cfg, now):
|
|
|
|
|
problems.append("task #%d claim has lapsed and the head has not been pushed within %s hours" % (n, cfg["lease_hours"]))
|
|
|
|
|
for other in state.get("prs", []):
|
|
|
|
|
if other["number"] == pr["number"]:
|
|
|
|
|
continue
|
|
|
|
|
shared = sorted(set(pr.get("files", [])) & set(other.get("files", [])))
|
|
|
|
|
if shared:
|
|
|
|
|
problems.append("overlaps open PR #%d on: %s" % (other["number"], ", ".join(shared[:10])))
|
|
|
|
|
ok_by = verified_by(pr, comments, tasks, cfg)
|
|
|
|
|
if not ok_by:
|
2026-11-24 01:05:28 -06:00
|
|
|
problems.append("independent verification missing: an eligible verifier must comment `/verified %s`" % pr.get("head_sha", ""))
|
2026-11-24 00:09:38 -06:00
|
|
|
return {"pr": pr["number"], "ok": not problems, "problems": problems, "verified_by": ok_by}
|