@@ -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