Skip to content

Commit b707474

Browse files
committed
crev-to-vet converter that converts a proof db into audits.toml
1 parent 20845de commit b707474

File tree

7 files changed

+513
-20
lines changed

7 files changed

+513
-20
lines changed

Cargo.lock

+12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ members = [
66
"crev-data",
77
"crev-wot",
88
"crev-lib",
9+
"crevette",
910
]
1011

1112
[workspace.package]

crev-lib/src/local.rs

+16-20
Original file line numberDiff line numberDiff line change
@@ -1094,35 +1094,31 @@ impl Local {
10941094
continue;
10951095
}
10961096

1097-
let url = match git2::Repository::open(&path) {
1098-
Ok(repo) => Self::url_for_repo(&repo),
1099-
Err(_) => continue,
1100-
};
1101-
1102-
match url {
1103-
Ok(url) => {
1104-
let _ = self
1105-
.get_fetch_source_for_url(Url::new_git(url))
1106-
.map(|fetch_source| {
1107-
db.import_from_iter(
1108-
proofs_iter_for_path(path.clone())
1109-
.map(move |p| (p, fetch_source.clone())),
1110-
);
1111-
})
1112-
.map_err(|e| warn!("{}", e));
1113-
}
1097+
let url = match Self::url_for_repo_at_path(&path) {
1098+
Ok(url) => url,
11141099
Err(e) => {
1115-
error!("in {}: {}", path.display(), e);
1100+
warn!("repo at {}: {e}", path.display());
1101+
continue;
11161102
}
1117-
}
1103+
};
1104+
1105+
let _ = self
1106+
.get_fetch_source_for_url(Url::new_git(url))
1107+
.map(|fetch_source| {
1108+
db.import_from_iter(
1109+
proofs_iter_for_path(path.clone()).map(move |p| (p, fetch_source.clone())),
1110+
);
1111+
})
1112+
.map_err(|e| warn!("{}", e));
11181113
}
11191114

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

11221117
Ok(())
11231118
}
11241119

1125-
fn url_for_repo(repo: &git2::Repository) -> Result<String> {
1120+
pub fn url_for_repo_at_path(repo: &Path) -> Result<String> {
1121+
let repo = git2::Repository::open(repo)?;
11261122
let remote = repo.find_remote("origin")?;
11271123
let url = remote
11281124
.url()

crevette/Cargo.toml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[package]
2+
name = "crevette"
3+
description = "Converter for using cargo-crev reviews with cargo-vet"
4+
keywords = ["cargo-vet", "crev2vet", "cargo-crev", "exporter", "supply-chain-security"]
5+
categories = ["development-tools"]
6+
authors.workspace = true
7+
edition.workspace = true
8+
license.workspace = true
9+
repository.workspace = true
10+
rust-version.workspace = true
11+
version.workspace = true
12+
13+
[dependencies]
14+
crev-lib.workspace = true
15+
crev-data.workspace = true
16+
crev-wot.workspace = true
17+
semver.workspace = true
18+
serde.workspace = true
19+
toml_edit = { version = "0.19.14", features = ["serde"] }

crevette/src/bin/crevette.rs

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
use crevette::Crevette;
2+
use std::error::Error as _;
3+
use std::process::ExitCode;
4+
5+
fn main() -> ExitCode {
6+
match Crevette::new().and_then(|c| c.convert_into_repo()) {
7+
Ok(res) => {
8+
println!(
9+
"Wrote '{}'\nRun `cargo crev publish` to upload the file to {}\nThen run `cargo vet import yourname {}`\n",
10+
res.local_path.display(),
11+
res.repo_git_url.as_deref().unwrap_or("your git repo (not configured yet?)"),
12+
res.repo_https_url.as_deref().unwrap_or("https://<your repo URL>/audits.toml"),
13+
);
14+
ExitCode::SUCCESS
15+
}
16+
Err(e) => {
17+
eprintln!("error: {e}");
18+
let mut source = e.source();
19+
while let Some(e) = source {
20+
eprintln!(" {e}");
21+
source = e.source();
22+
}
23+
ExitCode::FAILURE
24+
}
25+
}
26+
}

0 commit comments

Comments
 (0)