Skip to content

Commit 742e5a9

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

4 files changed

Lines changed: 61 additions & 29 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>"

Plugins/plugin_list.json

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -222,18 +222,6 @@
222222
"update_date": "2025/4/13",
223223
"tag": "实用 | 提醒 | 工具"
224224
},
225-
"TomorrowTip": {
226-
"name": "明日课程提醒",
227-
"description": "在指定时间通知明日课程信息",
228-
"version": "1.2.0",
229-
"plugin_ver": 2,
230-
"author": "白杳",
231-
"settings": true,
232-
"url": "https://github.com/baiyao105/cw-tomorrow-tip",
233-
"branch": "main",
234-
"update_date": "2025/09/21",
235-
"tag": "实用 | 提醒 | 信息"
236-
},
237225
"cw-plugin-count-down": {
238226
"name": "MONKEY-COUNTDOWN",
239227
"description": "BYMONKEY",

scripts/plugin_validation.py

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

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

0 commit comments

Comments
 (0)