Skip to content

Commit 3606426

Browse files
committed
feat(harbor-sbom-browser): sort releases by semantic version
1 parent c30657b commit 3606426

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[toolchain]
2-
channel = "1.77.0"
2+
channel = "1.82.0"
33
components = ["rustc", "cargo", "rustfmt", "clippy", "rust-analyzer", "rust-src"]

tools/harbor-sbom-browser/src/handlers/artifact_tree.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,27 @@ pub async fn render_as_html(
118118
<ul id='tree'>"#,
119119
);
120120

121-
for (release_version, repositories) in artifact_tree {
121+
// Convert the artifact tree into a sorted list of releases
122+
let mut releases: Vec<(&String, &BTreeMap<String, BTreeSet<TagInfo>>)> = artifact_tree.iter().collect();
123+
releases.sort_by(|(ver_a, _), (ver_b, _)| {
124+
// Parse versions like "24.3.0" into components for semantic comparison
125+
let parse_version = |v: &str| -> Vec<u32> {
126+
v.split('.')
127+
.filter_map(|part| {
128+
// Ignore any suffixes like "-dev" or "-arm64"
129+
part.split('-')
130+
.next()
131+
.and_then(|num| num.parse::<u32>().ok())
132+
})
133+
.collect()
134+
};
135+
136+
let ver_a_parts = parse_version(ver_a);
137+
let ver_b_parts = parse_version(ver_b);
138+
ver_b_parts.cmp(&ver_a_parts) // Reverse order to get newest versions first
139+
});
140+
141+
for (release_version, repositories) in releases {
122142
html.push_str(&format!("<li>Release {}<ul>", release_version));
123143
for (repository, artifacts) in repositories {
124144
html.push_str(&format!("<li>{}<ul>", repository));

0 commit comments

Comments
 (0)