use quanttide_devops::stage::release::{ReleaseState, ReleaseStatus};
use quanttide_devops::source::git::tag::{latest_tag_with, latest_version_with, TagSource, TagError};
fn main() {
let mock = MockTagSource::new(&[
"cli/v0.3.0",
"cli/v0.2.0",
"studio/v0.5.0",
]);
let scopes = vec![
("cli", "src/cli", "0.3.0", "CHANGELOG.md", 3), ("studio", "src/studio", "0.5.0", "CHANGELOG.md", 0), ("docs", "docs", "0.1.0", "CHANGELOG.md", 2), ];
let mut states: Vec<ReleaseState> = Vec::new();
for (name, path, config_ver, changelog, pending) in &scopes {
let tag_version = latest_version_with(&mock, name).unwrap();
let raw_tag = latest_tag_with(&mock, name).unwrap();
let consistent = if tag_version.as_deref() == Some(config_ver) {
Some(true)
} else if tag_version.is_none() && *config_ver == "0.1.0" {
Some(false) } else {
tag_version.as_ref().map(|_| false)
};
let status = match (tag_version.as_deref(), pending) {
(None, _) => ReleaseStatus::Unreleased,
(Some(_), 0) => ReleaseStatus::Latest,
(Some(_), _) => ReleaseStatus::Pending,
};
let status = match (status, consistent) {
(_, Some(false)) => ReleaseStatus::Inconsistent,
(s, _) => s,
};
states.push(ReleaseState {
status,
scope: name.to_string(),
scope_path: path.to_string(),
current_version: raw_tag,
pending_commits: *pending,
changelog: changelog.to_string(),
version_consistent: consistent,
});
}
println!("发布状态报告 ({} scopes)", states.len());
println!("{}", "─".repeat(40));
for s in &states {
print!("{}", s);
}
println!("\n版本冲突示例:");
let conflict = ReleaseState::builder()
.status(ReleaseStatus::Inconsistent)
.scope("web")
.scope_path("src/web")
.current_version("web/v0.1.0")
.pending_commits(0)
.version_consistent(false)
.build();
print!("{}", conflict);
}
struct MockTagSource {
tags: Vec<String>,
}
impl MockTagSource {
fn new(tags: &[&str]) -> Self {
Self {
tags: tags.iter().map(|s| s.to_string()).collect(),
}
}
}
impl TagSource for MockTagSource {
fn all_tags(&self) -> Result<Vec<String>, TagError> {
Ok(self.tags.clone())
}
}