mirror of
https://github.com/MacosPorters/betterxen.git
synced 2026-11-26 18:10:43 +00:00
From independent review of the queue follow-up: - Bot replies echoed user text (/blocked reasons, /reassign logins, file patterns) verbatim. Markers count when the bot posts them, so a reason containing an approval or done marker became a bot marker and could approve an acceptance command or hide another user's claim. Echoed text now has angle brackets and backticks escaped. - /verified accepted a 7-character prefix and ignored extra arguments; a commit with the same short prefix is cheap to make. Require exactly one full 40-character SHA, with one parser shared by decide and the check. - After a verification, the job looked up the check run by the pull request head SHA, but pull_request_target runs carry the base branch SHA, so it found nothing and || true hid it. The verify job now evaluates the same advisory check itself and no longer needs actions: write. - The issue form renders Files inside a ```text fence and the parser took "text" as a path, so any two form-created tasks overlapped. Fence lines are skipped. - A command still unanswered after lease_hours now gets a "Not decided" reply (window 2 x lease_hours) instead of being dropped silently. Each fix has a test shown to fail with the fix reverted. Refs #210, #211 Signed-off-by: elforeign <324243036+elforeign@users.noreply.github.com>
50 lines
2.5 KiB
Python
50 lines
2.5 KiB
Python
# 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
|
|
from .decide import task_index, verified_sha
|
|
|
|
|
|
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:
|
|
sha, who = verified_sha(c["body"]), c["user"]
|
|
if (sha and sha == head and who != pr.get("author") and who not in holders
|
|
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:
|
|
problems.append("independent verification missing: an eligible verifier must comment `/verified %s`" % pr.get("head_sha", ""))
|
|
return {"pr": pr["number"], "ok": not problems, "problems": problems, "verified_by": ok_by}
|