Skip to content

armgit / peach

Public Imported from GitHub
0

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

fix(tooling): 检查已有类型的新 Issue 模板章节

longmeidao0b2bba9f1553
diff --git a/scripts/issue_intake.py b/scripts/issue_intake.py
index a34a00406..c0cfb4749 100644
--- a/scripts/issue_intake.py
+++ b/scripts/issue_intake.py
@@ -1,9 +1,9 @@
"""外部 issue 的模板检查:让命令行和 API 提交的 issue 与网页模板提交的结果一致。
网页「New issue」按模板提交时,即使删光模板文字也会带上模板的 Issue Type;用 `gh` 或 API
-提交则不经过模板。作者不是维护者、也没有 Issue Type 的新 issue 按下列规则处理:正文含有
-某个模板的章节,补上那个模板的 Issue Type;缺少模板章节,关闭;按模板补齐章节后重开并
-补上类型。GitHub 写操作由 `.github/workflows/issue-intake.yml` 完成,
+提交则不经过模板。作者不是维护者的新 issue 均检查正文:含有某个模板的章节时保留已有类型,
+没有类型则补上那个模板的 Issue Type;缺少模板章节则关闭;按模板补齐章节后重开并补上类型。
+GitHub 写操作由 `.github/workflows/issue-intake.yml` 完成,
本脚本只输出 `keep`、`close`、`type <类型>` 或 `reopen <类型>`。
"""
from __future__ import annotations
@@ -72,10 +72,10 @@ def verdict(payload: dict, templates: list[Template] | None = None) -> str:
kind = matched_type(body, templates)
if action == "edited" and issue.get("state") == "closed" and LABEL in labels:
return f"reopen {kind}" if kind else "keep"
- if action not in {"opened", "edited"} or issue.get("state") == "closed" or issue.get("type"):
+ if action not in {"opened", "edited"} or issue.get("state") == "closed":
return "keep"
if kind:
- return f"type {kind}"
+ return "keep" if issue.get("type") else f"type {kind}"
return "close" if action == "opened" else "keep"
diff --git a/tests/test_issue_intake.py b/tests/test_issue_intake.py
index d53513d01..9fdae4841 100644
--- a/tests/test_issue_intake.py
+++ b/tests/test_issue_intake.py
@@ -42,12 +42,22 @@ class IssueIntakeTests(unittest.TestCase):
self.assertEqual(issue_intake.verdict(event(body=body)), "close")
self.assertEqual(issue_intake.verdict(event("edited")), "keep")
- def test_web_form_issues_keep_their_text_even_without_sections(self):
- for payload in (event(type={"name": "Feature"}),
- event(body=FEATURE_BODY, type={"name": "Feature"}),
- event(body="希望垃圾文件可以批量删除", type={"name": "Feature"})):
- with self.subTest(body=payload["issue"]["body"][:12]):
- self.assertEqual(issue_intake.verdict(payload), "keep")
+ def test_已有类型的新问题缺少模板章节时关闭(self):
+ for kind in ("Bug", "Feature"):
+ for body in (JARGON_BODY, "nas中docker无法自动更新,是不是因为版本号是edge的原因,能不能优化一下", ""):
+ with self.subTest(kind=kind, body=body[:12]):
+ self.assertEqual(issue_intake.verdict(event(body=body, type={"name": kind})), "close")
+
+ def test_已有类型且符合模板的问题保留类型(self):
+ for action in ("opened", "edited"):
+ for kind, body in (("Bug", BUG_BODY), ("Feature", FEATURE_BODY)):
+ with self.subTest(action=action, kind=kind):
+ self.assertEqual(issue_intake.verdict(event(action, body, type={"name": kind})), "keep")
+
+ def test_已有类型的待补模板问题补齐后按正文类型重开(self):
+ closed = {"state": "closed", "labels": [{"name": issue_intake.LABEL}], "type": {"name": "Feature"}}
+ self.assertEqual(issue_intake.verdict(event("edited", BUG_BODY, **closed)), "reopen Bug")
+ self.assertEqual(issue_intake.verdict(event("edited", JARGON_BODY, **closed)), "keep")
def test_maintainers_bots_and_pull_requests_are_exempt(self):
for issue in ({"author_association": "MEMBER"}, {"author_association": "OWNER"},