feat: get dependency url
This commit is contained in:
parent
2869d692e8
commit
d6bb8fa4b6
1 changed files with 36 additions and 6 deletions
42
src/main.rs
42
src/main.rs
|
@ -1,4 +1,4 @@
|
||||||
use cargo_toml::{Dependency, Manifest};
|
use cargo_toml::{Dependency as Crate, Manifest};
|
||||||
use color_eyre::{eyre::eyre, Result};
|
use color_eyre::{eyre::eyre, Result};
|
||||||
use forgejo_api::{
|
use forgejo_api::{
|
||||||
structs::{OrgListReposQuery, RepoGetRawFileQuery},
|
structs::{OrgListReposQuery, RepoGetRawFileQuery},
|
||||||
|
@ -6,9 +6,29 @@ use forgejo_api::{
|
||||||
};
|
};
|
||||||
use futures::future::join_all;
|
use futures::future::join_all;
|
||||||
use semver::Version;
|
use semver::Version;
|
||||||
use std::env;
|
use std::{borrow::Cow, env};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
enum DependencySource {
|
||||||
|
Crates,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct Dependency {
|
||||||
|
name: Cow<'static, str>,
|
||||||
|
version: Version,
|
||||||
|
source: DependencySource,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Dependency {
|
||||||
|
pub fn get_url(&self) -> String {
|
||||||
|
match self.source {
|
||||||
|
DependencySource::Crates => format!("https://crates.io/crates/{}", self.name),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<()> {
|
async fn main() -> Result<()> {
|
||||||
color_eyre::install()?;
|
color_eyre::install()?;
|
||||||
|
@ -52,8 +72,8 @@ async fn main() -> Result<()> {
|
||||||
(
|
(
|
||||||
name,
|
name,
|
||||||
match metadata {
|
match metadata {
|
||||||
Dependency::Simple(version) => Some(version),
|
Crate::Simple(version) => Some(version),
|
||||||
Dependency::Detailed(details) => details.version,
|
Crate::Detailed(details) => details.version,
|
||||||
_ => None,
|
_ => None,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -72,9 +92,19 @@ async fn main() -> Result<()> {
|
||||||
acc.push((name, version));
|
acc.push((name, version));
|
||||||
}
|
}
|
||||||
acc
|
acc
|
||||||
});
|
})
|
||||||
|
.iter()
|
||||||
|
.map(|(name, version)| Dependency {
|
||||||
|
name: name.clone().into(),
|
||||||
|
version: version.clone(),
|
||||||
|
source: DependencySource::Crates,
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
|
||||||
println!("{:?}", crates);
|
println!(
|
||||||
|
"{:?}",
|
||||||
|
crates.iter().map(|c| c.get_url()).collect::<Vec<_>>()
|
||||||
|
);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue