(&self, context: &PrUpdateContext<'_>)
| 502 | } |
| 503 | |
| 504 | pub async fn update_pr(&self, context: &PrUpdateContext<'_>) -> Result<()> { |
| 505 | info!( |
| 506 | "正在处理来自 @{} 的更新 PR #{} 请求...", |
| 507 | context.requester, context.pr_number |
| 508 | ); |
| 509 | |
| 510 | let Some(pr) = self |
| 511 | .verify_pr_permission(context.pr_number, context.requester) |
| 512 | .await? |
| 513 | else { |
| 514 | return Ok(()); |
| 515 | }; |
| 516 | |
| 517 | let file_to_update = self |
| 518 | .find_target_file(context.pr_number, context.root_path) |
| 519 | .await?; |
| 520 | |
| 521 | let branch_name = &pr.head.ref_field; |
| 522 | let changes_made = self |
| 523 | .execute_git_changes(branch_name, &file_to_update, context) |
| 524 | .await?; |
| 525 | |
| 526 | if !changes_made { |
| 527 | return Ok(()); |
| 528 | } |
| 529 | |
| 530 | if let Err(e) = self.refresh_pr_metadata(&pr, context).await { |
| 531 | warn!("更新 PR #{} 元数据失败: {:?}", context.pr_number, e); |
| 532 | } |
| 533 | |
| 534 | self.send_feedback_reaction(context.comment_id).await; |
| 535 | |
| 536 | // 用户用 /update 更新歌词后,如果有 “待更新” 标签则移除它 |
| 537 | if let Some(labels) = &pr.labels |
| 538 | && labels.iter().any(|l| l.name == PENDING_UPDATE_LABEL) |
| 539 | { |
| 540 | info!("在更新后找到 “{PENDING_UPDATE_LABEL}” 标签, 正在尝试移除"); |
| 541 | if let Err(e) = self |
| 542 | .client |
| 543 | .issues(&self.owner, &self.repo) |
| 544 | .remove_label(context.pr_number, PENDING_UPDATE_LABEL) |
| 545 | .await |
| 546 | { |
| 547 | warn!("移除标签失败: {e:?}"); |
| 548 | } else { |
| 549 | info!("已移除 “{PENDING_UPDATE_LABEL}” 标签"); |
| 550 | } |
| 551 | } |
| 552 | |
| 553 | info!("成功更新 PR #{}", context.pr_number); |
| 554 | Ok(()) |
| 555 | } |
| 556 | |
| 557 | async fn find_target_file( |
| 558 | &self, |
no test coverage detected