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 forgejo_api::{
|
||||
structs::{OrgListReposQuery, RepoGetRawFileQuery},
|
||||
|
@ -6,9 +6,29 @@ use forgejo_api::{
|
|||
};
|
||||
use futures::future::join_all;
|
||||
use semver::Version;
|
||||
use std::env;
|
||||
use std::{borrow::Cow, env};
|
||||
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]
|
||||
async fn main() -> Result<()> {
|
||||
color_eyre::install()?;
|
||||
|
@ -52,8 +72,8 @@ async fn main() -> Result<()> {
|
|||
(
|
||||
name,
|
||||
match metadata {
|
||||
Dependency::Simple(version) => Some(version),
|
||||
Dependency::Detailed(details) => details.version,
|
||||
Crate::Simple(version) => Some(version),
|
||||
Crate::Detailed(details) => details.version,
|
||||
_ => None,
|
||||
},
|
||||
)
|
||||
|
@ -72,9 +92,19 @@ async fn main() -> Result<()> {
|
|||
acc.push((name, version));
|
||||
}
|
||||
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(())
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue