fix: ensure only latest version of crate appears
This commit is contained in:
parent
06307071d4
commit
2869d692e8
3 changed files with 23 additions and 1 deletions
7
Cargo.lock
generated
7
Cargo.lock
generated
|
@ -150,6 +150,7 @@ dependencies = [
|
|||
"color-eyre",
|
||||
"forgejo-api",
|
||||
"futures",
|
||||
"semver",
|
||||
"tokio",
|
||||
"url",
|
||||
]
|
||||
|
@ -856,6 +857,12 @@ dependencies = [
|
|||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "semver"
|
||||
version = "1.0.23"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b"
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.210"
|
||||
|
|
|
@ -9,5 +9,6 @@ cargo_toml = "0.20.4"
|
|||
color-eyre = "0.6.3"
|
||||
forgejo-api = "0.4.1"
|
||||
futures = "0.3.30"
|
||||
semver = "1.0.23"
|
||||
tokio = { version = "1.40.0", features = ["full"] }
|
||||
url = "2.5.2"
|
||||
|
|
16
src/main.rs
16
src/main.rs
|
@ -5,6 +5,7 @@ use forgejo_api::{
|
|||
Forgejo,
|
||||
};
|
||||
use futures::future::join_all;
|
||||
use semver::Version;
|
||||
use std::env;
|
||||
use url::Url;
|
||||
|
||||
|
@ -58,7 +59,20 @@ async fn main() -> Result<()> {
|
|||
)
|
||||
})
|
||||
.filter_map(|(name, version)| version.map(|version| (name, version)))
|
||||
.collect();
|
||||
.map(|(name, version)| (name, Version::parse(&version)))
|
||||
.filter_map(|(name, version)| version.ok().map(|version| (name, version)))
|
||||
// ensure we only have the latest version of each crate
|
||||
.fold(Vec::new(), |mut acc, (name, version)| {
|
||||
if let Some((_, existing_version)) = acc.iter().find(|(n, _)| n == &name) {
|
||||
if &version > existing_version {
|
||||
acc.retain(|(n, _)| n != &name);
|
||||
acc.push((name, version));
|
||||
}
|
||||
} else {
|
||||
acc.push((name, version));
|
||||
}
|
||||
acc
|
||||
});
|
||||
|
||||
println!("{:?}", crates);
|
||||
|
||||
|
|
Loading…
Reference in a new issue