From 460a831c3f9c2c7f366887a0c1a1b16141488f3f Mon Sep 17 00:00:00 2001 From: figsoda Date: Sun, 1 Feb 2026 16:56:24 -0500 Subject: [PATCH] github: sort tags --- Cargo.lock | 7 +++++++ Cargo.toml | 1 + src/fetcher/github.rs | 9 ++++++++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 6a930a0..56a7584 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3236,6 +3236,7 @@ dependencies = [ "tracing", "tracing-subscriber", "url", + "version-compare", "which", "xdg", "zip", @@ -5353,6 +5354,12 @@ version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" +[[package]] +name = "version-compare" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03c2856837ef78f57382f06b2b8563a2f512f7185d732608fd9176cb3b8edf0e" + [[package]] name = "version_check" version = "0.9.5" diff --git a/Cargo.toml b/Cargo.toml index fc1ba63..0faa553 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -53,6 +53,7 @@ serde_yaml = "0.9.34" shlex = "1.3.0" spdx = "0.13.3" tar = "0.4.44" +version-compare = "0.2.1" tempfile = "3.24.0" time = { version = "0.3.45", features = ["parsing", "serde"] } tracing = "0.1.44" diff --git a/src/fetcher/github.rs b/src/fetcher/github.rs index 108bb8e..f675f09 100644 --- a/src/fetcher/github.rs +++ b/src/fetcher/github.rs @@ -1,8 +1,10 @@ use anyhow::Result; +use itertools::Itertools; use reqwest::{Client, header::HeaderMap}; use rustc_hash::FxHashMap; use rustyline::completion::Pair; use serde::Deserialize; +use version_compare::{Cmp, compare}; use crate::{ cfg::AccessTokens, @@ -100,10 +102,15 @@ impl Fetcher for FetchFromGitHub { if let Some(tags) = tags { let mut tags = tags .into_iter() - .rev() .filter_map(|Reference { reference }| { reference.strip_prefix("refs/tags/").map(ToOwned::to_owned) }) + .sorted_unstable_by(|x, y| { + compare(y, x) + .ok() + .and_then(Cmp::ord) + .unwrap_or_else(|| y.cmp(x)) + }) .take(12); if latest.is_empty()