Skip to content

Commit

Permalink
update: Allow any string prefix until the first - for semver
Browse files Browse the repository at this point in the history
Allow any string prefix until the first `-` for semver versions.

Closes: #189

Possible follow up:
Allow for a list of semver separation characters.
  • Loading branch information
a-kenji committed Oct 31, 2024
1 parent b1c5b09 commit 80a7ecd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,13 @@ fn query_tags(repo: &str, owner: &str) -> Result<IntermediaryTags, ()> {

impl From<IntermediaryTags> 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 {
Expand All @@ -133,6 +140,11 @@ impl From<IntermediaryTags> 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);
Expand Down
7 changes: 7 additions & 0 deletions src/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> {
s.find(c).map(|index| s[index + 1..].to_string())
}
let uri = self
.text
.slice(
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 80a7ecd

Please sign in to comment.