Skip to content

Commit

Permalink
crev-to-vet converter that converts a proof db into audits.toml
Browse files Browse the repository at this point in the history
  • Loading branch information
kornelski committed Sep 5, 2023
1 parent 20845de commit b707474
Show file tree
Hide file tree
Showing 7 changed files with 513 additions and 20 deletions.
12 changes: 12 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ members = [
"crev-data",
"crev-wot",
"crev-lib",
"crevette",
]

[workspace.package]
Expand Down
36 changes: 16 additions & 20 deletions crev-lib/src/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1094,35 +1094,31 @@ impl Local {
continue;
}

let url = match git2::Repository::open(&path) {
Ok(repo) => Self::url_for_repo(&repo),
Err(_) => continue,
};

match url {
Ok(url) => {
let _ = self
.get_fetch_source_for_url(Url::new_git(url))
.map(|fetch_source| {
db.import_from_iter(
proofs_iter_for_path(path.clone())
.map(move |p| (p, fetch_source.clone())),
);
})
.map_err(|e| warn!("{}", e));
}
let url = match Self::url_for_repo_at_path(&path) {
Ok(url) => url,
Err(e) => {
error!("in {}: {}", path.display(), e);
warn!("repo at {}: {e}", path.display());
continue;
}
}
};

let _ = self
.get_fetch_source_for_url(Url::new_git(url))
.map(|fetch_source| {
db.import_from_iter(
proofs_iter_for_path(path.clone()).map(move |p| (p, fetch_source.clone())),
);
})
.map_err(|e| warn!("{}", e));
}

self.fetch_all_ids_recursively(fetched_urls, &mut db)?;

Ok(())
}

fn url_for_repo(repo: &git2::Repository) -> Result<String> {
pub fn url_for_repo_at_path(repo: &Path) -> Result<String> {
let repo = git2::Repository::open(repo)?;
let remote = repo.find_remote("origin")?;
let url = remote
.url()
Expand Down
19 changes: 19 additions & 0 deletions crevette/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[package]
name = "crevette"
description = "Converter for using cargo-crev reviews with cargo-vet"
keywords = ["cargo-vet", "crev2vet", "cargo-crev", "exporter", "supply-chain-security"]
categories = ["development-tools"]
authors.workspace = true
edition.workspace = true
license.workspace = true
repository.workspace = true
rust-version.workspace = true
version.workspace = true

[dependencies]
crev-lib.workspace = true
crev-data.workspace = true
crev-wot.workspace = true
semver.workspace = true
serde.workspace = true
toml_edit = { version = "0.19.14", features = ["serde"] }
26 changes: 26 additions & 0 deletions crevette/src/bin/crevette.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use crevette::Crevette;
use std::error::Error as _;
use std::process::ExitCode;

fn main() -> ExitCode {
match Crevette::new().and_then(|c| c.convert_into_repo()) {
Ok(res) => {
println!(
"Wrote '{}'\nRun `cargo crev publish` to upload the file to {}\nThen run `cargo vet import yourname {}`\n",
res.local_path.display(),
res.repo_git_url.as_deref().unwrap_or("your git repo (not configured yet?)"),
res.repo_https_url.as_deref().unwrap_or("https://<your repo URL>/audits.toml"),
);
ExitCode::SUCCESS
}
Err(e) => {
eprintln!("error: {e}");
let mut source = e.source();
while let Some(e) = source {
eprintln!(" {e}");
source = e.source();
}
ExitCode::FAILURE
}
}
}
Loading

0 comments on commit b707474

Please sign in to comment.