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