crate_seq_ledger/tag.rs
1//! Tag pattern detection and `SemVer` extraction from git tag names.
2
3/// Returns the default glob pattern for tagging.
4///
5/// Single-crate repos: `"v*"`. Workspaces: `"{crate_name}-v*"`.
6#[must_use]
7pub fn detect_tag_pattern(crate_name: &str, is_workspace: bool) -> String {
8 if is_workspace {
9 format!("{crate_name}-v*")
10 } else {
11 "v*".to_owned()
12 }
13}
14
15/// Strips the tag prefix determined by `pattern` and parses the remainder as `SemVer`.
16///
17/// Derives the literal prefix by stripping the trailing `*` from `pattern`.
18/// Returns `None` if `tag` does not start with that prefix or the remainder is not valid `SemVer`.
19#[must_use]
20pub fn extract_semver_from_tag(tag: &str, pattern: &str) -> Option<semver::Version> {
21 let prefix = pattern.strip_suffix('*')?;
22 let version_str = tag.strip_prefix(prefix)?;
23 semver::Version::parse(version_str).ok()
24}