|
40 | 40 | from .render import render_comment |
41 | 41 |
|
42 | 42 | if TYPE_CHECKING: |
43 | | - from githubkit.rest.models import Issue, IssuePropLabelsItemsOneof1, Label |
| 43 | + from githubkit.rest.models import ( |
| 44 | + Issue, |
| 45 | + IssuePropLabelsItemsOneof1, |
| 46 | + Label, |
| 47 | + PullRequestPropLabelsItems, |
| 48 | + PullRequestSimplePropLabelsItems, |
| 49 | + ) |
44 | 50 | from githubkit.webhooks.models import Issue as WebhookIssue |
45 | 51 | from githubkit.webhooks.models import ( |
46 | 52 | IssueCommentCreatedPropIssue, |
@@ -71,7 +77,9 @@ def run_shell_command(command: list[str]): |
71 | 77 | def get_type_by_labels( |
72 | 78 | labels: list["Label"] |
73 | 79 | | list["WebhookLabel"] |
74 | | - | list[Union[str, "IssuePropLabelsItemsOneof1"]], |
| 80 | + | list[Union[str, "IssuePropLabelsItemsOneof1"]] |
| 81 | + | list["PullRequestSimplePropLabelsItems"] |
| 82 | + | list["PullRequestPropLabelsItems"], |
75 | 83 | ) -> PublishType | None: |
76 | 84 | """通过标签获取类型""" |
77 | 85 | for label in labels: |
@@ -208,6 +216,7 @@ def validate_info_from_issue( |
208 | 216 | "skip_plugin_test": plugin_config.skip_plugin_test, |
209 | 217 | "plugin_test_result": plugin_config.plugin_test_result, |
210 | 218 | "plugin_test_output": plugin_config.plugin_test_output, |
| 219 | + "plugin_test_metadata": plugin_config.plugin_test_metadata, |
211 | 220 | "previous_data": data, |
212 | 221 | } |
213 | 222 | # 如果插件测试被跳过,则从议题中获取信息 |
@@ -247,46 +256,63 @@ def validate_info_from_issue( |
247 | 256 |
|
248 | 257 |
|
249 | 258 | async def resolve_conflict_pull_requests( |
250 | | - bot: Bot, |
251 | | - repo_info: RepoInfo, |
252 | 259 | pulls: list[PullRequestSimple] | list[PullRequest], |
253 | 260 | ): |
254 | 261 | """根据关联的议题提交来解决冲突 |
255 | 262 |
|
256 | | - 参考对应的议题重新更新对应分支 |
| 263 | + 直接重新提交之前分支中的内容 |
257 | 264 | """ |
258 | | - # 跳过插件测试,因为这个时候插件测试任务没有运行 |
259 | | - plugin_config.skip_plugin_test = True |
260 | | - |
261 | 265 | for pull in pulls: |
262 | | - # 回到主分支 |
263 | | - run_shell_command(["git", "checkout", plugin_config.input_config.base]) |
264 | | - # 切换到对应分支 |
265 | | - run_shell_command(["git", "switch", "-C", pull.head.ref]) |
266 | | - |
267 | 266 | issue_number = extract_issue_number_from_ref(pull.head.ref) |
268 | 267 | if not issue_number: |
269 | | - logger.error(f"无法获取 {pull.title} 对应的议题") |
270 | | - return |
| 268 | + logger.error(f"无法获取 {pull.title} 对应的议题编号") |
| 269 | + continue |
271 | 270 |
|
272 | 271 | logger.info(f"正在处理 {pull.title}") |
273 | | - issue = ( |
274 | | - await bot.rest.issues.async_get( |
275 | | - **repo_info.dict(), issue_number=issue_number |
276 | | - ) |
277 | | - ).parsed_data |
| 272 | + if pull.draft: |
| 273 | + logger.info("拉取请求为草稿,跳过处理") |
| 274 | + continue |
278 | 275 |
|
279 | | - publish_type = get_type_by_labels(issue.labels) |
| 276 | + publish_type = get_type_by_labels(pull.labels) |
280 | 277 | if publish_type: |
281 | | - result = validate_info_from_issue(issue, publish_type) |
282 | | - if result["valid"]: |
283 | | - update_file(result) |
284 | | - commit_and_push(result, pull.head.ref, issue_number) |
285 | | - logger.info("拉取请求更新完毕") |
286 | | - else: |
287 | | - comment = await render_comment(result) |
288 | | - logger.info(comment) |
289 | | - logger.info("发布没通过检查,已跳过") |
| 278 | + result = generate_validation_dict_from_file(publish_type) |
| 279 | + # 回到主分支 |
| 280 | + run_shell_command(["git", "checkout", plugin_config.input_config.base]) |
| 281 | + # 切换到对应分支 |
| 282 | + run_shell_command(["git", "switch", "-C", pull.head.ref]) |
| 283 | + update_file(result) |
| 284 | + commit_and_push(result, pull.head.ref, issue_number) |
| 285 | + logger.info("拉取请求更新完毕") |
| 286 | + |
| 287 | + |
| 288 | +def generate_validation_dict_from_file(publish_type: PublishType) -> ValidationDict: |
| 289 | + """从文件中获取发布所需数据""" |
| 290 | + match publish_type: |
| 291 | + case PublishType.ADAPTER: |
| 292 | + with plugin_config.input_config.adapter_path.open( |
| 293 | + "r", encoding="utf-8" |
| 294 | + ) as f: |
| 295 | + data: list[dict[str, str]] = json.load(f) |
| 296 | + raw_data = data[-1] |
| 297 | + case PublishType.BOT: |
| 298 | + with plugin_config.input_config.bot_path.open("r", encoding="utf-8") as f: |
| 299 | + data: list[dict[str, str]] = json.load(f) |
| 300 | + raw_data = data[-1] |
| 301 | + case PublishType.PLUGIN: |
| 302 | + with plugin_config.input_config.plugin_path.open( |
| 303 | + "r", encoding="utf-8" |
| 304 | + ) as f: |
| 305 | + data: list[dict[str, str]] = json.load(f) |
| 306 | + raw_data = data[-1] |
| 307 | + |
| 308 | + return ValidationDict( |
| 309 | + valid=True, |
| 310 | + type=publish_type, |
| 311 | + name=raw_data["name"], |
| 312 | + author=raw_data["author"], |
| 313 | + data=raw_data, |
| 314 | + errors=[], |
| 315 | + ) |
290 | 316 |
|
291 | 317 |
|
292 | 318 | def update_file(result: ValidationDict) -> None: |
|
0 commit comments