Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 119 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ anyhow = "1.0"
async-trait = "0.1"
config = "0.13"
regex = "1.10"
chrono = "0.4"
textwrap = "0.16"
clap = { version = "4.4", features = ["derive"] }
clap_complete = { version = "4.5", features = ["unstable-dynamic"] }
Expand Down
37 changes: 35 additions & 2 deletions src/commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ use regex::Regex;
use crate::ai_service;
use crate::config;
use crate::git;
use crate::review;
use crate::copyright_check;

/// 从提交消息中提取 Change-Id
fn extract_change_id(message: &str) -> Option<String> {
Expand Down Expand Up @@ -718,9 +720,8 @@ impl CommitMessage {
}
}

use crate::review;
use dialoguer::Confirm;
use log::{debug, info};
use log::{debug, info, warn};
use std::process::Command;

pub async fn generate_commit_message(
Expand Down Expand Up @@ -786,6 +787,38 @@ pub async fn generate_commit_message(

let config = config::Config::load()?;

// 执行版权检查(对于 amend 模式,我们跳过检查)
if !amend {
info!("正在进行版权检查...");

// 优先使用 AI 检查,如果失败则回退到硬编码检查
let check_result = match copyright_check::check_copyright_with_ai(&config).await {
Ok(result) => {
info!("AI 版权检查完成");
result
}
Err(e) => {
warn!("AI 版权检查失败,回退到硬编码检查: {}", e);
copyright_check::check_copyright()?
}
};

let formatted = copyright_check::format_copyright_result(&check_result);
println!("\n{}\n", formatted);

// 如果有版权问题,询问用户是否继续
if check_result.has_issues {
if !Confirm::with_theme(&dialoguer::theme::ColorfulTheme::default())
.with_prompt("发现版权问题,是否继续提交?")
.default(false)
.interact()?
{
println!("已取消提交");
return Ok(());
}
}
}

// 在确认有差异内容后执行代码审查(对于 amend 模式,我们跳过审查,因为是对已有提交的修改)
if !amend && !no_review && config.ai_review {
info!("正在进行代码审查...");
Expand Down
Loading