✨ 新增对 Kimi、DeepSeek、OpenRouter 的支持并升级版本至 0.1.2
This commit is contained in:
@@ -9,11 +9,11 @@ pub struct CommitBuilder {
|
||||
description: Option<String>,
|
||||
body: Option<String>,
|
||||
footer: Option<String>,
|
||||
message: Option<String>,
|
||||
breaking: bool,
|
||||
sign: bool,
|
||||
amend: bool,
|
||||
no_verify: bool,
|
||||
dry_run: bool,
|
||||
format: crate::config::CommitFormat,
|
||||
}
|
||||
|
||||
@@ -26,11 +26,11 @@ impl CommitBuilder {
|
||||
description: None,
|
||||
body: None,
|
||||
footer: None,
|
||||
message: None,
|
||||
breaking: false,
|
||||
sign: false,
|
||||
amend: false,
|
||||
no_verify: false,
|
||||
dry_run: false,
|
||||
format: crate::config::CommitFormat::Conventional,
|
||||
}
|
||||
}
|
||||
@@ -65,6 +65,12 @@ impl CommitBuilder {
|
||||
self
|
||||
}
|
||||
|
||||
/// Set message
|
||||
pub fn message(mut self, message: impl Into<String>) -> Self {
|
||||
self.message = Some(message.into());
|
||||
self
|
||||
}
|
||||
|
||||
/// Mark as breaking change
|
||||
pub fn breaking(mut self, breaking: bool) -> Self {
|
||||
self.breaking = breaking;
|
||||
@@ -89,12 +95,6 @@ impl CommitBuilder {
|
||||
self
|
||||
}
|
||||
|
||||
/// Dry run (don't actually commit)
|
||||
pub fn dry_run(mut self, dry_run: bool) -> Self {
|
||||
self.dry_run = dry_run;
|
||||
self
|
||||
}
|
||||
|
||||
/// Set commit format
|
||||
pub fn format(mut self, format: crate::config::CommitFormat) -> Self {
|
||||
self.format = format;
|
||||
@@ -103,6 +103,10 @@ impl CommitBuilder {
|
||||
|
||||
/// Build commit message
|
||||
pub fn build_message(&self) -> Result<String> {
|
||||
if let Some(ref msg) = self.message {
|
||||
return Ok(msg.clone());
|
||||
}
|
||||
|
||||
let commit_type = self.commit_type.as_ref()
|
||||
.ok_or_else(|| anyhow::anyhow!("Commit type is required"))?;
|
||||
|
||||
@@ -139,33 +143,13 @@ impl CommitBuilder {
|
||||
pub fn execute(&self, repo: &GitRepo) -> Result<Option<String>> {
|
||||
let message = self.build_message()?;
|
||||
|
||||
if self.dry_run {
|
||||
return Ok(Some(message));
|
||||
}
|
||||
|
||||
// Check if there are staged changes
|
||||
let staged_files = repo.get_staged_files()?;
|
||||
if staged_files.is_empty() && !self.amend {
|
||||
bail!("No staged changes to commit. Use 'git add' to stage files first.");
|
||||
}
|
||||
|
||||
// Validate message
|
||||
match self.format {
|
||||
crate::config::CommitFormat::Conventional => {
|
||||
crate::utils::validators::validate_conventional_commit(&message)?;
|
||||
}
|
||||
crate::config::CommitFormat::Commitlint => {
|
||||
crate::utils::validators::validate_commitlint_commit(&message)?;
|
||||
}
|
||||
}
|
||||
|
||||
if self.amend {
|
||||
self.amend_commit(repo, &message)?;
|
||||
Ok(None)
|
||||
} else {
|
||||
repo.commit(&message, self.sign)?;
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
fn amend_commit(&self, repo: &GitRepo, message: &str) -> Result<()> {
|
||||
|
||||
Reference in New Issue
Block a user