Skip to content

Commit d0a7025

Browse files
committed
chore: 从plugin.json获得tag。
1 parent 908126a commit d0a7025

3 files changed

Lines changed: 60 additions & 17 deletions

File tree

.github/ISSUE_TEMPLATE/plugin-add.yml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,6 @@ body:
3333
validations:
3434
required: true
3535

36-
- type: input
37-
id: plugin_tag
38-
attributes:
39-
label: 插件标签
40-
description: "插件的分类标签, 使用 ' | ' 分隔多个标签"
41-
placeholder: "实用 | 工具"
42-
validations:
43-
required: true
44-
4536
- type: input
4637
id: plugin_branch
4738
attributes:

.github/workflows/plugin_submission_review.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ jobs:
270270
271271
Co-authored-by: "ChimeYao-bot <ChimeYao@outlook.jp>"
272272
commit_options: "--no-verify --signoff"
273-
file_pattern: "Plugins/plugin_list.json"
273+
file_pattern: "Plugins/plugin_list.json,Plugins/tags.json"
274274
commit_user_name: "ChimeYao-bot"
275275
commit_user_email: "ChimeYao@outlook.jp"
276276
commit_author: "${{ github.event.issue.user.login }} <${{ github.event.issue.user.id }}+${{ github.event.issue.user.login }}@users.noreply.github.com>"

scripts/plugin_validation.py

Lines changed: 59 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,13 @@ def extract_form_data_from_issue(issue_body: str) -> dict[str, str] | None:
4646
id_match = re.search(r"### 插件 ID\s*\n\s*(.+)", issue_body)
4747
if id_match:
4848
data["id"] = id_match.group(1).strip()
49-
tag_match = re.search(r"### 插件标签\s*\n\s*(.+)", issue_body)
50-
if tag_match:
51-
data["tag"] = tag_match.group(1).strip()
5249
branch_match = re.search(r"### 插件分支\s*\n\s*(.+)", issue_body)
5350
if branch_match:
5451
data["branch"] = branch_match.group(1).strip()
5552
else:
5653
data["branch"] = "main"
5754

58-
return data if all(k in data for k in ["url", "id", "tag", "branch"]) else None
55+
return data if all(k in data for k in ["url", "id", "branch"]) else None
5956
except Exception:
6057
return None
6158

@@ -131,7 +128,7 @@ def validate_submission() -> None:
131128
无法从Issue表单中提取必要信息,请确保正确填写了以下字段:
132129
- 插件仓库 URL
133130
- 插件 ID
134-
- 插件标签
131+
- 插件分支
135132
"""
136133

137134
artifacts_dir = Path("artifacts")
@@ -154,12 +151,28 @@ def validate_submission() -> None:
154151
with open(artifacts_dir / "comment.md", "w", encoding="utf-8") as f:
155152
f.write(comment)
156153
return
154+
t = plugin_json.get("tag")
155+
if isinstance(t, str):
156+
tags_str = t.strip()
157+
158+
if not tags_str:
159+
comment = """<!-- plugin-review -->
160+
❌ **验证失败**
161+
162+
未能从仓库文件读取标签信息。请在仓库 `plugin.json` 中提供 `tag` 字段, 例如: `"tag": "工具 | 实用"`。
163+
"""
164+
artifacts_dir = Path("artifacts")
165+
artifacts_dir.mkdir(exist_ok=True)
166+
with open(artifacts_dir / "comment.md", "w", encoding="utf-8") as f:
167+
f.write(comment)
168+
return
169+
157170
merged_data = {
158171
"id": form_data["id"],
159-
"tag": form_data["tag"],
172+
"tag": tags_str,
160173
"url": form_data["url"],
161174
"branch": plugin_json.get("branch", "main"),
162-
**plugin_json, # plugin.json中的数据会覆盖同名字段
175+
**plugin_json,
163176
}
164177

165178
success, errors, registry_item = validate_submission_metadata(merged_data)
@@ -260,6 +273,45 @@ def handle_toggle() -> None:
260273
plugin_list[plugin_id] = registry_item_data
261274
with open(plugin_list_path, "w", encoding="utf-8") as f:
262275
json.dump(plugin_list, f, indent=4, ensure_ascii=False)
276+
tags_file = Path("Plugins/tags.json")
277+
tags_data = {"tags": []}
278+
if tags_file.exists():
279+
try:
280+
with open(tags_file, encoding="utf-8") as tf:
281+
tags_data = json.load(tf) or tags_data
282+
except Exception:
283+
pass
284+
existing_tags = tags_data.get("tags", [])
285+
286+
def _parse_tags(s: str) -> list[str]:
287+
seps = ["|", ",", ",", "、"]
288+
tmp = [s]
289+
for sep in seps:
290+
new = []
291+
for part in tmp:
292+
new.extend([p.strip() for p in part.split(sep)])
293+
tmp = new
294+
seen = set()
295+
result = []
296+
for t in tmp:
297+
if t and t not in seen:
298+
seen.add(t)
299+
result.append(t)
300+
return result
301+
302+
new_tags = _parse_tags(registry_item_data.get("tag", ""))
303+
appended = False
304+
for t in new_tags:
305+
if t and t not in existing_tags:
306+
existing_tags.append(t)
307+
appended = True
308+
if appended:
309+
try:
310+
with open(tags_file, "w", encoding="utf-8") as tf:
311+
json.dump({"tags": existing_tags}, tf, indent=2, ensure_ascii=False)
312+
except Exception:
313+
pass
314+
263315
with open("artifacts/commit.flag", "w") as f:
264316
f.write("true")
265317
with open("artifacts/plugin_to_add.json", "w", encoding="utf-8") as f:

0 commit comments

Comments
 (0)