Skip to content

armgit / peach

Public Imported from GitHub
0

Peach: Local-first video metadata scraper and media manager.

feat(tooling): integrate 合入前检查 PR 正文与提交说明的公开文字

longmeidao1bb6db3cbf80
diff --git a/.claude/skills/peach-issue-delivery/SKILL.md b/.claude/skills/peach-issue-delivery/SKILL.md
index e1ca07713..1509da731 100644
--- a/.claude/skills/peach-issue-delivery/SKILL.md
+++ b/.claude/skills/peach-issue-delivery/SKILL.md
@@ -5,7 +5,7 @@ description: Peach 收集或汇总用户反馈、代码交付、issue 与 PR、
# 反馈、Issue 交付与验证
-最后复核:2026-11-03
+最后复核:2026-11-04
证据来源:用户确认的维护者 PR 流程、相关修复合为一个 PR 的要求、反馈来源与优先级约定(2026-11-03 用户确认 GitGud 不收反馈)、[issue #95](https://github.com/peach-mitao/peach/issues/95)、[PR #96](https://github.com/peach-mitao/peach/pull/96)、[项目看板状态判据](../../../scripts/project_board.py)。
## 反馈收集与汇总
@@ -23,6 +23,7 @@ description: Peach 收集或汇总用户反馈、代码交付、issue 与 PR、
- PR 按可独立验收的目标分组。同一目标的实现、测试、升级补修和解除该交付 CI 失败所需的修复,默认放在同一个 PR,按可单独描述与回退的改动分提交;不按工具、工作者、文件类型或单条警告拆 PR。
- 无关目标分别评审;只有需要独立交付、发布或回退,或确需隔离产品授权、维护归属与实际冲突时才拆 PR,并在说明中写明理由。批次可包含这些独立目标的多个 PR,统一组合验证与集成。
- 提交保持 `type(scope): 描述`,实现与测试原子提交。PR 记录目标、实际改动、影响面、验证及适用的升级生效方式,具体格式见 [贡献约定](../../../CONTRIBUTING.md)。
+- PR、issue、评论与提交说明都公开,改了旧版仍留在编辑历史:不成串列出真实账本的番号、人物、标题与条数,规则效果写类型和定性结论;问题本身需要的一两个例子照写。`scripts/check_public_text.py` 对照本机账本检查,Claude 发布前钩子与 `integrate` 拦截;确需多列时正文加 `peach-public-text: <理由>`。
- 在主线合入前完成 PR 审阅与必要验证;本地组合树可用于统一验收。平台不可写时保存分支、PR 说明和验证回执,明确远端 PR 未完成,不以事后补单替代合入前审阅。
## 沟通与标记
diff --git a/scripts/agent_worktree.py b/scripts/agent_worktree.py
index 366a38474..e38100f7e 100644
--- a/scripts/agent_worktree.py
+++ b/scripts/agent_worktree.py
@@ -16,7 +16,7 @@ from pathlib import Path
if not __package__:
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
__package__ = "scripts"
-from . import (changelog, check_readme_impact, co_author, commit_subject,
+from . import (changelog, check_public_text, check_readme_impact, co_author, commit_subject,
test_evidence, test_runner, version_bump)
from .release_tag import MASTER_WRITER
@@ -207,7 +207,19 @@ def require_pull_request(worker: Path, branch: str, target_branch: str, head: st
raise WorkspaceError(f"PR 目标分支不是 {target_branch}")
body = pr.get("body") if isinstance(pr.get("body"), str) else ""
refs = [line.strip() for line in body.splitlines() if ISSUE_LINK.fullmatch(line.strip())]
- return {"url": pr["url"], "head": head, "base": target_branch, "refs": refs}
+ return {"url": pr["url"], "head": head, "base": target_branch, "refs": refs, "body": body}
+
+
+def require_public_text(repo: Path, texts: dict[str, str]) -> None:
+ """PR 正文与提交说明都公开在 GitHub 上:成串列出本机馆藏细节的拒收。
+
+ 判据在 `scripts/check_public_text.py`,只读本机账本;没有账本的机器放行。
+ """
+ library = check_public_text.load_library(repo)
+ found = [f"{name}({';'.join(problems)})" for name, text in texts.items()
+ for problems in [check_public_text.problems(text, library)] if problems]
+ if found:
+ raise WorkspaceError("公开文字成串列出了馆藏细节,改写 PR 正文或提交说明后再合入:" + ",".join(found))
def merge_message(branch: str, pull_request: dict[str, object]) -> str:
@@ -277,6 +289,10 @@ def _integrate_locked(repo: Path, worker_branch: str,
worker_head = _git(main, "rev-parse", worker_branch).stdout.strip()
require_verified(workers[0], target_branch, worker_files)
pull_request = require_pull_request(workers[0], worker_branch, target_branch, worker_head)
+ commits = _git(main, "log", "--format=%h%x00%B%x1e", f"{base}..{worker_head}").stdout
+ require_public_text(main, {"PR 正文": str(pull_request.get("body") or ""), **{
+ f"提交 {sha}": message for sha, _, message in
+ (entry.strip().partition("\0") for entry in commits.split("\x1e") if entry.strip())}})
if _git(main, "rev-parse", worker_branch).stdout.strip() != worker_head or \
_git(workers[0], "rev-parse", "HEAD").stdout.strip() != worker_head:
raise WorkspaceError("验证检查期间工作者分支改变,请重试")
diff --git a/tests/test_agent_worktree.py b/tests/test_agent_worktree.py
index 884ab37cc..17546d264 100644
--- a/tests/test_agent_worktree.py
+++ b/tests/test_agent_worktree.py
@@ -13,7 +13,7 @@ from pathlib import Path
from threading import Event
from unittest import mock
-from scripts import agent_worktree, release_tag
+from scripts import agent_worktree, check_public_text, release_tag
from scripts.agent_worktree import (
WorkspaceError, _git, _lines, create, integrate, processes_under, prune, ready,
)
@@ -264,7 +264,7 @@ class PullRequestIntegrationTests(_WorktreeCase):
with self.github() as query:
result = integrate(self.repo, self.branch)
self.assertEqual(result["pull_request"],
- {"url": self.pr["url"], "head": self.head, "base": "master", "refs": []})
+ {"url": self.pr["url"], "head": self.head, "base": "master", "refs": [], "body": ""})
self.assertEqual((self.repo / "worker.txt").read_text(encoding="utf-8"), "worker\n")
command = query.call_args.args[0]
self.assertEqual(command[:4], ["gh", "pr", "view", self.branch])
@@ -285,6 +285,25 @@ class PullRequestIntegrationTests(_WorktreeCase):
self.assertEqual(_git(self.repo, "log", "-1", "--format=%B").stdout.strip(),
f"Merge branch '{self.branch}' (#12)\n\n" + "\n".join(refs))
+ def test_library_lists_in_the_body_or_a_commit_message_are_refused(self):
+ """PR 正文和提交说明公开在 GitHub 上,成串列出本机馆藏的不合入;问题需要的一两个例子照常合入。"""
+ library = check_public_text.Library(codes={"ZZQ-101", "ZZQ-102", "ZZQ-103"}, names={"测试女优甲", "测试女优乙"})
+ listed = "剩下要人判的:ZZQ-101、ZZQ-102、ZZQ-103。"
+ with mock.patch.object(check_public_text, "load_library", return_value=library):
+ with self.github(json.dumps({**self.pr, "body": listed})):
+ self.assert_refused("PR 正文(番号 3 个")
+ (self.worker / "worker.txt").write_text("worker again\n", encoding="utf-8")
+ commit(self.worker, "fix(tooling): 测试女优甲与测试女优乙的别名")
+ self.pr["headRefOid"] = _git(self.worker, "rev-parse", "HEAD").stdout.strip()
+ with self.github(json.dumps({**self.pr, "body": "只修 ZZQ-101 的前缀。"})):
+ self.assertRaisesRegex(WorkspaceError, "提交 [0-9a-f]+(人物 2 个", integrate, self.repo, self.branch)
+
+ def test_a_single_example_or_a_machine_without_a_ledger_still_integrates(self):
+ library = check_public_text.Library(codes={"ZZQ-101", "ZZQ-102", "ZZQ-103"})
+ for loaded, body in ((library, "只修 ZZQ-101 的前缀。"), (None, "ZZQ-101、ZZQ-102、ZZQ-103")):
+ with self.subTest(body=body), mock.patch.object(check_public_text, "load_library", return_value=loaded):
+ agent_worktree.require_public_text(self.repo, {"PR 正文": body})
+
def test_an_older_remote_head_and_another_base_are_refused(self):
for field, value, message in (("headRefOid", "0" * 40, "提交.*不一致"),
("baseRefName", "other", "目标分支"),