From 80a7ecdfffc24afcc70b1eb5c45efa3175a98624 Mon Sep 17 00:00:00 2001 From: a-kenji Date: Thu, 31 Oct 2024 22:10:56 +0100 Subject: [PATCH] update: Allow any string prefix until the first `-` for semver Allow any string prefix until the first `-` for semver versions. Closes: #189 Possible follow up: Allow for a list of semver separation characters. --- src/api.rs | 12 ++++++++++++ src/update.rs | 7 +++++++ 2 files changed, 19 insertions(+) diff --git a/src/api.rs b/src/api.rs index fe2bb0a..78ef987 100644 --- a/src/api.rs +++ b/src/api.rs @@ -123,6 +123,13 @@ fn query_tags(repo: &str, owner: &str) -> Result { impl From for Tags { fn from(value: IntermediaryTags) -> Self { + fn strip_until_char(s: &str, c: char) -> Option<(String, String)> { + s.find(c).map(|index| { + let prefix = s[..index].to_string(); + let remaining = s[index + 1..].to_string(); + (prefix, remaining) + }) + } let mut versions = vec![]; let mut prefix = String::new(); for itag in value.0 { @@ -133,6 +140,11 @@ impl From for Tags { prefix = "v".to_string(); } + if let Some((new_prefix, new_tag)) = strip_until_char(&tag, '-') { + tag = new_tag; + prefix = format!("{new_prefix}-").to_string(); + } + match Version::parse(&tag) { Ok(semver) => { versions.push(semver); diff --git a/src/update.rs b/src/update.rs index 63fa224..955da63 100644 --- a/src/update.rs +++ b/src/update.rs @@ -85,6 +85,9 @@ impl Updater { } /// Query a forge api for the latest release and update, if necessary. pub fn query_and_update_all_inputs(&mut self, input: &UpdateInput, init: bool) { + fn strip_until_char(s: &str, c: char) -> Option { + s.find(c).map(|index| s[index + 1..].to_string()) + } let uri = self .text .slice( @@ -113,6 +116,10 @@ impl Updater { maybe_version = normalized_version.to_string(); } + if let Some(normalized_version) = strip_until_char(&maybe_version, '-') { + maybe_version = normalized_version.to_string(); + } + // If we init the version specifier we don't care if there was already a // correct semver specified, we automatically pin to the latest semver. if !init {