Skip to content

Commit

Permalink
fix: Sort operator versions by semver version instead of alphabetically
Browse files Browse the repository at this point in the history
  • Loading branch information
sbernauer committed Nov 18, 2024
1 parent 20b99d1 commit a4dedd2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
4 changes: 4 additions & 0 deletions rust/stackablectl/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ All notable changes to this project will be documented in this file.
[CVE-2024-45311] ([#318]).
- Bump Rust toolchain version to 1.80.1 ([#318]).

### Fixed

- Sort operator versions by semver version instead of alphabetically ([#XXX]).

[#318]: https://github.com/stackabletech/stackable-cockpit/pull/318
[CVE-2024-45311]: https://github.com/advisories/GHSA-vr26-jcq5-fjj8

Expand Down
21 changes: 13 additions & 8 deletions rust/stackablectl/src/cmds/operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,12 @@ pub enum CmdError {
#[snafu(display("invalid repository name"))]
InvalidRepoName { source: InvalidRepoNameError },

#[snafu(display("invalid helm chart version {version:?}"))]
InvalidHelmChartVersion {
source: semver::Error,
version: String,
},

#[snafu(display("unknown repository name '{name}'"))]
UnknownRepoName { name: String },

Expand Down Expand Up @@ -524,16 +530,15 @@ where
Some(entries) => {
let mut versions = entries
.iter()
.map(|e| Version::parse(&e.version))
.map_while(|r| match r {
Ok(v) => Some(v),
Err(_) => None,
.map(|entry| {
Version::parse(&entry.version).context(InvalidHelmChartVersionSnafu {
version: entry.version.clone(),
})
})
.map(|v| v.to_string())
.collect::<Vec<String>>();

.collect::<Result<Vec<_>, _>>()?;
versions.sort();
Ok(versions)

Ok(versions.iter().map(|version| version.to_string()).collect())
}
None => Ok(vec![]),
}
Expand Down

0 comments on commit a4dedd2

Please sign in to comment.