style: 格式化代码并优化导入顺序
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
use super::GitRepo;
|
||||
use anyhow::{bail, Result};
|
||||
use anyhow::{Result, bail};
|
||||
use semver::Version;
|
||||
|
||||
/// Tag builder for creating tags
|
||||
@@ -69,19 +69,19 @@ impl TagBuilder {
|
||||
|
||||
/// Build tag message
|
||||
pub fn build_message(&self) -> Result<String> {
|
||||
let message = self.message.as_ref()
|
||||
.cloned()
|
||||
.unwrap_or_else(|| {
|
||||
let name = self.name.as_deref().unwrap_or("unknown");
|
||||
format!("Release {}", name)
|
||||
});
|
||||
|
||||
let message = self.message.as_ref().cloned().unwrap_or_else(|| {
|
||||
let name = self.name.as_deref().unwrap_or("unknown");
|
||||
format!("Release {}", name)
|
||||
});
|
||||
|
||||
Ok(message)
|
||||
}
|
||||
|
||||
/// Execute tag creation
|
||||
pub fn execute(&self, repo: &GitRepo) -> Result<()> {
|
||||
let name = self.name.as_ref()
|
||||
let name = self
|
||||
.name
|
||||
.as_ref()
|
||||
.ok_or_else(|| anyhow::anyhow!("Tag name is required"))?;
|
||||
|
||||
if !self.force {
|
||||
@@ -105,10 +105,10 @@ impl TagBuilder {
|
||||
/// Execute and push tag
|
||||
pub fn execute_and_push(&self, repo: &GitRepo, remote: &str) -> Result<()> {
|
||||
self.execute(repo)?;
|
||||
|
||||
|
||||
let name = self.name.as_ref().unwrap();
|
||||
repo.push(remote, &format!("refs/tags/{}", name))?;
|
||||
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -136,7 +136,10 @@ impl VersionBump {
|
||||
"minor" => Ok(Self::Minor),
|
||||
"patch" => Ok(Self::Patch),
|
||||
"prerelease" | "pre" => Ok(Self::Prerelease),
|
||||
_ => bail!("Invalid version bump: {}. Use: major, minor, patch, prerelease", s),
|
||||
_ => bail!(
|
||||
"Invalid version bump: {}. Use: major, minor, patch, prerelease",
|
||||
s
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -149,7 +152,7 @@ impl VersionBump {
|
||||
/// Get latest version tag from repository
|
||||
pub fn get_latest_version(repo: &GitRepo, prefix: &str) -> Result<Option<Version>> {
|
||||
let tags = repo.get_tags()?;
|
||||
|
||||
|
||||
let mut versions: Vec<Version> = tags
|
||||
.iter()
|
||||
.filter_map(|t| {
|
||||
@@ -158,9 +161,9 @@ pub fn get_latest_version(repo: &GitRepo, prefix: &str) -> Result<Option<Version
|
||||
Version::parse(version_str).ok()
|
||||
})
|
||||
.collect();
|
||||
|
||||
|
||||
versions.sort_by(|a, b| b.cmp(a)); // Descending order
|
||||
|
||||
|
||||
Ok(versions.into_iter().next())
|
||||
}
|
||||
|
||||
@@ -183,14 +186,17 @@ pub fn suggest_version_bump(commits: &[super::CommitInfo]) -> VersionBump {
|
||||
let mut has_breaking = false;
|
||||
let mut has_feature = false;
|
||||
let mut has_fix = false;
|
||||
|
||||
|
||||
for commit in commits {
|
||||
let msg = commit.message.to_lowercase();
|
||||
|
||||
if msg.contains("breaking change") || msg.contains("breaking-change") || msg.contains("breaking_change") {
|
||||
|
||||
if msg.contains("breaking change")
|
||||
|| msg.contains("breaking-change")
|
||||
|| msg.contains("breaking_change")
|
||||
{
|
||||
has_breaking = true;
|
||||
}
|
||||
|
||||
|
||||
if let Some(commit_type) = commit.commit_type() {
|
||||
match commit_type.as_str() {
|
||||
"feat" => has_feature = true,
|
||||
@@ -199,7 +205,7 @@ pub fn suggest_version_bump(commits: &[super::CommitInfo]) -> VersionBump {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if has_breaking {
|
||||
VersionBump::Major
|
||||
} else if has_feature {
|
||||
@@ -214,20 +220,20 @@ pub fn suggest_version_bump(commits: &[super::CommitInfo]) -> VersionBump {
|
||||
/// Generate tag message from commits
|
||||
pub fn generate_tag_message(version: &str, commits: &[super::CommitInfo]) -> String {
|
||||
let mut message = format!("Release {}\n\n", version);
|
||||
|
||||
|
||||
// Group commits by type
|
||||
let mut features = vec![];
|
||||
let mut fixes = vec![];
|
||||
let mut other = vec![];
|
||||
let mut breaking = vec![];
|
||||
|
||||
|
||||
for commit in commits {
|
||||
let subject = commit.subject();
|
||||
|
||||
|
||||
if commit.message.contains("BREAKING CHANGE") {
|
||||
breaking.push(subject.to_string());
|
||||
}
|
||||
|
||||
|
||||
if let Some(commit_type) = commit.commit_type() {
|
||||
match commit_type.as_str() {
|
||||
"feat" => features.push(subject.to_string()),
|
||||
@@ -238,7 +244,7 @@ pub fn generate_tag_message(version: &str, commits: &[super::CommitInfo]) -> Str
|
||||
other.push(subject.to_string());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Build message
|
||||
if !breaking.is_empty() {
|
||||
message.push_str("## Breaking Changes\n\n");
|
||||
@@ -247,7 +253,7 @@ pub fn generate_tag_message(version: &str, commits: &[super::CommitInfo]) -> Str
|
||||
}
|
||||
message.push('\n');
|
||||
}
|
||||
|
||||
|
||||
if !features.is_empty() {
|
||||
message.push_str("## Features\n\n");
|
||||
for item in &features {
|
||||
@@ -255,7 +261,7 @@ pub fn generate_tag_message(version: &str, commits: &[super::CommitInfo]) -> Str
|
||||
}
|
||||
message.push('\n');
|
||||
}
|
||||
|
||||
|
||||
if !fixes.is_empty() {
|
||||
message.push_str("## Bug Fixes\n\n");
|
||||
for item in &fixes {
|
||||
@@ -263,36 +269,36 @@ pub fn generate_tag_message(version: &str, commits: &[super::CommitInfo]) -> Str
|
||||
}
|
||||
message.push('\n');
|
||||
}
|
||||
|
||||
|
||||
if !other.is_empty() {
|
||||
message.push_str("## Other Changes\n\n");
|
||||
for item in &other {
|
||||
message.push_str(&format!("- {}\n", item));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
message
|
||||
}
|
||||
|
||||
/// Tag deletion helper
|
||||
pub fn delete_tag(repo: &GitRepo, name: &str, remote: Option<&str>) -> Result<()> {
|
||||
repo.delete_tag(name)?;
|
||||
|
||||
|
||||
if let Some(remote) = remote {
|
||||
use std::process::Command;
|
||||
|
||||
|
||||
let refspec = format!(":refs/tags/{}", name);
|
||||
let output = Command::new("git")
|
||||
.args(["push", remote, &refspec])
|
||||
.current_dir(repo.path())
|
||||
.output()?;
|
||||
|
||||
|
||||
if !output.status.success() {
|
||||
let stderr = String::from_utf8_lossy(&output.stderr);
|
||||
bail!("Failed to delete remote tag: {}", stderr);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -303,7 +309,7 @@ pub fn list_tags(
|
||||
limit: Option<usize>,
|
||||
) -> Result<Vec<super::TagInfo>> {
|
||||
let tags = repo.get_tags()?;
|
||||
|
||||
|
||||
let filtered: Vec<_> = tags
|
||||
.into_iter()
|
||||
.filter(|t| {
|
||||
@@ -314,7 +320,7 @@ pub fn list_tags(
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
|
||||
|
||||
if let Some(limit) = limit {
|
||||
Ok(filtered.into_iter().take(limit).collect())
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user