Skip to content

Commit

Permalink
Merge pull request #625 from divergentdave/add-diff-rs
Browse files Browse the repository at this point in the history
Add support for diff.rs to `cargo vet diff`
  • Loading branch information
mystor authored Jul 18, 2024
2 parents 5ab8fb0 + 5a61b3e commit c1145f8
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 11 deletions.
4 changes: 2 additions & 2 deletions book/src/how-it-works.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ themselves, and cargo-vet streamlines this process. Often someone will have
already audited a different version of the same crate, in which case cargo-vet
computes the relevant diffs and identifies the smallest one[^1]. After walking
the developer through the process of determining what to audit, it then presents
the relevant artifacts for inspection, either locally or on
[Sourcegraph](https://sourcegraph.com).
the relevant artifacts for inspection, either locally, on
[Sourcegraph](https://sourcegraph.com), or on [diff.rs](https://diff.rs).

Cargo-vet minimizes developer friction by storing audits in-tree. This means
that developers don’t need to navigate or authenticate with an external system.
Expand Down
14 changes: 11 additions & 3 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ pub struct InspectArgs {
pub version: VetVersion,
/// How to inspect the source
#[clap(long, action, default_value = "sourcegraph")]
pub mode: FetchMode,
pub mode: InspectFetchMode,
}

/// Emits a diff of the two versions
Expand All @@ -483,7 +483,7 @@ pub struct DiffArgs {
pub version2: VetVersion,
/// How to inspect the source
#[clap(long, action, default_value = "sourcegraph")]
pub mode: FetchMode,
pub mode: DiffFetchMode,
}

/// Certifies a package as audited
Expand Down Expand Up @@ -773,11 +773,19 @@ pub enum Verbose {
}

#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, ValueEnum)]
pub enum FetchMode {
pub enum InspectFetchMode {
Local,
Sourcegraph,
}

#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, ValueEnum)]
pub enum DiffFetchMode {
Local,
Sourcegraph,
#[clap(name = "diff.rs")]
DiffRs,
}

#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, ValueEnum)]
pub enum OutputFormat {
/// Print output in a human-readable form.
Expand Down
18 changes: 13 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ fn cmd_inspect(
version: version.clone(),
});

if sub_args.mode == FetchMode::Sourcegraph && version.git_rev.is_none() {
if sub_args.mode == InspectFetchMode::Sourcegraph && version.git_rev.is_none() {
let url = format!("https://sourcegraph.com/crates/{package}@v{version}");
tokio::runtime::Handle::current()
.block_on(prompt_criteria_eulas(
Expand Down Expand Up @@ -2052,13 +2052,21 @@ fn cmd_diff(out: &Arc<dyn Out>, cfg: &Config, sub_args: &DiffArgs) -> Result<(),
version2: version2.clone(),
});

if sub_args.mode == FetchMode::Sourcegraph
if sub_args.mode != FetchMode::Local
&& version1.git_rev.is_none()
&& version2.git_rev.is_none()
{
let url = format!(
"https://sourcegraph.com/crates/{package}/-/compare/v{version1}...v{version2}?visible=7000"
);
let url = match sub_args.mode {
DiffFetchMode::Sourcegraph => {
format!(
"https://sourcegraph.com/crates/{package}/-/compare/v{version1}...v{version2}?visible=7000"
)
}
DiffFetchMode::DiffRs => {
format!("https://diff.rs/{package}/{version1}/{version2}/")
}
DiffFetchMode::Local => unreachable!(),
};
tokio::runtime::Handle::current()
.block_on(prompt_criteria_eulas(
out,
Expand Down
2 changes: 1 addition & 1 deletion tests/snapshots/test_cli__markdown-help.snap
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ The target version to diff
How to inspect the source
\[default: sourcegraph]
\[possible values: local, sourcegraph]
\[possible values: local, sourcegraph, diff.rs]
#### `-h, --help`
Print help information
Expand Down

0 comments on commit c1145f8

Please sign in to comment.