Compare commits

..

2 commits

Author SHA1 Message Date
fe9546fbff feat: output to csv file 2024-09-07 02:42:48 +01:00
d6bb8fa4b6 feat: get dependency url 2024-09-07 02:17:34 +01:00
5 changed files with 85 additions and 5 deletions

24
Cargo.lock generated
View file

@ -148,13 +148,37 @@ version = "0.1.0"
dependencies = [ dependencies = [
"cargo_toml", "cargo_toml",
"color-eyre", "color-eyre",
"csv",
"forgejo-api", "forgejo-api",
"futures", "futures",
"semver", "semver",
"serde",
"serde_json",
"tokio", "tokio",
"url", "url",
] ]
[[package]]
name = "csv"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac574ff4d437a7b5ad237ef331c17ccca63c46479e5b5453eb8e10bb99a759fe"
dependencies = [
"csv-core",
"itoa",
"ryu",
"serde",
]
[[package]]
name = "csv-core"
version = "0.1.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5efa2b3d7902f4b634a20cae3c9c4e6209dc4779feb6863329607560143efa70"
dependencies = [
"memchr",
]
[[package]] [[package]]
name = "deranged" name = "deranged"
version = "0.3.11" version = "0.3.11"

View file

@ -7,8 +7,11 @@ edition = "2021"
[dependencies] [dependencies]
cargo_toml = "0.20.4" cargo_toml = "0.20.4"
color-eyre = "0.6.3" color-eyre = "0.6.3"
csv = "1.3.0"
forgejo-api = "0.4.1" forgejo-api = "0.4.1"
futures = "0.3.30" futures = "0.3.30"
semver = "1.0.23" semver = "1.0.23"
serde = { version = "1.0.210", features = ["derive"] }
serde_json = "1.0.128"
tokio = { version = "1.40.0", features = ["full"] } tokio = { version = "1.40.0", features = ["full"] }
url = "2.5.2" url = "2.5.2"

10
dependencies.csv Normal file
View file

@ -0,0 +1,10 @@
name,version,source
color-eyre,0.6.3,0
tracing,0.1.40,0
tracing-subscriber,0.3.18,0
cargo_toml,0.20.4,0
forgejo-api,0.4.1,0
futures,0.3.30,0
semver,1.0.23,0
tokio,1.40.0,0
url,2.5.2,0
1 name version source
2 color-eyre 0.6.3 0
3 tracing 0.1.40 0
4 tracing-subscriber 0.3.18 0
5 cargo_toml 0.20.4 0
6 forgejo-api 0.4.1 0
7 futures 0.3.30 0
8 semver 1.0.23 0
9 tokio 1.40.0 0
10 url 2.5.2 0

24
src/dependency.rs Normal file
View file

@ -0,0 +1,24 @@
use serde::Serialize;
use std::borrow::Cow;
#[derive(Debug, Clone, Copy)]
#[repr(i8)]
pub enum DependencySource {
Crates = 0,
}
impl Serialize for DependencySource {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
serializer.serialize_i8(*self as i8)
}
}
#[derive(Debug, Serialize)]
pub struct Dependency {
pub name: Cow<'static, str>,
pub version: Cow<'static, str>,
pub source: DependencySource,
}

View file

@ -1,5 +1,9 @@
use cargo_toml::{Dependency, Manifest}; mod dependency;
use cargo_toml::{Dependency as Crate, Manifest};
use color_eyre::{eyre::eyre, Result}; use color_eyre::{eyre::eyre, Result};
use csv::Writer;
use dependency::{Dependency, DependencySource};
use forgejo_api::{ use forgejo_api::{
structs::{OrgListReposQuery, RepoGetRawFileQuery}, structs::{OrgListReposQuery, RepoGetRawFileQuery},
Forgejo, Forgejo,
@ -52,8 +56,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 +76,24 @@ 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.to_string().into(),
source: DependencySource::Crates,
})
.collect();
println!("{:?}", crates); // write the dependencies to a file
let mut dependencies = vec![];
dependencies.extend(crates);
let file = std::fs::File::create("dependencies.csv")?;
let mut wtr = Writer::from_writer(file);
for dependency in dependencies {
wtr.serialize(dependency)?;
}
wtr.flush()?;
Ok(()) Ok(())
} }