Peach: Local-first video metadata scraper and media manager.
fix(tooling): 合并 Issue 看板同步并保留两小时修改窗口
longmeidaoe54b084b0ced
diff --git a/.github/workflows/project-board.yml b/.github/workflows/project-board.ymlindex 7db7a3169..fa3f4325c 100644--- a/.github/workflows/project-board.yml+++ b/.github/workflows/project-board.yml@@ -1,8 +1,6 @@name: 项目看板同步on:- issues:- types: [opened, reopened, closed, labeled, unlabeled, edited]pull_request_target:types: [opened, reopened, closed, edited, ready_for_review, converted_to_draft]release:@@ -11,7 +9,8 @@ on:branches: [master]workflow_dispatch:schedule:- - cron: '17 */6 * * *'+ # Issue 的编辑、标签与开闭合并到小时同步,避免模板补齐期间逐事件移动。+ - cron: '17 * * * *'permissions:contents: readdiff --git a/CONTRIBUTING.md b/CONTRIBUTING.mdindex 6fa787c54..d43fa1022 100644--- a/CONTRIBUTING.md+++ b/CONTRIBUTING.md@@ -17,9 +17,11 @@ Issue 按 [`.github/ISSUE_TEMPLATE/`](.github/ISSUE_TEMPLATE/) 的模板写:gh issue create --repo peach-mitao/peach --title "<标题>" --type Bug --body-file <填好的模板>```-建议把 `Bug` 换成 `Feature`;没有设置类型的权限时省略 `--type`,按模板章节写的 issue 会自动补上类型。正文写给维护者和其他用户看,用通用技术说法;`AGENTS.md` 与技能里的术语和交付格式只用于改代码,不用于 issue。用命令行或 API 提交、既没有类型也没有模板章节的 issue 会被自动关闭,按模板补齐章节后自动重开。+建议把 `Bug` 换成 `Feature`;没有设置类型的权限时省略 `--type`,按模板章节写的 issue 会自动补上类型。正文写给维护者和其他用户看,用通用技术说法;`AGENTS.md` 与技能里的术语和交付格式只用于改代码,不用于 issue。外部新 issue 无论通过网页、命令行还是 API 提交,缺少模板章节都会自动关闭;已有类型不豁免检查,按模板补齐章节后自动重开。-Write issues with the templates in [`.github/ISSUE_TEMPLATE/`](.github/ISSUE_TEMPLATE/): `bug_report.md` for bugs, `feature_request.md` for features. Keep the template headings in order and fill in each one; drop optional sections you have nothing for, and put extra material such as a root-cause analysis after the template sections. The web form under New issue is the easiest path. When an AI tool or the command line submits the issue, copy the template file, remove the leading `---` block and the `<!-- -->` comments, fill it in, and submit it with the command above; use `--type Feature` for features, and leave out `--type` if you lack permission to set it: issues that follow a template get their type automatically. Write for maintainers and other users in plain technical language; the terms and delivery format in `AGENTS.md` and the skills are for code changes, not issues. Issues submitted through the command line or the API with neither a type nor the template sections are closed automatically, and reopen once the sections are filled in.+Write issues with the templates in [`.github/ISSUE_TEMPLATE/`](.github/ISSUE_TEMPLATE/): `bug_report.md` for bugs, `feature_request.md` for features. Keep the template headings in order and fill in each one; drop optional sections you have nothing for, and put extra material such as a root-cause analysis after the template sections. The web form under New issue is the easiest path. When an AI tool or the command line submits the issue, copy the template file, remove the leading `---` block and the `<!-- -->` comments, fill it in, and submit it with the command above; use `--type Feature` for features, and leave out `--type` if you lack permission to set it: issues that follow a template get their type automatically. Write for maintainers and other users in plain technical language; the terms and delivery format in `AGENTS.md` and the skills are for code changes, not issues. New external issues without template sections are closed automatically regardless of their submission method or existing type, and reopen once the sections are filled in.++Issue 的看板变更每小时集中同步,新条目先通过模板检查再加入看板。已有条目因待补模板关闭时,关闭后的 2 小时内保持原位置;到期仍未补齐并重开,在后续同步时移到「已取消」。PR、主线提交与发布事件仍可触发同步,同样遵守这段缓冲。公开截图、录屏和附件使用不含露骨画面的演示资料,并遮盖隐私信息;不要上传影片、封面原图或数据库。公开内容与素材许可要求见[文档规范](docs/WRITING.md#公开与私有记录)。diff --git a/docs/REUSE.md b/docs/REUSE.mdindex d6f8f2b79..9bde4188e 100644--- a/docs/REUSE.md+++ b/docs/REUSE.md@@ -313,7 +313,7 @@ Windows 复用 FFmpeg 的 D3D11VA 解码与 `h264_amf`、`h264_qsv` 编码,沿## GitHub 项目看板-用户反馈归属应用仓库 `peach-mitao/peach`,维护者项目任务归属 `peach-mitao/peach-roadmap`,共同使用一个公开 Project。集中在应用仓库处理事件并每 6 小时补查规划仓库,凭据仅保留在应用仓库。Issue 关联使用仓库名与编号,迁移映射兼容已存在的关联行;交付版本始终按应用仓库的主线提交和发布制品核验。+用户反馈归属应用仓库 `peach-mitao/peach`,维护者项目任务归属 `peach-mitao/peach-roadmap`,共同使用一个公开 Project。集中在应用仓库处理 PR、主线与发布事件,每小时同步两仓 Issue,不逐次响应 Issue 的编辑、标签与开闭事件,凭据仅保留在应用仓库。应用仓库的新 Issue 复用 `issue_intake.verdict` 的模板准入判定;已有条目因待补模板关闭时,以 GitHub `closedAt` 为起点保留 2 小时修改窗口,再按当前状态同步。Issue 关联使用仓库名与编号,迁移映射兼容已存在的关联行;交付版本始终按应用仓库的主线提交和发布制品核验。看板同步复用 GitHub CLI 的已登录认证、GraphQL Projects API 和 Git 的提交祖先校验;不新增 Python 依赖。官方 [Projects Actions 自动化](https://docs.github.com/en/issues/planning-and-tracking-with-projects/automating-your-project/automating-projects-using-actions)支持独立项目凭据,仓库默认令牌不能写组织 Project。项目原生状态工作流没有发布标签与制品归属判定;通用自动加卡 Action 也不覆盖验收和发布的分别记录,因此由 `scripts/project_board.py` 保留 Peach 的状态规则,传输与认证交给系统已安装的 `gh`。运行依赖是官方维护、MIT 许可的 GitHub CLI 和 GPL-2.0 Git,使用 GitHub 托管 runner 内置版本;本机只读 GraphQL 与标签祖先验证后再应用。无生产服务、ledger 或媒体写入。diff --git a/scripts/project_board.py b/scripts/project_board.pyindex dc3d0d1fa..d267e2797 100644--- a/scripts/project_board.py+++ b/scripts/project_board.py@@ -2,14 +2,23 @@from __future__ import annotationsimport argparse+from datetime import datetime, timedelta, timezoneimport jsonimport osfrom pathlib import Pathimport reimport subprocess+import sys++if not __package__:+ sys.path.insert(0, str(Path(__file__).resolve().parents[1]))+ __package__ = "scripts"++from . import issue_intakeROOT = Path(__file__).resolve().parents[1]CONFIG = ROOT / ".github/project-board.json"+TEMPLATE_GRACE = timedelta(hours=2)def gh(*args, payload=None):@@ -99,6 +108,9 @@ def decision(content, current, linked, published):status = current.get("Status", "待评估")if is_pr:status = "已完成" if merged else ("已关闭未合入" if content["state"] == "CLOSED" else "进行中")+ elif content["state"] == "CLOSED" and issue_intake.LABEL in labels and \+ datetime.now(timezone.utc) - datetime.fromisoformat(content["closedAt"]) < TEMPLATE_GRACE:+ status = current.get("Status", "待评估")elif content["state"] == "CLOSED":status = "已取消" if content.get("stateReason") == "NOT_PLANNED" else "已完成"elif "status:needs-verification" in labels:@@ -119,8 +131,9 @@ def decision(content, current, linked, published):return result-CONTENT = '''__typename ... on DraftIssue{id title} ... on Issue{id number title url state stateReason repository{nameWithOwner}-labels(first:100){nodes{name}}}+ISSUE_CONTENT = '''__typename id number title url state stateReason closedAt body authorAssociation author{__typename} repository{nameWithOwner}+labels(first:100){nodes{name}}'''+CONTENT = '''__typename ... on DraftIssue{id title} ... on Issue{''' + ISSUE_CONTENT + '''}... on PullRequest{id number title url state merged mergeCommit{oid} body repository{nameWithOwner}closingIssuesReferences(first:100){nodes{id number repository{nameWithOwner}}}}'''PR_CONTENT = '''__typename id number title url state merged mergeCommit{oid} body repository{nameWithOwner}@@ -169,13 +182,22 @@ def incoming_issues(config):for repository in config.get("issue_repositories", [config["repository"]]):owner, name = repository.split("/")incoming.extend(connection('''query($owner:String!,$name:String!,$states:[IssueState!],$cursor:String){repository(owner:$owner,name:$name){-issues(first:100,after:$cursor,states:$states){nodes{__typename id number title url state stateReason repository{nameWithOwner}-labels(first:100){nodes{name}}}pageInfo{hasNextPage endCursor}}}}''',+issues(first:100,after:$cursor,states:$states){nodes{''' + ISSUE_CONTENT + '''}pageInfo{hasNextPage endCursor}}}}''',("repository", "issues"), owner=owner, name=name,states=None if repository == config.get("planning_repository") else ["OPEN"]))return incoming+def eligible_incoming(node, repository):+ """应用仓库的新 Issue 先通过同一模板判定,再加入看板;既有条目不追溯清退。"""+ if node["__typename"] != "Issue" or node["repository"]["nameWithOwner"] != repository:+ return True+ return issue_intake.verdict({"action": "opened", "issue": {+ "body": node["body"], "author_association": node["authorAssociation"],+ "user": {"type": (node["author"] or {}).get("__typename")},+ }}) != "close"++def include_incoming(config, candidates, prs, event, apply):repository, project = config["repository"], config["project_id"]incoming = incoming_issues(config)@@ -191,6 +213,8 @@ def include_incoming(config, candidates, prs, event, apply):if config.get("issues_only") and node["__typename"] != "Issue":continueif node["id"] not in candidates:+ if not eligible_incoming(node, repository):+ continueitem = {"id": None, "content": node, "fieldValues": {"nodes": []}, "isArchived": False}if apply:item["id"] = graphql('''mutation($project:ID!,$content:ID!){addProjectV2ItemById(diff --git a/tests/test_scripts.py b/tests/test_scripts.pyindex 7bbca59c4..a5c74d9db 100644--- a/tests/test_scripts.py+++ b/tests/test_scripts.py@@ -61,8 +61,72 @@ class ProjectBoardTests(unittest.TestCase):def issue(self, **changes):return {"__typename": "Issue", "state": "OPEN", "labels": {"nodes": []},+ "body": "## 问题描述\n闪退\n## 运行环境\nWindows 11", "authorAssociation": "NONE",+ "author": {"__typename": "User"},"repository": {"nameWithOwner": "peach-mitao/peach"}, **changes}+ def test_待补模板关闭两小时内不移动随后补齐保持原位置(self):+ issue = self.issue(state="CLOSED", stateReason="NOT_PLANNED", closedAt="2026-11-06T02:00:00Z",+ labels={"nodes": [{"name": "status:needs-template"}]})+ current = {"Status": "待评估"}+ for hour, minute, expected in ((2, 0, "待评估"), (3, 59, "待评估"), (4, 0, "已取消")):+ with self.subTest(hour=hour, minute=minute):+ with mock.patch.object(self.script, "datetime") as clock:+ clock.now.return_value = datetime(2026, 11, 6, hour, minute, tzinfo=timezone.utc)+ clock.fromisoformat.side_effect = datetime.fromisoformat+ self.assertEqual(self.script.decision(issue, current, [], None)["Status"], expected)+ reopened = {**issue, "state": "OPEN", "closedAt": None, "labels": {"nodes": []}}+ self.assertEqual(self.script.decision(reopened, current, [], None)["Status"], "待评估")++ def test_普通关闭不等待补模板缓冲(self):+ issue = self.issue(state="CLOSED", stateReason="NOT_PLANNED", closedAt="2026-11-06T02:00:00Z")+ self.assertEqual(self.script.decision(issue, {"Status": "待评估"}, [], None)["Status"], "已取消")++ def test_看板新条目先按模板校验并保留维护者豁免(self):+ invalid = self.issue(id="invalid", number=444, body="nas中docker无法自动更新", issueType={"name": "Feature"})+ valid = self.issue(id="valid", number=445)+ maintained = self.issue(id="maintained", number=446, body="维护任务", authorAssociation="MEMBER")+ config = {"repository": "peach-mitao/peach", "project_id": "public", "issues_only": True}+ candidates = {}+ with mock.patch.object(self.script, "incoming_issues", return_value=[invalid, valid, maintained]), \+ mock.patch.object(self.script, "graphql", side_effect=lambda query, **kw: {+ "addProjectV2ItemById": {"item": {"id": "item-" + kw["content"]}}}) as api:+ self.script.include_incoming(config, candidates, [], None, True)+ self.assertEqual(set(candidates), {"valid", "maintained"})+ self.assertEqual([call.kwargs["content"] for call in api.call_args_list], ["valid", "maintained"])++ def test_整体同步在缓冲期不写状态到期只移动一次(self):+ issue = self.issue(id="issue", number=444, title="更新失败", state="CLOSED", stateReason="NOT_PLANNED",+ closedAt="2026-11-06T02:00:00Z", labels={"nodes": [{"name": "status:needs-template"}]})+ current = {"Status": "待评估", "交付进度": "未关联实现"}+ item = {"id": "item", "content": issue, "isArchived": False}+ fields = {name: {"id": name} for name in ("发布版本", "发布说明", "实现关联")}+ fields["Status"] = {"id": "Status", "options": [{"id": name, "name": name} for name in ("待评估", "已取消")]}+ fields["交付进度"] = {"id": "交付进度", "options": [{"id": "未关联实现", "name": "未关联实现"}]}+ config = {"repository": "peach-mitao/peach", "project_id": "public"}+ def update(query, **variables):+ current[variables["field"]] = variables["value"]["singleSelectOptionId"]+ with mock.patch.object(self.script, "read_project", return_value=(fields, [item])), \+ mock.patch.object(self.script, "values", side_effect=lambda item: dict(current)), \+ mock.patch.object(self.script, "pull_requests", return_value=[]), \+ mock.patch.object(self.script, "incoming_issues", return_value=[]), \+ mock.patch.object(self.script, "published_releases", return_value=[]), \+ mock.patch.object(self.script, "graphql", side_effect=update) as api, \+ mock.patch.object(self.script, "datetime") as clock:+ clock.now.return_value = datetime(2026, 11, 6, 3, 0, tzinfo=timezone.utc)+ clock.fromisoformat.side_effect = datetime.fromisoformat+ self.assertEqual(self.script.reconcile(config, apply=True), [])+ issue.update(state="OPEN", labels={"nodes": []}, closedAt=None)+ clock.now.return_value = datetime(2026, 11, 6, 5, 0, tzinfo=timezone.utc)+ self.assertEqual(self.script.reconcile(config, apply=True), [])+ api.assert_not_called()+ issue.update(state="CLOSED", closedAt="2026-11-06T02:00:00Z",+ labels={"nodes": [{"name": "status:needs-template"}]})+ changes = self.script.reconcile(config, apply=True)+ self.assertEqual([(change["field"], change["value"]) for change in changes], [("Status", "已取消")])+ self.assertEqual(self.script.reconcile(config, apply=True), [])+ api.assert_called_once()+def test_merge_and_publication_keep_open_issue_waiting_for_acceptance(self):release = {"tag_name": "v1.2.0", "html_url": "https://example.test/release"}result = self.script.decision(self.issue(), {"Status": "进行中"}, [{"merged": True}], release)