From a3c49743e899046fa999f7682289df563926496e Mon Sep 17 00:00:00 2001 From: Andrew Lilley Brinker Date: Mon, 6 May 2024 13:49:33 -0700 Subject: [PATCH 01/14] chore: Moved `hc_version` into `hc_common`. This commit eliminates the `hc_version` crate by moving its contents into `hc_common`. Signed-off-by: Andrew Lilley Brinker --- Cargo.lock | 18 +++++------ Cargo.toml | 7 +---- libs/hc_analysis/Cargo.toml | 3 +- libs/hc_analysis/src/session/mod.rs | 5 ++-- libs/hc_common/Cargo.toml | 12 ++++++-- libs/{hc_version/src => hc_common}/build.rs | 14 ++++----- libs/hc_common/src/lib.rs | 1 + .../src/lib.rs => hc_common/src/version.rs} | 30 ++++++++++++++----- libs/hc_core/Cargo.toml | 2 -- libs/hc_core/src/lib.rs | 2 +- libs/hc_data/Cargo.toml | 6 ++-- libs/hc_data/src/git/query/mod.rs | 3 +- libs/hc_data/src/query/code_quality.rs | 3 +- libs/hc_data/src/query/dependencies.rs | 3 +- libs/hc_report/Cargo.toml | 1 - libs/hc_report/src/query.rs | 2 +- libs/hc_version/Cargo.toml | 13 -------- libs/hc_version/src/query.rs | 24 --------------- 18 files changed, 61 insertions(+), 88 deletions(-) rename libs/{hc_version/src => hc_common}/build.rs (77%) rename libs/{hc_version/src/lib.rs => hc_common/src/version.rs} (51%) delete mode 100644 libs/hc_version/Cargo.toml delete mode 100644 libs/hc_version/src/query.rs diff --git a/Cargo.lock b/Cargo.lock index 4e48250e..3ed39c90 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -86,6 +86,12 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "anyhow" +version = "1.0.83" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25bdb32cbbdce2b519a9cd7df3a678443100e265d5e25ca763b7572a5104f5f3" + [[package]] name = "ascii" version = "0.9.3" @@ -611,7 +617,6 @@ dependencies = [ "hc_report", "hc_serde", "hc_shell", - "hc_version", "maplit", "petgraph", "serde_derive", @@ -629,6 +634,7 @@ dependencies = [ name = "hc_common" version = "0.1.0" dependencies = [ + "anyhow", "chrono", "hc_serde", "lazy_static", @@ -662,7 +668,6 @@ dependencies = [ "hc_analysis", "hc_common", "hc_shell", - "hc_version", "tempfile", ] @@ -676,7 +681,6 @@ dependencies = [ "hc_config", "hc_serde", "hc_shell", - "hc_version", "nom", "petgraph", "tempfile", @@ -688,7 +692,6 @@ name = "hc_report" version = "0.1.0" dependencies = [ "hc_common", - "hc_version", "paste", ] @@ -711,13 +714,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "hc_version" -version = "0.1.0" -dependencies = [ - "hc_common", -] - [[package]] name = "heck" version = "0.3.3" diff --git a/Cargo.toml b/Cargo.toml index 2caef84f..cace5fda 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,12 +6,7 @@ cargo-features = ["resolver"] resolver = "2" # All the actual crates are in `libs/` or `hipcheck/` -members = [ - "hipcheck", - "libs/*", - "xtask", -] +members = ["hipcheck", "libs/*", "xtask"] # Make sure Hipcheck is run with `cargo run`. default-members = ["hipcheck"] - diff --git a/libs/hc_analysis/Cargo.toml b/libs/hc_analysis/Cargo.toml index 84c2af06..6fb40b51 100644 --- a/libs/hc_analysis/Cargo.toml +++ b/libs/hc_analysis/Cargo.toml @@ -17,7 +17,6 @@ hc_data = { path = "../hc_data" } hc_report = { path = "../hc_report" } hc_serde = { path = "../hc_serde" } hc_shell = { path = "../hc_shell" } -hc_version = { path = "../hc_version" } maplit = "1.0.2" petgraph = { version = "0.6.0" } serde_derive = "1.0.137" @@ -30,4 +29,4 @@ walkdir = "2" xml-rs = "0.8" [dev_dependencies] -tempfile = "3.10.1" \ No newline at end of file +tempfile = "3.10.1" diff --git a/libs/hc_analysis/src/session/mod.rs b/libs/hc_analysis/src/session/mod.rs index 8f27e3c7..0bb3af96 100644 --- a/libs/hc_analysis/src/session/mod.rs +++ b/libs/hc_analysis/src/session/mod.rs @@ -17,7 +17,9 @@ use hc_common::{ command_util::DependentProgram, error::{Error, Result}, filesystem::create_dir_all, - hc_error, pathbuf, salsa, HIPCHECK_TOML_FILE, + hc_error, pathbuf, salsa, + version::{get_version, VersionQuery, VersionQueryStorage}, + HIPCHECK_TOML_FILE, }; use hc_config::{ AttacksConfigQueryStorage, CommitConfigQueryStorage, Config, ConfigSource, ConfigSourceStorage, @@ -37,7 +39,6 @@ use hc_data::{ }; use hc_report::{Format, ReportParams, ReportParamsStorage}; use hc_shell::{Phase, Shell}; -use hc_version::{get_version, VersionQuery, VersionQueryStorage}; use std::ffi::{OsStr, OsString}; use std::fmt; use std::path::{Path, PathBuf}; diff --git a/libs/hc_common/Cargo.toml b/libs/hc_common/Cargo.toml index 8024994c..f50ba786 100644 --- a/libs/hc_common/Cargo.toml +++ b/libs/hc_common/Cargo.toml @@ -14,9 +14,17 @@ once_cell = "1.10.0" ordered-float = { version = "4.2.0", features = ["serde"] } regex = "1.5.5" salsa = "0.16.1" -schemars = { version = "0.8.17", default-features = false, features = ["derive", "preserve_order", "chrono" ] } +schemars = { version = "0.8.17", default-features = false, features = [ + "derive", + "preserve_order", + "chrono", +] } semver = "1.0.9" serde_json = "1.0.80" toml = "0.8.12" url = "2.2.2" -which = { version = "6.0.1", default-features = false } \ No newline at end of file +which = { version = "6.0.1", default-features = false } + +[build-dependencies] +anyhow = "1.0.83" +which = { version = "6.0.1", default-features = false } diff --git a/libs/hc_version/src/build.rs b/libs/hc_common/build.rs similarity index 77% rename from libs/hc_version/src/build.rs rename to libs/hc_common/build.rs index 42df4c0b..6a23a56c 100644 --- a/libs/hc_version/src/build.rs +++ b/libs/hc_common/build.rs @@ -1,12 +1,13 @@ // SPDX-License-Identifier: Apache-2.0 -use hc_common::{command_util::log_git_args, context::Context, error::Result, hc_error, which}; +use anyhow::{anyhow, Context as _, Result}; use std::convert::AsRef; use std::ffi::OsStr; use std::iter::IntoIterator; use std::ops::Not as _; use std::path::Path; use std::process::Command; +use which::which; fn main() { let repo_dir = env!("CARGO_MANIFEST_DIR", "can't find Cargo manifest directory"); @@ -38,11 +39,8 @@ impl GitCommand { S: AsRef, { // Init the command. - let git_path = which::which("git").context("can't find git command")?; - let repo = repo_path.display().to_string(); - let path = git_path.display().to_string(); - log_git_args(&repo, args, &path); - let mut command = Command::new(&git_path); + let git_path = which("git").context("can't find git command")?; + let mut command = Command::new(git_path); command.args(args); // Set the path if necessary @@ -67,12 +65,12 @@ impl GitCommand { } match String::from_utf8(output.stderr) { - Ok(msg) if msg.is_empty().not() => Err(hc_error!( + Ok(msg) if msg.is_empty().not() => Err(anyhow!( "git failed with message '{}' [status: {}]", msg.trim(), output.status )), - _ => Err(hc_error!("git failed [status: {}]", output.status)), + _ => Err(anyhow!("git failed [status: {}]", output.status)), } } } diff --git a/libs/hc_common/src/lib.rs b/libs/hc_common/src/lib.rs index eba442bd..4864a2f0 100644 --- a/libs/hc_common/src/lib.rs +++ b/libs/hc_common/src/lib.rs @@ -13,6 +13,7 @@ pub mod test_util; mod tests; mod try_any; mod try_filter; +pub mod version; pub use try_any::TryAny; pub use try_filter::{FallibleFilter, TryFilter}; diff --git a/libs/hc_version/src/lib.rs b/libs/hc_common/src/version.rs similarity index 51% rename from libs/hc_version/src/lib.rs rename to libs/hc_common/src/version.rs index 3141c337..8876ee90 100644 --- a/libs/hc_version/src/lib.rs +++ b/libs/hc_common/src/version.rs @@ -1,15 +1,11 @@ // SPDX-License-Identifier: Apache-2.0 -mod query; - -pub use query::*; - -use hc_common::{context::Context, error::Result, log, semver::Version}; +use crate::{context::Context, error::Result, log, salsa, semver::Version}; use std::ops::Not as _; +use std::rc::Rc; +/// Query the environment to identify the proper version string. pub fn get_version(raw_version: &str) -> Result { - // Queries the environment to identify the proper version string. - // // Basic algorithm: // 1. Check the version number in `Cargo.toml`. // 2. If it's an "alpha" release, then in addition to printing @@ -31,3 +27,23 @@ pub fn get_version(raw_version: &str) -> Result { Ok(raw_version.to_string()) } + +/// Queries for current versions of Hipcheck and tool dependencies +#[salsa::query_group(VersionQueryStorage)] +pub trait VersionQuery: salsa::Database { + /// Returns the current Hipcheck version + #[salsa::input] + fn hc_version(&self) -> Rc; + + /// Returns the version of npm currently running on user's machine + #[salsa::input] + fn npm_version(&self) -> Rc; + + /// Returns the version of eslint currently running on user's machine + #[salsa::input] + fn eslint_version(&self) -> Rc; + + /// Returns the version of git currently running on user's machine + #[salsa::input] + fn git_version(&self) -> Rc; +} diff --git a/libs/hc_core/Cargo.toml b/libs/hc_core/Cargo.toml index 82a79a14..d78f20f9 100644 --- a/libs/hc_core/Cargo.toml +++ b/libs/hc_core/Cargo.toml @@ -9,7 +9,6 @@ publish = false hc_analysis = { path = "../hc_analysis" } hc_common = { path = "../hc_common" } hc_shell = { path = "../hc_shell" } -hc_version = { path = "../hc_version" } [dev_dependencies] duct = "0.13.7" @@ -25,4 +24,3 @@ path = "../../benches/basic.rs" [[test]] name = "can_run" path = "../../tests/can_run.rs" - diff --git a/libs/hc_core/src/lib.rs b/libs/hc_core/src/lib.rs index a4299558..f4c55483 100644 --- a/libs/hc_core/src/lib.rs +++ b/libs/hc_core/src/lib.rs @@ -4,8 +4,8 @@ pub use hc_analysis::{ report_builder::{AnyReport, Format, PrReport, Report}, session::{resolve_config, resolve_data, resolve_home, Check, CheckType}, }; +pub use hc_common::version; pub use hc_shell::{ColorChoice, Output, Shell, Verbosity}; -pub use hc_version as version; use hc_analysis::{ report_builder::{build_pr_report, build_report}, diff --git a/libs/hc_data/Cargo.toml b/libs/hc_data/Cargo.toml index c338b195..d89dcc8f 100644 --- a/libs/hc_data/Cargo.toml +++ b/libs/hc_data/Cargo.toml @@ -11,11 +11,13 @@ graphql_client = "0.14.0" hc_common = { path = "../hc_common" } hc_config = { path = "../hc_config" } hc_shell = { path = "../hc_shell" } -hc_version = { path = "../hc_version" } nom = "7.1.3" petgraph = { version = "0.6.0", features = ["serde-1"] } serde = { path = "../hc_serde", package = "hc_serde" } -ureq = { version = "2.9.7", default-features = false, features = ["json", "native-tls"] } +ureq = { version = "2.9.7", default-features = false, features = [ + "json", + "native-tls", +] } [dev-dependencies] dirs = "5.0.1" diff --git a/libs/hc_data/src/git/query/mod.rs b/libs/hc_data/src/git/query/mod.rs index da1e8997..0e461561 100644 --- a/libs/hc_data/src/git/query/mod.rs +++ b/libs/hc_data/src/git/query/mod.rs @@ -12,8 +12,7 @@ use crate::{ }, source::SourceQuery, }; -use hc_common::{chrono::prelude::*, error::Result, salsa}; -use hc_version::VersionQuery; +use hc_common::{chrono::prelude::*, error::Result, salsa, version::VersionQuery}; use std::rc::Rc; /// Queries about Git objects diff --git a/libs/hc_data/src/query/code_quality.rs b/libs/hc_data/src/query/code_quality.rs index ed18a5eb..41c9b674 100644 --- a/libs/hc_data/src/query/code_quality.rs +++ b/libs/hc_data/src/query/code_quality.rs @@ -6,8 +6,7 @@ use std::rc::Rc; use crate::code_quality::{get_eslint_report, CodeQualityReport}; use crate::source::SourceQuery; -use hc_common::{error::Result, salsa}; -use hc_version::VersionQuery; +use hc_common::{error::Result, salsa, version::VersionQuery}; /// Queries about code quality #[salsa::query_group(CodeQualityProviderStorage)] diff --git a/libs/hc_data/src/query/dependencies.rs b/libs/hc_data/src/query/dependencies.rs index bbd3f12d..a8e819cc 100644 --- a/libs/hc_data/src/query/dependencies.rs +++ b/libs/hc_data/src/query/dependencies.rs @@ -5,8 +5,7 @@ use crate::npm::{get_package_file, PackageFile}; use crate::source::SourceQuery; use crate::Dependencies; -use hc_common::{error::Result, salsa}; -use hc_version::VersionQuery; +use hc_common::{error::Result, salsa, version::VersionQuery}; use std::rc::Rc; /// Queries about dependencies diff --git a/libs/hc_report/Cargo.toml b/libs/hc_report/Cargo.toml index 8d392dbd..5b705a9a 100644 --- a/libs/hc_report/Cargo.toml +++ b/libs/hc_report/Cargo.toml @@ -7,5 +7,4 @@ publish = false [dependencies] hc_common = { path = "../hc_common" } -hc_version = { path = "../hc_version" } paste = "1.0.7" diff --git a/libs/hc_report/src/query.rs b/libs/hc_report/src/query.rs index 3a93037e..56687fa5 100644 --- a/libs/hc_report/src/query.rs +++ b/libs/hc_report/src/query.rs @@ -2,7 +2,7 @@ //! Query groups for how Hipcheck reports and dumps session results. -pub use hc_version::VersionQuery; +pub use hc_common::version::VersionQuery; use crate::Format; use hc_common::{chrono::prelude::*, salsa}; diff --git a/libs/hc_version/Cargo.toml b/libs/hc_version/Cargo.toml deleted file mode 100644 index 039dd8a8..00000000 --- a/libs/hc_version/Cargo.toml +++ /dev/null @@ -1,13 +0,0 @@ -[package] -name = "hc_version" -version = "0.1.0" -edition = "2021" -license = "Apache-2.0" -publish = false -build = "src/build.rs" - -[dependencies] -hc_common = { path = "../hc_common" } - -[build-dependencies] -hc_common = { path = "../hc_common" } \ No newline at end of file diff --git a/libs/hc_version/src/query.rs b/libs/hc_version/src/query.rs deleted file mode 100644 index e1b05b1d..00000000 --- a/libs/hc_version/src/query.rs +++ /dev/null @@ -1,24 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 - -//! A query group for current versions of Hipcheck and tool -//! dependencies. - -use hc_common::salsa; -use std::rc::Rc; - -/// Queries for current versions of Hipcheck and tool dependencies -#[salsa::query_group(VersionQueryStorage)] -pub trait VersionQuery: salsa::Database { - /// Returns the current Hipcheck version - #[salsa::input] - fn hc_version(&self) -> Rc; - /// Returns the version of npm currently running on user's machine - #[salsa::input] - fn npm_version(&self) -> Rc; - /// Returns the version of eslint currently running on user's machine - #[salsa::input] - fn eslint_version(&self) -> Rc; - /// Returns the version of git currently running on user's machine - #[salsa::input] - fn git_version(&self) -> Rc; -} From 1aa7b25851376e14787f1dc075187a6425cc2fa2 Mon Sep 17 00:00:00 2001 From: Andrew Lilley Brinker Date: Mon, 6 May 2024 13:59:35 -0700 Subject: [PATCH 02/14] chore: Merge `hc_config` into `hc_common` This commit moves `hc_config` into `hc_common`. Signed-off-by: Andrew Lilley Brinker --- Cargo.lock | 11 +- libs/hc_analysis/Cargo.toml | 1 - libs/hc_analysis/src/analysis.rs | 2 +- .../src/metric/binary_detector/query.rs | 4 +- libs/hc_analysis/src/metric/linguist/query.rs | 3 +- libs/hc_analysis/src/metric/mod.rs | 7 +- libs/hc_analysis/src/report_builder.rs | 2 +- libs/hc_analysis/src/session/mod.rs | 10 +- libs/hc_common/Cargo.toml | 1 + .../src/query.rs => hc_common/src/config.rs} | 463 ++++++++++++++++- libs/hc_common/src/lib.rs | 1 + libs/hc_config/Cargo.toml | 10 - libs/hc_config/src/lib.rs | 465 ------------------ libs/hc_data/Cargo.toml | 1 - libs/hc_data/src/query/fuzz.rs | 2 +- libs/hc_data/src/query/pr_review.rs | 2 +- 16 files changed, 478 insertions(+), 507 deletions(-) rename libs/{hc_config/src/query.rs => hc_common/src/config.rs} (52%) delete mode 100644 libs/hc_config/Cargo.toml delete mode 100644 libs/hc_config/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index 3ed39c90..c9f132bc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -612,7 +612,6 @@ dependencies = [ "dotenv", "glob", "hc_common", - "hc_config", "hc_data", "hc_report", "hc_serde", @@ -646,19 +645,12 @@ dependencies = [ "schemars", "semver", "serde_json", + "smart-default", "toml", "url", "which", ] -[[package]] -name = "hc_config" -version = "0.1.0" -dependencies = [ - "hc_common", - "smart-default", -] - [[package]] name = "hc_core" version = "0.1.0" @@ -678,7 +670,6 @@ dependencies = [ "dirs", "graphql_client", "hc_common", - "hc_config", "hc_serde", "hc_shell", "nom", diff --git a/libs/hc_analysis/Cargo.toml b/libs/hc_analysis/Cargo.toml index 6fb40b51..54ce57aa 100644 --- a/libs/hc_analysis/Cargo.toml +++ b/libs/hc_analysis/Cargo.toml @@ -12,7 +12,6 @@ dotenv = "0.15.0" curl = "0.4.38" glob = "0.3.0" hc_common = { path = "../hc_common" } -hc_config = { path = "../hc_config" } hc_data = { path = "../hc_data" } hc_report = { path = "../hc_report" } hc_serde = { path = "../hc_serde" } diff --git a/libs/hc_analysis/src/analysis.rs b/libs/hc_analysis/src/analysis.rs index 72bb78f9..c2191ded 100644 --- a/libs/hc_analysis/src/analysis.rs +++ b/libs/hc_analysis/src/analysis.rs @@ -3,10 +3,10 @@ use crate::metric::{affiliation::AffiliatedType, MetricProvider}; use hc_common::{ chrono::Duration, + config::{AttacksConfigQuery, CommitConfigQuery, FuzzConfigQuery, PracticesConfigQuery}, error::{Error, Result}, salsa, F64, }; -use hc_config::{AttacksConfigQuery, CommitConfigQuery, FuzzConfigQuery, PracticesConfigQuery}; use hc_data::git::GitProvider; use hc_report::{Concern, PrConcern}; use std::collections::{HashMap, HashSet}; diff --git a/libs/hc_analysis/src/metric/binary_detector/query.rs b/libs/hc_analysis/src/metric/binary_detector/query.rs index d5502857..2c1295d0 100644 --- a/libs/hc_analysis/src/metric/binary_detector/query.rs +++ b/libs/hc_analysis/src/metric/binary_detector/query.rs @@ -3,9 +3,7 @@ //! A query group for binary file detection queries. use crate::metric::binary_detector::BinaryFileDetector; -use hc_common::context::Context as _; -use hc_common::{error::Result, salsa}; -use hc_config::PracticesConfigQuery; +use hc_common::{config::PracticesConfigQuery, context::Context as _, error::Result, salsa}; use std::rc::Rc; /// Queries related to binary file detection diff --git a/libs/hc_analysis/src/metric/linguist/query.rs b/libs/hc_analysis/src/metric/linguist/query.rs index 94eee4e2..1ecf8089 100644 --- a/libs/hc_analysis/src/metric/linguist/query.rs +++ b/libs/hc_analysis/src/metric/linguist/query.rs @@ -3,8 +3,7 @@ //! A query group for source file language detection queries. use crate::metric::linguist::SourceFileDetector; -use hc_common::{context::Context, error::Result, salsa}; -use hc_config::LanguagesConfigQuery; +use hc_common::{config::LanguagesConfigQuery, context::Context, error::Result, salsa}; use std::rc::Rc; /// Queries related to source file language detection diff --git a/libs/hc_analysis/src/metric/mod.rs b/libs/hc_analysis/src/metric/mod.rs index bc86df28..6da761d2 100644 --- a/libs/hc_analysis/src/metric/mod.rs +++ b/libs/hc_analysis/src/metric/mod.rs @@ -28,8 +28,11 @@ use commit_trust::CommitTrustOutput; use contributor_trust::ContributorTrustOutput; use entropy::EntropyOutput; use fuzz::FuzzOutput; -use hc_common::{error::Result, salsa}; -use hc_config::{AttacksConfigQuery, CommitConfigQuery}; +use hc_common::{ + config::{AttacksConfigQuery, CommitConfigQuery}, + error::Result, + salsa, +}; use hc_data::{ git::GitProvider, DependenciesProvider, FuzzProvider, ModuleProvider, PullRequestReviewProvider, }; diff --git a/libs/hc_analysis/src/report_builder.rs b/libs/hc_analysis/src/report_builder.rs index dace63bb..4d7339ec 100644 --- a/libs/hc_analysis/src/report_builder.rs +++ b/libs/hc_analysis/src/report_builder.rs @@ -2,10 +2,10 @@ use crate::{analysis::AnalysisReport, score::ScoringResults, session::Session}; use hc_common::{ + config::RiskConfigQuery, error::{Error, Result}, hc_error, log, }; -use hc_config::RiskConfigQuery; use hc_data::source::SourceQuery; pub use hc_report::*; use std::default::Default; diff --git a/libs/hc_analysis/src/session/mod.rs b/libs/hc_analysis/src/session/mod.rs index 0bb3af96..50a3b845 100644 --- a/libs/hc_analysis/src/session/mod.rs +++ b/libs/hc_analysis/src/session/mod.rs @@ -15,17 +15,17 @@ use hc_common::context::Context as _; use hc_common::{ chrono::prelude::*, command_util::DependentProgram, + config::{ + AttacksConfigQueryStorage, CommitConfigQueryStorage, Config, ConfigSource, + ConfigSourceStorage, FuzzConfigQueryStorage, LanguagesConfigQueryStorage, + PracticesConfigQueryStorage, RiskConfigQueryStorage, + }, error::{Error, Result}, filesystem::create_dir_all, hc_error, pathbuf, salsa, version::{get_version, VersionQuery, VersionQueryStorage}, HIPCHECK_TOML_FILE, }; -use hc_config::{ - AttacksConfigQueryStorage, CommitConfigQueryStorage, Config, ConfigSource, ConfigSourceStorage, - FuzzConfigQueryStorage, LanguagesConfigQueryStorage, PracticesConfigQueryStorage, - RiskConfigQueryStorage, -}; use hc_data::ModuleProvider; use hc_data::{ git::get_git_version, diff --git a/libs/hc_common/Cargo.toml b/libs/hc_common/Cargo.toml index f50ba786..7e7b5ffc 100644 --- a/libs/hc_common/Cargo.toml +++ b/libs/hc_common/Cargo.toml @@ -21,6 +21,7 @@ schemars = { version = "0.8.17", default-features = false, features = [ ] } semver = "1.0.9" serde_json = "1.0.80" +smart-default = "0.7.1" toml = "0.8.12" url = "2.2.2" which = { version = "6.0.1", default-features = false } diff --git a/libs/hc_config/src/query.rs b/libs/hc_common/src/config.rs similarity index 52% rename from libs/hc_config/src/query.rs rename to libs/hc_common/src/config.rs index cb8cdb7e..0edb367d 100644 --- a/libs/hc_config/src/query.rs +++ b/libs/hc_common/src/config.rs @@ -1,12 +1,467 @@ // SPDX-License-Identifier: Apache-2.0 -//! Query groups for accessing Hipcheck configuration data. - -use crate::Config; -use hc_common::{pathbuf, salsa, BINARY_CONFIG_FILE, F64, LANGS_FILE, ORGS_FILE, TYPO_FILE}; +//! Defines the configuration file format. + +use crate::{ + context::Context, + error::Result, + filesystem as file, pathbuf, salsa, + serde::{self, Deserialize, Serialize}, + BINARY_CONFIG_FILE, F64, LANGS_FILE, ORGS_FILE, TYPO_FILE, +}; +use smart_default::SmartDefault; +use std::default::Default; +use std::path::Path; use std::path::PathBuf; use std::rc::Rc; +impl Config { + /// Load configuration from the given directory. + pub fn load_from(config_path: &Path) -> Result { + file::exists(config_path)?; + let config = file::read_toml(config_path).context("can't parse config file")?; + + Ok(config) + } +} + +/// Represents the configuration of Hipcheck's analyses. +#[derive(Debug, Deserialize, Serialize, Default, PartialEq, Eq)] +#[serde(crate = "self::serde")] +pub struct Config { + /// The configuration of overall project risk tolerance. + #[serde(default)] + pub risk: RiskConfig, + + /// The configuration of Hipcheck's different analyses. + #[serde(default)] + pub analysis: AnalysisConfig, + + /// The configuration of Hipcheck's knowledge about languages. + #[serde(default)] + pub languages: LanguagesConfig, +} + +/// Represents configuration of the overall risk threshold of an assessment. +#[derive(Debug, Serialize, Deserialize, SmartDefault, PartialEq, Eq)] +#[serde(default, crate = "self::serde")] +pub struct RiskConfig { + /// The risk tolerance threshold, a value between 0 and 1. + #[default(_code = "F64::new(0.5).unwrap()")] + #[serde(deserialize_with = "de::percent")] + pub threshold: F64, +} + +/// Defines configuration for all of Hipcheck's analyses. +#[derive(Debug, Deserialize, Serialize, Default, PartialEq, Eq)] +#[serde(default, crate = "self::serde")] +pub struct AnalysisConfig { + /// Defines configuration for practices analysis. + #[serde(default)] + pub practices: PracticesConfig, + + /// Defines configuration for attack analysis. + #[serde(default)] + pub attacks: AttacksConfig, +} + +/// Configuration of analyses on a repo's development practices. +#[derive(Debug, Deserialize, Serialize, SmartDefault, PartialEq, Eq)] +#[serde(default, crate = "self::serde")] +pub struct PracticesConfig { + /// Whether the analysis is active. + #[default = true] + pub active: bool, + + /// How heavily the analysis' results weigh in risk scoring. + #[default = 1] + pub weight: u64, + + /// Defines configuration for activity analysis. + #[serde(default)] + pub activity: ActivityConfig, + + /// Defines configuration for binary file analysis. + #[serde(default)] + pub binary: BinaryConfig, + + /// Defines configuration for in fuzz analysis. + #[serde(default)] + pub fuzz: FuzzConfig, + + /// Defines configuration for identity analysis. + #[serde(default)] + pub identity: IdentityConfig, + + /// Defines configuration for review analysis. + #[serde(default)] + pub review: ReviewConfig, +} + +/// Configuration of analyses on potential attacks against a repo. +#[derive(Debug, Deserialize, Serialize, SmartDefault, PartialEq, Eq)] +#[serde(default, crate = "self::serde")] +pub struct AttacksConfig { + /// Whether the analysis is active. + #[default = true] + pub active: bool, + + /// How heavily the analysis' results weigh in risk scoring. + #[default = 1] + pub weight: u64, + + /// Defines configuration for typo analysis. + #[serde(default)] + pub typo: TypoConfig, + + /// Defines configuration for commit analysis. + #[serde(default)] + pub commit: CommitConfig, +} + +/// Configuration of analyses on individual commits. +#[derive(Debug, Deserialize, Serialize, SmartDefault, PartialEq, Eq)] +#[serde(default, crate = "self::serde")] +pub struct CommitConfig { + /// Whether the analysis is active. + #[default = true] + pub active: bool, + + /// How heavily the analysis' results weigh in risk scoring. + #[default = 1] + pub weight: u64, + + /// Defines configuration for affiliation analysis. + #[serde(default)] + pub affiliation: AffiliationConfig, + + /// Defines configuration for churn analysis. + #[serde(default)] + pub churn: ChurnConfig, + + /// Defines configuration for contributor trust analysis. + #[serde(default)] + pub contributor_trust: ContributorTrustConfig, + + /// Defines configuration for contributor trust analysis. + #[serde(default)] + pub commit_trust: CommitTrustConfig, + + /// Defines configuration for entropy analysis. + #[serde(default)] + pub entropy: EntropyConfig, + + /// Defines configuration for pull request affiliation analysis. + #[serde(default)] + pub pr_affiliation: PrAffiliationConfig, + + /// Defines configuration for pull request module contributors analysis. + #[serde(default)] + pub pr_module_contributors: PrModuleContributorsConfig, +} + +/// Defines configuration for activity analysis. +#[derive(Debug, Deserialize, Serialize, SmartDefault, PartialEq, Eq)] +#[serde(default, crate = "self::serde")] +pub struct ActivityConfig { + /// Whether the analysis is active. + #[default = true] + pub active: bool, + + /// How heavily the analysis' results weigh in risk scoring. + #[default = 1] + pub weight: u64, + + /// A number of weeks, over which a repo fails the analysis. + #[default = 71] + pub week_count_threshold: u64, +} + +/// Defines configuration for affiliation analysis. +#[derive(Debug, Deserialize, Serialize, SmartDefault, PartialEq, Eq)] +#[serde(default, crate = "self::serde")] +pub struct AffiliationConfig { + /// Whether the analysis is active. + #[default = true] + pub active: bool, + + /// How heavily the analysis' results weigh in risk scoring. + #[default = 1] + pub weight: u64, + + /// A number of affiliations permitted, over which a repo fails the analysis. + #[default = 0] + pub count_threshold: u64, + + /// An "orgs file" containing info for affiliation matching. + #[default = "Orgs.toml"] + pub orgs_file: String, +} + +/// Defines configuration for binary file analysis. +#[derive(Debug, Deserialize, Serialize, SmartDefault, PartialEq, Eq)] +#[serde(default, crate = "self::serde")] +pub struct BinaryConfig { + /// Binary file extension configuration file. + #[default = "Binary.toml"] + pub binary_config_file: String, + + /// Whether the analysis is active. + #[default = true] + pub active: bool, + + /// How heavily the analysis' results weigh in risk scoring. + #[default = 1] + pub weight: u64, + + /// A count of binary files over which a repo fails the analysis. + #[default = 0] + pub binary_file_threshold: u64, +} + +/// Defines configuration for churn analysis. +#[derive(Debug, Deserialize, Serialize, SmartDefault, PartialEq, Eq)] +#[serde(default, crate = "self::serde")] +pub struct ChurnConfig { + /// Whether the analysis is active. + #[default = true] + pub active: bool, + + /// How heavily the analysis' results weigh in risk scoring. + #[default = 1] + pub weight: u64, + + /// A churn Z-score, over which a commit is marked as "bad" + #[default(_code = "F64::new(3.0).unwrap()")] + pub value_threshold: F64, + + /// A percentage of "bad" commits over which a repo fails the analysis. + #[default(_code = "F64::new(0.02).unwrap()")] + #[serde(deserialize_with = "de::percent")] + pub percent_threshold: F64, +} + +/// Defines configuration for commit trust analysis. +#[derive(Debug, Deserialize, Serialize, SmartDefault, PartialEq, Eq)] +#[serde(default, crate = "self::serde")] +pub struct CommitTrustConfig { + /// Whether the analysis is active. + #[default = true] + pub active: bool, + + /// How heavily the analysis' results weigh in risk scoring. + #[default = 1] + pub weight: u64, +} + +/// Defines configuration for contributor trust analysis. +#[derive(Debug, Deserialize, Serialize, SmartDefault, PartialEq, Eq)] +#[serde(default, crate = "self::serde")] +pub struct ContributorTrustConfig { + /// Whether the analysis is active. + #[default = true] + pub active: bool, + + /// How heavily the analysis' results weigh in risk scoring. + #[default = 1] + pub weight: u64, + + /// A trust N-score, number of commits over which a commitor is marked as trusted or not + #[default = 3] + pub value_threshold: u64, + + /// A number of months over which a contributor would be tracked for trust. + #[default = 3] + pub trust_month_count_threshold: u64, + + /// A percentage of "bad" commits over which a repo fails the analysis because commit is not trusted. + #[default(_code = "F64::new(0.0).unwrap()")] + #[serde(deserialize_with = "de::percent")] + pub percent_threshold: F64, +} + +/// Defines configuration for entropy analysis. +#[derive(Debug, Deserialize, Serialize, SmartDefault, PartialEq, Eq)] +#[serde(default, crate = "self::serde")] +pub struct EntropyConfig { + /// Whether the analysis is active. + #[default = true] + pub active: bool, + + /// How heavily the analysis' results weigh in risk scoring. + #[default = 1] + pub weight: u64, + + /// An entropy Z-score, over which a commit is marked as "bad" + #[default(_code = "F64::new(10.0).unwrap()")] + pub value_threshold: F64, + + /// A percentage of "bad" commits over which a repo fails the analysis. + #[default(_code = "F64::new(0.0).unwrap()")] + #[serde(deserialize_with = "de::percent")] + pub percent_threshold: F64, +} + +/// Defines configuration for identity analysis. +#[derive(Debug, Deserialize, Serialize, SmartDefault, PartialEq, Eq)] +#[serde(default, crate = "self::serde")] +pub struct IdentityConfig { + /// Whether the analysis is active. + #[default = true] + pub active: bool, + + /// How heavily the analysis' results weigh in risk scoring. + #[default = 1] + pub weight: u64, + + /// A percentage of commits permitted to have a mismatch between committer and + /// submitter identity, over which a repo fails the analysis. + #[default(_code = "F64::new(0.20).unwrap()")] + #[serde(deserialize_with = "de::percent")] + pub percent_threshold: F64, +} + +/// Defines configuration for review analysis. +#[derive(Debug, Deserialize, Serialize, SmartDefault, PartialEq, Eq)] +#[serde(default, crate = "self::serde")] +pub struct ReviewConfig { + /// Whether the analysis is active. + #[default = true] + pub active: bool, + + /// How heavily the analysis' results weigh in risk scoring. + #[default = 1] + pub weight: u64, + + /// A percentage of pull requests permitted to not have review prior to being + /// merged, over which a repo fails the analysis. + #[default(_code = "F64::new(0.05).unwrap()")] + #[serde(deserialize_with = "de::percent")] + pub percent_threshold: F64, +} + +/// Defines configuration for typo analysis. +#[derive(Debug, Deserialize, Serialize, SmartDefault, PartialEq, Eq)] +#[serde(default, crate = "self::serde")] +pub struct TypoConfig { + /// Whether the analysis is active. + #[default = true] + pub active: bool, + + /// How heavily the analysis' results weigh in risk scoring. + #[default = 1] + pub weight: u64, + + /// The number of potential dependency name typos permitted, over which + /// a repo fails the analysis. + #[default = 0] + pub count_threshold: u64, + + /// Path to a "typos file" containing necessary information for typo detection. + #[default = "Typos.toml"] + pub typo_file: String, +} + +/// Defines configuration for pull request affiliation analysis. +#[derive(Debug, Deserialize, Serialize, SmartDefault, PartialEq, Eq)] +#[serde(default, crate = "self::serde")] +pub struct PrAffiliationConfig { + /// Whether the analysis is active. + #[default = true] + pub active: bool, + + /// How heavily the analysis' results weigh in risk scoring. + #[default = 1] + pub weight: u64, + + /// A number of affiliations permitted, over which a repo fails the analysis. + #[default = 0] + pub count_threshold: u64, +} + +/// Defines configuration for pull request module committers analysis. +#[derive(Debug, Deserialize, Serialize, SmartDefault, PartialEq, Eq)] +#[serde(default, crate = "self::serde")] +pub struct PrModuleContributorsConfig { + /// Whether the analysis is active. + #[default = true] + pub active: bool, + + /// How heavily the analysis' results weigh in risk scoring. + #[default = 1] + pub weight: u64, + + /// Percent of committers working on a module for the first time permitted, over which a repo fails the analysis. + #[default(_code = "F64::new(0.30).unwrap()")] + #[serde(deserialize_with = "de::percent")] + pub percent_threshold: F64, +} + +/// Defines the configuration of language-specific info. +#[derive(Debug, Deserialize, Serialize, SmartDefault, PartialEq, Eq)] +#[serde(crate = "self::serde")] +pub struct LanguagesConfig { + /// The file to pull language information from. + #[default = "Langs.toml"] + pub langs_file: String, +} + +/// Defines configuration for fuzz analysis. +#[derive(Debug, Deserialize, Serialize, SmartDefault, PartialEq, Eq)] +#[serde(default, crate = "self::serde")] +pub struct FuzzConfig { + /// Whether the analysis is active. + #[default = true] + pub active: bool, + + /// How heavily the analysis' results weigh in risk scoring. + #[default = 1] + pub weight: u64, +} + +/// Inner module for deserialization helpers. +mod de { + use super::serde::de::{self, Deserializer, Visitor}; + use super::F64; + use std::fmt::{self, Formatter}; + + /// Deserialize a float, ensuring it's between 0.0 and 1.0 inclusive. + pub(super) fn percent<'de, D>(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct PercentVisitor; + + impl<'de> Visitor<'de> for PercentVisitor { + type Value = f64; + + fn expecting(&self, formatter: &mut Formatter) -> fmt::Result { + formatter.write_str("a float between 0.0 and 1.0 inclusive") + } + + fn visit_f64(self, value: f64) -> Result + where + E: de::Error, + { + if is_percent(value) { + Ok(value) + } else { + Err(de::Error::custom("must be between 0.0 and 1.0 inclusive")) + } + } + } + + // Deserialize and return as `F64` + let percent = deserializer.deserialize_f64(PercentVisitor)?; + Ok(F64::new(percent).unwrap()) + } + + /// Check if a float is a valid percent value. + fn is_percent(f: f64) -> bool { + (0.0..=1.0).contains(&f) + } +} + /// Query for accessing a source of Hipcheck config data #[salsa::query_group(ConfigSourceStorage)] pub trait ConfigSource: salsa::Database { diff --git a/libs/hc_common/src/lib.rs b/libs/hc_common/src/lib.rs index 4864a2f0..829acfdd 100644 --- a/libs/hc_common/src/lib.rs +++ b/libs/hc_common/src/lib.rs @@ -4,6 +4,7 @@ //! functionality used widely throughout Hipcheck. pub mod command_util; +pub mod config; pub mod context; pub mod error; pub mod filesystem; diff --git a/libs/hc_config/Cargo.toml b/libs/hc_config/Cargo.toml deleted file mode 100644 index 5a4f983a..00000000 --- a/libs/hc_config/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "hc_config" -version = "0.1.0" -edition = "2021" -license = "Apache-2.0" -publish = false - -[dependencies] -hc_common = { path = "../hc_common" } -smart-default = "0.7.1" diff --git a/libs/hc_config/src/lib.rs b/libs/hc_config/src/lib.rs deleted file mode 100644 index 73bbe874..00000000 --- a/libs/hc_config/src/lib.rs +++ /dev/null @@ -1,465 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 - -//! Defines the configuration file format. - -mod query; - -pub use query::*; - -use hc_common::{ - context::Context, - error::Result, - filesystem as file, - serde::{self, Deserialize, Serialize}, - F64, -}; -use smart_default::SmartDefault; -use std::default::Default; -use std::path::Path; - -impl Config { - /// Load configuration from the given directory. - pub fn load_from(config_path: &Path) -> Result { - file::exists(config_path)?; - let config = file::read_toml(config_path).context("can't parse config file")?; - - Ok(config) - } -} - -/// Represents the configuration of Hipcheck's analyses. -#[derive(Debug, Deserialize, Serialize, Default, PartialEq, Eq)] -#[serde(crate = "self::serde")] -pub struct Config { - /// The configuration of overall project risk tolerance. - #[serde(default)] - pub risk: RiskConfig, - - /// The configuration of Hipcheck's different analyses. - #[serde(default)] - pub analysis: AnalysisConfig, - - /// The configuration of Hipcheck's knowledge about languages. - #[serde(default)] - pub languages: LanguagesConfig, -} - -/// Represents configuration of the overall risk threshold of an assessment. -#[derive(Debug, Serialize, Deserialize, SmartDefault, PartialEq, Eq)] -#[serde(default, crate = "self::serde")] -pub struct RiskConfig { - /// The risk tolerance threshold, a value between 0 and 1. - #[default(_code = "F64::new(0.5).unwrap()")] - #[serde(deserialize_with = "de::percent")] - pub threshold: F64, -} - -/// Defines configuration for all of Hipcheck's analyses. -#[derive(Debug, Deserialize, Serialize, Default, PartialEq, Eq)] -#[serde(default, crate = "self::serde")] -pub struct AnalysisConfig { - /// Defines configuration for practices analysis. - #[serde(default)] - pub practices: PracticesConfig, - - /// Defines configuration for attack analysis. - #[serde(default)] - pub attacks: AttacksConfig, -} - -/// Configuration of analyses on a repo's development practices. -#[derive(Debug, Deserialize, Serialize, SmartDefault, PartialEq, Eq)] -#[serde(default, crate = "self::serde")] -pub struct PracticesConfig { - /// Whether the analysis is active. - #[default = true] - pub active: bool, - - /// How heavily the analysis' results weigh in risk scoring. - #[default = 1] - pub weight: u64, - - /// Defines configuration for activity analysis. - #[serde(default)] - pub activity: ActivityConfig, - - /// Defines configuration for binary file analysis. - #[serde(default)] - pub binary: BinaryConfig, - - /// Defines configuration for in fuzz analysis. - #[serde(default)] - pub fuzz: FuzzConfig, - - /// Defines configuration for identity analysis. - #[serde(default)] - pub identity: IdentityConfig, - - /// Defines configuration for review analysis. - #[serde(default)] - pub review: ReviewConfig, -} - -/// Configuration of analyses on potential attacks against a repo. -#[derive(Debug, Deserialize, Serialize, SmartDefault, PartialEq, Eq)] -#[serde(default, crate = "self::serde")] -pub struct AttacksConfig { - /// Whether the analysis is active. - #[default = true] - pub active: bool, - - /// How heavily the analysis' results weigh in risk scoring. - #[default = 1] - pub weight: u64, - - /// Defines configuration for typo analysis. - #[serde(default)] - pub typo: TypoConfig, - - /// Defines configuration for commit analysis. - #[serde(default)] - pub commit: CommitConfig, -} - -/// Configuration of analyses on individual commits. -#[derive(Debug, Deserialize, Serialize, SmartDefault, PartialEq, Eq)] -#[serde(default, crate = "self::serde")] -pub struct CommitConfig { - /// Whether the analysis is active. - #[default = true] - pub active: bool, - - /// How heavily the analysis' results weigh in risk scoring. - #[default = 1] - pub weight: u64, - - /// Defines configuration for affiliation analysis. - #[serde(default)] - pub affiliation: AffiliationConfig, - - /// Defines configuration for churn analysis. - #[serde(default)] - pub churn: ChurnConfig, - - /// Defines configuration for contributor trust analysis. - #[serde(default)] - pub contributor_trust: ContributorTrustConfig, - - /// Defines configuration for contributor trust analysis. - #[serde(default)] - pub commit_trust: CommitTrustConfig, - - /// Defines configuration for entropy analysis. - #[serde(default)] - pub entropy: EntropyConfig, - - /// Defines configuration for pull request affiliation analysis. - #[serde(default)] - pub pr_affiliation: PrAffiliationConfig, - - /// Defines configuration for pull request module contributors analysis. - #[serde(default)] - pub pr_module_contributors: PrModuleContributorsConfig, -} - -/// Defines configuration for activity analysis. -#[derive(Debug, Deserialize, Serialize, SmartDefault, PartialEq, Eq)] -#[serde(default, crate = "self::serde")] -pub struct ActivityConfig { - /// Whether the analysis is active. - #[default = true] - pub active: bool, - - /// How heavily the analysis' results weigh in risk scoring. - #[default = 1] - pub weight: u64, - - /// A number of weeks, over which a repo fails the analysis. - #[default = 71] - pub week_count_threshold: u64, -} - -/// Defines configuration for affiliation analysis. -#[derive(Debug, Deserialize, Serialize, SmartDefault, PartialEq, Eq)] -#[serde(default, crate = "self::serde")] -pub struct AffiliationConfig { - /// Whether the analysis is active. - #[default = true] - pub active: bool, - - /// How heavily the analysis' results weigh in risk scoring. - #[default = 1] - pub weight: u64, - - /// A number of affiliations permitted, over which a repo fails the analysis. - #[default = 0] - pub count_threshold: u64, - - /// An "orgs file" containing info for affiliation matching. - #[default = "Orgs.toml"] - pub orgs_file: String, -} - -/// Defines configuration for binary file analysis. -#[derive(Debug, Deserialize, Serialize, SmartDefault, PartialEq, Eq)] -#[serde(default, crate = "self::serde")] -pub struct BinaryConfig { - /// Binary file extension configuration file. - #[default = "Binary.toml"] - pub binary_config_file: String, - - /// Whether the analysis is active. - #[default = true] - pub active: bool, - - /// How heavily the analysis' results weigh in risk scoring. - #[default = 1] - pub weight: u64, - - /// A count of binary files over which a repo fails the analysis. - #[default = 0] - pub binary_file_threshold: u64, -} - -/// Defines configuration for churn analysis. -#[derive(Debug, Deserialize, Serialize, SmartDefault, PartialEq, Eq)] -#[serde(default, crate = "self::serde")] -pub struct ChurnConfig { - /// Whether the analysis is active. - #[default = true] - pub active: bool, - - /// How heavily the analysis' results weigh in risk scoring. - #[default = 1] - pub weight: u64, - - /// A churn Z-score, over which a commit is marked as "bad" - #[default(_code = "F64::new(3.0).unwrap()")] - pub value_threshold: F64, - - /// A percentage of "bad" commits over which a repo fails the analysis. - #[default(_code = "F64::new(0.02).unwrap()")] - #[serde(deserialize_with = "de::percent")] - pub percent_threshold: F64, -} - -/// Defines configuration for commit trust analysis. -#[derive(Debug, Deserialize, Serialize, SmartDefault, PartialEq, Eq)] -#[serde(default, crate = "self::serde")] -pub struct CommitTrustConfig { - /// Whether the analysis is active. - #[default = true] - pub active: bool, - - /// How heavily the analysis' results weigh in risk scoring. - #[default = 1] - pub weight: u64, -} - -/// Defines configuration for contributor trust analysis. -#[derive(Debug, Deserialize, Serialize, SmartDefault, PartialEq, Eq)] -#[serde(default, crate = "self::serde")] -pub struct ContributorTrustConfig { - /// Whether the analysis is active. - #[default = true] - pub active: bool, - - /// How heavily the analysis' results weigh in risk scoring. - #[default = 1] - pub weight: u64, - - /// A trust N-score, number of commits over which a commitor is marked as trusted or not - #[default = 3] - pub value_threshold: u64, - - /// A number of months over which a contributor would be tracked for trust. - #[default = 3] - pub trust_month_count_threshold: u64, - - /// A percentage of "bad" commits over which a repo fails the analysis because commit is not trusted. - #[default(_code = "F64::new(0.0).unwrap()")] - #[serde(deserialize_with = "de::percent")] - pub percent_threshold: F64, -} - -/// Defines configuration for entropy analysis. -#[derive(Debug, Deserialize, Serialize, SmartDefault, PartialEq, Eq)] -#[serde(default, crate = "self::serde")] -pub struct EntropyConfig { - /// Whether the analysis is active. - #[default = true] - pub active: bool, - - /// How heavily the analysis' results weigh in risk scoring. - #[default = 1] - pub weight: u64, - - /// An entropy Z-score, over which a commit is marked as "bad" - #[default(_code = "F64::new(10.0).unwrap()")] - pub value_threshold: F64, - - /// A percentage of "bad" commits over which a repo fails the analysis. - #[default(_code = "F64::new(0.0).unwrap()")] - #[serde(deserialize_with = "de::percent")] - pub percent_threshold: F64, -} - -/// Defines configuration for identity analysis. -#[derive(Debug, Deserialize, Serialize, SmartDefault, PartialEq, Eq)] -#[serde(default, crate = "self::serde")] -pub struct IdentityConfig { - /// Whether the analysis is active. - #[default = true] - pub active: bool, - - /// How heavily the analysis' results weigh in risk scoring. - #[default = 1] - pub weight: u64, - - /// A percentage of commits permitted to have a mismatch between committer and - /// submitter identity, over which a repo fails the analysis. - #[default(_code = "F64::new(0.20).unwrap()")] - #[serde(deserialize_with = "de::percent")] - pub percent_threshold: F64, -} - -/// Defines configuration for review analysis. -#[derive(Debug, Deserialize, Serialize, SmartDefault, PartialEq, Eq)] -#[serde(default, crate = "self::serde")] -pub struct ReviewConfig { - /// Whether the analysis is active. - #[default = true] - pub active: bool, - - /// How heavily the analysis' results weigh in risk scoring. - #[default = 1] - pub weight: u64, - - /// A percentage of pull requests permitted to not have review prior to being - /// merged, over which a repo fails the analysis. - #[default(_code = "F64::new(0.05).unwrap()")] - #[serde(deserialize_with = "de::percent")] - pub percent_threshold: F64, -} - -/// Defines configuration for typo analysis. -#[derive(Debug, Deserialize, Serialize, SmartDefault, PartialEq, Eq)] -#[serde(default, crate = "self::serde")] -pub struct TypoConfig { - /// Whether the analysis is active. - #[default = true] - pub active: bool, - - /// How heavily the analysis' results weigh in risk scoring. - #[default = 1] - pub weight: u64, - - /// The number of potential dependency name typos permitted, over which - /// a repo fails the analysis. - #[default = 0] - pub count_threshold: u64, - - /// Path to a "typos file" containing necessary information for typo detection. - #[default = "Typos.toml"] - pub typo_file: String, -} - -/// Defines configuration for pull request affiliation analysis. -#[derive(Debug, Deserialize, Serialize, SmartDefault, PartialEq, Eq)] -#[serde(default, crate = "self::serde")] -pub struct PrAffiliationConfig { - /// Whether the analysis is active. - #[default = true] - pub active: bool, - - /// How heavily the analysis' results weigh in risk scoring. - #[default = 1] - pub weight: u64, - - /// A number of affiliations permitted, over which a repo fails the analysis. - #[default = 0] - pub count_threshold: u64, -} - -/// Defines configuration for pull request module committers analysis. -#[derive(Debug, Deserialize, Serialize, SmartDefault, PartialEq, Eq)] -#[serde(default, crate = "self::serde")] -pub struct PrModuleContributorsConfig { - /// Whether the analysis is active. - #[default = true] - pub active: bool, - - /// How heavily the analysis' results weigh in risk scoring. - #[default = 1] - pub weight: u64, - - /// Percent of committers working on a module for the first time permitted, over which a repo fails the analysis. - #[default(_code = "F64::new(0.30).unwrap()")] - #[serde(deserialize_with = "de::percent")] - pub percent_threshold: F64, -} - -/// Defines the configuration of language-specific info. -#[derive(Debug, Deserialize, Serialize, SmartDefault, PartialEq, Eq)] -#[serde(crate = "self::serde")] -pub struct LanguagesConfig { - /// The file to pull language information from. - #[default = "Langs.toml"] - pub langs_file: String, -} - -/// Defines configuration for fuzz analysis. -#[derive(Debug, Deserialize, Serialize, SmartDefault, PartialEq, Eq)] -#[serde(default, crate = "self::serde")] -pub struct FuzzConfig { - /// Whether the analysis is active. - #[default = true] - pub active: bool, - - /// How heavily the analysis' results weigh in risk scoring. - #[default = 1] - pub weight: u64, -} - -/// Inner module for deserialization helpers. -mod de { - use super::serde::de::{self, Deserializer, Visitor}; - use super::F64; - use std::fmt::{self, Formatter}; - - /// Deserialize a float, ensuring it's between 0.0 and 1.0 inclusive. - pub(super) fn percent<'de, D>(deserializer: D) -> Result - where - D: Deserializer<'de>, - { - struct PercentVisitor; - - impl<'de> Visitor<'de> for PercentVisitor { - type Value = f64; - - fn expecting(&self, formatter: &mut Formatter) -> fmt::Result { - formatter.write_str("a float between 0.0 and 1.0 inclusive") - } - - fn visit_f64(self, value: f64) -> Result - where - E: de::Error, - { - if is_percent(value) { - Ok(value) - } else { - Err(de::Error::custom("must be between 0.0 and 1.0 inclusive")) - } - } - } - - // Deserialize and return as `F64` - let percent = deserializer.deserialize_f64(PercentVisitor)?; - Ok(F64::new(percent).unwrap()) - } - - /// Check if a float is a valid percent value. - fn is_percent(f: f64) -> bool { - (0.0..=1.0).contains(&f) - } -} diff --git a/libs/hc_data/Cargo.toml b/libs/hc_data/Cargo.toml index d89dcc8f..bdcd7f41 100644 --- a/libs/hc_data/Cargo.toml +++ b/libs/hc_data/Cargo.toml @@ -9,7 +9,6 @@ publish = false dirs = "5.0.1" graphql_client = "0.14.0" hc_common = { path = "../hc_common" } -hc_config = { path = "../hc_config" } hc_shell = { path = "../hc_shell" } nom = "7.1.3" petgraph = { version = "0.6.0", features = ["serde-1"] } diff --git a/libs/hc_data/src/query/fuzz.rs b/libs/hc_data/src/query/fuzz.rs index e388b3bb..ef9c6223 100644 --- a/libs/hc_data/src/query/fuzz.rs +++ b/libs/hc_data/src/query/fuzz.rs @@ -5,10 +5,10 @@ use super::github::GitHubProvider; use crate::{get_fuzz_check, Fuzz}; use hc_common::{ + config::ConfigSource, error::{Error, Result}, log, salsa, }; -use hc_config::ConfigSource; /// A query that provides a fuzz check #[salsa::query_group(FuzzProviderStorage)] diff --git a/libs/hc_data/src/query/pr_review.rs b/libs/hc_data/src/query/pr_review.rs index dee99579..8d05e0b5 100644 --- a/libs/hc_data/src/query/pr_review.rs +++ b/libs/hc_data/src/query/pr_review.rs @@ -9,11 +9,11 @@ use crate::{ PullRequest, SinglePullRequest, }; use hc_common::{ + config::ConfigSource, context::Context, error::{Error, Result}, salsa, }; -use hc_config::ConfigSource; use std::rc::Rc; /// A query that provides GitHub pull request reviews From 6c1d976658147c83f697096c9dbc4f173a9f35a1 Mon Sep 17 00:00:00 2001 From: Andrew Lilley Brinker Date: Mon, 6 May 2024 14:22:51 -0700 Subject: [PATCH 03/14] chore: Eliminate `hc_serde`. This commit removes `hc_serde` in favor of directly importing `serde` where it's needed. Since everything will soon be merged into a single crate anyway it won't matter much. Signed-off-by: Andrew Lilley Brinker --- Cargo.lock | 20 ++++-------- libs/hc_analysis/Cargo.toml | 2 +- libs/hc_analysis/src/metric/activity.rs | 2 +- libs/hc_analysis/src/metric/affiliation.rs | 10 +++--- libs/hc_analysis/src/metric/binary.rs | 8 ++--- .../src/metric/binary_detector/mod.rs | 9 ++---- libs/hc_analysis/src/metric/churn.rs | 8 ++--- libs/hc_analysis/src/metric/entropy.rs | 8 ++--- libs/hc_analysis/src/metric/fuzz.rs | 7 ++-- libs/hc_analysis/src/metric/identity.rs | 7 ++-- libs/hc_analysis/src/metric/linguist/mod.rs | 8 ++--- libs/hc_analysis/src/metric/module.rs | 7 ++-- .../src/metric/module_contributors.rs | 7 ++-- libs/hc_analysis/src/metric/review.rs | 7 ++-- libs/hc_analysis/src/metric/typo.rs | 7 ++-- libs/hc_common/Cargo.toml | 2 +- libs/hc_common/src/config.rs | 8 ++--- libs/hc_common/src/filesystem.rs | 8 ++--- libs/hc_common/src/lib.rs | 6 ++-- libs/hc_data/Cargo.toml | 2 +- libs/hc_data/src/es_lint/data.rs | 2 +- libs/hc_data/src/git/data.rs | 6 ++-- libs/hc_data/src/github/data.rs | 2 +- libs/hc_data/src/lib.rs | 9 ++---- libs/hc_data/src/modules.rs | 5 ++- libs/hc_data/src/npm.rs | 5 ++- libs/hc_report/Cargo.toml | 1 + libs/hc_report/src/lib.rs | 32 ++++++------------- libs/hc_serde/Cargo.toml | 9 ------ libs/hc_serde/src/lib.rs | 15 --------- 30 files changed, 65 insertions(+), 164 deletions(-) delete mode 100644 libs/hc_serde/Cargo.toml delete mode 100644 libs/hc_serde/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index c9f132bc..77125435 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -614,10 +614,10 @@ dependencies = [ "hc_common", "hc_data", "hc_report", - "hc_serde", "hc_shell", "maplit", "petgraph", + "serde", "serde_derive", "spdx-rs", "tempfile", @@ -635,7 +635,6 @@ version = "0.1.0" dependencies = [ "anyhow", "chrono", - "hc_serde", "lazy_static", "log", "once_cell", @@ -644,6 +643,7 @@ dependencies = [ "salsa", "schemars", "semver", + "serde", "serde_json", "smart-default", "toml", @@ -670,10 +670,10 @@ dependencies = [ "dirs", "graphql_client", "hc_common", - "hc_serde", "hc_shell", "nom", "petgraph", + "serde", "tempfile", "ureq", ] @@ -684,12 +684,6 @@ version = "0.1.0" dependencies = [ "hc_common", "paste", -] - -[[package]] -name = "hc_serde" -version = "0.1.0" -dependencies = [ "serde", ] @@ -1471,18 +1465,18 @@ checksum = "92d43fe69e652f3df9bdc2b85b2854a0825b86e4fb76bc44d945137d053639ca" [[package]] name = "serde" -version = "1.0.198" +version = "1.0.200" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9846a40c979031340571da2545a4e5b7c4163bdae79b301d5f86d03979451fcc" +checksum = "ddc6f9cc94d67c0e21aaf7eda3a010fd3af78ebf6e096aa6e2e13c79749cce4f" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.198" +version = "1.0.200" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e88edab869b01783ba905e7d0153f9fc1a6505a96e4ad3018011eedb838566d9" +checksum = "856f046b9400cee3c8c94ed572ecdb752444c24528c035cd35882aad6f492bcb" dependencies = [ "proc-macro2", "quote", diff --git a/libs/hc_analysis/Cargo.toml b/libs/hc_analysis/Cargo.toml index 54ce57aa..0e9ed722 100644 --- a/libs/hc_analysis/Cargo.toml +++ b/libs/hc_analysis/Cargo.toml @@ -14,10 +14,10 @@ glob = "0.3.0" hc_common = { path = "../hc_common" } hc_data = { path = "../hc_data" } hc_report = { path = "../hc_report" } -hc_serde = { path = "../hc_serde" } hc_shell = { path = "../hc_shell" } maplit = "1.0.2" petgraph = { version = "0.6.0" } +serde = { version = "1.0.200", features = ["derive", "rc"] } serde_derive = "1.0.137" spdx-rs = "0.5.0" toml = "0.8.12" diff --git a/libs/hc_analysis/src/metric/activity.rs b/libs/hc_analysis/src/metric/activity.rs index 25cecbc8..3f313a5a 100644 --- a/libs/hc_analysis/src/metric/activity.rs +++ b/libs/hc_analysis/src/metric/activity.rs @@ -6,8 +6,8 @@ use hc_common::{ chrono::{prelude::*, Duration}, error::Result, log, - serde::{ser::SerializeStruct, Serialize, Serializer}, }; +use serde::{ser::SerializeStruct, Serialize, Serializer}; use std::{rc::Rc, result::Result as StdResult}; #[derive(Debug, Eq, PartialEq)] diff --git a/libs/hc_analysis/src/metric/affiliation.rs b/libs/hc_analysis/src/metric/affiliation.rs index 533d89f2..6e9a0925 100644 --- a/libs/hc_analysis/src/metric/affiliation.rs +++ b/libs/hc_analysis/src/metric/affiliation.rs @@ -5,13 +5,13 @@ use hc_common::{ context::Context as _, error::{Error, Result}, filesystem as file, hc_error, log, - serde::{ - self, - de::{Error as SerdeError, Visitor}, - Deserialize, Deserializer, Serialize, - }, }; use hc_data::git::{Commit, CommitContributorView}; +use serde::{ + self, + de::{Error as SerdeError, Visitor}, + Deserialize, Deserializer, Serialize, +}; use std::cell::RefCell; use std::collections::HashMap; use std::convert::{TryFrom, TryInto}; diff --git a/libs/hc_analysis/src/metric/binary.rs b/libs/hc_analysis/src/metric/binary.rs index 492e21f3..c708d98b 100644 --- a/libs/hc_analysis/src/metric/binary.rs +++ b/libs/hc_analysis/src/metric/binary.rs @@ -2,12 +2,8 @@ use crate::metric::binary_detector::detect_binary_files; use crate::MetricProvider; -use hc_common::{ - error::Result, - log, - serde::{self, Serialize}, - TryFilter, -}; +use hc_common::{error::Result, log, TryFilter}; +use serde::{self, Serialize}; use std::rc::Rc; #[derive(Debug, Eq, PartialEq, Serialize)] diff --git a/libs/hc_analysis/src/metric/binary_detector/mod.rs b/libs/hc_analysis/src/metric/binary_detector/mod.rs index 57a62d93..ec931b92 100644 --- a/libs/hc_analysis/src/metric/binary_detector/mod.rs +++ b/libs/hc_analysis/src/metric/binary_detector/mod.rs @@ -5,13 +5,8 @@ mod query; pub use query::*; use content_inspector::{inspect, ContentType}; -use hc_common::{ - context::Context, - error::Result, - filesystem::read_toml, - hc_error, - serde::{self, de::Visitor, Deserialize, Deserializer}, -}; +use hc_common::{context::Context, error::Result, filesystem::read_toml, hc_error}; +use serde::{self, de::Visitor, Deserialize, Deserializer}; use std::fmt::{self, Formatter}; use std::fs::File; use std::io::prelude::Read; diff --git a/libs/hc_analysis/src/metric/churn.rs b/libs/hc_analysis/src/metric/churn.rs index 10db789b..2519c1fd 100644 --- a/libs/hc_analysis/src/metric/churn.rs +++ b/libs/hc_analysis/src/metric/churn.rs @@ -3,13 +3,9 @@ use crate::metric::math::{mean, std_dev}; use crate::MetricProvider; use hc_common::context::Context as _; -use hc_common::{ - error::Result, - hc_error, log, - serde::{self, Serialize}, - TryAny, TryFilter, F64, -}; +use hc_common::{error::Result, hc_error, log, TryAny, TryFilter, F64}; use hc_data::git::Commit; +use serde::{self, Serialize}; use std::collections::HashMap; use std::rc::Rc; diff --git a/libs/hc_analysis/src/metric/entropy.rs b/libs/hc_analysis/src/metric/entropy.rs index e02b6854..f8f90daa 100644 --- a/libs/hc_analysis/src/metric/entropy.rs +++ b/libs/hc_analysis/src/metric/entropy.rs @@ -3,13 +3,9 @@ use crate::metric::math::{mean, std_dev}; use crate::MetricProvider; use hc_common::context::Context as _; -use hc_common::{ - error::Result, - hc_error, log, - serde::{self, Serialize}, - TryAny, TryFilter, F64, -}; +use hc_common::{error::Result, hc_error, log, TryAny, TryFilter, F64}; use hc_data::git::{Commit, CommitDiff, Diff}; +use serde::{self, Serialize}; use std::collections::HashMap; use std::iter::Iterator; use std::ops::Not as _; diff --git a/libs/hc_analysis/src/metric/fuzz.rs b/libs/hc_analysis/src/metric/fuzz.rs index 2a5abfa9..53fcdde2 100644 --- a/libs/hc_analysis/src/metric/fuzz.rs +++ b/libs/hc_analysis/src/metric/fuzz.rs @@ -2,12 +2,9 @@ use crate::MetricProvider; use hc_common::context::Context as _; -use hc_common::{ - error::Result, - log, - serde::{self, Serialize}, -}; +use hc_common::{error::Result, log}; use hc_data::Fuzz; +use serde::{self, Serialize}; use std::rc::Rc; #[derive(Debug, Eq, PartialEq, Serialize)] diff --git a/libs/hc_analysis/src/metric/identity.rs b/libs/hc_analysis/src/metric/identity.rs index 4ba9bdf5..775f9f8e 100644 --- a/libs/hc_analysis/src/metric/identity.rs +++ b/libs/hc_analysis/src/metric/identity.rs @@ -2,12 +2,9 @@ use crate::MetricProvider; use hc_common::context::Context as _; -use hc_common::{ - error::Result, - log, - serde::{self, Serialize}, -}; +use hc_common::{error::Result, log}; use hc_data::git::Commit; +use serde::{self, Serialize}; use std::rc::Rc; #[derive(Debug, Eq, PartialEq, Serialize)] diff --git a/libs/hc_analysis/src/metric/linguist/mod.rs b/libs/hc_analysis/src/metric/linguist/mod.rs index d56a1f9e..a0150de5 100644 --- a/libs/hc_analysis/src/metric/linguist/mod.rs +++ b/libs/hc_analysis/src/metric/linguist/mod.rs @@ -5,12 +5,8 @@ mod query; pub use query::*; use hc_common::context::Context as _; -use hc_common::{ - error::Result, - filesystem::read_toml, - log, - serde::{self, de::Visitor, Deserialize, Deserializer}, -}; +use hc_common::{error::Result, filesystem::read_toml, log}; +use serde::{self, de::Visitor, Deserialize, Deserializer}; use std::convert::AsRef; use std::fmt::{self, Formatter}; use std::path::Path; diff --git a/libs/hc_analysis/src/metric/module.rs b/libs/hc_analysis/src/metric/module.rs index 97cb5f8a..6bdc67a6 100644 --- a/libs/hc_analysis/src/metric/module.rs +++ b/libs/hc_analysis/src/metric/module.rs @@ -2,12 +2,9 @@ use crate::MetricProvider; use hc_common::context::Context as _; -use hc_common::{ - error::Result, - log, - serde::{self, Serialize}, -}; +use hc_common::{error::Result, log}; use hc_data::ModuleGraph; +use serde::{self, Serialize}; use std::rc::Rc; #[derive(Debug, Eq, PartialEq, Serialize)] diff --git a/libs/hc_analysis/src/metric/module_contributors.rs b/libs/hc_analysis/src/metric/module_contributors.rs index 1965c7bf..d34d8c6d 100644 --- a/libs/hc_analysis/src/metric/module_contributors.rs +++ b/libs/hc_analysis/src/metric/module_contributors.rs @@ -2,12 +2,9 @@ use crate::MetricProvider; use hc_common::context::Context as _; -use hc_common::{ - error::Result, - log, - serde::{self, Serialize}, -}; +use hc_common::{error::Result, log}; use hc_data::{git::Contributor, Module}; +use serde::{self, Serialize}; use std::{collections::HashMap, rc::Rc}; #[derive(Debug, Eq, PartialEq, Serialize)] diff --git a/libs/hc_analysis/src/metric/review.rs b/libs/hc_analysis/src/metric/review.rs index 3b164100..a1fd8d23 100644 --- a/libs/hc_analysis/src/metric/review.rs +++ b/libs/hc_analysis/src/metric/review.rs @@ -2,12 +2,9 @@ use crate::MetricProvider; use hc_common::context::Context as _; -use hc_common::{ - error::Result, - log, - serde::{self, Serialize}, -}; +use hc_common::{error::Result, log}; use hc_data::PullRequest; +use serde::{self, Serialize}; use std::rc::Rc; #[derive(Debug, Eq, PartialEq, Serialize)] diff --git a/libs/hc_analysis/src/metric/typo.rs b/libs/hc_analysis/src/metric/typo.rs index 31c93513..8884b934 100644 --- a/libs/hc_analysis/src/metric/typo.rs +++ b/libs/hc_analysis/src/metric/typo.rs @@ -2,13 +2,10 @@ use crate::MetricProvider; use hc_common::context::Context as _; -use hc_common::{ - error::Result, - filesystem as file, log, - serde::{self, Deserialize, Serialize}, -}; +use hc_common::{error::Result, filesystem as file, log}; use hc_data::{Dependencies, Lang}; use maplit::hashmap; +use serde::{self, Deserialize, Serialize}; use std::cmp::Ordering; use std::collections::HashMap; use std::convert::AsRef; diff --git a/libs/hc_common/Cargo.toml b/libs/hc_common/Cargo.toml index 7e7b5ffc..cc920c87 100644 --- a/libs/hc_common/Cargo.toml +++ b/libs/hc_common/Cargo.toml @@ -7,7 +7,6 @@ publish = false [dependencies] chrono = { version = "0.4.19", features = ["serde"] } -hc_serde = { path = "../hc_serde" } lazy_static = "1.4.0" log = "0.4.16" once_cell = "1.10.0" @@ -20,6 +19,7 @@ schemars = { version = "0.8.17", default-features = false, features = [ "chrono", ] } semver = "1.0.9" +serde = { version = "1.0.200", features = ["derive", "rc"] } serde_json = "1.0.80" smart-default = "0.7.1" toml = "0.8.12" diff --git a/libs/hc_common/src/config.rs b/libs/hc_common/src/config.rs index 0edb367d..5a53b9cc 100644 --- a/libs/hc_common/src/config.rs +++ b/libs/hc_common/src/config.rs @@ -3,12 +3,10 @@ //! Defines the configuration file format. use crate::{ - context::Context, - error::Result, - filesystem as file, pathbuf, salsa, - serde::{self, Deserialize, Serialize}, - BINARY_CONFIG_FILE, F64, LANGS_FILE, ORGS_FILE, TYPO_FILE, + context::Context, error::Result, filesystem as file, pathbuf, salsa, BINARY_CONFIG_FILE, F64, + LANGS_FILE, ORGS_FILE, TYPO_FILE, }; +use serde::{self, Deserialize, Serialize}; use smart_default::SmartDefault; use std::default::Default; use std::path::Path; diff --git a/libs/hc_common/src/filesystem.rs b/libs/hc_common/src/filesystem.rs index 75860556..1a2d5349 100644 --- a/libs/hc_common/src/filesystem.rs +++ b/libs/hc_common/src/filesystem.rs @@ -1,12 +1,8 @@ // SPDX-License-Identifier: Apache-2.0 use crate::context::Context as _; -use crate::{ - error::Result, - hc_error, - serde::{de::DeserializeOwned, Serialize}, - serde_json, -}; +use crate::{error::Result, hc_error, serde_json}; +use serde::{de::DeserializeOwned, Serialize}; use std::fs::{self, File}; use std::ops::Not; use std::path::Path; diff --git a/libs/hc_common/src/lib.rs b/libs/hc_common/src/lib.rs index 829acfdd..727d61af 100644 --- a/libs/hc_common/src/lib.rs +++ b/libs/hc_common/src/lib.rs @@ -16,11 +16,7 @@ mod try_any; mod try_filter; pub mod version; -pub use try_any::TryAny; -pub use try_filter::{FallibleFilter, TryFilter}; - pub use chrono; -pub use hc_serde::serde; pub use lazy_static; pub use log; pub use ordered_float; @@ -28,6 +24,8 @@ pub use salsa; pub use schemars; pub use semver; pub use serde_json; +pub use try_any::TryAny; +pub use try_filter::{FallibleFilter, TryFilter}; pub use url; pub use which; diff --git a/libs/hc_data/Cargo.toml b/libs/hc_data/Cargo.toml index bdcd7f41..37373c1c 100644 --- a/libs/hc_data/Cargo.toml +++ b/libs/hc_data/Cargo.toml @@ -12,7 +12,7 @@ hc_common = { path = "../hc_common" } hc_shell = { path = "../hc_shell" } nom = "7.1.3" petgraph = { version = "0.6.0", features = ["serde-1"] } -serde = { path = "../hc_serde", package = "hc_serde" } +serde = { version = "1.0.200", features = ["derive", "rc"] } ureq = { version = "2.9.7", default-features = false, features = [ "json", "native-tls", diff --git a/libs/hc_data/src/es_lint/data.rs b/libs/hc_data/src/es_lint/data.rs index 48f78423..53d205e2 100644 --- a/libs/hc_data/src/es_lint/data.rs +++ b/libs/hc_data/src/es_lint/data.rs @@ -4,7 +4,7 @@ /// https://eslint.org/docs/user-guide/formatters/#json /// /// This parser has been tested with the output from ESLint v7.31.0 -use hc_common::serde::{self, Deserialize}; +use serde::{self, Deserialize}; pub type ESLintReports = Vec; diff --git a/libs/hc_data/src/git/data.rs b/libs/hc_data/src/git/data.rs index c69a03d7..701b9696 100644 --- a/libs/hc_data/src/git/data.rs +++ b/libs/hc_data/src/git/data.rs @@ -1,9 +1,7 @@ // SPDX-License-Identifier: Apache-2.0 -use hc_common::{ - chrono::{DateTime, FixedOffset}, - serde::{self, Deserialize, Serialize}, -}; +use hc_common::chrono::{DateTime, FixedOffset}; +use serde::{self, Deserialize, Serialize}; use std::fmt::{self, Display, Formatter}; use std::rc::Rc; diff --git a/libs/hc_data/src/github/data.rs b/libs/hc_data/src/github/data.rs index b9827f05..7fb69508 100644 --- a/libs/hc_data/src/github/data.rs +++ b/libs/hc_data/src/github/data.rs @@ -1,8 +1,8 @@ // SPDX-License-Identifier: Apache-2.0 use crate::git::{Diff, RawCommit}; - use serde::Deserialize; + #[derive(Debug, Deserialize)] pub struct GitHubFullPullRequest { pub pull_request: GitHubPullRequest, diff --git a/libs/hc_data/src/lib.rs b/libs/hc_data/src/lib.rs index 4ba6f471..0b1cfb1c 100644 --- a/libs/hc_data/src/lib.rs +++ b/libs/hc_data/src/lib.rs @@ -18,16 +18,11 @@ use std::collections::HashSet; use git::{get_commits_for_file, Commit, CommitContributor, Contributor, Diff}; use github::*; -use hc_common::{ - context::Context, - error::Error, - error::Result, - hc_error, log, pathbuf, - serde::{self, Serialize}, -}; +use hc_common::{context::Context, error::Error, error::Result, hc_error, log, pathbuf}; use modules::RawModule; use petgraph::visit::Dfs; use petgraph::Graph; +use serde::{self, Serialize}; use std::path::Path; use std::rc::Rc; diff --git a/libs/hc_data/src/modules.rs b/libs/hc_data/src/modules.rs index 252fdbfa..c1c55f18 100644 --- a/libs/hc_data/src/modules.rs +++ b/libs/hc_data/src/modules.rs @@ -4,10 +4,9 @@ use hc_common::context::Context as _; use hc_common::{ command_util::{log_args, DependentProgram}, error::{Error, Result}, - hc_error, pathbuf, - serde::{self, Deserialize}, - serde_json, + hc_error, pathbuf, serde_json, }; +use serde::{self, Deserialize}; use serde_json::Value as JsonValue; use std::collections::HashMap; use std::convert::AsRef; diff --git a/libs/hc_data/src/npm.rs b/libs/hc_data/src/npm.rs index b2f93b7a..09594e31 100644 --- a/libs/hc_data/src/npm.rs +++ b/libs/hc_data/src/npm.rs @@ -4,10 +4,9 @@ use hc_common::{ command_util::{log_args, DependentProgram}, context::Context, error::Result, - filesystem as file, hc_error, log, pathbuf, - serde::{self, Deserialize}, - which, + filesystem as file, hc_error, log, pathbuf, which, }; +use serde::{self, Deserialize}; use std::convert::AsRef; use std::ffi::OsStr; use std::iter::IntoIterator; diff --git a/libs/hc_report/Cargo.toml b/libs/hc_report/Cargo.toml index 5b705a9a..a9efe99a 100644 --- a/libs/hc_report/Cargo.toml +++ b/libs/hc_report/Cargo.toml @@ -7,4 +7,5 @@ publish = false [dependencies] hc_common = { path = "../hc_common" } +serde = { version = "1.0.200", features = ["derive", "rc"] } paste = "1.0.7" diff --git a/libs/hc_report/src/lib.rs b/libs/hc_report/src/lib.rs index 897cd82a..13ff47e1 100644 --- a/libs/hc_report/src/lib.rs +++ b/libs/hc_report/src/lib.rs @@ -18,9 +18,9 @@ use hc_common::{ error::{Error, Result}, hc_error, log, schemars::{self, JsonSchema}, - serde::{self, Serialize, Serializer}, }; use paste::paste; +use serde::{Serialize, Serializer}; use std::default::Default; use std::fmt::{self, Display, Formatter}; use std::hash::{Hash, Hasher}; @@ -57,7 +57,6 @@ pub enum AnyReport { /// The report output to the user. #[derive(Debug, Serialize, JsonSchema)] -#[serde(crate = "self::serde")] #[schemars(crate = "self::schemars")] pub struct Report { /// The name of the repository being analyzed. @@ -129,7 +128,7 @@ impl Report { /// An analysis which passed. #[derive(Debug, Serialize, JsonSchema)] -#[serde(transparent, crate = "self::serde")] +#[serde(transparent)] #[schemars(crate = "self::schemars")] pub struct PassingAnalysis( /// The analysis which passed. @@ -144,7 +143,6 @@ impl PassingAnalysis { /// An analysis which failed, including potential specific concerns. #[derive(Debug, Serialize, JsonSchema)] -#[serde(crate = "self::serde")] #[schemars(crate = "self::schemars")] pub struct FailingAnalysis { /// The analysis. @@ -224,7 +222,6 @@ fn no_concerns(concerns: &[Concern]) -> bool { /// An analysis that did _not_ succeed. #[derive(Debug, Serialize, JsonSchema)] -#[serde(crate = "self::serde")] #[schemars(crate = "self::schemars")] pub struct ErroredAnalysis { analysis: AnalysisIdent, @@ -262,7 +259,6 @@ fn try_add_msg(msgs: &mut Vec, error_report: &Option>) /// The name of the analyses. #[derive(Debug, Serialize, JsonSchema)] -#[serde(crate = "self::serde")] #[schemars(crate = "self::schemars")] pub enum AnalysisIdent { Activity, @@ -298,7 +294,6 @@ impl Display for AnalysisIdent { /// A simple, serializable version of `Error`. #[derive(Debug, Serialize, JsonSchema)] -#[serde(crate = "self::serde")] #[schemars(crate = "self::schemars")] pub struct ErrorReport { msg: String, @@ -353,7 +348,7 @@ impl From<&(dyn std::error::Error + 'static)> for ErrorReport { /// An analysis, with score and threshold. #[derive(Debug, Serialize, JsonSchema, Clone, Copy)] -#[serde(tag = "analysis", crate = "self::serde")] +#[serde(tag = "analysis")] #[schemars(crate = "self::schemars")] pub enum Analysis { /// Activity analysis. @@ -661,7 +656,7 @@ impl Analysis { /// only used where additional detail / evidence should be provided beyond the /// top-level information. #[derive(Clone, Debug, Serialize, JsonSchema)] -#[serde(untagged, crate = "self::serde")] +#[serde(untagged)] #[schemars(crate = "self::schemars")] pub enum Concern { /// Commits with affiliated contributor(s) @@ -794,7 +789,6 @@ impl Eq for Concern {} /// The pull request report output to the user. #[derive(Debug, Serialize, JsonSchema)] -#[serde(crate = "self::serde")] #[schemars(crate = "self::schemars")] pub struct PrReport { /// The URI of the pull request being analyzed. @@ -866,7 +860,7 @@ impl PrReport { /// An analysis which passed. #[derive(Debug, Serialize, JsonSchema)] -#[serde(transparent, crate = "self::serde")] +#[serde(transparent)] #[schemars(crate = "self::schemars")] pub struct PrPassingAnalysis( /// The analysis which passed. @@ -881,7 +875,6 @@ impl PrPassingAnalysis { /// An analysis which failed, including potential specific concerns. #[derive(Debug, Serialize, JsonSchema)] -#[serde(crate = "self::serde")] #[schemars(crate = "self::schemars")] pub struct PrFailingAnalysis { /// The analysis. @@ -945,7 +938,6 @@ fn pr_no_concerns(concerns: &[PrConcern]) -> bool { /// An analysis that did _not_ succeed. #[derive(Debug, Serialize, JsonSchema)] -#[serde(crate = "self::serde")] #[schemars(crate = "self::schemars")] pub struct PrErroredAnalysis { analysis: PrAnalysisIdent, @@ -983,7 +975,6 @@ fn pr_try_add_msg(msgs: &mut Vec, error_report: &Option /// The name of the analyses. #[derive(Debug, Serialize, JsonSchema)] -#[serde(crate = "self::serde")] #[schemars(crate = "self::schemars")] pub enum PrAnalysisIdent { PrAffiliation, @@ -1007,7 +998,7 @@ impl Display for PrAnalysisIdent { /// An analysis, with score and threshold. #[derive(Debug, Serialize, JsonSchema, Clone, Copy)] -#[serde(tag = "analysis", crate = "self::serde")] +#[serde(tag = "analysis")] #[schemars(crate = "self::schemars")] pub enum PrAnalysis { /// Pull request affiliation analysis. @@ -1154,7 +1145,7 @@ impl PrAnalysis { /// only used where additional detail / evidence should be provided beyond the /// top-level information. #[derive(Clone, Debug, Serialize, JsonSchema)] -#[serde(untagged, crate = "self::serde")] +#[serde(untagged)] #[schemars(crate = "self::schemars")] pub enum PrConcern { /// Commits with affiliated contributor(s) @@ -1225,7 +1216,6 @@ impl<'opt, T, E> From<&'opt Option>> for AnalysisResult<&'opt T, /// Value and threshold for counting-based analyses. #[derive(Debug, Serialize, JsonSchema, Clone, Copy)] -#[serde(crate = "self::serde")] #[schemars(crate = "self::schemars")] pub struct Count { value: u64, @@ -1234,7 +1224,6 @@ pub struct Count { /// Value for binary-based analyses. #[derive(Debug, Serialize, JsonSchema, Clone, Copy)] -#[serde(crate = "self::serde")] #[schemars(crate = "self::schemars")] pub struct Exists { value: bool, @@ -1242,7 +1231,6 @@ pub struct Exists { /// Value and threshold for percentage-based analyses. #[derive(Debug, Serialize, JsonSchema, Clone, Copy)] -#[serde(crate = "self::serde")] #[schemars(crate = "self::schemars")] pub struct Percent { value: f64, @@ -1252,7 +1240,6 @@ pub struct Percent { /// A final recommendation of whether to use or investigate a piece of software, /// including the risk threshold associated with that decision. #[derive(Debug, Serialize, JsonSchema, Clone, Copy)] -#[serde(crate = "self::serde")] #[schemars(crate = "self::schemars")] pub struct Recommendation { pub kind: RecommendationKind, @@ -1282,7 +1269,6 @@ impl Recommendation { /// The kind of recommendation being made. #[derive(Debug, Serialize, JsonSchema, Clone, Copy)] -#[serde(crate = "self::serde")] #[schemars(crate = "self::schemars")] pub enum RecommendationKind { Pass, @@ -1301,13 +1287,13 @@ impl RecommendationKind { /// The overall final risk score for a repo. #[derive(Debug, Serialize, JsonSchema, Clone, Copy)] -#[serde(transparent, crate = "self::serde")] +#[serde(transparent)] #[schemars(crate = "self::schemars")] pub struct RiskScore(pub f64); /// The risk threshold configured for the Hipcheck session. #[derive(Debug, Serialize, JsonSchema, Clone, Copy)] -#[serde(transparent, crate = "self::serde")] +#[serde(transparent)] #[schemars(crate = "self::schemars")] pub struct RiskThreshold(pub f64); diff --git a/libs/hc_serde/Cargo.toml b/libs/hc_serde/Cargo.toml deleted file mode 100644 index 32189b16..00000000 --- a/libs/hc_serde/Cargo.toml +++ /dev/null @@ -1,9 +0,0 @@ -[package] -name = "hc_serde" -version = "0.1.0" -edition = "2021" -license = "Apache-2.0" -publish = false - -[dependencies] -serde = { version = "1.0.137", features = ["derive", "rc"] } diff --git a/libs/hc_serde/src/lib.rs b/libs/hc_serde/src/lib.rs deleted file mode 100644 index 4d56de19..00000000 --- a/libs/hc_serde/src/lib.rs +++ /dev/null @@ -1,15 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 - -//! Provides common access to the `serde` crate, used widely -//! throughout Hipcheck. -//! -//! This dependency has not been included in `hc_common` in order to -//! support use of `graphql_client` derive macros, which require that -//! `serde` be a direct dependency of the containing crate. By -//! placing the direct `serde` dependency here, we can alias this -//! crate as `serde` when we need to. -//! -//! Note that `hc_common` re-exports this crate's own `serde` export. -//! Use `hc_common` over this whenever possible. - -pub use serde::{self, *}; From f3ca7c3e0ef8dda1828af462871d783a4d9a4c73 Mon Sep 17 00:00:00 2001 From: Andrew Lilley Brinker Date: Mon, 6 May 2024 14:30:11 -0700 Subject: [PATCH 04/14] chore: Merge `hc_report` into `hc_common`. This commit merges the contents of `hc_report` into the `hc_common` crate. Signed-off-by: Andrew Lilley Brinker --- Cargo.lock | 12 +---------- libs/hc_analysis/Cargo.toml | 1 - libs/hc_analysis/src/analysis.rs | 2 +- libs/hc_analysis/src/report_builder.rs | 3 ++- libs/hc_analysis/src/session/mod.rs | 5 +++-- libs/hc_common/Cargo.toml | 1 + libs/hc_common/src/lib.rs | 1 + .../src/lib.rs => hc_common/src/report.rs} | 21 +++++++++++++------ libs/hc_report/Cargo.toml | 11 ---------- libs/hc_report/src/query.rs | 20 ------------------ libs/hc_shell/Cargo.toml | 9 +------- libs/hc_shell/src/lib.rs | 5 +++-- 12 files changed, 28 insertions(+), 63 deletions(-) rename libs/{hc_report/src/lib.rs => hc_common/src/report.rs} (98%) delete mode 100644 libs/hc_report/Cargo.toml delete mode 100644 libs/hc_report/src/query.rs diff --git a/Cargo.lock b/Cargo.lock index 77125435..06ba18e4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -613,7 +613,6 @@ dependencies = [ "glob", "hc_common", "hc_data", - "hc_report", "hc_shell", "maplit", "petgraph", @@ -639,6 +638,7 @@ dependencies = [ "log", "once_cell", "ordered-float", + "paste", "regex", "salsa", "schemars", @@ -678,22 +678,12 @@ dependencies = [ "ureq", ] -[[package]] -name = "hc_report" -version = "0.1.0" -dependencies = [ - "hc_common", - "paste", - "serde", -] - [[package]] name = "hc_shell" version = "0.1.0" dependencies = [ "duct", "hc_common", - "hc_report", "libc", "termcolor", "winapi", diff --git a/libs/hc_analysis/Cargo.toml b/libs/hc_analysis/Cargo.toml index 0e9ed722..22014586 100644 --- a/libs/hc_analysis/Cargo.toml +++ b/libs/hc_analysis/Cargo.toml @@ -13,7 +13,6 @@ curl = "0.4.38" glob = "0.3.0" hc_common = { path = "../hc_common" } hc_data = { path = "../hc_data" } -hc_report = { path = "../hc_report" } hc_shell = { path = "../hc_shell" } maplit = "1.0.2" petgraph = { version = "0.6.0" } diff --git a/libs/hc_analysis/src/analysis.rs b/libs/hc_analysis/src/analysis.rs index c2191ded..c0fe7ac6 100644 --- a/libs/hc_analysis/src/analysis.rs +++ b/libs/hc_analysis/src/analysis.rs @@ -5,10 +5,10 @@ use hc_common::{ chrono::Duration, config::{AttacksConfigQuery, CommitConfigQuery, FuzzConfigQuery, PracticesConfigQuery}, error::{Error, Result}, + report::{Concern, PrConcern}, salsa, F64, }; use hc_data::git::GitProvider; -use hc_report::{Concern, PrConcern}; use std::collections::{HashMap, HashSet}; use std::default::Default; use std::fmt::{self, Display, Formatter}; diff --git a/libs/hc_analysis/src/report_builder.rs b/libs/hc_analysis/src/report_builder.rs index 4d7339ec..185acc8c 100644 --- a/libs/hc_analysis/src/report_builder.rs +++ b/libs/hc_analysis/src/report_builder.rs @@ -1,13 +1,14 @@ // SPDX-License-Identifier: Apache-2.0 use crate::{analysis::AnalysisReport, score::ScoringResults, session::Session}; +pub use hc_common::report::*; use hc_common::{ config::RiskConfigQuery, error::{Error, Result}, hc_error, log, + version::VersionQuery, }; use hc_data::source::SourceQuery; -pub use hc_report::*; use std::default::Default; use std::result::Result as StdResult; diff --git a/libs/hc_analysis/src/session/mod.rs b/libs/hc_analysis/src/session/mod.rs index 50a3b845..252ccfa4 100644 --- a/libs/hc_analysis/src/session/mod.rs +++ b/libs/hc_analysis/src/session/mod.rs @@ -22,7 +22,9 @@ use hc_common::{ }, error::{Error, Result}, filesystem::create_dir_all, - hc_error, pathbuf, salsa, + hc_error, pathbuf, + report::{Format, ReportParams, ReportParamsStorage}, + salsa, version::{get_version, VersionQuery, VersionQueryStorage}, HIPCHECK_TOML_FILE, }; @@ -37,7 +39,6 @@ use hc_data::{ CodeQualityProviderStorage, DependenciesProviderStorage, FuzzProviderStorage, GitHubProviderStorage, ModuleProviderStorage, PullRequestReviewProviderStorage, }; -use hc_report::{Format, ReportParams, ReportParamsStorage}; use hc_shell::{Phase, Shell}; use std::ffi::{OsStr, OsString}; use std::fmt; diff --git a/libs/hc_common/Cargo.toml b/libs/hc_common/Cargo.toml index cc920c87..06bf0f19 100644 --- a/libs/hc_common/Cargo.toml +++ b/libs/hc_common/Cargo.toml @@ -11,6 +11,7 @@ lazy_static = "1.4.0" log = "0.4.16" once_cell = "1.10.0" ordered-float = { version = "4.2.0", features = ["serde"] } +paste = "1.0.7" regex = "1.5.5" salsa = "0.16.1" schemars = { version = "0.8.17", default-features = false, features = [ diff --git a/libs/hc_common/src/lib.rs b/libs/hc_common/src/lib.rs index 727d61af..2917ef59 100644 --- a/libs/hc_common/src/lib.rs +++ b/libs/hc_common/src/lib.rs @@ -9,6 +9,7 @@ pub mod context; pub mod error; pub mod filesystem; pub mod pathbuf; +pub mod report; pub mod test_util; #[cfg(test)] mod tests; diff --git a/libs/hc_report/src/lib.rs b/libs/hc_common/src/report.rs similarity index 98% rename from libs/hc_report/src/lib.rs rename to libs/hc_common/src/report.rs index 13ff47e1..3c271238 100644 --- a/libs/hc_report/src/lib.rs +++ b/libs/hc_common/src/report.rs @@ -9,15 +9,12 @@ // The report serves double-duty, because it's both the thing used to print user-friendly // results on the CLI, and the type that's serialized out to JSON for machine-friendly output. -mod query; - -pub use query::*; - -use hc_common::{ +use crate::{ chrono::prelude::*, error::{Error, Result}, - hc_error, log, + hc_error, log, salsa, schemars::{self, JsonSchema}, + version::VersionQuery, }; use paste::paste; use serde::{Serialize, Serializer}; @@ -1329,3 +1326,15 @@ impl Serialize for Timestamp { serializer.serialize_str(&self.0.to_rfc3339()) } } + +/// Queries for how Hipcheck reports session results +#[salsa::query_group(ReportParamsStorage)] +pub trait ReportParams: VersionQuery { + /// Returns the time the current Hipcheck session started + #[salsa::input] + fn started_at(&self) -> DateTime; + + /// Returns the format of the final report + #[salsa::input] + fn format(&self) -> Format; +} diff --git a/libs/hc_report/Cargo.toml b/libs/hc_report/Cargo.toml deleted file mode 100644 index a9efe99a..00000000 --- a/libs/hc_report/Cargo.toml +++ /dev/null @@ -1,11 +0,0 @@ -[package] -name = "hc_report" -version = "0.1.0" -edition = "2021" -license = "Apache-2.0" -publish = false - -[dependencies] -hc_common = { path = "../hc_common" } -serde = { version = "1.0.200", features = ["derive", "rc"] } -paste = "1.0.7" diff --git a/libs/hc_report/src/query.rs b/libs/hc_report/src/query.rs deleted file mode 100644 index 56687fa5..00000000 --- a/libs/hc_report/src/query.rs +++ /dev/null @@ -1,20 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 - -//! Query groups for how Hipcheck reports and dumps session results. - -pub use hc_common::version::VersionQuery; - -use crate::Format; -use hc_common::{chrono::prelude::*, salsa}; - -/// Queries for how Hipcheck reports session results -#[salsa::query_group(ReportParamsStorage)] -pub trait ReportParams: VersionQuery { - /// Returns the time the current Hipcheck session started - #[salsa::input] - fn started_at(&self) -> DateTime; - - /// Returns the format of the final report - #[salsa::input] - fn format(&self) -> Format; -} diff --git a/libs/hc_shell/Cargo.toml b/libs/hc_shell/Cargo.toml index 780af4bb..a762098c 100644 --- a/libs/hc_shell/Cargo.toml +++ b/libs/hc_shell/Cargo.toml @@ -8,16 +8,9 @@ publish = false [dependencies] duct = "0.13.5" hc_common = { path = "../hc_common" } -hc_report = { path = "../hc_report" } libc = "0.2.154" termcolor = "1.1.3" [target.'cfg(windows)'.dependencies.winapi] version = "0.3" -features = [ - "handleapi", - "processenv", - "winbase", - "wincon", - "winnt", -] +features = ["handleapi", "processenv", "winbase", "wincon", "winnt"] diff --git a/libs/hc_shell/src/lib.rs b/libs/hc_shell/src/lib.rs index 04e7863b..a2cdd0a8 100644 --- a/libs/hc_shell/src/lib.rs +++ b/libs/hc_shell/src/lib.rs @@ -86,9 +86,10 @@ use hc_common::{ error::{Error, Result}, - hc_error, log, serde_json, + hc_error, log, + report::{Format, PrReport, RecommendationKind, Report}, + serde_json, }; -use hc_report::{Format, PrReport, RecommendationKind, Report}; use std::cell::Cell; use std::fmt::{self, Debug, Formatter}; use std::io::stderr; From 3342fe4a8dcc0e8b55d12b38c40dc8db6144ba4e Mon Sep 17 00:00:00 2001 From: Andrew Lilley Brinker Date: Mon, 6 May 2024 14:34:23 -0700 Subject: [PATCH 05/14] chore: Merge `hc_shell` into `hc_common`. This commits merges `hc_shell` into `hc_common`. Signed-off-by: Andrew Lilley Brinker --- Cargo.lock | 18 ++++-------------- libs/hc_analysis/Cargo.toml | 1 - libs/hc_analysis/src/score.rs | 3 +-- libs/hc_analysis/src/session/mod.rs | 5 ++--- libs/hc_common/Cargo.toml | 7 +++++++ libs/hc_common/src/lib.rs | 1 + .../src/lib.rs => hc_common/src/shell.rs} | 8 ++++---- libs/hc_core/Cargo.toml | 1 - libs/hc_core/src/lib.rs | 6 ++++-- libs/hc_data/Cargo.toml | 1 - libs/hc_data/src/source/mod.rs | 2 +- libs/hc_shell/Cargo.toml | 16 ---------------- 12 files changed, 24 insertions(+), 45 deletions(-) rename libs/{hc_shell/src/lib.rs => hc_common/src/shell.rs} (99%) delete mode 100644 libs/hc_shell/Cargo.toml diff --git a/Cargo.lock b/Cargo.lock index 06ba18e4..e8ac499f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -613,7 +613,6 @@ dependencies = [ "glob", "hc_common", "hc_data", - "hc_shell", "maplit", "petgraph", "serde", @@ -634,7 +633,9 @@ version = "0.1.0" dependencies = [ "anyhow", "chrono", + "duct", "lazy_static", + "libc", "log", "once_cell", "ordered-float", @@ -646,9 +647,11 @@ dependencies = [ "serde", "serde_json", "smart-default", + "termcolor", "toml", "url", "which", + "winapi", ] [[package]] @@ -659,7 +662,6 @@ dependencies = [ "duct", "hc_analysis", "hc_common", - "hc_shell", "tempfile", ] @@ -670,7 +672,6 @@ dependencies = [ "dirs", "graphql_client", "hc_common", - "hc_shell", "nom", "petgraph", "serde", @@ -678,17 +679,6 @@ dependencies = [ "ureq", ] -[[package]] -name = "hc_shell" -version = "0.1.0" -dependencies = [ - "duct", - "hc_common", - "libc", - "termcolor", - "winapi", -] - [[package]] name = "heck" version = "0.3.3" diff --git a/libs/hc_analysis/Cargo.toml b/libs/hc_analysis/Cargo.toml index 22014586..2971119a 100644 --- a/libs/hc_analysis/Cargo.toml +++ b/libs/hc_analysis/Cargo.toml @@ -13,7 +13,6 @@ curl = "0.4.38" glob = "0.3.0" hc_common = { path = "../hc_common" } hc_data = { path = "../hc_data" } -hc_shell = { path = "../hc_shell" } maplit = "1.0.2" petgraph = { version = "0.6.0" } serde = { version = "1.0.200", features = ["derive", "rc"] } diff --git a/libs/hc_analysis/src/score.rs b/libs/hc_analysis/src/score.rs index 6eabbfe8..5a45d916 100644 --- a/libs/hc_analysis/src/score.rs +++ b/libs/hc_analysis/src/score.rs @@ -4,8 +4,7 @@ use crate::{ analysis::{AnalysisOutcome, AnalysisReport}, AnalysisProvider, }; -use hc_common::{error::Result, hc_error, salsa}; -use hc_shell::Phase; +use hc_common::{error::Result, hc_error, salsa, shell::Phase}; use std::default::Default; use std::rc::Rc; diff --git a/libs/hc_analysis/src/session/mod.rs b/libs/hc_analysis/src/session/mod.rs index 252ccfa4..3a92e52d 100644 --- a/libs/hc_analysis/src/session/mod.rs +++ b/libs/hc_analysis/src/session/mod.rs @@ -25,10 +25,10 @@ use hc_common::{ hc_error, pathbuf, report::{Format, ReportParams, ReportParamsStorage}, salsa, + shell::{Phase, Shell}, version::{get_version, VersionQuery, VersionQueryStorage}, HIPCHECK_TOML_FILE, }; -use hc_data::ModuleProvider; use hc_data::{ git::get_git_version, git::GitProviderStorage, @@ -37,9 +37,8 @@ use hc_data::{ Source, SourceChangeRequest, SourceKind, SourceQuery, SourceQueryStorage, SourceRepo, }, CodeQualityProviderStorage, DependenciesProviderStorage, FuzzProviderStorage, - GitHubProviderStorage, ModuleProviderStorage, PullRequestReviewProviderStorage, + GitHubProviderStorage, ModuleProvider, ModuleProviderStorage, PullRequestReviewProviderStorage, }; -use hc_shell::{Phase, Shell}; use std::ffi::{OsStr, OsString}; use std::fmt; use std::path::{Path, PathBuf}; diff --git a/libs/hc_common/Cargo.toml b/libs/hc_common/Cargo.toml index 06bf0f19..2a27a47a 100644 --- a/libs/hc_common/Cargo.toml +++ b/libs/hc_common/Cargo.toml @@ -26,6 +26,13 @@ smart-default = "0.7.1" toml = "0.8.12" url = "2.2.2" which = { version = "6.0.1", default-features = false } +libc = "0.2.154" +termcolor = "1.1.3" +duct = "0.13.5" + +[target.'cfg(windows)'.dependencies.winapi] +version = "0.3" +features = ["handleapi", "processenv", "winbase", "wincon", "winnt"] [build-dependencies] anyhow = "1.0.83" diff --git a/libs/hc_common/src/lib.rs b/libs/hc_common/src/lib.rs index 2917ef59..154af87b 100644 --- a/libs/hc_common/src/lib.rs +++ b/libs/hc_common/src/lib.rs @@ -10,6 +10,7 @@ pub mod error; pub mod filesystem; pub mod pathbuf; pub mod report; +pub mod shell; pub mod test_util; #[cfg(test)] mod tests; diff --git a/libs/hc_shell/src/lib.rs b/libs/hc_common/src/shell.rs similarity index 99% rename from libs/hc_shell/src/lib.rs rename to libs/hc_common/src/shell.rs index a2cdd0a8..7bcde02a 100644 --- a/libs/hc_shell/src/lib.rs +++ b/libs/hc_common/src/shell.rs @@ -30,7 +30,7 @@ * These methods take a `&mut Output`, a [`Report`] or [`PrReport`], and a [`Format`]. * * At any point, errors may also be printed using [`Shell::error`], which takes an - * [`&Error`][hc_common::error:Error] and a [`Format`]. + * [`&Error`][crate::error:Error] and a [`Format`]. * * ## Why the shell interface? * @@ -84,7 +84,7 @@ #![deny(missing_docs)] -use hc_common::{ +use crate::{ error::{Error, Result}, hc_error, log, report::{Format, PrReport, RecommendationKind, Report}, @@ -1523,7 +1523,7 @@ enum TtyWidth { #[cfg(unix)] mod imp { use super::TtyWidth; - use hc_common::{error::Result, log}; + use crate::{error::Result, log}; use libc::{ioctl, winsize, STDOUT_FILENO, TIOCGWINSZ}; use std::mem::zeroed; use termcolor::WriteColor; @@ -1561,7 +1561,7 @@ mod imp { #[cfg(windows)] mod imp { use super::TtyWidth; - use hc_common::{error::Result, log}; + use crate::{error::Result, log}; use std::mem::zeroed; use std::{cmp, ptr}; use termcolor::WriteColor; diff --git a/libs/hc_core/Cargo.toml b/libs/hc_core/Cargo.toml index d78f20f9..33b0b41e 100644 --- a/libs/hc_core/Cargo.toml +++ b/libs/hc_core/Cargo.toml @@ -8,7 +8,6 @@ publish = false [dependencies] hc_analysis = { path = "../hc_analysis" } hc_common = { path = "../hc_common" } -hc_shell = { path = "../hc_shell" } [dev_dependencies] duct = "0.13.7" diff --git a/libs/hc_core/src/lib.rs b/libs/hc_core/src/lib.rs index f4c55483..20e9247c 100644 --- a/libs/hc_core/src/lib.rs +++ b/libs/hc_core/src/lib.rs @@ -4,8 +4,10 @@ pub use hc_analysis::{ report_builder::{AnyReport, Format, PrReport, Report}, session::{resolve_config, resolve_data, resolve_home, Check, CheckType}, }; -pub use hc_common::version; -pub use hc_shell::{ColorChoice, Output, Shell, Verbosity}; +pub use hc_common::{ + shell::{ColorChoice, Output, Shell, Verbosity}, + version, +}; use hc_analysis::{ report_builder::{build_pr_report, build_report}, diff --git a/libs/hc_data/Cargo.toml b/libs/hc_data/Cargo.toml index 37373c1c..156b3c27 100644 --- a/libs/hc_data/Cargo.toml +++ b/libs/hc_data/Cargo.toml @@ -9,7 +9,6 @@ publish = false dirs = "5.0.1" graphql_client = "0.14.0" hc_common = { path = "../hc_common" } -hc_shell = { path = "../hc_shell" } nom = "7.1.3" petgraph = { version = "0.6.0", features = ["serde-1"] } serde = { version = "1.0.200", features = ["derive", "rc"] } diff --git a/libs/hc_data/src/source/mod.rs b/libs/hc_data/src/source/mod.rs index 907ef2ce..a4d34b09 100644 --- a/libs/hc_data/src/source/mod.rs +++ b/libs/hc_data/src/source/mod.rs @@ -10,9 +10,9 @@ use hc_common::{ context::Context, error::{Error, Result}, hc_error, pathbuf, + shell::Phase, url::Url, }; -use hc_shell::Phase; use std::ffi::OsStr; use std::fmt::{self, Debug, Display, Formatter}; use std::fs; diff --git a/libs/hc_shell/Cargo.toml b/libs/hc_shell/Cargo.toml deleted file mode 100644 index a762098c..00000000 --- a/libs/hc_shell/Cargo.toml +++ /dev/null @@ -1,16 +0,0 @@ -[package] -name = "hc_shell" -version = "0.1.0" -edition = "2021" -license = "Apache-2.0" -publish = false - -[dependencies] -duct = "0.13.5" -hc_common = { path = "../hc_common" } -libc = "0.2.154" -termcolor = "1.1.3" - -[target.'cfg(windows)'.dependencies.winapi] -version = "0.3" -features = ["handleapi", "processenv", "winbase", "wincon", "winnt"] From c959abbb8dac800d5f52b22b9dff0a8fe23de60b Mon Sep 17 00:00:00 2001 From: Andrew Lilley Brinker Date: Mon, 6 May 2024 14:47:11 -0700 Subject: [PATCH 06/14] chore: Merge `hc_data` into `hc_common`. This commit merges `hc_data` into the `hc_common` crate. Signed-off-by: Andrew Lilley Brinker --- Cargo.lock | 21 +++------ libs/hc_analysis/Cargo.toml | 1 - libs/hc_analysis/src/analysis.rs | 2 +- libs/hc_analysis/src/metric/affiliation.rs | 2 +- libs/hc_analysis/src/metric/churn.rs | 3 +- libs/hc_analysis/src/metric/entropy.rs | 7 ++- libs/hc_analysis/src/metric/fuzz.rs | 3 +- libs/hc_analysis/src/metric/identity.rs | 3 +- libs/hc_analysis/src/metric/mod.rs | 7 +-- libs/hc_analysis/src/metric/module.rs | 3 +- .../src/metric/module_contributors.rs | 7 ++- libs/hc_analysis/src/metric/review.rs | 3 +- libs/hc_analysis/src/metric/typo.rs | 7 ++- libs/hc_analysis/src/report_builder.rs | 2 +- libs/hc_analysis/src/session/mod.rs | 21 +++++---- libs/hc_common/Cargo.toml | 12 +++++ .../src/lib.rs => hc_common/src/data.rs} | 2 +- .../src/data}/code_quality.rs | 6 +-- .../src/data}/es_lint/command.rs | 4 +- .../src/data}/es_lint/data.rs | 2 +- .../src => hc_common/src/data}/es_lint/mod.rs | 5 +- .../src => hc_common/src/data}/git/data.rs | 2 +- .../src => hc_common/src/data}/git/mod.rs | 8 ++-- .../src => hc_common/src/data}/git/parse.rs | 46 +++++++++---------- .../src/data}/git/query/impls.rs | 4 +- .../src/data}/git/query/mod.rs | 4 +- .../src => hc_common/src/data}/git_command.rs | 3 +- .../src/data}/github/authenticated_agent.rs | 2 +- .../src/data}/github/code_search.rs | 4 +- .../src => hc_common/src/data}/github/data.rs | 2 +- .../src/data}/github/gh_query.graphql | 0 .../src/data}/github/gh_schema.graphql | 0 .../src/data}/github/graphql.rs | 10 ++-- .../src/data}/github/graphql_pr.rs | 10 ++-- .../src/data}/github/hidden.rs | 0 .../src => hc_common/src/data}/github/mod.rs | 16 +++---- .../src => hc_common/src/data}/hash.rs | 0 .../src => hc_common/src/data}/modules.rs | 4 +- .../src => hc_common/src/data}/npm.rs | 4 +- .../src/data}/query/code_quality.rs | 6 +-- .../src/data}/query/dependencies.rs | 8 ++-- .../src => hc_common/src/data}/query/fuzz.rs | 4 +- .../src/data}/query/github.rs | 4 +- .../src => hc_common/src/data}/query/mod.rs | 0 .../src/data}/query/module.rs | 4 +- .../src/data}/query/pr_review.rs | 4 +- .../src => hc_common/src/data}/source/mod.rs | 9 ++-- .../src/data}/source/query.rs | 10 ++-- libs/hc_common/src/lib.rs | 1 + libs/hc_data/Cargo.toml | 22 --------- 50 files changed, 149 insertions(+), 165 deletions(-) rename libs/{hc_data/src/lib.rs => hc_common/src/data.rs} (98%) rename libs/{hc_data/src => hc_common/src/data}/code_quality.rs (93%) rename libs/{hc_data/src => hc_common/src/data}/es_lint/command.rs (97%) rename libs/{hc_data/src => hc_common/src/data}/es_lint/data.rs (99%) rename libs/{hc_data/src => hc_common/src/data}/es_lint/mod.rs (95%) rename libs/{hc_data/src => hc_common/src/data}/git/data.rs (98%) rename libs/{hc_data/src => hc_common/src/data}/git/mod.rs (95%) rename libs/{hc_data/src => hc_common/src/data}/git/parse.rs (99%) rename libs/{hc_data/src => hc_common/src/data}/git/query/impls.rs (99%) rename libs/{hc_data/src => hc_common/src/data}/git/query/mod.rs (97%) rename libs/{hc_data/src => hc_common/src/data}/git_command.rs (94%) rename libs/{hc_data/src => hc_common/src/data}/github/authenticated_agent.rs (97%) rename libs/{hc_data/src => hc_common/src/data}/github/code_search.rs (95%) rename libs/{hc_data/src => hc_common/src/data}/github/data.rs (91%) rename libs/{hc_data/src => hc_common/src/data}/github/gh_query.graphql (100%) rename libs/{hc_data/src => hc_common/src/data}/github/gh_schema.graphql (100%) rename libs/{hc_data/src => hc_common/src/data}/github/graphql.rs (95%) rename libs/{hc_data/src => hc_common/src/data}/github/graphql_pr.rs (98%) rename libs/{hc_data/src => hc_common/src/data}/github/hidden.rs (100%) rename libs/{hc_data/src => hc_common/src/data}/github/mod.rs (84%) rename libs/{hc_data/src => hc_common/src/data}/hash.rs (100%) rename libs/{hc_data/src => hc_common/src/data}/modules.rs (98%) rename libs/{hc_data/src => hc_common/src/data}/npm.rs (99%) rename libs/{hc_data/src => hc_common/src/data}/query/code_quality.rs (79%) rename libs/{hc_data/src => hc_common/src/data}/query/dependencies.rs (86%) rename libs/{hc_data/src => hc_common/src/data}/query/fuzz.rs (94%) rename libs/{hc_data/src => hc_common/src/data}/query/github.rs (97%) rename libs/{hc_data/src => hc_common/src/data}/query/mod.rs (100%) rename libs/{hc_data/src => hc_common/src/data}/query/module.rs (99%) rename libs/{hc_data/src => hc_common/src/data}/query/pr_review.rs (99%) rename libs/{hc_data/src => hc_common/src/data}/source/mod.rs (99%) rename libs/{hc_data/src => hc_common/src/data}/source/query.rs (95%) delete mode 100644 libs/hc_data/Cargo.toml diff --git a/Cargo.lock b/Cargo.lock index e8ac499f..b6ccef61 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -612,7 +612,6 @@ dependencies = [ "dotenv", "glob", "hc_common", - "hc_data", "maplit", "petgraph", "serde", @@ -633,13 +632,17 @@ version = "0.1.0" dependencies = [ "anyhow", "chrono", + "dirs", "duct", + "graphql_client", "lazy_static", "libc", "log", + "nom", "once_cell", "ordered-float", "paste", + "petgraph", "regex", "salsa", "schemars", @@ -647,8 +650,10 @@ dependencies = [ "serde", "serde_json", "smart-default", + "tempfile", "termcolor", "toml", + "ureq", "url", "which", "winapi", @@ -665,20 +670,6 @@ dependencies = [ "tempfile", ] -[[package]] -name = "hc_data" -version = "0.1.0" -dependencies = [ - "dirs", - "graphql_client", - "hc_common", - "nom", - "petgraph", - "serde", - "tempfile", - "ureq", -] - [[package]] name = "heck" version = "0.3.3" diff --git a/libs/hc_analysis/Cargo.toml b/libs/hc_analysis/Cargo.toml index 2971119a..ee695455 100644 --- a/libs/hc_analysis/Cargo.toml +++ b/libs/hc_analysis/Cargo.toml @@ -12,7 +12,6 @@ dotenv = "0.15.0" curl = "0.4.38" glob = "0.3.0" hc_common = { path = "../hc_common" } -hc_data = { path = "../hc_data" } maplit = "1.0.2" petgraph = { version = "0.6.0" } serde = { version = "1.0.200", features = ["derive", "rc"] } diff --git a/libs/hc_analysis/src/analysis.rs b/libs/hc_analysis/src/analysis.rs index c0fe7ac6..3041e9b7 100644 --- a/libs/hc_analysis/src/analysis.rs +++ b/libs/hc_analysis/src/analysis.rs @@ -4,11 +4,11 @@ use crate::metric::{affiliation::AffiliatedType, MetricProvider}; use hc_common::{ chrono::Duration, config::{AttacksConfigQuery, CommitConfigQuery, FuzzConfigQuery, PracticesConfigQuery}, + data::git::GitProvider, error::{Error, Result}, report::{Concern, PrConcern}, salsa, F64, }; -use hc_data::git::GitProvider; use std::collections::{HashMap, HashSet}; use std::default::Default; use std::fmt::{self, Display, Formatter}; diff --git a/libs/hc_analysis/src/metric/affiliation.rs b/libs/hc_analysis/src/metric/affiliation.rs index 6e9a0925..a11b42bd 100644 --- a/libs/hc_analysis/src/metric/affiliation.rs +++ b/libs/hc_analysis/src/metric/affiliation.rs @@ -3,10 +3,10 @@ use crate::MetricProvider; use hc_common::{ context::Context as _, + data::git::{Commit, CommitContributorView}, error::{Error, Result}, filesystem as file, hc_error, log, }; -use hc_data::git::{Commit, CommitContributorView}; use serde::{ self, de::{Error as SerdeError, Visitor}, diff --git a/libs/hc_analysis/src/metric/churn.rs b/libs/hc_analysis/src/metric/churn.rs index 2519c1fd..b06ef8f2 100644 --- a/libs/hc_analysis/src/metric/churn.rs +++ b/libs/hc_analysis/src/metric/churn.rs @@ -3,8 +3,7 @@ use crate::metric::math::{mean, std_dev}; use crate::MetricProvider; use hc_common::context::Context as _; -use hc_common::{error::Result, hc_error, log, TryAny, TryFilter, F64}; -use hc_data::git::Commit; +use hc_common::{data::git::Commit, error::Result, hc_error, log, TryAny, TryFilter, F64}; use serde::{self, Serialize}; use std::collections::HashMap; use std::rc::Rc; diff --git a/libs/hc_analysis/src/metric/entropy.rs b/libs/hc_analysis/src/metric/entropy.rs index f8f90daa..0494922c 100644 --- a/libs/hc_analysis/src/metric/entropy.rs +++ b/libs/hc_analysis/src/metric/entropy.rs @@ -3,8 +3,11 @@ use crate::metric::math::{mean, std_dev}; use crate::MetricProvider; use hc_common::context::Context as _; -use hc_common::{error::Result, hc_error, log, TryAny, TryFilter, F64}; -use hc_data::git::{Commit, CommitDiff, Diff}; +use hc_common::{ + data::git::{Commit, CommitDiff, Diff}, + error::Result, + hc_error, log, TryAny, TryFilter, F64, +}; use serde::{self, Serialize}; use std::collections::HashMap; use std::iter::Iterator; diff --git a/libs/hc_analysis/src/metric/fuzz.rs b/libs/hc_analysis/src/metric/fuzz.rs index 53fcdde2..a28cda11 100644 --- a/libs/hc_analysis/src/metric/fuzz.rs +++ b/libs/hc_analysis/src/metric/fuzz.rs @@ -2,8 +2,7 @@ use crate::MetricProvider; use hc_common::context::Context as _; -use hc_common::{error::Result, log}; -use hc_data::Fuzz; +use hc_common::{data::Fuzz, error::Result, log}; use serde::{self, Serialize}; use std::rc::Rc; diff --git a/libs/hc_analysis/src/metric/identity.rs b/libs/hc_analysis/src/metric/identity.rs index 775f9f8e..32d11430 100644 --- a/libs/hc_analysis/src/metric/identity.rs +++ b/libs/hc_analysis/src/metric/identity.rs @@ -2,8 +2,7 @@ use crate::MetricProvider; use hc_common::context::Context as _; -use hc_common::{error::Result, log}; -use hc_data::git::Commit; +use hc_common::{data::git::Commit, error::Result, log}; use serde::{self, Serialize}; use std::rc::Rc; diff --git a/libs/hc_analysis/src/metric/mod.rs b/libs/hc_analysis/src/metric/mod.rs index 6da761d2..502a68a3 100644 --- a/libs/hc_analysis/src/metric/mod.rs +++ b/libs/hc_analysis/src/metric/mod.rs @@ -30,12 +30,13 @@ use entropy::EntropyOutput; use fuzz::FuzzOutput; use hc_common::{ config::{AttacksConfigQuery, CommitConfigQuery}, + data::{ + git::GitProvider, DependenciesProvider, FuzzProvider, ModuleProvider, + PullRequestReviewProvider, + }, error::Result, salsa, }; -use hc_data::{ - git::GitProvider, DependenciesProvider, FuzzProvider, ModuleProvider, PullRequestReviewProvider, -}; use identity::IdentityOutput; use linguist::Linguist; use module::ModuleOutput; diff --git a/libs/hc_analysis/src/metric/module.rs b/libs/hc_analysis/src/metric/module.rs index 6bdc67a6..0a8ec124 100644 --- a/libs/hc_analysis/src/metric/module.rs +++ b/libs/hc_analysis/src/metric/module.rs @@ -2,8 +2,7 @@ use crate::MetricProvider; use hc_common::context::Context as _; -use hc_common::{error::Result, log}; -use hc_data::ModuleGraph; +use hc_common::{data::ModuleGraph, error::Result, log}; use serde::{self, Serialize}; use std::rc::Rc; diff --git a/libs/hc_analysis/src/metric/module_contributors.rs b/libs/hc_analysis/src/metric/module_contributors.rs index d34d8c6d..cf10459e 100644 --- a/libs/hc_analysis/src/metric/module_contributors.rs +++ b/libs/hc_analysis/src/metric/module_contributors.rs @@ -2,8 +2,11 @@ use crate::MetricProvider; use hc_common::context::Context as _; -use hc_common::{error::Result, log}; -use hc_data::{git::Contributor, Module}; +use hc_common::{ + data::{git::Contributor, Module}, + error::Result, + log, +}; use serde::{self, Serialize}; use std::{collections::HashMap, rc::Rc}; diff --git a/libs/hc_analysis/src/metric/review.rs b/libs/hc_analysis/src/metric/review.rs index a1fd8d23..b0d46a28 100644 --- a/libs/hc_analysis/src/metric/review.rs +++ b/libs/hc_analysis/src/metric/review.rs @@ -2,8 +2,7 @@ use crate::MetricProvider; use hc_common::context::Context as _; -use hc_common::{error::Result, log}; -use hc_data::PullRequest; +use hc_common::{data::PullRequest, error::Result, log}; use serde::{self, Serialize}; use std::rc::Rc; diff --git a/libs/hc_analysis/src/metric/typo.rs b/libs/hc_analysis/src/metric/typo.rs index 8884b934..e21824a8 100644 --- a/libs/hc_analysis/src/metric/typo.rs +++ b/libs/hc_analysis/src/metric/typo.rs @@ -2,8 +2,11 @@ use crate::MetricProvider; use hc_common::context::Context as _; -use hc_common::{error::Result, filesystem as file, log}; -use hc_data::{Dependencies, Lang}; +use hc_common::{ + data::{Dependencies, Lang}, + error::Result, + filesystem as file, log, +}; use maplit::hashmap; use serde::{self, Deserialize, Serialize}; use std::cmp::Ordering; diff --git a/libs/hc_analysis/src/report_builder.rs b/libs/hc_analysis/src/report_builder.rs index 185acc8c..8a83f2c1 100644 --- a/libs/hc_analysis/src/report_builder.rs +++ b/libs/hc_analysis/src/report_builder.rs @@ -4,11 +4,11 @@ use crate::{analysis::AnalysisReport, score::ScoringResults, session::Session}; pub use hc_common::report::*; use hc_common::{ config::RiskConfigQuery, + data::source::SourceQuery, error::{Error, Result}, hc_error, log, version::VersionQuery, }; -use hc_data::source::SourceQuery; use std::default::Default; use std::result::Result as StdResult; diff --git a/libs/hc_analysis/src/session/mod.rs b/libs/hc_analysis/src/session/mod.rs index 3a92e52d..de4c1bf3 100644 --- a/libs/hc_analysis/src/session/mod.rs +++ b/libs/hc_analysis/src/session/mod.rs @@ -20,6 +20,17 @@ use hc_common::{ ConfigSourceStorage, FuzzConfigQueryStorage, LanguagesConfigQueryStorage, PracticesConfigQueryStorage, RiskConfigQueryStorage, }, + data::{ + git::get_git_version, + git::GitProviderStorage, + npm::get_npm_version, + source::{ + Source, SourceChangeRequest, SourceKind, SourceQuery, SourceQueryStorage, SourceRepo, + }, + CodeQualityProviderStorage, DependenciesProviderStorage, FuzzProviderStorage, + GitHubProviderStorage, ModuleProvider, ModuleProviderStorage, + PullRequestReviewProviderStorage, + }, error::{Error, Result}, filesystem::create_dir_all, hc_error, pathbuf, @@ -29,16 +40,6 @@ use hc_common::{ version::{get_version, VersionQuery, VersionQueryStorage}, HIPCHECK_TOML_FILE, }; -use hc_data::{ - git::get_git_version, - git::GitProviderStorage, - npm::get_npm_version, - source::{ - Source, SourceChangeRequest, SourceKind, SourceQuery, SourceQueryStorage, SourceRepo, - }, - CodeQualityProviderStorage, DependenciesProviderStorage, FuzzProviderStorage, - GitHubProviderStorage, ModuleProvider, ModuleProviderStorage, PullRequestReviewProviderStorage, -}; use std::ffi::{OsStr, OsString}; use std::fmt; use std::path::{Path, PathBuf}; diff --git a/libs/hc_common/Cargo.toml b/libs/hc_common/Cargo.toml index 2a27a47a..0776c2b3 100644 --- a/libs/hc_common/Cargo.toml +++ b/libs/hc_common/Cargo.toml @@ -29,6 +29,14 @@ which = { version = "6.0.1", default-features = false } libc = "0.2.154" termcolor = "1.1.3" duct = "0.13.5" +dirs = "5.0.1" +graphql_client = "0.14.0" +nom = "7.1.3" +petgraph = { version = "0.6.0", features = ["serde-1"] } +ureq = { version = "2.9.7", default-features = false, features = [ + "json", + "native-tls", +] } [target.'cfg(windows)'.dependencies.winapi] version = "0.3" @@ -37,3 +45,7 @@ features = ["handleapi", "processenv", "winbase", "wincon", "winnt"] [build-dependencies] anyhow = "1.0.83" which = { version = "6.0.1", default-features = false } + +[dev-dependencies] +dirs = "5.0.1" +tempfile = "3.2.0" diff --git a/libs/hc_data/src/lib.rs b/libs/hc_common/src/data.rs similarity index 98% rename from libs/hc_data/src/lib.rs rename to libs/hc_common/src/data.rs index 0b1cfb1c..0d4f9432 100644 --- a/libs/hc_data/src/lib.rs +++ b/libs/hc_common/src/data.rs @@ -16,9 +16,9 @@ pub mod source; pub use query::*; use std::collections::HashSet; +use crate::{context::Context, error::Error, error::Result, hc_error, log, pathbuf}; use git::{get_commits_for_file, Commit, CommitContributor, Contributor, Diff}; use github::*; -use hc_common::{context::Context, error::Error, error::Result, hc_error, log, pathbuf}; use modules::RawModule; use petgraph::visit::Dfs; use petgraph::Graph; diff --git a/libs/hc_data/src/code_quality.rs b/libs/hc_common/src/data/code_quality.rs similarity index 93% rename from libs/hc_data/src/code_quality.rs rename to libs/hc_common/src/data/code_quality.rs index bb2ff80b..da472e6e 100644 --- a/libs/hc_data/src/code_quality.rs +++ b/libs/hc_common/src/data/code_quality.rs @@ -2,9 +2,9 @@ use std::path::{Path, PathBuf}; -use crate::es_lint::data::{ESLintMessage, ESLintReports}; -use crate::es_lint::get_eslint_reports; -use hc_common::{error::Result, hc_error}; +use crate::data::es_lint::data::{ESLintMessage, ESLintReports}; +use crate::data::es_lint::get_eslint_reports; +use crate::{error::Result, hc_error}; pub type CodeQualityReport = Vec; diff --git a/libs/hc_data/src/es_lint/command.rs b/libs/hc_common/src/data/es_lint/command.rs similarity index 97% rename from libs/hc_data/src/es_lint/command.rs rename to libs/hc_common/src/data/es_lint/command.rs index fe2d1d96..576e424d 100644 --- a/libs/hc_data/src/es_lint/command.rs +++ b/libs/hc_common/src/data/es_lint/command.rs @@ -3,9 +3,9 @@ use std::ffi::OsStr; use std::process::Command; -use hc_common::context::Context as _; -use hc_common::{ +use crate::{ command_util::{log_args, DependentProgram}, + context::Context as _, error::Result, hc_error, log, which, }; diff --git a/libs/hc_data/src/es_lint/data.rs b/libs/hc_common/src/data/es_lint/data.rs similarity index 99% rename from libs/hc_data/src/es_lint/data.rs rename to libs/hc_common/src/data/es_lint/data.rs index 53d205e2..5e03b9e4 100644 --- a/libs/hc_data/src/es_lint/data.rs +++ b/libs/hc_common/src/data/es_lint/data.rs @@ -43,7 +43,7 @@ pub struct ESLintMessage { #[cfg(test)] mod test { use super::*; - use hc_common::serde_json; + use crate::serde_json; #[test] fn parse_message() { diff --git a/libs/hc_data/src/es_lint/mod.rs b/libs/hc_common/src/data/es_lint/mod.rs similarity index 95% rename from libs/hc_data/src/es_lint/mod.rs rename to libs/hc_common/src/data/es_lint/mod.rs index e478d42a..8c9e54f7 100644 --- a/libs/hc_data/src/es_lint/mod.rs +++ b/libs/hc_common/src/data/es_lint/mod.rs @@ -3,10 +3,9 @@ use std::ffi::OsStr; use std::path::Path; +use crate::{context::Context as _, error::Result, semver::Version, serde_json}; use command::ESLintCommand; use data::ESLintReports; -use hc_common::context::Context as _; -use hc_common::{error::Result, semver::Version, serde_json}; pub mod command; pub mod data; @@ -47,7 +46,7 @@ pub fn get_eslint_reports(path: &Path, version: String) -> Result mod test { use super::*; - use hc_common::command_util::DependentProgram; + use crate::command_util::DependentProgram; use std::fs::File; use std::io::Write; diff --git a/libs/hc_data/src/git/data.rs b/libs/hc_common/src/data/git/data.rs similarity index 98% rename from libs/hc_data/src/git/data.rs rename to libs/hc_common/src/data/git/data.rs index 701b9696..2eb8c475 100644 --- a/libs/hc_data/src/git/data.rs +++ b/libs/hc_common/src/data/git/data.rs @@ -1,6 +1,6 @@ // SPDX-License-Identifier: Apache-2.0 -use hc_common::chrono::{DateTime, FixedOffset}; +use crate::chrono::{DateTime, FixedOffset}; use serde::{self, Deserialize, Serialize}; use std::fmt::{self, Display, Formatter}; use std::rc::Rc; diff --git a/libs/hc_data/src/git/mod.rs b/libs/hc_common/src/data/git/mod.rs similarity index 95% rename from libs/hc_data/src/git/mod.rs rename to libs/hc_common/src/data/git/mod.rs index b7fef0bb..ede0afea 100644 --- a/libs/hc_data/src/git/mod.rs +++ b/libs/hc_common/src/data/git/mod.rs @@ -8,9 +8,9 @@ pub use data::*; use parse::*; pub use query::*; -pub use crate::git_command::*; -use hc_common::context::Context as _; -use hc_common::{ +pub use crate::data::git_command::*; +use crate::{ + context::Context as _, error::{Error, Result}, log, }; @@ -106,7 +106,7 @@ pub fn get_commits_for_file(repo_path: &Path, file: &str) -> Result { #[cfg(test)] mod test { use super::*; - use hc_common::command_util::DependentProgram; + use crate::command_util::DependentProgram; #[test] #[ignore = "can't guarantee availability of Git"] diff --git a/libs/hc_data/src/git/parse.rs b/libs/hc_common/src/data/git/parse.rs similarity index 99% rename from libs/hc_data/src/git/parse.rs rename to libs/hc_common/src/data/git/parse.rs index 9c6aac32..3fa8d369 100644 --- a/libs/hc_data/src/git/parse.rs +++ b/libs/hc_common/src/data/git/parse.rs @@ -2,10 +2,10 @@ #![allow(dead_code)] -use crate::git::{Contributor, Diff, FileDiff, RawCommit}; -use hc_common::context::Context as _; -use hc_common::{ +use crate::data::git::{Contributor, Diff, FileDiff, RawCommit}; +use crate::{ chrono::{DateTime, FixedOffset}, + context::Context as _, error::{Error, Result}, log, }; @@ -1001,7 +1001,7 @@ index 20b42ecfdf..b0f30e8e35 100644 +++ b/README.md @@ -432,24 +432,31 @@ Other Style Guides }); - + // bad - inbox.filter((msg) => { - const { subject, author } = msg; @@ -1014,28 +1014,28 @@ index 20b42ecfdf..b0f30e8e35 100644 + var indexMap = myArray.reduce(function(memo, item, index) { + memo[item] = index; + }, {}); - + - // good - inbox.filter((msg) => { - const { subject, author } = msg; - if (subject === 'Mockingbird') { - return author === 'Harper Lee'; - } - + - return false; + // good + var indexMap = myArray.reduce(function(memo, item, index) { + memo[item] = index; + return memo; + }, {}); -+ -+ ++ ++ + // bad + const alpha = people.sort((lastOne, nextOne) => { + const [aLast, aFirst] = lastOne.split(', '); + const [bLast, bFirst] = nextOne.split(', '); }); -+ ++ + // good + const alpha = people.sort((lastOne, nextOne) => { + const [aLast, aFirst] = lastOne.split(', '); @@ -1044,7 +1044,7 @@ index 20b42ecfdf..b0f30e8e35 100644 + }); + ``` - + "#; @@ -1071,13 +1071,13 @@ index 20b42ecfdf..b0f30e8e35 100644 memo[item] = index; return memo; }, {}); - - + + // bad const alpha = people.sort((lastOne, nextOne) => { const [aLast, aFirst] = lastOne.split(', '); const [bLast, bFirst] = nextOne.split(', '); - + // good const alpha = people.sort((lastOne, nextOne) => { const [aLast, aFirst] = lastOne.split(', '); @@ -1105,7 +1105,7 @@ index 20b42ecfdf..b0f30e8e35 100644 +++ b/README.md @@ -432,24 +432,31 @@ Other Style Guides }); - + // bad - inbox.filter((msg) => { - const { subject, author } = msg; @@ -1118,28 +1118,28 @@ index 20b42ecfdf..b0f30e8e35 100644 + var indexMap = myArray.reduce(function(memo, item, index) { + memo[item] = index; + }, {}); - + - // good - inbox.filter((msg) => { - const { subject, author } = msg; - if (subject === 'Mockingbird') { - return author === 'Harper Lee'; - } - + - return false; + // good + var indexMap = myArray.reduce(function(memo, item, index) { + memo[item] = index; + return memo; + }, {}); -+ -+ ++ ++ + // bad + const alpha = people.sort((lastOne, nextOne) => { + const [aLast, aFirst] = lastOne.split(', '); + const [bLast, bFirst] = nextOne.split(', '); }); -+ ++ + // good + const alpha = people.sort((lastOne, nextOne) => { + const [aLast, aFirst] = lastOne.split(', '); @@ -1148,7 +1148,7 @@ index 20b42ecfdf..b0f30e8e35 100644 + }); + ``` - + "#; @@ -1175,13 +1175,13 @@ index 20b42ecfdf..b0f30e8e35 100644 memo[item] = index; return memo; }, {}); - - + + // bad const alpha = people.sort((lastOne, nextOne) => { const [aLast, aFirst] = lastOne.split(', '); const [bLast, bFirst] = nextOne.split(', '); - + // good const alpha = people.sort((lastOne, nextOne) => { const [aLast, aFirst] = lastOne.split(', '); diff --git a/libs/hc_data/src/git/query/impls.rs b/libs/hc_common/src/data/git/query/impls.rs similarity index 99% rename from libs/hc_data/src/git/query/impls.rs rename to libs/hc_common/src/data/git/query/impls.rs index 0293a7ed..6aedfd6b 100644 --- a/libs/hc_data/src/git/query/impls.rs +++ b/libs/hc_common/src/data/git/query/impls.rs @@ -3,12 +3,12 @@ //! Derived query implementations for the `GitProvider` query group. use super::GitProvider; -use crate::git::{ +use crate::data::git::{ get_commits, get_commits_from_date, get_diffs, Commit, CommitContributor, CommitContributorView, CommitDiff, CommitSigner, CommitSignerView, Contributor, ContributorView, Diff, GitCommand, RawCommit, SignerKeyView, SignerNameView, SignerView, }; -use hc_common::{ +use crate::{ chrono::prelude::*, context::Context, error::{Error, Result}, diff --git a/libs/hc_data/src/git/query/mod.rs b/libs/hc_common/src/data/git/query/mod.rs similarity index 97% rename from libs/hc_data/src/git/query/mod.rs rename to libs/hc_common/src/data/git/query/mod.rs index 0e461561..70d59ea9 100644 --- a/libs/hc_data/src/git/query/mod.rs +++ b/libs/hc_common/src/data/git/query/mod.rs @@ -4,7 +4,7 @@ mod impls; -use crate::{ +use crate::data::{ git::{ Commit, CommitContributor, CommitContributorView, CommitDiff, CommitSigner, CommitSignerView, Contributor, ContributorView, Diff, RawCommit, SignerKeyView, @@ -12,7 +12,7 @@ use crate::{ }, source::SourceQuery, }; -use hc_common::{chrono::prelude::*, error::Result, salsa, version::VersionQuery}; +use crate::{chrono::prelude::*, error::Result, salsa, version::VersionQuery}; use std::rc::Rc; /// Queries about Git objects diff --git a/libs/hc_data/src/git_command.rs b/libs/hc_common/src/data/git_command.rs similarity index 94% rename from libs/hc_data/src/git_command.rs rename to libs/hc_common/src/data/git_command.rs index 6c04835b..52b59d7a 100644 --- a/libs/hc_data/src/git_command.rs +++ b/libs/hc_common/src/data/git_command.rs @@ -1,7 +1,6 @@ // SPDX-License-Identifier: Apache-2.0 -use hc_common::context::Context as _; -use hc_common::{command_util::log_git_args, error::Result, hc_error, which}; +use crate::{command_util::log_git_args, context::Context as _, error::Result, hc_error, which}; use std::convert::AsRef; use std::ffi::OsStr; use std::iter::IntoIterator; diff --git a/libs/hc_data/src/github/authenticated_agent.rs b/libs/hc_common/src/data/github/authenticated_agent.rs similarity index 97% rename from libs/hc_data/src/github/authenticated_agent.rs rename to libs/hc_common/src/data/github/authenticated_agent.rs index 49804686..b3bd1af5 100644 --- a/libs/hc_data/src/github/authenticated_agent.rs +++ b/libs/hc_common/src/data/github/authenticated_agent.rs @@ -1,6 +1,6 @@ //! Defines an authenticated [`Agent`] type that adds token auth to all requests. -use crate::github::hidden::Hidden; +use crate::data::github::hidden::Hidden; use ureq::{Agent, Request}; /// An [`Agent`] which authenticates requests with token auth. diff --git a/libs/hc_data/src/github/code_search.rs b/libs/hc_common/src/data/github/code_search.rs similarity index 95% rename from libs/hc_data/src/github/code_search.rs rename to libs/hc_common/src/data/github/code_search.rs index d2c80951..b8ecbf85 100644 --- a/libs/hc_data/src/github/code_search.rs +++ b/libs/hc_common/src/data/github/code_search.rs @@ -1,7 +1,7 @@ // SPDX-License-Identifier: Apache-2.0 -use crate::github::authenticated_agent::AuthenticatedAgent; -use hc_common::{ +use crate::data::github::authenticated_agent::AuthenticatedAgent; +use crate::{ error::{Error, Result}, hc_error, serde_json::Value, diff --git a/libs/hc_data/src/github/data.rs b/libs/hc_common/src/data/github/data.rs similarity index 91% rename from libs/hc_data/src/github/data.rs rename to libs/hc_common/src/data/github/data.rs index 7fb69508..493e06bf 100644 --- a/libs/hc_data/src/github/data.rs +++ b/libs/hc_common/src/data/github/data.rs @@ -1,6 +1,6 @@ // SPDX-License-Identifier: Apache-2.0 -use crate::git::{Diff, RawCommit}; +use crate::data::git::{Diff, RawCommit}; use serde::Deserialize; #[derive(Debug, Deserialize)] diff --git a/libs/hc_data/src/github/gh_query.graphql b/libs/hc_common/src/data/github/gh_query.graphql similarity index 100% rename from libs/hc_data/src/github/gh_query.graphql rename to libs/hc_common/src/data/github/gh_query.graphql diff --git a/libs/hc_data/src/github/gh_schema.graphql b/libs/hc_common/src/data/github/gh_schema.graphql similarity index 100% rename from libs/hc_data/src/github/gh_schema.graphql rename to libs/hc_common/src/data/github/gh_schema.graphql diff --git a/libs/hc_data/src/github/graphql.rs b/libs/hc_common/src/data/github/graphql.rs similarity index 95% rename from libs/hc_data/src/github/graphql.rs rename to libs/hc_common/src/data/github/graphql.rs index 790b968a..1d65ad5e 100644 --- a/libs/hc_data/src/github/graphql.rs +++ b/libs/hc_common/src/data/github/graphql.rs @@ -3,13 +3,13 @@ use std::convert::TryInto; use self::reviews::{ResponseData, ReviewsRepositoryPullRequestsNodes as RawPull, Variables}; -use crate::github::{authenticated_agent::AuthenticatedAgent, data::*}; -use graphql_client::{GraphQLQuery, QueryBody, Response}; -use hc_common::{ +use crate::data::github::{authenticated_agent::AuthenticatedAgent, data::*}; +use crate::{ error::{Error, Result}, hc_error, serde_json::{from_value as from_json_value, to_value as to_json_value}, }; +use graphql_client::{GraphQLQuery, QueryBody, Response}; /// The URL of the GitHub GraphQL API. const GH_API_V4: &str = "https://api.github.com/graphql"; @@ -17,8 +17,8 @@ const GH_API_V4: &str = "https://api.github.com/graphql"; /// Defines the query being made against the GitHub API. #[derive(GraphQLQuery)] #[graphql( - schema_path = "src/github/gh_schema.graphql", - query_path = "src/github/gh_query.graphql", + schema_path = "src/data/github/gh_schema.graphql", + query_path = "src/data/github/gh_query.graphql", response_derives = "Debug" )] pub struct Reviews; diff --git a/libs/hc_data/src/github/graphql_pr.rs b/libs/hc_common/src/data/github/graphql_pr.rs similarity index 98% rename from libs/hc_data/src/github/graphql_pr.rs rename to libs/hc_common/src/data/github/graphql_pr.rs index 251f21bd..ac77bb9e 100644 --- a/libs/hc_data/src/github/graphql_pr.rs +++ b/libs/hc_common/src/data/github/graphql_pr.rs @@ -4,18 +4,18 @@ use self::review::{ ResponseData, ReviewRepositoryPullRequest as RawPull, ReviewRepositoryPullRequestCommitsNodes as RawPullCommit, Variables, }; -use crate::{ +use crate::data::{ git::{Contributor, RawCommit}, github::{authenticated_agent::AuthenticatedAgent, data::*}, }; -use graphql_client::{GraphQLQuery, QueryBody, Response}; -use hc_common::{ +use crate::{ chrono::DateTime, context::Context, error::{Error, Result}, hc_error, serde_json::{from_value as from_json_value, to_value as to_json_value}, }; +use graphql_client::{GraphQLQuery, QueryBody, Response}; use std::convert::TryFrom; /// The URL of the GitHub GraphQL API. @@ -24,8 +24,8 @@ const GH_API_V4: &str = "https://api.github.com/graphql"; /// Defines the query being made against the GitHub API. #[derive(GraphQLQuery)] #[graphql( - schema_path = "src/github/gh_schema.graphql", - query_path = "src/github/gh_query.graphql", + schema_path = "src/data/github/gh_schema.graphql", + query_path = "src/data/github/gh_query.graphql", response_derives = "Debug" )] pub struct Review; diff --git a/libs/hc_data/src/github/hidden.rs b/libs/hc_common/src/data/github/hidden.rs similarity index 100% rename from libs/hc_data/src/github/hidden.rs rename to libs/hc_common/src/data/github/hidden.rs diff --git a/libs/hc_data/src/github/mod.rs b/libs/hc_common/src/data/github/mod.rs similarity index 84% rename from libs/hc_data/src/github/mod.rs rename to libs/hc_common/src/data/github/mod.rs index afd113fd..775a2b92 100644 --- a/libs/hc_data/src/github/mod.rs +++ b/libs/hc_common/src/data/github/mod.rs @@ -7,14 +7,14 @@ mod graphql; mod graphql_pr; mod hidden; -use crate::code_search::search_code_request; -use crate::git::parse::github_diff; -use crate::github::authenticated_agent::AuthenticatedAgent; -use crate::github::data::*; -use crate::github::graphql::get_all_reviews; -use crate::github::graphql_pr::get_all_pr_reviews; -use hc_common::context::Context as _; -use hc_common::{error::Result, log}; +use crate::context::Context as _; +use crate::data::code_search::search_code_request; +use crate::data::git::parse::github_diff; +use crate::data::github::authenticated_agent::AuthenticatedAgent; +use crate::data::github::data::*; +use crate::data::github::graphql::get_all_reviews; +use crate::data::github::graphql_pr::get_all_pr_reviews; +use crate::{error::Result, log}; use std::rc::Rc; pub struct GitHub<'a> { diff --git a/libs/hc_data/src/hash.rs b/libs/hc_common/src/data/hash.rs similarity index 100% rename from libs/hc_data/src/hash.rs rename to libs/hc_common/src/data/hash.rs diff --git a/libs/hc_data/src/modules.rs b/libs/hc_common/src/data/modules.rs similarity index 98% rename from libs/hc_data/src/modules.rs rename to libs/hc_common/src/data/modules.rs index c1c55f18..c66fd3c0 100644 --- a/libs/hc_data/src/modules.rs +++ b/libs/hc_common/src/data/modules.rs @@ -1,8 +1,8 @@ // SPDX-License-Identifier: Apache-2.0 -use hc_common::context::Context as _; -use hc_common::{ +use crate::{ command_util::{log_args, DependentProgram}, + context::Context as _, error::{Error, Result}, hc_error, pathbuf, serde_json, }; diff --git a/libs/hc_data/src/npm.rs b/libs/hc_common/src/data/npm.rs similarity index 99% rename from libs/hc_data/src/npm.rs rename to libs/hc_common/src/data/npm.rs index 09594e31..0514bd37 100644 --- a/libs/hc_data/src/npm.rs +++ b/libs/hc_common/src/data/npm.rs @@ -1,6 +1,6 @@ // SPDX-License-Identifier: Apache-2.0 -use hc_common::{ +use crate::{ command_util::{log_args, DependentProgram}, context::Context, error::Result, @@ -254,7 +254,7 @@ impl NpmCommand { #[cfg(test)] mod test { use super::*; - use hc_common::command_util::DependentProgram; + use crate::command_util::DependentProgram; #[test] #[ignore = "can't guarantee availability of NPM"] diff --git a/libs/hc_data/src/query/code_quality.rs b/libs/hc_common/src/data/query/code_quality.rs similarity index 79% rename from libs/hc_data/src/query/code_quality.rs rename to libs/hc_common/src/data/query/code_quality.rs index 41c9b674..ee311d52 100644 --- a/libs/hc_data/src/query/code_quality.rs +++ b/libs/hc_common/src/data/query/code_quality.rs @@ -4,9 +4,9 @@ use std::rc::Rc; -use crate::code_quality::{get_eslint_report, CodeQualityReport}; -use crate::source::SourceQuery; -use hc_common::{error::Result, salsa, version::VersionQuery}; +use crate::data::code_quality::{get_eslint_report, CodeQualityReport}; +use crate::data::source::SourceQuery; +use crate::{error::Result, salsa, version::VersionQuery}; /// Queries about code quality #[salsa::query_group(CodeQualityProviderStorage)] diff --git a/libs/hc_data/src/query/dependencies.rs b/libs/hc_common/src/data/query/dependencies.rs similarity index 86% rename from libs/hc_data/src/query/dependencies.rs rename to libs/hc_common/src/data/query/dependencies.rs index a8e819cc..e4155db4 100644 --- a/libs/hc_data/src/query/dependencies.rs +++ b/libs/hc_common/src/data/query/dependencies.rs @@ -2,10 +2,10 @@ //! Query group for dependencies information. -use crate::npm::{get_package_file, PackageFile}; -use crate::source::SourceQuery; -use crate::Dependencies; -use hc_common::{error::Result, salsa, version::VersionQuery}; +use crate::data::npm::{get_package_file, PackageFile}; +use crate::data::source::SourceQuery; +use crate::data::Dependencies; +use crate::{error::Result, salsa, version::VersionQuery}; use std::rc::Rc; /// Queries about dependencies diff --git a/libs/hc_data/src/query/fuzz.rs b/libs/hc_common/src/data/query/fuzz.rs similarity index 94% rename from libs/hc_data/src/query/fuzz.rs rename to libs/hc_common/src/data/query/fuzz.rs index ef9c6223..e8907d57 100644 --- a/libs/hc_data/src/query/fuzz.rs +++ b/libs/hc_common/src/data/query/fuzz.rs @@ -3,8 +3,8 @@ //! Query group for fuzzing checks. use super::github::GitHubProvider; -use crate::{get_fuzz_check, Fuzz}; -use hc_common::{ +use crate::data::{get_fuzz_check, Fuzz}; +use crate::{ config::ConfigSource, error::{Error, Result}, log, salsa, diff --git a/libs/hc_data/src/query/github.rs b/libs/hc_common/src/data/query/github.rs similarity index 97% rename from libs/hc_data/src/query/github.rs rename to libs/hc_common/src/data/query/github.rs index 65e8f836..ab777468 100644 --- a/libs/hc_data/src/query/github.rs +++ b/libs/hc_common/src/data/query/github.rs @@ -2,8 +2,8 @@ //! Query group for data pertaining to a remote GitHub source. -use crate::source::{Remote, SourceQuery}; -use hc_common::{ +use crate::data::source::{Remote, SourceQuery}; +use crate::{ error::{Error, Result}, salsa, }; diff --git a/libs/hc_data/src/query/mod.rs b/libs/hc_common/src/data/query/mod.rs similarity index 100% rename from libs/hc_data/src/query/mod.rs rename to libs/hc_common/src/data/query/mod.rs diff --git a/libs/hc_data/src/query/module.rs b/libs/hc_common/src/data/query/module.rs similarity index 99% rename from libs/hc_data/src/query/module.rs rename to libs/hc_common/src/data/query/module.rs index ddf941dd..9309dfdc 100644 --- a/libs/hc_data/src/query/module.rs +++ b/libs/hc_common/src/data/query/module.rs @@ -4,13 +4,13 @@ use std::{path::PathBuf, rc::Rc}; -use crate::{ +use crate::data::{ associate_modules_and_commits, git::{Commit, GitProvider}, Module, ModuleGraph, }; -use hc_common::{ +use crate::{ error::{Error, Result}, pathbuf, salsa, }; diff --git a/libs/hc_data/src/query/pr_review.rs b/libs/hc_common/src/data/query/pr_review.rs similarity index 99% rename from libs/hc_data/src/query/pr_review.rs rename to libs/hc_common/src/data/query/pr_review.rs index 8d05e0b5..e9a8907d 100644 --- a/libs/hc_data/src/query/pr_review.rs +++ b/libs/hc_common/src/data/query/pr_review.rs @@ -3,12 +3,12 @@ //! Query group for GitHub pull request reviews. use super::github::GitHubProvider; -use crate::{ +use crate::data::{ get_pull_request_reviews_from_github, get_single_pull_request_review_from_github, git::{Commit, CommitContributorView, CommitDiff, Contributor, ContributorView}, PullRequest, SinglePullRequest, }; -use hc_common::{ +use crate::{ config::ConfigSource, context::Context, error::{Error, Result}, diff --git a/libs/hc_data/src/source/mod.rs b/libs/hc_common/src/data/source/mod.rs similarity index 99% rename from libs/hc_data/src/source/mod.rs rename to libs/hc_common/src/data/source/mod.rs index a4d34b09..c0e03f29 100644 --- a/libs/hc_data/src/source/mod.rs +++ b/libs/hc_common/src/data/source/mod.rs @@ -4,12 +4,13 @@ mod query; pub use query::*; -use crate::git_command::GitCommand; -use hc_common::log::{self, debug}; -use hc_common::{ +use crate::data::git_command::GitCommand; +use crate::{ context::Context, error::{Error, Result}, - hc_error, pathbuf, + hc_error, + log::{self, debug}, + pathbuf, shell::Phase, url::Url, }; diff --git a/libs/hc_data/src/source/query.rs b/libs/hc_common/src/data/source/query.rs similarity index 95% rename from libs/hc_data/src/source/query.rs rename to libs/hc_common/src/data/source/query.rs index ab2dc86f..c489cc5b 100644 --- a/libs/hc_data/src/source/query.rs +++ b/libs/hc_common/src/data/source/query.rs @@ -2,11 +2,9 @@ //! A query group for accessing Git repository data. -use crate::{ - hash, - source::{Remote, Source}, -}; -use hc_common::{pathbuf, salsa}; +use crate::data::source::{Remote, Source}; +use crate::hash; +use crate::{pathbuf, salsa}; use std::path::PathBuf; use std::rc::Rc; @@ -69,7 +67,7 @@ fn url(db: &dyn SourceQuery) -> Option> { // Computes the appropriate path based on the remote or local info fn storage_path(db: &dyn SourceQuery) -> Rc { - use crate::source::Remote::*; + use crate::data::source::Remote::*; let path_buf = match db.remote() { Some(remote) => match remote.as_ref() { diff --git a/libs/hc_common/src/lib.rs b/libs/hc_common/src/lib.rs index 154af87b..7ce4ed30 100644 --- a/libs/hc_common/src/lib.rs +++ b/libs/hc_common/src/lib.rs @@ -6,6 +6,7 @@ pub mod command_util; pub mod config; pub mod context; +pub mod data; pub mod error; pub mod filesystem; pub mod pathbuf; diff --git a/libs/hc_data/Cargo.toml b/libs/hc_data/Cargo.toml deleted file mode 100644 index 156b3c27..00000000 --- a/libs/hc_data/Cargo.toml +++ /dev/null @@ -1,22 +0,0 @@ -[package] -name = "hc_data" -version = "0.1.0" -edition = "2021" -license = "Apache-2.0" -publish = false - -[dependencies] -dirs = "5.0.1" -graphql_client = "0.14.0" -hc_common = { path = "../hc_common" } -nom = "7.1.3" -petgraph = { version = "0.6.0", features = ["serde-1"] } -serde = { version = "1.0.200", features = ["derive", "rc"] } -ureq = { version = "2.9.7", default-features = false, features = [ - "json", - "native-tls", -] } - -[dev-dependencies] -dirs = "5.0.1" -tempfile = "3.2.0" From dbef961f3b17a118f29133c0ef87196bc578ac7b Mon Sep 17 00:00:00 2001 From: Andrew Lilley Brinker Date: Mon, 6 May 2024 15:00:25 -0700 Subject: [PATCH 07/14] chore: Merge `hc_core` and `hc_analysis` into `hc_common`. This commit merges `hc_core` and `hc_analysis` into `hc_common`. Signed-off-by: Andrew Lilley Brinker --- Cargo.lock | 167 +------------- hipcheck/Cargo.toml | 7 +- hipcheck/src/main.rs | 13 +- libs/hc_analysis/Cargo.toml | 28 --- libs/hc_common/Cargo.toml | 26 ++- .../src/lib.rs => hc_common/src/analysis.rs} | 0 .../src/analysis}/analysis.rs | 4 +- .../src/analysis}/metric/activity.rs | 6 +- .../src/analysis}/metric/affiliation.rs | 4 +- .../src/analysis}/metric/binary.rs | 8 +- .../analysis}/metric/binary_detector/mod.rs | 8 +- .../analysis}/metric/binary_detector/query.rs | 4 +- .../src/analysis}/metric/churn.rs | 19 +- .../src/analysis}/metric/commit_trust.rs | 5 +- .../src/analysis}/metric/contributor_trust.rs | 6 +- .../src/analysis}/metric/entropy.rs | 16 +- .../src/analysis}/metric/fuzz.rs | 6 +- .../src/analysis}/metric/identity.rs | 6 +- .../src/analysis}/metric/linguist/mod.rs | 4 +- .../src/analysis}/metric/linguist/query.rs | 4 +- .../src/analysis}/metric/math.rs | 0 .../src/analysis}/metric/mod.rs | 18 +- .../src/analysis}/metric/module.rs | 6 +- .../analysis}/metric/module_contributors.rs | 6 +- .../src/analysis}/metric/review.rs | 6 +- .../src/analysis}/metric/typo.rs | 10 +- .../src/analysis}/report_builder.rs | 30 +-- .../src => hc_common/src/analysis}/score.rs | 4 +- .../src/analysis}/session/mod.rs | 10 +- .../src/analysis}/session/pm.rs | 6 +- .../src/analysis}/session/spdx.rs | 4 +- libs/hc_common/src/lib.rs | 204 +++++++++++++++++ libs/hc_core/Cargo.toml | 25 --- libs/hc_core/src/lib.rs | 208 ------------------ 34 files changed, 351 insertions(+), 527 deletions(-) delete mode 100644 libs/hc_analysis/Cargo.toml rename libs/{hc_analysis/src/lib.rs => hc_common/src/analysis.rs} (100%) rename libs/{hc_analysis/src => hc_common/src/analysis}/analysis.rs (99%) rename libs/{hc_analysis/src => hc_common/src/analysis}/metric/activity.rs (95%) rename libs/{hc_analysis/src => hc_common/src/analysis}/metric/affiliation.rs (99%) rename libs/{hc_analysis/src => hc_common/src/analysis}/metric/binary.rs (82%) rename libs/{hc_analysis/src => hc_common/src/analysis}/metric/binary_detector/mod.rs (94%) rename libs/{hc_analysis/src => hc_common/src/analysis}/metric/binary_detector/query.rs (87%) rename libs/{hc_analysis/src => hc_common/src/analysis}/metric/churn.rs (88%) rename libs/{hc_analysis/src => hc_common/src/analysis}/metric/commit_trust.rs (94%) rename libs/{hc_analysis/src => hc_common/src/analysis}/metric/contributor_trust.rs (98%) rename libs/{hc_analysis/src => hc_common/src/analysis}/metric/entropy.rs (95%) rename libs/{hc_analysis/src => hc_common/src/analysis}/metric/fuzz.rs (81%) rename libs/{hc_analysis/src => hc_common/src/analysis}/metric/identity.rs (88%) rename libs/{hc_analysis/src => hc_common/src/analysis}/metric/linguist/mod.rs (97%) rename libs/{hc_analysis/src => hc_common/src/analysis}/metric/linguist/query.rs (87%) rename libs/{hc_analysis/src => hc_common/src/analysis}/metric/math.rs (100%) rename libs/{hc_analysis/src => hc_common/src/analysis}/metric/mod.rs (99%) rename libs/{hc_analysis/src => hc_common/src/analysis}/metric/module.rs (84%) rename libs/{hc_analysis/src => hc_common/src/analysis}/metric/module_contributors.rs (97%) rename libs/{hc_analysis/src => hc_common/src/analysis}/metric/review.rs (89%) rename libs/{hc_analysis/src => hc_common/src/analysis}/metric/typo.rs (99%) rename libs/{hc_analysis/src => hc_common/src/analysis}/report_builder.rs (95%) rename libs/{hc_analysis/src => hc_common/src/analysis}/score.rs (99%) rename libs/{hc_analysis/src => hc_common/src/analysis}/session/mod.rs (99%) rename libs/{hc_analysis/src => hc_common/src/analysis}/session/pm.rs (99%) rename libs/{hc_analysis/src => hc_common/src/analysis}/session/spdx.rs (96%) delete mode 100644 libs/hc_core/Cargo.toml delete mode 100644 libs/hc_core/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index b6ccef61..605df1ef 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,12 +2,6 @@ # It is not intended for manual editing. version = 3 -[[package]] -name = "adler" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" - [[package]] name = "aho-corasick" version = "1.1.3" @@ -263,15 +257,6 @@ version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" -[[package]] -name = "crc32fast" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3855a8a784b474f333699ef2bbca9db2c4a1f6d9088a90a2d25b1eb53111eaa" -dependencies = [ - "cfg-if", -] - [[package]] name = "criterion" version = "0.5.1" @@ -471,16 +456,6 @@ version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80" -[[package]] -name = "flate2" -version = "1.0.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46303f565772937ffe1d394a4fac6f411c6013172fadde9dcdb1e147a086940e" -dependencies = [ - "crc32fast", - "miniz_oxide", -] - [[package]] name = "foreign-types" version = "0.3.2" @@ -602,42 +577,24 @@ version = "0.14.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" -[[package]] -name = "hc_analysis" -version = "0.1.0" -dependencies = [ - "content_inspector", - "curl", - "dirs", - "dotenv", - "glob", - "hc_common", - "maplit", - "petgraph", - "serde", - "serde_derive", - "spdx-rs", - "tempfile", - "toml", - "unicode-normalization", - "unicode-segmentation", - "ureq", - "walkdir", - "xml-rs", -] - [[package]] name = "hc_common" version = "0.1.0" dependencies = [ "anyhow", "chrono", + "content_inspector", + "criterion", + "curl", "dirs", + "dotenv", "duct", + "glob", "graphql_client", "lazy_static", "libc", "log", + "maplit", "nom", "once_cell", "ordered-float", @@ -648,26 +605,21 @@ dependencies = [ "schemars", "semver", "serde", + "serde_derive", "serde_json", "smart-default", + "spdx-rs", "tempfile", "termcolor", "toml", + "unicode-normalization", + "unicode-segmentation", "ureq", "url", + "walkdir", "which", "winapi", -] - -[[package]] -name = "hc_core" -version = "0.1.0" -dependencies = [ - "criterion", - "duct", - "hc_analysis", - "hc_common", - "tempfile", + "xml-rs", ] [[package]] @@ -697,9 +649,7 @@ version = "3.1.0" dependencies = [ "clap", "env_logger", - "hc_analysis", "hc_common", - "hc_core", ] [[package]] @@ -908,15 +858,6 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" -[[package]] -name = "miniz_oxide" -version = "0.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" -dependencies = [ - "adler", -] - [[package]] name = "native-tls" version = "0.2.11" @@ -1249,21 +1190,6 @@ version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "adad44e29e4c806119491a7f06f03de4d1af22c3a680dd47f1e6e179439d1f56" -[[package]] -name = "ring" -version = "0.17.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d" -dependencies = [ - "cc", - "cfg-if", - "getrandom", - "libc", - "spin", - "untrusted", - "windows-sys 0.52.0", -] - [[package]] name = "rustc-hash" version = "1.1.0" @@ -1283,37 +1209,6 @@ dependencies = [ "windows-sys 0.52.0", ] -[[package]] -name = "rustls" -version = "0.22.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf4ef73721ac7bcd79b2b315da7779d8fc09718c6b3d2d1b2d94850eb8c18432" -dependencies = [ - "log", - "ring", - "rustls-pki-types", - "rustls-webpki", - "subtle", - "zeroize", -] - -[[package]] -name = "rustls-pki-types" -version = "1.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ecd36cc4259e3e4514335c4a138c6b43171a8d61d8f5c9348f9fc7529416f247" - -[[package]] -name = "rustls-webpki" -version = "0.102.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "faaa0a62740bedb9b2ef5afa303da42764c012f743917351dc9a237ea1663610" -dependencies = [ - "ring", - "rustls-pki-types", - "untrusted", -] - [[package]] name = "rustversion" version = "1.0.15" @@ -1551,12 +1446,6 @@ dependencies = [ "uuid", ] -[[package]] -name = "spin" -version = "0.9.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" - [[package]] name = "strum" version = "0.24.1" @@ -1576,12 +1465,6 @@ dependencies = [ "syn 1.0.109", ] -[[package]] -name = "subtle" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" - [[package]] name = "syn" version = "1.0.109" @@ -1771,12 +1654,6 @@ dependencies = [ "void", ] -[[package]] -name = "untrusted" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" - [[package]] name = "ureq" version = "2.9.7" @@ -1784,17 +1661,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d11a831e3c0b56e438a28308e7c810799e3c118417f342d30ecec080105395cd" dependencies = [ "base64", - "flate2", "log", "native-tls", "once_cell", - "rustls", - "rustls-pki-types", - "rustls-webpki", "serde", "serde_json", "url", - "webpki-roots", ] [[package]] @@ -1915,15 +1787,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "webpki-roots" -version = "0.26.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3de34ae270483955a94f4b21bdaaeb83d508bb84a01435f393818edb0012009" -dependencies = [ - "rustls-pki-types", -] - [[package]] name = "which" version = "6.0.1" @@ -2149,9 +2012,3 @@ dependencies = [ "toml", "which", ] - -[[package]] -name = "zeroize" -version = "1.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "525b4ec142c6b68a2d10f01f7bbf6755599ca3f81ea53b8431b7dd348f5fdb2d" diff --git a/hipcheck/Cargo.toml b/hipcheck/Cargo.toml index aaff8826..de1963f2 100644 --- a/hipcheck/Cargo.toml +++ b/hipcheck/Cargo.toml @@ -13,10 +13,11 @@ path = "src/main.rs" [dependencies] # Internal dependencies. -hc_analysis = { path = "../libs/hc_analysis" } hc_common = { path = "../libs/hc_common" } -hc_core = { path = "../libs/hc_core" } # External dependencies. -clap = { version = "4.5.4", default-features = false, features = ["string", "std"]} +clap = { version = "4.5.4", default-features = false, features = [ + "string", + "std", +] } env_logger = { version = "0.11.3" } diff --git a/hipcheck/src/main.rs b/hipcheck/src/main.rs index 5999e85a..d85e17a8 100644 --- a/hipcheck/src/main.rs +++ b/hipcheck/src/main.rs @@ -2,13 +2,14 @@ use clap::{Arg, ArgAction, Command}; use env_logger::{Builder, Env}; -use hc_analysis::session::{Check, CheckType}; use hc_common::{ - context::Context, error::Result, hc_error, schemars::schema_for, serde_json, CheckKind, -}; -use hc_core::{ - print_error, resolve_config, resolve_data, resolve_home, run, version, AnyReport, ColorChoice, - Format, Outcome, Output, PrReport, Report, Verbosity, + analysis::session::{Check, CheckType}, + context::Context, + error::Result, + hc_error, print_error, resolve_config, resolve_data, resolve_home, run, + schemars::schema_for, + serde_json, version, AnyReport, CheckKind, ColorChoice, Format, Outcome, Output, PrReport, + Report, Verbosity, }; use std::ffi::OsString; use std::path::PathBuf; diff --git a/libs/hc_analysis/Cargo.toml b/libs/hc_analysis/Cargo.toml deleted file mode 100644 index ee695455..00000000 --- a/libs/hc_analysis/Cargo.toml +++ /dev/null @@ -1,28 +0,0 @@ -[package] -name = "hc_analysis" -version = "0.1.0" -edition = "2021" -license = "Apache-2.0" -publish = false - -[dependencies] -content_inspector = "0.2.4" -dirs = "5.0.1" -dotenv = "0.15.0" -curl = "0.4.38" -glob = "0.3.0" -hc_common = { path = "../hc_common" } -maplit = "1.0.2" -petgraph = { version = "0.6.0" } -serde = { version = "1.0.200", features = ["derive", "rc"] } -serde_derive = "1.0.137" -spdx-rs = "0.5.0" -toml = "0.8.12" -unicode-normalization = "0.1.19" -unicode-segmentation = "1.9.0" -ureq = { version = "2.9.7", features = ["json"] } -walkdir = "2" -xml-rs = "0.8" - -[dev_dependencies] -tempfile = "3.10.1" diff --git a/libs/hc_common/Cargo.toml b/libs/hc_common/Cargo.toml index 0776c2b3..d291b538 100644 --- a/libs/hc_common/Cargo.toml +++ b/libs/hc_common/Cargo.toml @@ -6,6 +6,18 @@ license = "Apache-2.0" publish = false [dependencies] + +content_inspector = "0.2.4" +dotenv = "0.15.0" +curl = "0.4.38" +glob = "0.3.0" +maplit = "1.0.2" +serde_derive = "1.0.137" +spdx-rs = "0.5.0" +unicode-normalization = "0.1.19" +unicode-segmentation = "1.9.0" +walkdir = "2" +xml-rs = "0.8" chrono = { version = "0.4.19", features = ["serde"] } lazy_static = "1.4.0" log = "0.4.16" @@ -48,4 +60,16 @@ which = { version = "6.0.1", default-features = false } [dev-dependencies] dirs = "5.0.1" -tempfile = "3.2.0" +tempfile = "3.10.1" +duct = "0.13.7" +criterion = "0.5.1" + + +[[bench]] +name = "basic" +harness = false +path = "../../benches/basic.rs" + +[[test]] +name = "can_run" +path = "../../tests/can_run.rs" diff --git a/libs/hc_analysis/src/lib.rs b/libs/hc_common/src/analysis.rs similarity index 100% rename from libs/hc_analysis/src/lib.rs rename to libs/hc_common/src/analysis.rs diff --git a/libs/hc_analysis/src/analysis.rs b/libs/hc_common/src/analysis/analysis.rs similarity index 99% rename from libs/hc_analysis/src/analysis.rs rename to libs/hc_common/src/analysis/analysis.rs index 3041e9b7..8d5ad863 100644 --- a/libs/hc_analysis/src/analysis.rs +++ b/libs/hc_common/src/analysis/analysis.rs @@ -1,7 +1,7 @@ // SPDX-License-Identifier: Apache-2.0 -use crate::metric::{affiliation::AffiliatedType, MetricProvider}; -use hc_common::{ +use crate::analysis::metric::{affiliation::AffiliatedType, MetricProvider}; +use crate::{ chrono::Duration, config::{AttacksConfigQuery, CommitConfigQuery, FuzzConfigQuery, PracticesConfigQuery}, data::git::GitProvider, diff --git a/libs/hc_analysis/src/metric/activity.rs b/libs/hc_common/src/analysis/metric/activity.rs similarity index 95% rename from libs/hc_analysis/src/metric/activity.rs rename to libs/hc_common/src/analysis/metric/activity.rs index 3f313a5a..da07146f 100644 --- a/libs/hc_analysis/src/metric/activity.rs +++ b/libs/hc_common/src/analysis/metric/activity.rs @@ -1,9 +1,9 @@ // SPDX-License-Identifier: Apache-2.0 -use crate::MetricProvider; -use hc_common::context::Context as _; -use hc_common::{ +use crate::analysis::MetricProvider; +use crate::{ chrono::{prelude::*, Duration}, + context::Context as _, error::Result, log, }; diff --git a/libs/hc_analysis/src/metric/affiliation.rs b/libs/hc_common/src/analysis/metric/affiliation.rs similarity index 99% rename from libs/hc_analysis/src/metric/affiliation.rs rename to libs/hc_common/src/analysis/metric/affiliation.rs index a11b42bd..66d50ea9 100644 --- a/libs/hc_analysis/src/metric/affiliation.rs +++ b/libs/hc_common/src/analysis/metric/affiliation.rs @@ -1,7 +1,7 @@ // SPDX-License-Identifier: Apache-2.0 -use crate::MetricProvider; -use hc_common::{ +use crate::analysis::MetricProvider; +use crate::{ context::Context as _, data::git::{Commit, CommitContributorView}, error::{Error, Result}, diff --git a/libs/hc_analysis/src/metric/binary.rs b/libs/hc_common/src/analysis/metric/binary.rs similarity index 82% rename from libs/hc_analysis/src/metric/binary.rs rename to libs/hc_common/src/analysis/metric/binary.rs index c708d98b..2d7799b6 100644 --- a/libs/hc_analysis/src/metric/binary.rs +++ b/libs/hc_common/src/analysis/metric/binary.rs @@ -1,8 +1,8 @@ // SPDX-License-Identifier: Apache-2.0 -use crate::metric::binary_detector::detect_binary_files; -use crate::MetricProvider; -use hc_common::{error::Result, log, TryFilter}; +use crate::analysis::metric::binary_detector::detect_binary_files; +use crate::analysis::MetricProvider; +use crate::{error::Result, log, TryFilter}; use serde::{self, Serialize}; use std::rc::Rc; @@ -24,7 +24,7 @@ pub fn binary_metric(db: &dyn MetricProvider) -> Result> { let binary_files = detect_binary_files(&pathbuf_rc)? .into_iter() .try_filter(|f| db.is_likely_binary_file(Rc::clone(f))) - .collect::>()?; + .collect::>()?; log::info!("completed binary metric"); diff --git a/libs/hc_analysis/src/metric/binary_detector/mod.rs b/libs/hc_common/src/analysis/metric/binary_detector/mod.rs similarity index 94% rename from libs/hc_analysis/src/metric/binary_detector/mod.rs rename to libs/hc_common/src/analysis/metric/binary_detector/mod.rs index ec931b92..cb8d8206 100644 --- a/libs/hc_analysis/src/metric/binary_detector/mod.rs +++ b/libs/hc_common/src/analysis/metric/binary_detector/mod.rs @@ -4,8 +4,8 @@ mod query; pub use query::*; +use crate::{context::Context, error::Result, filesystem::read_toml, hc_error}; use content_inspector::{inspect, ContentType}; -use hc_common::{context::Context, error::Result, filesystem::read_toml, hc_error}; use serde::{self, de::Visitor, Deserialize, Deserializer}; use std::fmt::{self, Formatter}; use std::fs::File; @@ -23,10 +23,8 @@ pub struct BinaryFileDetector { impl BinaryFileDetector { /// Constructs a new `BinaryFileDetector` from the `Binary.toml` file. - pub fn load>( - binary_config_file: P, - ) -> hc_common::error::Result { - fn inner(binary_config_file: &Path) -> hc_common::error::Result { + pub fn load>(binary_config_file: P) -> crate::error::Result { + fn inner(binary_config_file: &Path) -> crate::error::Result { let extensions_file: ExtensionsFile = read_toml(binary_config_file) .context("failed to read binary type defintions from Binary config file")?; diff --git a/libs/hc_analysis/src/metric/binary_detector/query.rs b/libs/hc_common/src/analysis/metric/binary_detector/query.rs similarity index 87% rename from libs/hc_analysis/src/metric/binary_detector/query.rs rename to libs/hc_common/src/analysis/metric/binary_detector/query.rs index 2c1295d0..9d95c905 100644 --- a/libs/hc_analysis/src/metric/binary_detector/query.rs +++ b/libs/hc_common/src/analysis/metric/binary_detector/query.rs @@ -2,8 +2,8 @@ //! A query group for binary file detection queries. -use crate::metric::binary_detector::BinaryFileDetector; -use hc_common::{config::PracticesConfigQuery, context::Context as _, error::Result, salsa}; +use crate::analysis::metric::binary_detector::BinaryFileDetector; +use crate::{config::PracticesConfigQuery, context::Context as _, error::Result, salsa}; use std::rc::Rc; /// Queries related to binary file detection diff --git a/libs/hc_analysis/src/metric/churn.rs b/libs/hc_common/src/analysis/metric/churn.rs similarity index 88% rename from libs/hc_analysis/src/metric/churn.rs rename to libs/hc_common/src/analysis/metric/churn.rs index b06ef8f2..b61fbdd2 100644 --- a/libs/hc_analysis/src/metric/churn.rs +++ b/libs/hc_common/src/analysis/metric/churn.rs @@ -1,9 +1,10 @@ // SPDX-License-Identifier: Apache-2.0 -use crate::metric::math::{mean, std_dev}; -use crate::MetricProvider; -use hc_common::context::Context as _; -use hc_common::{data::git::Commit, error::Result, hc_error, log, TryAny, TryFilter, F64}; +use crate::analysis::metric::math::{mean, std_dev}; +use crate::analysis::MetricProvider; +use crate::{ + context::Context as _, data::git::Commit, error::Result, hc_error, log, TryAny, TryFilter, F64, +}; use serde::{self, Serialize}; use std::collections::HashMap; use std::rc::Rc; @@ -34,7 +35,7 @@ pub fn churn_metric(db: &dyn MetricProvider) -> Result> { .iter() .try_any(|fd| db.is_likely_source_file(Rc::clone(&fd.file_name))) }) - .collect::>>()?; + .collect::>>()?; let mut commit_churns = Vec::new(); let mut total_files_changed: i64 = 0; @@ -46,7 +47,7 @@ pub fn churn_metric(db: &dyn MetricProvider) -> Result> { .file_diffs .iter() .try_filter(|file_diff| db.is_likely_source_file(Rc::clone(&file_diff.file_name))) - .collect::>>()?; + .collect::>>()?; // Update files changed. let files_changed = source_files.len() as i64; @@ -126,10 +127,10 @@ pub fn churn_metric(db: &dyn MetricProvider) -> Result> { .map(|c| c.churn.into_inner()) .collect(); - let mean = mean(&churns) - .ok_or_else(|| hc_common::error::Error::msg("failed to get mean churn value"))?; + let mean = + mean(&churns).ok_or_else(|| crate::error::Error::msg("failed to get mean churn value"))?; let std_dev = std_dev(mean, &churns) - .ok_or_else(|| hc_common::error::Error::msg("failed to get churn standard deviation"))?; + .ok_or_else(|| crate::error::Error::msg("failed to get churn standard deviation"))?; log::trace!("mean of churn scores [mean='{}']", mean); log::trace!("standard deviation of churn scores [stddev='{}']", std_dev); diff --git a/libs/hc_analysis/src/metric/commit_trust.rs b/libs/hc_common/src/analysis/metric/commit_trust.rs similarity index 94% rename from libs/hc_analysis/src/metric/commit_trust.rs rename to libs/hc_common/src/analysis/metric/commit_trust.rs index 33a8dda8..493435c3 100644 --- a/libs/hc_analysis/src/metric/commit_trust.rs +++ b/libs/hc_common/src/analysis/metric/commit_trust.rs @@ -1,8 +1,7 @@ // SPDX-License-Identifier: Apache-2.0 -use crate::MetricProvider; -use hc_common::context::Context as _; -use hc_common::{error::Result, log}; +use crate::analysis::MetricProvider; +use crate::{context::Context as _, error::Result, log}; use std::{collections::HashMap, rc::Rc}; pub const TRUST_PHASE: &str = "commit trust"; diff --git a/libs/hc_analysis/src/metric/contributor_trust.rs b/libs/hc_common/src/analysis/metric/contributor_trust.rs similarity index 98% rename from libs/hc_analysis/src/metric/contributor_trust.rs rename to libs/hc_common/src/analysis/metric/contributor_trust.rs index 71feec11..3aace4a8 100644 --- a/libs/hc_analysis/src/metric/contributor_trust.rs +++ b/libs/hc_common/src/analysis/metric/contributor_trust.rs @@ -1,8 +1,8 @@ // SPDX-License-Identifier: Apache-2.0 -use crate::MetricProvider; -use hc_common::context::Context as _; -use hc_common::{error::Result, log}; +use crate::analysis::MetricProvider; +use crate::context::Context as _; +use crate::{error::Result, log}; use std::{collections::HashMap, rc::Rc}; pub const TRUST_PHASE: &str = "contributor trust"; diff --git a/libs/hc_analysis/src/metric/entropy.rs b/libs/hc_common/src/analysis/metric/entropy.rs similarity index 95% rename from libs/hc_analysis/src/metric/entropy.rs rename to libs/hc_common/src/analysis/metric/entropy.rs index 0494922c..fad27780 100644 --- a/libs/hc_analysis/src/metric/entropy.rs +++ b/libs/hc_common/src/analysis/metric/entropy.rs @@ -1,9 +1,9 @@ // SPDX-License-Identifier: Apache-2.0 -use crate::metric::math::{mean, std_dev}; -use crate::MetricProvider; -use hc_common::context::Context as _; -use hc_common::{ +use crate::analysis::metric::math::{mean, std_dev}; +use crate::analysis::MetricProvider; +use crate::context::Context as _; +use crate::{ data::git::{Commit, CommitDiff, Diff}, error::Result, hc_error, log, TryAny, TryFilter, F64, @@ -138,7 +138,7 @@ struct GraphemeFreqView<'gra> { fn is_likely_source_file( commit_diff: &CommitDiff, db: &dyn MetricProvider, -) -> hc_common::error::Result { +) -> crate::error::Result { commit_diff .diff .file_diffs @@ -211,10 +211,10 @@ fn z_scores(mut commit_entropies: Vec) -> Result Result> { let typo_output = match dependencies.language { Lang::JavaScript => typos_for_javascript(&typo_file, dependencies), - Lang::Unknown => Err(hc_common::error::Error::msg( + Lang::Unknown => Err(crate::error::Error::msg( "failed to identify a known language", )), }?; @@ -735,7 +735,7 @@ impl KeyboardLayout { mod test { use super::NameFuzzer; use super::Typo; - use hc_common::lazy_static::lazy_static; + use crate::lazy_static::lazy_static; macro_rules! test_typos { ( from: $name:ident, to: $to:literal, expected: [ $( $expected:ident ),* ] ) => { diff --git a/libs/hc_analysis/src/report_builder.rs b/libs/hc_common/src/analysis/report_builder.rs similarity index 95% rename from libs/hc_analysis/src/report_builder.rs rename to libs/hc_common/src/analysis/report_builder.rs index 8a83f2c1..0a001f2f 100644 --- a/libs/hc_analysis/src/report_builder.rs +++ b/libs/hc_common/src/analysis/report_builder.rs @@ -1,8 +1,8 @@ // SPDX-License-Identifier: Apache-2.0 -use crate::{analysis::AnalysisReport, score::ScoringResults, session::Session}; -pub use hc_common::report::*; -use hc_common::{ +use crate::analysis::{analysis::AnalysisReport, score::ScoringResults, session::Session}; +pub use crate::report::*; +use crate::{ config::RiskConfigQuery, data::source::SourceQuery, error::{Error, Result}, @@ -41,7 +41,7 @@ pub fn build_report(session: &Session, scoring: &ScoringResults) -> Result { return Err(hc_error!( "phase name does not match {} analysis", - crate::score::ACTIVITY_PHASE + crate::analysis::score::ACTIVITY_PHASE )) } } @@ -73,7 +73,7 @@ pub fn build_report(session: &Session, scoring: &ScoringResults) -> Result { return Err(hc_error!( "phase name does not match {} analysis", - crate::score::AFFILIATION_PHASE + crate::analysis::score::AFFILIATION_PHASE )) } } @@ -105,7 +105,7 @@ pub fn build_report(session: &Session, scoring: &ScoringResults) -> Result { return Err(hc_error!( "phase name does not match {} analysis", - crate::score::BINARY_PHASE + crate::analysis::score::BINARY_PHASE )) } } @@ -136,7 +136,7 @@ pub fn build_report(session: &Session, scoring: &ScoringResults) -> Result { return Err(hc_error!( "phase name does not match {} analysis", - crate::score::CHURN_PHASE + crate::analysis::score::CHURN_PHASE )) } } @@ -167,7 +167,7 @@ pub fn build_report(session: &Session, scoring: &ScoringResults) -> Result { return Err(hc_error!( "phase name does not match {} analysis", - crate::score::ENTROPY_PHASE + crate::analysis::score::ENTROPY_PHASE )) } } @@ -198,7 +198,7 @@ pub fn build_report(session: &Session, scoring: &ScoringResults) -> Result { return Err(hc_error!( "phase name does not match {} analysis", - crate::score::IDENTITY_PHASE + crate::analysis::score::IDENTITY_PHASE )) } } @@ -226,7 +226,7 @@ pub fn build_report(session: &Session, scoring: &ScoringResults) -> Result { return Err(hc_error!( "phase name does not match {} analysis", - crate::score::FUZZ_PHASE + crate::analysis::score::FUZZ_PHASE )) } } @@ -257,7 +257,7 @@ pub fn build_report(session: &Session, scoring: &ScoringResults) -> Result { return Err(hc_error!( "phase name does not match {} analysis", - crate::score::REVIEW_PHASE + crate::analysis::score::REVIEW_PHASE )) } } @@ -288,7 +288,7 @@ pub fn build_report(session: &Session, scoring: &ScoringResults) -> Result { return Err(hc_error!( "phase name does not match {} analysis", - crate::score::TYPO_PHASE + crate::analysis::score::TYPO_PHASE )) } } @@ -483,7 +483,7 @@ pub fn build_pr_report(session: &Session, scoring: &ScoringResults) -> Result { return Err(hc_error!( "phase name does not match {} analysis", - crate::score::PR_AFFILIATION_PHASE + crate::analysis::score::PR_AFFILIATION_PHASE )) } } @@ -517,7 +517,7 @@ pub fn build_pr_report(session: &Session, scoring: &ScoringResults) -> Result { return Err(hc_error!( "phase name does not match {} analysis", - crate::score::PR_CONTRIBUTOR_TRUST_PHASE + crate::analysis::score::PR_CONTRIBUTOR_TRUST_PHASE )) } } @@ -551,7 +551,7 @@ pub fn build_pr_report(session: &Session, scoring: &ScoringResults) -> Result { return Err(hc_error!( "phase name does not match {} analysis", - crate::score::PR_MODULE_CONTRIBUTORS_PHASE + crate::analysis::score::PR_MODULE_CONTRIBUTORS_PHASE )) } } diff --git a/libs/hc_analysis/src/score.rs b/libs/hc_common/src/analysis/score.rs similarity index 99% rename from libs/hc_analysis/src/score.rs rename to libs/hc_common/src/analysis/score.rs index 5a45d916..48ce27bc 100644 --- a/libs/hc_analysis/src/score.rs +++ b/libs/hc_common/src/analysis/score.rs @@ -1,10 +1,10 @@ // SPDX-License-Identifier: Apache-2.0 -use crate::{ +use crate::analysis::{ analysis::{AnalysisOutcome, AnalysisReport}, AnalysisProvider, }; -use hc_common::{error::Result, hc_error, salsa, shell::Phase}; +use crate::{error::Result, hc_error, salsa, shell::Phase}; use std::default::Default; use std::rc::Rc; diff --git a/libs/hc_analysis/src/session/mod.rs b/libs/hc_common/src/analysis/session/mod.rs similarity index 99% rename from libs/hc_analysis/src/session/mod.rs rename to libs/hc_common/src/analysis/session/mod.rs index de4c1bf3..6e68f29f 100644 --- a/libs/hc_analysis/src/session/mod.rs +++ b/libs/hc_common/src/analysis/session/mod.rs @@ -3,16 +3,15 @@ mod pm; mod spdx; -use crate::{ +use crate::analysis::{ metric::{ binary_detector::BinaryFileStorage, linguist::LinguistStorage, MetricProviderStorage, }, score::ScoringProviderStorage, AnalysisProviderStorage, }; -use dotenv::var; -use hc_common::context::Context as _; -use hc_common::{ +use crate::context::Context as _; +use crate::{ chrono::prelude::*, command_util::DependentProgram, config::{ @@ -40,6 +39,7 @@ use hc_common::{ version::{get_version, VersionQuery, VersionQueryStorage}, HIPCHECK_TOML_FILE, }; +use dotenv::var; use std::ffi::{OsStr, OsString}; use std::fmt; use std::path::{Path, PathBuf}; @@ -501,7 +501,7 @@ pub enum CheckType { #[cfg(test)] mod tests { use super::*; - use hc_common::test_util::with_env_vars; + use crate::test_util::with_env_vars; use tempfile::TempDir; const TEMPDIR_PREFIX: &str = "hc_test"; diff --git a/libs/hc_analysis/src/session/pm.rs b/libs/hc_common/src/analysis/session/pm.rs similarity index 99% rename from libs/hc_analysis/src/session/pm.rs rename to libs/hc_common/src/analysis/session/pm.rs index 3d87c878..faf1ee79 100644 --- a/libs/hc_analysis/src/session/pm.rs +++ b/libs/hc_common/src/analysis/session/pm.rs @@ -1,8 +1,8 @@ // SPDX-License-Identifier: Apache-2.0 #![allow(dead_code)] -use hc_common::context::Context as _; -use hc_common::{ +use crate::context::Context as _; +use crate::{ error::{Error, Result}, hc_error, serde_json::{self, Value}, @@ -506,7 +506,7 @@ fn is_none_or_empty(s: Option<&str>) -> bool { mod tests { // Note this useful idiom: importing names from outer (for mod tests) scope. use super::*; - use hc_common::url::Url; + use crate::url::Url; use serde_json::json; #[test] diff --git a/libs/hc_analysis/src/session/spdx.rs b/libs/hc_common/src/analysis/session/spdx.rs similarity index 96% rename from libs/hc_analysis/src/session/spdx.rs rename to libs/hc_common/src/analysis/session/spdx.rs index 2ccfbb67..558d1a73 100644 --- a/libs/hc_analysis/src/session/spdx.rs +++ b/libs/hc_common/src/analysis/session/spdx.rs @@ -2,8 +2,8 @@ //! Utilities for extracting repository info from SPDX documents. -use hc_common::context::Context as _; -use hc_common::{error::Result, hc_error, serde_json, url::Url}; +use crate::context::Context as _; +use crate::{error::Result, hc_error, serde_json, url::Url}; use spdx_rs::models::SPDX; use std::ffi::{OsStr, OsString}; diff --git a/libs/hc_common/src/lib.rs b/libs/hc_common/src/lib.rs index 7ce4ed30..4b3e6c04 100644 --- a/libs/hc_common/src/lib.rs +++ b/libs/hc_common/src/lib.rs @@ -3,6 +3,7 @@ //! Provides common access to third-party crates and other //! functionality used widely throughout Hipcheck. +pub mod analysis; pub mod command_util; pub mod config; pub mod context; @@ -32,6 +33,22 @@ pub use try_filter::{FallibleFilter, TryFilter}; pub use url; pub use which; +use crate::analysis::{ + report_builder::{build_pr_report, build_report}, + score::{score_pr_results, score_results}, + session::Session, +}; +pub use crate::analysis::{ + report_builder::{AnyReport, Format, PrReport, Report}, + session::{resolve_config, resolve_data, resolve_home, Check, CheckType}, +}; +pub use crate::shell::{ColorChoice, Output, Shell, Verbosity}; +use crate::{ + context::Context as _, + error::{Error, Result}, +}; +use std::path::PathBuf; + /// An `f64` that is never `NaN`. pub type F64 = ordered_float::NotNan; @@ -73,3 +90,190 @@ impl CheckKind { } } } + +/// Run Hipcheck. +/// +/// Parses arguments, sets up shell output, and then runs the main logic. +#[allow(clippy::too_many_arguments)] +pub fn run( + output: Output, + error_output: Output, + verbosity: Verbosity, + check: Check, + config_path: Option, + data_path: Option, + home_dir: Option, + format: Format, + raw_version: &str, +) -> (Shell, Result) { + // Setup wrapper for shell output. + let shell = Shell::new(output, error_output, verbosity); + + // Run and print / report errors. + run_with_shell( + shell, + check, + config_path, + data_path, + home_dir, + format, + raw_version, + ) +} + +// This is pub for testing purposes. +/// Now that we're fully-initialized, run Hipcheck's analyses. +#[allow(clippy::too_many_arguments)] +#[doc(hidden)] +pub fn run_with_shell( + shell: Shell, + check: Check, + config_path: Option, + data_path: Option, + home_dir: Option, + format: Format, + raw_version: &str, +) -> (Shell, Result) { + // Initialize the session. + let session = match Session::new( + shell, + &check, + &check.check_value, + config_path, + data_path, + home_dir, + format, + raw_version, + ) { + Ok(session) => session, + Err((shell, err)) => return (shell, Err(err)), + }; + + match check.check_type { + CheckType::RepoSource | CheckType::SpdxDocument => { + // Run analyses against a repo and score the results (score calls analyses that call metrics). + let mut phase = match session.shell.phase("analyzing and scoring results") { + Ok(phase) => phase, + Err(err) => return (session.end(), Err(err)), + }; + + let scoring = match score_results(&mut phase, &session) { + Ok(scoring) => scoring, + _ => { + return ( + session.end(), + Err(Error::msg("Trouble scoring and analyzing results")), + ) + } + }; + + match phase.finish() { + Ok(()) => {} + Err(err) => return (session.end(), Err(err)), + }; + + // Build the final report. + let report = + match build_report(&session, &scoring).context("failed to build final report") { + Ok(report) => report, + Err(err) => return (session.end(), Err(err)), + }; + + (session.end(), Ok(AnyReport::Report(report))) + } + CheckType::PackageVersion => { + // Run analyses against a repo and score the results (score calls analyses that call metrics). + let mut phase = match session.shell.phase("analyzing and scoring results") { + Ok(phase) => phase, + Err(err) => return (session.end(), Err(err)), + }; + + let scoring = match score_results(&mut phase, &session) { + Ok(scoring) => scoring, + _ => { + return ( + session.end(), + Err(Error::msg("Trouble scoring and analyzing results")), + ) + } + }; + + match phase.finish() { + Ok(()) => {} + Err(err) => return (session.end(), Err(err)), + }; + + // Build the final report. + let report = + match build_report(&session, &scoring).context("failed to build final report") { + Ok(report) => report, + Err(err) => return (session.end(), Err(err)), + }; + + (session.end(), Ok(AnyReport::Report(report))) + } + CheckType::PrUri => { + // Run analyses against a pull request and score the results (score calls analyses that call metrics). + let mut phase = match session.shell.phase("scoring and analyzing results") { + Ok(phase) => phase, + Err(err) => return (session.end(), Err(err)), + }; + + let score = match score_pr_results(&mut phase, &session) { + Ok(score) => score, + _ => { + return ( + session.end(), + Err(Error::msg("Trouble scoring and analyzing results")), + ) + } + }; + + match phase.finish() { + Ok(()) => {} + Err(err) => return (session.end(), Err(err)), + }; + + // Build the final report. + let pr_report = + match build_pr_report(&session, &score).context("failed to build final report") { + Ok(pr_report) => pr_report, + Err(err) => return (session.end(), Err(err)), + }; + + (session.end(), Ok(AnyReport::PrReport(pr_report))) + } + _ => ( + session.end(), + Err(Error::msg( + "Hipcheck attempted to analyze an unsupported type", + )), + ), + } +} + +/// Print errors which occur before the `Shell` type can be setup. +pub fn print_error(err: &Error) { + let mut chain = err.chain(); + + // PANIC: First error is guaranteed to be present. + eprintln!("error: {}", chain.next().unwrap()); + + for err in chain { + eprintln!(" {}", err); + } +} + +pub enum Outcome { + Ok, + Err, +} + +impl Outcome { + pub fn exit_code(&self) -> i32 { + match self { + Outcome::Ok => 0, + Outcome::Err => 1, + } + } +} diff --git a/libs/hc_core/Cargo.toml b/libs/hc_core/Cargo.toml deleted file mode 100644 index 33b0b41e..00000000 --- a/libs/hc_core/Cargo.toml +++ /dev/null @@ -1,25 +0,0 @@ -[package] -name = "hc_core" -version = "0.1.0" -edition = "2021" -license = "Apache-2.0" -publish = false - -[dependencies] -hc_analysis = { path = "../hc_analysis" } -hc_common = { path = "../hc_common" } - -[dev_dependencies] -duct = "0.13.7" -tempfile = "3.10.1" -hc_common = { path = "../hc_common" } -criterion = "0.5.1" - -[[bench]] -name = "basic" -harness = false -path = "../../benches/basic.rs" - -[[test]] -name = "can_run" -path = "../../tests/can_run.rs" diff --git a/libs/hc_core/src/lib.rs b/libs/hc_core/src/lib.rs deleted file mode 100644 index 20e9247c..00000000 --- a/libs/hc_core/src/lib.rs +++ /dev/null @@ -1,208 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 - -pub use hc_analysis::{ - report_builder::{AnyReport, Format, PrReport, Report}, - session::{resolve_config, resolve_data, resolve_home, Check, CheckType}, -}; -pub use hc_common::{ - shell::{ColorChoice, Output, Shell, Verbosity}, - version, -}; - -use hc_analysis::{ - report_builder::{build_pr_report, build_report}, - score::{score_pr_results, score_results}, - session::Session, -}; -use hc_common::{ - context::Context as _, - error::{Error, Result}, -}; -use std::path::PathBuf; - -/// Run Hipcheck. -/// -/// Parses arguments, sets up shell output, and then runs the main logic. -#[allow(clippy::too_many_arguments)] -pub fn run( - output: Output, - error_output: Output, - verbosity: Verbosity, - check: Check, - config_path: Option, - data_path: Option, - home_dir: Option, - format: Format, - raw_version: &str, -) -> (Shell, Result) { - // Setup wrapper for shell output. - let shell = Shell::new(output, error_output, verbosity); - - // Run and print / report errors. - run_with_shell( - shell, - check, - config_path, - data_path, - home_dir, - format, - raw_version, - ) -} - -// This is pub for testing purposes. -/// Now that we're fully-initialized, run Hipcheck's analyses. -#[allow(clippy::too_many_arguments)] -#[doc(hidden)] -pub fn run_with_shell( - shell: Shell, - check: Check, - config_path: Option, - data_path: Option, - home_dir: Option, - format: Format, - raw_version: &str, -) -> (Shell, Result) { - // Initialize the session. - let session = match Session::new( - shell, - &check, - &check.check_value, - config_path, - data_path, - home_dir, - format, - raw_version, - ) { - Ok(session) => session, - Err((shell, err)) => return (shell, Err(err)), - }; - - match check.check_type { - CheckType::RepoSource | CheckType::SpdxDocument => { - // Run analyses against a repo and score the results (score calls analyses that call metrics). - let mut phase = match session.shell.phase("analyzing and scoring results") { - Ok(phase) => phase, - Err(err) => return (session.end(), Err(err)), - }; - - let scoring = match score_results(&mut phase, &session) { - Ok(scoring) => scoring, - _ => { - return ( - session.end(), - Err(Error::msg("Trouble scoring and analyzing results")), - ) - } - }; - - match phase.finish() { - Ok(()) => {} - Err(err) => return (session.end(), Err(err)), - }; - - // Build the final report. - let report = - match build_report(&session, &scoring).context("failed to build final report") { - Ok(report) => report, - Err(err) => return (session.end(), Err(err)), - }; - - (session.end(), Ok(AnyReport::Report(report))) - } - CheckType::PackageVersion => { - // Run analyses against a repo and score the results (score calls analyses that call metrics). - let mut phase = match session.shell.phase("analyzing and scoring results") { - Ok(phase) => phase, - Err(err) => return (session.end(), Err(err)), - }; - - let scoring = match score_results(&mut phase, &session) { - Ok(scoring) => scoring, - _ => { - return ( - session.end(), - Err(Error::msg("Trouble scoring and analyzing results")), - ) - } - }; - - match phase.finish() { - Ok(()) => {} - Err(err) => return (session.end(), Err(err)), - }; - - // Build the final report. - let report = - match build_report(&session, &scoring).context("failed to build final report") { - Ok(report) => report, - Err(err) => return (session.end(), Err(err)), - }; - - (session.end(), Ok(AnyReport::Report(report))) - } - CheckType::PrUri => { - // Run analyses against a pull request and score the results (score calls analyses that call metrics). - let mut phase = match session.shell.phase("scoring and analyzing results") { - Ok(phase) => phase, - Err(err) => return (session.end(), Err(err)), - }; - - let score = match score_pr_results(&mut phase, &session) { - Ok(score) => score, - _ => { - return ( - session.end(), - Err(Error::msg("Trouble scoring and analyzing results")), - ) - } - }; - - match phase.finish() { - Ok(()) => {} - Err(err) => return (session.end(), Err(err)), - }; - - // Build the final report. - let pr_report = - match build_pr_report(&session, &score).context("failed to build final report") { - Ok(pr_report) => pr_report, - Err(err) => return (session.end(), Err(err)), - }; - - (session.end(), Ok(AnyReport::PrReport(pr_report))) - } - _ => ( - session.end(), - Err(Error::msg( - "Hipcheck attempted to analyze an unsupported type", - )), - ), - } -} - -/// Print errors which occur before the `Shell` type can be setup. -pub fn print_error(err: &Error) { - let mut chain = err.chain(); - - // PANIC: First error is guaranteed to be present. - eprintln!("error: {}", chain.next().unwrap()); - - for err in chain { - eprintln!(" {}", err); - } -} - -pub enum Outcome { - Ok, - Err, -} - -impl Outcome { - pub fn exit_code(&self) -> i32 { - match self { - Outcome::Ok => 0, - Outcome::Err => 1, - } - } -} From bae2860beb433a8ceeca696efa11955f9345a61f Mon Sep 17 00:00:00 2001 From: Andrew Lilley Brinker Date: Mon, 6 May 2024 15:30:40 -0700 Subject: [PATCH 08/14] chore: Merge `hc_common` into `hipcheck`. This completes the effort to unify Hipcheck into a single crate, by merging `hc_common` into `hipcheck`. Signed-off-by: Andrew Lilley Brinker --- .rustfmt.toml | 1 - Cargo.lock | 66 ++-- Cargo.toml | 2 +- benches/basic.rs | 5 +- hipcheck/Cargo.toml | 70 +++- {libs/hc_common => hipcheck}/build.rs | 4 +- hipcheck/src/analysis.rs | 12 + .../src/analysis/analysis.rs | 29 +- .../src/analysis/metric/activity.rs | 17 +- .../src/analysis/metric/affiliation.rs | 27 +- .../src/analysis/metric/binary.rs | 6 +- .../analysis/metric/binary_detector/mod.rs | 19 +- .../analysis/metric/binary_detector/query.rs | 4 +- .../src/analysis/metric/churn.rs | 16 +- .../src/analysis/metric/commit_trust.rs | 6 +- .../src/analysis/metric/contributor_trust.rs | 5 +- .../src/analysis/metric/entropy.rs | 19 +- .../src/analysis/metric/fuzz.rs | 6 +- .../src/analysis/metric/identity.rs | 6 +- .../src/analysis/metric/linguist/mod.rs | 11 +- .../src/analysis/metric/linguist/query.rs | 4 +- .../src/analysis/metric/math.rs | 0 .../src/analysis/metric/mod.rs | 17 +- .../src/analysis/metric/module.rs | 6 +- .../analysis/metric/module_contributors.rs | 14 +- .../src/analysis/metric/review.rs | 6 +- .../src/analysis/metric/typo.rs | 18 +- .../src/analysis/report_builder.rs | 17 +- .../src/analysis/score.rs | 17 +- .../src/analysis/session/mod.rs | 87 +++-- .../src/analysis/session/pm.rs | 20 +- .../src/analysis/session/spdx.rs | 7 +- .../src/command_util.rs | 366 +++++++++--------- {libs/hc_common => hipcheck}/src/config.rs | 24 +- {libs/hc_common => hipcheck}/src/context.rs | 6 +- {libs/hc_common => hipcheck}/src/data.rs | 16 +- .../src/data/code_quality.rs | 9 +- .../src/data/es_lint/command.rs | 11 +- .../src/data/es_lint/data.rs | 8 +- .../src/data/es_lint/mod.rs | 4 +- .../src/data/git/data.rs | 11 +- .../src/data/git/mod.rs | 9 +- .../src/data/git/parse.rs | 44 ++- .../src/data/git/query/impls.rs | 31 +- .../src/data/git/query/mod.rs | 26 +- .../src/data/git_command.rs | 5 +- .../src/data/github/authenticated_agent.rs | 3 +- .../src/data/github/code_search.rs | 9 +- .../src/data/github/data.rs | 3 +- .../src/data/github/gh_query.graphql | 0 .../src/data/github/gh_schema.graphql | 0 .../src/data/github/graphql.rs | 21 +- .../src/data/github/graphql_pr.rs | 34 +- .../src/data/github/hidden.rs | 4 +- .../src/data/github/mod.rs | 2 +- {libs/hc_common => hipcheck}/src/data/hash.rs | 3 +- .../src/data/modules.rs | 19 +- {libs/hc_common => hipcheck}/src/data/npm.rs | 26 +- .../src/data/query/code_quality.rs | 6 +- .../src/data/query/dependencies.rs | 6 +- .../src/data/query/fuzz.rs | 11 +- .../src/data/query/github.rs | 9 +- hipcheck/src/data/query/mod.rs | 26 ++ .../src/data/query/module.rs | 24 +- .../src/data/query/pr_review.rs | 24 +- .../src/data/source/mod.rs | 25 +- .../src/data/source/query.rs | 5 +- {libs/hc_common => hipcheck}/src/error.rs | 7 +- .../hc_common => hipcheck}/src/filesystem.rs | 10 +- hipcheck/src/main.rs | 290 +++++++++++++- {libs/hc_common => hipcheck}/src/pathbuf.rs | 0 {libs/hc_common => hipcheck}/src/report.rs | 71 ++-- {libs/hc_common => hipcheck}/src/shell.rs | 46 ++- {libs/hc_common => hipcheck}/src/test_util.rs | 10 +- {libs/hc_common => hipcheck}/src/tests.rs | 3 +- {libs/hc_common => hipcheck}/src/try_any.rs | 0 .../hc_common => hipcheck}/src/try_filter.rs | 0 {libs/hc_common => hipcheck}/src/version.rs | 4 +- libs/hc_common/Cargo.toml | 75 ---- libs/hc_common/src/analysis.rs | 11 - libs/hc_common/src/data/query/mod.rs | 18 - libs/hc_common/src/lib.rs | 279 ------------- tests/can_run.rs | 3 +- xtask/Cargo.toml | 8 +- xtask/src/main.rs | 12 +- xtask/src/task/bench.rs | 7 +- xtask/src/task/ci.rs | 14 +- xtask/src/task/doc.rs | 8 +- xtask/src/task/install.rs | 7 +- xtask/src/task/validate.rs | 45 ++- xtask/src/workspace.rs | 6 +- 91 files changed, 1275 insertions(+), 1033 deletions(-) rename {libs/hc_common => hipcheck}/build.rs (96%) create mode 100644 hipcheck/src/analysis.rs rename {libs/hc_common => hipcheck}/src/analysis/analysis.rs (97%) rename {libs/hc_common => hipcheck}/src/analysis/metric/activity.rs (87%) rename {libs/hc_common => hipcheck}/src/analysis/metric/affiliation.rs (96%) rename {libs/hc_common => hipcheck}/src/analysis/metric/binary.rs (91%) rename {libs/hc_common => hipcheck}/src/analysis/metric/binary_detector/mod.rs (92%) rename {libs/hc_common => hipcheck}/src/analysis/metric/binary_detector/query.rs (91%) rename {libs/hc_common => hipcheck}/src/analysis/metric/churn.rs (93%) rename {libs/hc_common => hipcheck}/src/analysis/metric/commit_trust.rs (94%) rename {libs/hc_common => hipcheck}/src/analysis/metric/contributor_trust.rs (98%) rename {libs/hc_common => hipcheck}/src/analysis/metric/entropy.rs (96%) rename {libs/hc_common => hipcheck}/src/analysis/metric/fuzz.rs (85%) rename {libs/hc_common => hipcheck}/src/analysis/metric/identity.rs (91%) rename {libs/hc_common => hipcheck}/src/analysis/metric/linguist/mod.rs (94%) rename {libs/hc_common => hipcheck}/src/analysis/metric/linguist/query.rs (91%) rename {libs/hc_common => hipcheck}/src/analysis/metric/math.rs (100%) rename {libs/hc_common => hipcheck}/src/analysis/metric/mod.rs (92%) rename {libs/hc_common => hipcheck}/src/analysis/metric/module.rs (87%) rename {libs/hc_common => hipcheck}/src/analysis/metric/module_contributors.rs (94%) rename {libs/hc_common => hipcheck}/src/analysis/metric/review.rs (91%) rename {libs/hc_common => hipcheck}/src/analysis/metric/typo.rs (98%) rename {libs/hc_common => hipcheck}/src/analysis/report_builder.rs (98%) rename {libs/hc_common => hipcheck}/src/analysis/score.rs (99%) rename {libs/hc_common => hipcheck}/src/analysis/session/mod.rs (92%) rename {libs/hc_common => hipcheck}/src/analysis/session/pm.rs (98%) rename {libs/hc_common => hipcheck}/src/analysis/session/spdx.rs (96%) rename {libs/hc_common => hipcheck}/src/command_util.rs (93%) rename {libs/hc_common => hipcheck}/src/config.rs (98%) rename {libs/hc_common => hipcheck}/src/context.rs (95%) rename {libs/hc_common => hipcheck}/src/data.rs (96%) rename {libs/hc_common => hipcheck}/src/data/code_quality.rs (92%) rename {libs/hc_common => hipcheck}/src/data/es_lint/command.rs (91%) rename {libs/hc_common => hipcheck}/src/data/es_lint/data.rs (94%) rename {libs/hc_common => hipcheck}/src/data/es_lint/mod.rs (97%) rename {libs/hc_common => hipcheck}/src/data/git/data.rs (96%) rename {libs/hc_common => hipcheck}/src/data/git/mod.rs (96%) rename {libs/hc_common => hipcheck}/src/data/git/parse.rs (97%) rename {libs/hc_common => hipcheck}/src/data/git/query/impls.rs (94%) rename {libs/hc_common => hipcheck}/src/data/git/query/mod.rs (85%) rename {libs/hc_common => hipcheck}/src/data/git_command.rs (94%) rename {libs/hc_common => hipcheck}/src/data/github/authenticated_agent.rs (97%) rename {libs/hc_common => hipcheck}/src/data/github/code_search.rs (94%) rename {libs/hc_common => hipcheck}/src/data/github/data.rs (88%) rename {libs/hc_common => hipcheck}/src/data/github/gh_query.graphql (100%) rename {libs/hc_common => hipcheck}/src/data/github/gh_schema.graphql (100%) rename {libs/hc_common => hipcheck}/src/data/github/graphql.rs (88%) rename {libs/hc_common => hipcheck}/src/data/github/graphql_pr.rs (91%) rename {libs/hc_common => hipcheck}/src/data/github/hidden.rs (85%) rename {libs/hc_common => hipcheck}/src/data/github/mod.rs (98%) rename {libs/hc_common => hipcheck}/src/data/hash.rs (94%) rename {libs/hc_common => hipcheck}/src/data/modules.rs (92%) rename {libs/hc_common => hipcheck}/src/data/npm.rs (94%) rename {libs/hc_common => hipcheck}/src/data/query/code_quality.rs (80%) rename {libs/hc_common => hipcheck}/src/data/query/dependencies.rs (89%) rename {libs/hc_common => hipcheck}/src/data/query/fuzz.rs (86%) rename {libs/hc_common => hipcheck}/src/data/query/github.rs (94%) create mode 100644 hipcheck/src/data/query/mod.rs rename {libs/hc_common => hipcheck}/src/data/query/module.rs (89%) rename {libs/hc_common => hipcheck}/src/data/query/pr_review.rs (90%) rename {libs/hc_common => hipcheck}/src/data/source/mod.rs (98%) rename {libs/hc_common => hipcheck}/src/data/source/query.rs (96%) rename {libs/hc_common => hipcheck}/src/error.rs (98%) rename {libs/hc_common => hipcheck}/src/filesystem.rs (95%) rename {libs/hc_common => hipcheck}/src/pathbuf.rs (100%) rename {libs/hc_common => hipcheck}/src/report.rs (96%) rename {libs/hc_common => hipcheck}/src/shell.rs (98%) rename {libs/hc_common => hipcheck}/src/test_util.rs (88%) rename {libs/hc_common => hipcheck}/src/tests.rs (98%) rename {libs/hc_common => hipcheck}/src/try_any.rs (100%) rename {libs/hc_common => hipcheck}/src/try_filter.rs (100%) rename {libs/hc_common => hipcheck}/src/version.rs (95%) delete mode 100644 libs/hc_common/Cargo.toml delete mode 100644 libs/hc_common/src/analysis.rs delete mode 100644 libs/hc_common/src/data/query/mod.rs delete mode 100644 libs/hc_common/src/lib.rs diff --git a/.rustfmt.toml b/.rustfmt.toml index e96b69b4..4729b684 100644 --- a/.rustfmt.toml +++ b/.rustfmt.toml @@ -5,4 +5,3 @@ # make it easier for people to access and contribute to the Hipcheck # source code. hard_tabs = true - diff --git a/Cargo.lock b/Cargo.lock index 605df1ef..7eecefcd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -578,17 +578,40 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" [[package]] -name = "hc_common" -version = "0.1.0" +name = "heck" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c" +dependencies = [ + "unicode-segmentation", +] + +[[package]] +name = "heck" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" + +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "hipcheck" +version = "3.1.0" dependencies = [ "anyhow", "chrono", + "clap", "content_inspector", "criterion", "curl", "dirs", "dotenv", "duct", + "env_logger", "glob", "graphql_client", "lazy_static", @@ -622,36 +645,6 @@ dependencies = [ "xml-rs", ] -[[package]] -name = "heck" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c" -dependencies = [ - "unicode-segmentation", -] - -[[package]] -name = "heck" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" - -[[package]] -name = "hermit-abi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" - -[[package]] -name = "hipcheck" -version = "3.1.0" -dependencies = [ - "clap", - "env_logger", - "hc_common", -] - [[package]] name = "home" version = "0.5.9" @@ -1020,6 +1013,12 @@ version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" +[[package]] +name = "pathbuf" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc5ef818343d9b62a8391bfbc8fbd449acf2e6ddd2f1a9aede0eae4c7d91c25c" + [[package]] name = "pathdiff" version = "0.2.1" @@ -2003,11 +2002,12 @@ checksum = "791978798f0597cfc70478424c2b4fdc2b7a8024aaff78497ef00f24ef674193" name = "xtask" version = "0.1.0" dependencies = [ + "anyhow", "clap", "duct", "glob", - "hc_common", "open", + "pathbuf", "serde", "toml", "which", diff --git a/Cargo.toml b/Cargo.toml index cace5fda..ac22f87d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,7 +6,7 @@ cargo-features = ["resolver"] resolver = "2" # All the actual crates are in `libs/` or `hipcheck/` -members = ["hipcheck", "libs/*", "xtask"] +members = ["hipcheck", "xtask"] # Make sure Hipcheck is run with `cargo run`. default-members = ["hipcheck"] diff --git a/benches/basic.rs b/benches/basic.rs index f4c1a14c..0572f012 100644 --- a/benches/basic.rs +++ b/benches/basic.rs @@ -1,4 +1,7 @@ -use criterion::{criterion_group, criterion_main, Criterion, PlottingBackend}; +use criterion::criterion_group; +use criterion::criterion_main; +use criterion::Criterion; +use criterion::PlottingBackend; use hc_common::CheckKind; use hc_core::*; use std::time::Duration; diff --git a/hipcheck/Cargo.toml b/hipcheck/Cargo.toml index de1963f2..ed4e2aec 100644 --- a/hipcheck/Cargo.toml +++ b/hipcheck/Cargo.toml @@ -12,12 +12,74 @@ path = "src/main.rs" [dependencies] -# Internal dependencies. -hc_common = { path = "../libs/hc_common" } - -# External dependencies. +content_inspector = "0.2.4" +dotenv = "0.15.0" +curl = "0.4.38" +glob = "0.3.0" +maplit = "1.0.2" +serde_derive = "1.0.137" +spdx-rs = "0.5.0" +unicode-normalization = "0.1.19" +unicode-segmentation = "1.9.0" +walkdir = "2" +xml-rs = "0.8" +chrono = { version = "0.4.19", features = ["serde"] } +lazy_static = "1.4.0" +log = "0.4.16" +once_cell = "1.10.0" +ordered-float = { version = "4.2.0", features = ["serde"] } +paste = "1.0.7" +regex = "1.5.5" +salsa = "0.16.1" +schemars = { version = "0.8.17", default-features = false, features = [ + "derive", + "preserve_order", + "chrono", +] } +semver = "1.0.9" +serde = { version = "1.0.200", features = ["derive", "rc"] } +serde_json = "1.0.80" +smart-default = "0.7.1" +toml = "0.8.12" +url = "2.2.2" +which = { version = "6.0.1", default-features = false } +libc = "0.2.154" +termcolor = "1.1.3" +duct = "0.13.5" +dirs = "5.0.1" +graphql_client = "0.14.0" +nom = "7.1.3" +petgraph = { version = "0.6.0", features = ["serde-1"] } +ureq = { version = "2.9.7", default-features = false, features = [ + "json", + "native-tls", +] } clap = { version = "4.5.4", default-features = false, features = [ "string", "std", ] } env_logger = { version = "0.11.3" } + +[target.'cfg(windows)'.dependencies.winapi] +version = "0.3" +features = ["handleapi", "processenv", "winbase", "wincon", "winnt"] + +[build-dependencies] +anyhow = "1.0.83" +which = { version = "6.0.1", default-features = false } + +[dev-dependencies] +dirs = "5.0.1" +tempfile = "3.10.1" +duct = "0.13.7" +criterion = "0.5.1" + + +[[bench]] +name = "basic" +harness = false +path = "../benches/basic.rs" + +[[test]] +name = "can_run" +path = "../tests/can_run.rs" diff --git a/libs/hc_common/build.rs b/hipcheck/build.rs similarity index 96% rename from libs/hc_common/build.rs rename to hipcheck/build.rs index 6a23a56c..44391b7d 100644 --- a/libs/hc_common/build.rs +++ b/hipcheck/build.rs @@ -1,6 +1,8 @@ // SPDX-License-Identifier: Apache-2.0 -use anyhow::{anyhow, Context as _, Result}; +use anyhow::anyhow; +use anyhow::Context as _; +use anyhow::Result; use std::convert::AsRef; use std::ffi::OsStr; use std::iter::IntoIterator; diff --git a/hipcheck/src/analysis.rs b/hipcheck/src/analysis.rs new file mode 100644 index 00000000..62aabf47 --- /dev/null +++ b/hipcheck/src/analysis.rs @@ -0,0 +1,12 @@ +// SPDX-License-Identifier: Apache-2.0 + +#[allow(clippy::module_inception)] +pub mod analysis; +pub mod metric; +pub mod report_builder; +pub mod score; +pub mod session; + +pub use analysis::AnalysisProvider; +pub use analysis::AnalysisProviderStorage; +pub use metric::MetricProvider; diff --git a/libs/hc_common/src/analysis/analysis.rs b/hipcheck/src/analysis/analysis.rs similarity index 97% rename from libs/hc_common/src/analysis/analysis.rs rename to hipcheck/src/analysis/analysis.rs index 8d5ad863..28d7aae0 100644 --- a/libs/hc_common/src/analysis/analysis.rs +++ b/hipcheck/src/analysis/analysis.rs @@ -1,17 +1,24 @@ // SPDX-License-Identifier: Apache-2.0 -use crate::analysis::metric::{affiliation::AffiliatedType, MetricProvider}; -use crate::{ - chrono::Duration, - config::{AttacksConfigQuery, CommitConfigQuery, FuzzConfigQuery, PracticesConfigQuery}, - data::git::GitProvider, - error::{Error, Result}, - report::{Concern, PrConcern}, - salsa, F64, -}; -use std::collections::{HashMap, HashSet}; +use crate::analysis::metric::affiliation::AffiliatedType; +use crate::analysis::metric::MetricProvider; +use crate::config::AttacksConfigQuery; +use crate::config::CommitConfigQuery; +use crate::config::FuzzConfigQuery; +use crate::config::PracticesConfigQuery; +use crate::data::git::GitProvider; +use crate::error::Error; +use crate::error::Result; +use crate::report::Concern; +use crate::report::PrConcern; +use crate::F64; +use chrono::Duration; +use std::collections::HashMap; +use std::collections::HashSet; use std::default::Default; -use std::fmt::{self, Display, Formatter}; +use std::fmt::Display; +use std::fmt::Formatter; +use std::fmt::{self}; use std::ops::Not; use std::rc::Rc; diff --git a/libs/hc_common/src/analysis/metric/activity.rs b/hipcheck/src/analysis/metric/activity.rs similarity index 87% rename from libs/hc_common/src/analysis/metric/activity.rs rename to hipcheck/src/analysis/metric/activity.rs index da07146f..0669a082 100644 --- a/libs/hc_common/src/analysis/metric/activity.rs +++ b/hipcheck/src/analysis/metric/activity.rs @@ -1,14 +1,15 @@ // SPDX-License-Identifier: Apache-2.0 use crate::analysis::MetricProvider; -use crate::{ - chrono::{prelude::*, Duration}, - context::Context as _, - error::Result, - log, -}; -use serde::{ser::SerializeStruct, Serialize, Serializer}; -use std::{rc::Rc, result::Result as StdResult}; +use crate::context::Context as _; +use crate::error::Result; +use chrono::prelude::*; +use chrono::Duration; +use serde::ser::SerializeStruct; +use serde::Serialize; +use serde::Serializer; +use std::rc::Rc; +use std::result::Result as StdResult; #[derive(Debug, Eq, PartialEq)] pub struct ActivityOutput { diff --git a/libs/hc_common/src/analysis/metric/affiliation.rs b/hipcheck/src/analysis/metric/affiliation.rs similarity index 96% rename from libs/hc_common/src/analysis/metric/affiliation.rs rename to hipcheck/src/analysis/metric/affiliation.rs index 66d50ea9..f265811a 100644 --- a/libs/hc_common/src/analysis/metric/affiliation.rs +++ b/hipcheck/src/analysis/metric/affiliation.rs @@ -1,20 +1,23 @@ // SPDX-License-Identifier: Apache-2.0 use crate::analysis::MetricProvider; -use crate::{ - context::Context as _, - data::git::{Commit, CommitContributorView}, - error::{Error, Result}, - filesystem as file, hc_error, log, -}; -use serde::{ - self, - de::{Error as SerdeError, Visitor}, - Deserialize, Deserializer, Serialize, -}; +use crate::context::Context as _; +use crate::data::git::Commit; +use crate::data::git::CommitContributorView; +use crate::error::Error; +use crate::error::Result; +use crate::filesystem as file; +use crate::hc_error; +use serde::de::Error as SerdeError; +use serde::de::Visitor; +use serde::Deserialize; +use serde::Deserializer; +use serde::Serialize; +use serde::{self}; use std::cell::RefCell; use std::collections::HashMap; -use std::convert::{TryFrom, TryInto}; +use std::convert::TryFrom; +use std::convert::TryInto; use std::fmt; use std::ops::Not as _; use std::path::Path; diff --git a/libs/hc_common/src/analysis/metric/binary.rs b/hipcheck/src/analysis/metric/binary.rs similarity index 91% rename from libs/hc_common/src/analysis/metric/binary.rs rename to hipcheck/src/analysis/metric/binary.rs index 2d7799b6..fb77fddd 100644 --- a/libs/hc_common/src/analysis/metric/binary.rs +++ b/hipcheck/src/analysis/metric/binary.rs @@ -2,8 +2,10 @@ use crate::analysis::metric::binary_detector::detect_binary_files; use crate::analysis::MetricProvider; -use crate::{error::Result, log, TryFilter}; -use serde::{self, Serialize}; +use crate::error::Result; +use crate::TryFilter; +use serde::Serialize; +use serde::{self}; use std::rc::Rc; #[derive(Debug, Eq, PartialEq, Serialize)] diff --git a/libs/hc_common/src/analysis/metric/binary_detector/mod.rs b/hipcheck/src/analysis/metric/binary_detector/mod.rs similarity index 92% rename from libs/hc_common/src/analysis/metric/binary_detector/mod.rs rename to hipcheck/src/analysis/metric/binary_detector/mod.rs index cb8d8206..29dd9fb2 100644 --- a/libs/hc_common/src/analysis/metric/binary_detector/mod.rs +++ b/hipcheck/src/analysis/metric/binary_detector/mod.rs @@ -4,17 +4,26 @@ mod query; pub use query::*; -use crate::{context::Context, error::Result, filesystem::read_toml, hc_error}; -use content_inspector::{inspect, ContentType}; -use serde::{self, de::Visitor, Deserialize, Deserializer}; -use std::fmt::{self, Formatter}; +use crate::context::Context; +use crate::error::Result; +use crate::filesystem::read_toml; +use crate::hc_error; +use content_inspector::inspect; +use content_inspector::ContentType; +use serde::de::Visitor; +use serde::Deserialize; +use serde::Deserializer; +use serde::{self}; +use std::fmt::Formatter; +use std::fmt::{self}; use std::fs::File; use std::io::prelude::Read; use std::io::BufReader; use std::path::Path; use std::rc::Rc; use std::result::Result as StdResult; -use walkdir::{DirEntry, WalkDir}; +use walkdir::DirEntry; +use walkdir::WalkDir; #[derive(Debug, PartialEq, Eq)] pub struct BinaryFileDetector { diff --git a/libs/hc_common/src/analysis/metric/binary_detector/query.rs b/hipcheck/src/analysis/metric/binary_detector/query.rs similarity index 91% rename from libs/hc_common/src/analysis/metric/binary_detector/query.rs rename to hipcheck/src/analysis/metric/binary_detector/query.rs index 9d95c905..e57bb81a 100644 --- a/libs/hc_common/src/analysis/metric/binary_detector/query.rs +++ b/hipcheck/src/analysis/metric/binary_detector/query.rs @@ -3,7 +3,9 @@ //! A query group for binary file detection queries. use crate::analysis::metric::binary_detector::BinaryFileDetector; -use crate::{config::PracticesConfigQuery, context::Context as _, error::Result, salsa}; +use crate::config::PracticesConfigQuery; +use crate::context::Context as _; +use crate::error::Result; use std::rc::Rc; /// Queries related to binary file detection diff --git a/libs/hc_common/src/analysis/metric/churn.rs b/hipcheck/src/analysis/metric/churn.rs similarity index 93% rename from libs/hc_common/src/analysis/metric/churn.rs rename to hipcheck/src/analysis/metric/churn.rs index b61fbdd2..d22b3482 100644 --- a/libs/hc_common/src/analysis/metric/churn.rs +++ b/hipcheck/src/analysis/metric/churn.rs @@ -1,11 +1,17 @@ // SPDX-License-Identifier: Apache-2.0 -use crate::analysis::metric::math::{mean, std_dev}; +use crate::analysis::metric::math::mean; +use crate::analysis::metric::math::std_dev; use crate::analysis::MetricProvider; -use crate::{ - context::Context as _, data::git::Commit, error::Result, hc_error, log, TryAny, TryFilter, F64, -}; -use serde::{self, Serialize}; +use crate::context::Context as _; +use crate::data::git::Commit; +use crate::error::Result; +use crate::hc_error; +use crate::TryAny; +use crate::TryFilter; +use crate::F64; +use serde::Serialize; +use serde::{self}; use std::collections::HashMap; use std::rc::Rc; diff --git a/libs/hc_common/src/analysis/metric/commit_trust.rs b/hipcheck/src/analysis/metric/commit_trust.rs similarity index 94% rename from libs/hc_common/src/analysis/metric/commit_trust.rs rename to hipcheck/src/analysis/metric/commit_trust.rs index 493435c3..b2a0680a 100644 --- a/libs/hc_common/src/analysis/metric/commit_trust.rs +++ b/hipcheck/src/analysis/metric/commit_trust.rs @@ -1,8 +1,10 @@ // SPDX-License-Identifier: Apache-2.0 use crate::analysis::MetricProvider; -use crate::{context::Context as _, error::Result, log}; -use std::{collections::HashMap, rc::Rc}; +use crate::context::Context as _; +use crate::error::Result; +use std::collections::HashMap; +use std::rc::Rc; pub const TRUST_PHASE: &str = "commit trust"; diff --git a/libs/hc_common/src/analysis/metric/contributor_trust.rs b/hipcheck/src/analysis/metric/contributor_trust.rs similarity index 98% rename from libs/hc_common/src/analysis/metric/contributor_trust.rs rename to hipcheck/src/analysis/metric/contributor_trust.rs index 3aace4a8..66d86025 100644 --- a/libs/hc_common/src/analysis/metric/contributor_trust.rs +++ b/hipcheck/src/analysis/metric/contributor_trust.rs @@ -2,8 +2,9 @@ use crate::analysis::MetricProvider; use crate::context::Context as _; -use crate::{error::Result, log}; -use std::{collections::HashMap, rc::Rc}; +use crate::error::Result; +use std::collections::HashMap; +use std::rc::Rc; pub const TRUST_PHASE: &str = "contributor trust"; pub const PR_TRUST_PHASE: &str = "pull request contributor trust"; diff --git a/libs/hc_common/src/analysis/metric/entropy.rs b/hipcheck/src/analysis/metric/entropy.rs similarity index 96% rename from libs/hc_common/src/analysis/metric/entropy.rs rename to hipcheck/src/analysis/metric/entropy.rs index fad27780..ed338280 100644 --- a/libs/hc_common/src/analysis/metric/entropy.rs +++ b/hipcheck/src/analysis/metric/entropy.rs @@ -1,14 +1,19 @@ // SPDX-License-Identifier: Apache-2.0 -use crate::analysis::metric::math::{mean, std_dev}; +use crate::analysis::metric::math::mean; +use crate::analysis::metric::math::std_dev; use crate::analysis::MetricProvider; use crate::context::Context as _; -use crate::{ - data::git::{Commit, CommitDiff, Diff}, - error::Result, - hc_error, log, TryAny, TryFilter, F64, -}; -use serde::{self, Serialize}; +use crate::data::git::Commit; +use crate::data::git::CommitDiff; +use crate::data::git::Diff; +use crate::error::Result; +use crate::hc_error; +use crate::TryAny; +use crate::TryFilter; +use crate::F64; +use serde::Serialize; +use serde::{self}; use std::collections::HashMap; use std::iter::Iterator; use std::ops::Not as _; diff --git a/libs/hc_common/src/analysis/metric/fuzz.rs b/hipcheck/src/analysis/metric/fuzz.rs similarity index 85% rename from libs/hc_common/src/analysis/metric/fuzz.rs rename to hipcheck/src/analysis/metric/fuzz.rs index fa422099..7c1d8bf5 100644 --- a/libs/hc_common/src/analysis/metric/fuzz.rs +++ b/hipcheck/src/analysis/metric/fuzz.rs @@ -2,8 +2,10 @@ use crate::analysis::MetricProvider; use crate::context::Context as _; -use crate::{data::Fuzz, error::Result, log}; -use serde::{self, Serialize}; +use crate::data::Fuzz; +use crate::error::Result; +use serde::Serialize; +use serde::{self}; use std::rc::Rc; #[derive(Debug, Eq, PartialEq, Serialize)] diff --git a/libs/hc_common/src/analysis/metric/identity.rs b/hipcheck/src/analysis/metric/identity.rs similarity index 91% rename from libs/hc_common/src/analysis/metric/identity.rs rename to hipcheck/src/analysis/metric/identity.rs index d569c1e9..c3979f08 100644 --- a/libs/hc_common/src/analysis/metric/identity.rs +++ b/hipcheck/src/analysis/metric/identity.rs @@ -2,8 +2,10 @@ use crate::analysis::MetricProvider; use crate::context::Context as _; -use crate::{data::git::Commit, error::Result, log}; -use serde::{self, Serialize}; +use crate::data::git::Commit; +use crate::error::Result; +use serde::Serialize; +use serde::{self}; use std::rc::Rc; #[derive(Debug, Eq, PartialEq, Serialize)] diff --git a/libs/hc_common/src/analysis/metric/linguist/mod.rs b/hipcheck/src/analysis/metric/linguist/mod.rs similarity index 94% rename from libs/hc_common/src/analysis/metric/linguist/mod.rs rename to hipcheck/src/analysis/metric/linguist/mod.rs index 77be3100..366e3627 100644 --- a/libs/hc_common/src/analysis/metric/linguist/mod.rs +++ b/hipcheck/src/analysis/metric/linguist/mod.rs @@ -5,10 +5,15 @@ mod query; pub use query::*; use crate::context::Context as _; -use crate::{error::Result, filesystem::read_toml, log}; -use serde::{self, de::Visitor, Deserialize, Deserializer}; +use crate::error::Result; +use crate::filesystem::read_toml; +use serde::de::Visitor; +use serde::Deserialize; +use serde::Deserializer; +use serde::{self}; use std::convert::AsRef; -use std::fmt::{self, Formatter}; +use std::fmt::Formatter; +use std::fmt::{self}; use std::path::Path; use std::result::Result as StdResult; diff --git a/libs/hc_common/src/analysis/metric/linguist/query.rs b/hipcheck/src/analysis/metric/linguist/query.rs similarity index 91% rename from libs/hc_common/src/analysis/metric/linguist/query.rs rename to hipcheck/src/analysis/metric/linguist/query.rs index 62808794..d71a4d87 100644 --- a/libs/hc_common/src/analysis/metric/linguist/query.rs +++ b/hipcheck/src/analysis/metric/linguist/query.rs @@ -3,7 +3,9 @@ //! A query group for source file language detection queries. use crate::analysis::metric::linguist::SourceFileDetector; -use crate::{config::LanguagesConfigQuery, context::Context, error::Result, salsa}; +use crate::config::LanguagesConfigQuery; +use crate::context::Context; +use crate::error::Result; use std::rc::Rc; /// Queries related to source file language detection diff --git a/libs/hc_common/src/analysis/metric/math.rs b/hipcheck/src/analysis/metric/math.rs similarity index 100% rename from libs/hc_common/src/analysis/metric/math.rs rename to hipcheck/src/analysis/metric/math.rs diff --git a/libs/hc_common/src/analysis/metric/mod.rs b/hipcheck/src/analysis/metric/mod.rs similarity index 92% rename from libs/hc_common/src/analysis/metric/mod.rs rename to hipcheck/src/analysis/metric/mod.rs index 02b30a01..d8a1d0a7 100644 --- a/libs/hc_common/src/analysis/metric/mod.rs +++ b/hipcheck/src/analysis/metric/mod.rs @@ -19,15 +19,14 @@ pub mod typo; use std::rc::Rc; -use crate::{ - config::{AttacksConfigQuery, CommitConfigQuery}, - data::{ - git::GitProvider, DependenciesProvider, FuzzProvider, ModuleProvider, - PullRequestReviewProvider, - }, - error::Result, - salsa, -}; +use crate::config::AttacksConfigQuery; +use crate::config::CommitConfigQuery; +use crate::data::git::GitProvider; +use crate::data::DependenciesProvider; +use crate::data::FuzzProvider; +use crate::data::ModuleProvider; +use crate::data::PullRequestReviewProvider; +use crate::error::Result; use activity::ActivityOutput; use affiliation::AffiliationOutput; use binary::BinaryOutput; diff --git a/libs/hc_common/src/analysis/metric/module.rs b/hipcheck/src/analysis/metric/module.rs similarity index 87% rename from libs/hc_common/src/analysis/metric/module.rs rename to hipcheck/src/analysis/metric/module.rs index 783b943c..3f5bb75b 100644 --- a/libs/hc_common/src/analysis/metric/module.rs +++ b/hipcheck/src/analysis/metric/module.rs @@ -2,8 +2,10 @@ use crate::analysis::MetricProvider; use crate::context::Context as _; -use crate::{data::ModuleGraph, error::Result, log}; -use serde::{self, Serialize}; +use crate::data::ModuleGraph; +use crate::error::Result; +use serde::Serialize; +use serde::{self}; use std::rc::Rc; #[derive(Debug, Eq, PartialEq, Serialize)] diff --git a/libs/hc_common/src/analysis/metric/module_contributors.rs b/hipcheck/src/analysis/metric/module_contributors.rs similarity index 94% rename from libs/hc_common/src/analysis/metric/module_contributors.rs rename to hipcheck/src/analysis/metric/module_contributors.rs index 000b236c..efbb94ca 100644 --- a/libs/hc_common/src/analysis/metric/module_contributors.rs +++ b/hipcheck/src/analysis/metric/module_contributors.rs @@ -2,13 +2,13 @@ use crate::analysis::MetricProvider; use crate::context::Context as _; -use crate::{ - data::{git::Contributor, Module}, - error::Result, - log, -}; -use serde::{self, Serialize}; -use std::{collections::HashMap, rc::Rc}; +use crate::data::git::Contributor; +use crate::data::Module; +use crate::error::Result; +use serde::Serialize; +use serde::{self}; +use std::collections::HashMap; +use std::rc::Rc; #[derive(Debug, Eq, PartialEq, Serialize)] #[serde(crate = "self::serde")] diff --git a/libs/hc_common/src/analysis/metric/review.rs b/hipcheck/src/analysis/metric/review.rs similarity index 91% rename from libs/hc_common/src/analysis/metric/review.rs rename to hipcheck/src/analysis/metric/review.rs index 1e742199..5a0637bc 100644 --- a/libs/hc_common/src/analysis/metric/review.rs +++ b/hipcheck/src/analysis/metric/review.rs @@ -2,8 +2,10 @@ use crate::analysis::MetricProvider; use crate::context::Context as _; -use crate::{data::PullRequest, error::Result, log}; -use serde::{self, Serialize}; +use crate::data::PullRequest; +use crate::error::Result; +use serde::Serialize; +use serde::{self}; use std::rc::Rc; #[derive(Debug, Eq, PartialEq, Serialize)] diff --git a/libs/hc_common/src/analysis/metric/typo.rs b/hipcheck/src/analysis/metric/typo.rs similarity index 98% rename from libs/hc_common/src/analysis/metric/typo.rs rename to hipcheck/src/analysis/metric/typo.rs index 25b68784..92709633 100644 --- a/libs/hc_common/src/analysis/metric/typo.rs +++ b/hipcheck/src/analysis/metric/typo.rs @@ -2,17 +2,19 @@ use crate::analysis::MetricProvider; use crate::context::Context as _; -use crate::{ - data::{Dependencies, Lang}, - error::Result, - filesystem as file, log, -}; +use crate::data::Dependencies; +use crate::data::Lang; +use crate::error::Result; +use crate::filesystem as file; use maplit::hashmap; -use serde::{self, Deserialize, Serialize}; +use serde::Deserialize; +use serde::Serialize; +use serde::{self}; use std::cmp::Ordering; use std::collections::HashMap; use std::convert::AsRef; -use std::fmt::{self, Display}; +use std::fmt::Display; +use std::fmt::{self}; use std::path::Path; use std::rc::Rc; use std::str; @@ -735,7 +737,7 @@ impl KeyboardLayout { mod test { use super::NameFuzzer; use super::Typo; - use crate::lazy_static::lazy_static; + use lazy_static::lazy_static; macro_rules! test_typos { ( from: $name:ident, to: $to:literal, expected: [ $( $expected:ident ),* ] ) => { diff --git a/libs/hc_common/src/analysis/report_builder.rs b/hipcheck/src/analysis/report_builder.rs similarity index 98% rename from libs/hc_common/src/analysis/report_builder.rs rename to hipcheck/src/analysis/report_builder.rs index 0a001f2f..c2f13801 100644 --- a/libs/hc_common/src/analysis/report_builder.rs +++ b/hipcheck/src/analysis/report_builder.rs @@ -1,14 +1,15 @@ // SPDX-License-Identifier: Apache-2.0 -use crate::analysis::{analysis::AnalysisReport, score::ScoringResults, session::Session}; +use crate::analysis::analysis::AnalysisReport; +use crate::analysis::score::ScoringResults; +use crate::analysis::session::Session; +use crate::config::RiskConfigQuery; +use crate::data::source::SourceQuery; +use crate::error::Error; +use crate::error::Result; +use crate::hc_error; pub use crate::report::*; -use crate::{ - config::RiskConfigQuery, - data::source::SourceQuery, - error::{Error, Result}, - hc_error, log, - version::VersionQuery, -}; +use crate::version::VersionQuery; use std::default::Default; use std::result::Result as StdResult; diff --git a/libs/hc_common/src/analysis/score.rs b/hipcheck/src/analysis/score.rs similarity index 99% rename from libs/hc_common/src/analysis/score.rs rename to hipcheck/src/analysis/score.rs index 48ce27bc..094cbc59 100644 --- a/libs/hc_common/src/analysis/score.rs +++ b/hipcheck/src/analysis/score.rs @@ -1,15 +1,18 @@ // SPDX-License-Identifier: Apache-2.0 -use crate::analysis::{ - analysis::{AnalysisOutcome, AnalysisReport}, - AnalysisProvider, -}; -use crate::{error::Result, hc_error, salsa, shell::Phase}; +use crate::analysis::analysis::AnalysisOutcome; +use crate::analysis::analysis::AnalysisReport; +use crate::analysis::AnalysisProvider; +use crate::error::Result; +use crate::hc_error; +use crate::shell::Phase; use std::default::Default; use std::rc::Rc; -use petgraph::graph::{node_index as n, NodeIndex}; -use petgraph::{prelude::Graph, EdgeDirection::Outgoing}; +use petgraph::graph::node_index as n; +use petgraph::graph::NodeIndex; +use petgraph::prelude::Graph; +use petgraph::EdgeDirection::Outgoing; pub const RISK_PHASE: &str = "risk"; diff --git a/libs/hc_common/src/analysis/session/mod.rs b/hipcheck/src/analysis/session/mod.rs similarity index 92% rename from libs/hc_common/src/analysis/session/mod.rs rename to hipcheck/src/analysis/session/mod.rs index 6e68f29f..78e496d9 100644 --- a/libs/hc_common/src/analysis/session/mod.rs +++ b/hipcheck/src/analysis/session/mod.rs @@ -3,46 +3,59 @@ mod pm; mod spdx; -use crate::analysis::{ - metric::{ - binary_detector::BinaryFileStorage, linguist::LinguistStorage, MetricProviderStorage, - }, - score::ScoringProviderStorage, - AnalysisProviderStorage, -}; +use crate::analysis::metric::binary_detector::BinaryFileStorage; +use crate::analysis::metric::linguist::LinguistStorage; +use crate::analysis::metric::MetricProviderStorage; +use crate::analysis::score::ScoringProviderStorage; +use crate::analysis::AnalysisProviderStorage; +use crate::command_util::DependentProgram; +use crate::config::AttacksConfigQueryStorage; +use crate::config::CommitConfigQueryStorage; +use crate::config::Config; +use crate::config::ConfigSource; +use crate::config::ConfigSourceStorage; +use crate::config::FuzzConfigQueryStorage; +use crate::config::LanguagesConfigQueryStorage; +use crate::config::PracticesConfigQueryStorage; +use crate::config::RiskConfigQueryStorage; use crate::context::Context as _; -use crate::{ - chrono::prelude::*, - command_util::DependentProgram, - config::{ - AttacksConfigQueryStorage, CommitConfigQueryStorage, Config, ConfigSource, - ConfigSourceStorage, FuzzConfigQueryStorage, LanguagesConfigQueryStorage, - PracticesConfigQueryStorage, RiskConfigQueryStorage, - }, - data::{ - git::get_git_version, - git::GitProviderStorage, - npm::get_npm_version, - source::{ - Source, SourceChangeRequest, SourceKind, SourceQuery, SourceQueryStorage, SourceRepo, - }, - CodeQualityProviderStorage, DependenciesProviderStorage, FuzzProviderStorage, - GitHubProviderStorage, ModuleProvider, ModuleProviderStorage, - PullRequestReviewProviderStorage, - }, - error::{Error, Result}, - filesystem::create_dir_all, - hc_error, pathbuf, - report::{Format, ReportParams, ReportParamsStorage}, - salsa, - shell::{Phase, Shell}, - version::{get_version, VersionQuery, VersionQueryStorage}, - HIPCHECK_TOML_FILE, -}; +use crate::data::git::get_git_version; +use crate::data::git::GitProviderStorage; +use crate::data::npm::get_npm_version; +use crate::data::source::Source; +use crate::data::source::SourceChangeRequest; +use crate::data::source::SourceKind; +use crate::data::source::SourceQuery; +use crate::data::source::SourceQueryStorage; +use crate::data::source::SourceRepo; +use crate::data::CodeQualityProviderStorage; +use crate::data::DependenciesProviderStorage; +use crate::data::FuzzProviderStorage; +use crate::data::GitHubProviderStorage; +use crate::data::ModuleProvider; +use crate::data::ModuleProviderStorage; +use crate::data::PullRequestReviewProviderStorage; +use crate::error::Error; +use crate::error::Result; +use crate::filesystem::create_dir_all; +use crate::hc_error; +use crate::pathbuf; +use crate::report::Format; +use crate::report::ReportParams; +use crate::report::ReportParamsStorage; +use crate::shell::Phase; +use crate::shell::Shell; +use crate::version::get_version; +use crate::version::VersionQuery; +use crate::version::VersionQueryStorage; +use crate::HIPCHECK_TOML_FILE; +use chrono::prelude::*; use dotenv::var; -use std::ffi::{OsStr, OsString}; +use std::ffi::OsStr; +use std::ffi::OsString; use std::fmt; -use std::path::{Path, PathBuf}; +use std::path::Path; +use std::path::PathBuf; use std::rc::Rc; use std::result::Result as StdResult; diff --git a/libs/hc_common/src/analysis/session/pm.rs b/hipcheck/src/analysis/session/pm.rs similarity index 98% rename from libs/hc_common/src/analysis/session/pm.rs rename to hipcheck/src/analysis/session/pm.rs index faf1ee79..cfd95334 100644 --- a/libs/hc_common/src/analysis/session/pm.rs +++ b/hipcheck/src/analysis/session/pm.rs @@ -2,17 +2,19 @@ #![allow(dead_code)] use crate::context::Context as _; -use crate::{ - error::{Error, Result}, - hc_error, - serde_json::{self, Value}, - url::{Host, Url}, - CheckKind, EXIT_FAILURE, -}; +use crate::error::Error; +use crate::error::Result; +use crate::hc_error; +use crate::CheckKind; +use crate::EXIT_FAILURE; +use serde_json::Value; use std::cmp::max; use std::cmp::Ordering; use std::process::exit; -use xml::reader::{EventReader, XmlEvent}; +use url::Host; +use url::Url; +use xml::reader::EventReader; +use xml::reader::XmlEvent; //This entire module was largely copied from https://gitlab.mitre.org/software-assurance/repofinder const MAVEN: &str = CheckKind::Maven.name(); @@ -506,8 +508,8 @@ fn is_none_or_empty(s: Option<&str>) -> bool { mod tests { // Note this useful idiom: importing names from outer (for mod tests) scope. use super::*; - use crate::url::Url; use serde_json::json; + use url::Url; #[test] fn test_extract_repo_for_pypi() { diff --git a/libs/hc_common/src/analysis/session/spdx.rs b/hipcheck/src/analysis/session/spdx.rs similarity index 96% rename from libs/hc_common/src/analysis/session/spdx.rs rename to hipcheck/src/analysis/session/spdx.rs index 558d1a73..fdd215e8 100644 --- a/libs/hc_common/src/analysis/session/spdx.rs +++ b/hipcheck/src/analysis/session/spdx.rs @@ -3,9 +3,12 @@ //! Utilities for extracting repository info from SPDX documents. use crate::context::Context as _; -use crate::{error::Result, hc_error, serde_json, url::Url}; +use crate::error::Result; +use crate::hc_error; use spdx_rs::models::SPDX; -use std::ffi::{OsStr, OsString}; +use std::ffi::OsStr; +use std::ffi::OsString; +use url::Url; // The package download location field tag const DLOAD_LOCN_TAG: &str = "PackageDownloadLocation"; diff --git a/libs/hc_common/src/command_util.rs b/hipcheck/src/command_util.rs similarity index 93% rename from libs/hc_common/src/command_util.rs rename to hipcheck/src/command_util.rs index 36c8eb97..ca7e2fd4 100644 --- a/libs/hc_common/src/command_util.rs +++ b/hipcheck/src/command_util.rs @@ -1,181 +1,185 @@ -// SPDX-License-Identifier: Apache-2.0 - -use crate::context::Context as _; -use crate::{error::Result, hc_error, log, semver::Version}; -use once_cell::sync::Lazy; -use regex::Regex; -use std::collections::HashMap; -use std::convert::AsRef; -use std::env; -use std::ffi::OsStr; -use std::fmt::{self, Display, Formatter}; -use std::iter::IntoIterator; - -use DependentProgram::*; - -type VersionMap = HashMap; - -static MIN_VERSIONS: Lazy = Lazy::new(|| { - fn insert_version(hm: &mut VersionMap, program: DependentProgram) { - // SAFETY: The versions in `min_version_str` are known to be valid. - hm.insert(program, Version::parse(program.min_version_str()).unwrap()); - } - - let mut versions = HashMap::new(); - insert_version(&mut versions, EsLint); - insert_version(&mut versions, Git); - insert_version(&mut versions, Npm); - insert_version(&mut versions, ModuleDeps); - versions -}); - -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] -pub enum DependentProgram { - EsLint, - Git, - Npm, - ModuleDeps, -} - -impl DependentProgram { - pub fn check_version(&self, version: &str) -> Result { - let version = parse_version(*self, version)?; - let min_version = self - .min_version() - .ok_or_else(|| hc_error!("failed to get min version for {}", self))?; - - if &version >= min_version { - Ok(true) - } else { - Err(hc_error!( - "{} version is {}; must be >= {}", - self, - version, - min_version - )) - } - } - - pub fn min_version<'v>(&self) -> Option<&'v Version> { - MIN_VERSIONS.get(self) - } - - fn min_version_str(&self) -> &'static str { - match self { - // https://github.com/eslint/eslint/blob/main/CHANGELOG.md - EsLint => "7.0.0", - - // https://github.com/git/git/search?q="flag-goes-here"+in%3Afile+filename%3A*.txt+path%3ADocumentation%2FRelNotes%2F - Git => "2.14.0", - - // https://docs.npmjs.com/cli/v6/commands - Npm => "6.0.0", - - // `module-deps` doesn't report a version number, so we just lie here. - ModuleDeps => "0.0.0", - } - } -} - -impl Display for DependentProgram { - fn fmt(&self, f: &mut Formatter) -> fmt::Result { - let name = match self { - EsLint => "eslint", - Git => "git", - Npm => "npm", - ModuleDeps => "module-deps", - }; - - write!(f, "{}", name) - } -} - -fn parse_version(program: DependentProgram, version: &str) -> Result { - // Typical version strings, at least on MacOS: - // - // - git: `git version 2.30.1 (Apple Git-130)` - // - eslint: `v7.32.0` - // - npm: `6.14.15` - - let re = Regex::new(r"(\d+\.\d+\.\d+)").context("failed to build version regex")?; - - let cap = re - .captures(version) - .ok_or_else(|| hc_error!("failed to capture {} version output", program))?; - - let version = cap - .get(1) - .ok_or_else(|| hc_error!("failed to find a {} version", program))? - .as_str(); - - log::debug!("{} version detected [version='{}']", program, version); - - Ok(Version::parse(version)?) -} - -/// Print command line args as well as commands and args for git commands -pub fn log_git_args(repo_path: &str, args: I, git_path: &str) -where - I: IntoIterator + Copy, - S: AsRef, -{ - let program = Git; - - log::debug!("logging {} CLI args", program); - - for arg in env::args() { - log::debug!("{} CLI environment arg [arg='{}']", program, arg); - } - - log::debug!("{} CLI executable location [path='{}']", program, git_path); - - log::debug!("{} CLI repository location [path='{}']", program, repo_path); - - log_each_arg(args, program); - - log::debug!("done logging {} CLI args", DependentProgram::Git); -} - -/// print command line args as well as commands and args for npm and other non git commands -pub fn log_args(command_path: &str, args: I, program: DependentProgram) -where - I: IntoIterator + Copy, - S: AsRef, -{ - log::debug!("logging {} CLI args", &program); - - // https://doc.rust-lang.org/std/env/fn.args.html - for arg in env::args() { - log::debug!("{} CLI environment arg [arg='{}']", program, arg); - } - - log::debug!( - "{} CLI executable location [path='{}']", - program, - command_path - ); - - log_each_arg(args, program); - - log::debug!("done logging {} CLI args", &program); -} - -pub fn log_each_arg(args: I, program: DependentProgram) -where - I: IntoIterator, - S: AsRef, -{ - for (index, val) in args.into_iter().enumerate() { - let arg_val = val - .as_ref() - .to_str() - .unwrap_or("argument for command could not be logged."); - - log::debug!( - "{} CLI argument [name='{}', value='{}']", - program, - index, - arg_val - ); - } -} +// SPDX-License-Identifier: Apache-2.0 + +use crate::context::Context as _; +use crate::error::Result; +use crate::hc_error; +use once_cell::sync::Lazy; +use regex::Regex; +use semver::Version; +use std::collections::HashMap; +use std::convert::AsRef; +use std::env; +use std::ffi::OsStr; +use std::fmt::Display; +use std::fmt::Formatter; +use std::fmt::{self}; +use std::iter::IntoIterator; + +use DependentProgram::*; + +type VersionMap = HashMap; + +static MIN_VERSIONS: Lazy = Lazy::new(|| { + fn insert_version(hm: &mut VersionMap, program: DependentProgram) { + // SAFETY: The versions in `min_version_str` are known to be valid. + hm.insert(program, Version::parse(program.min_version_str()).unwrap()); + } + + let mut versions = HashMap::new(); + insert_version(&mut versions, EsLint); + insert_version(&mut versions, Git); + insert_version(&mut versions, Npm); + insert_version(&mut versions, ModuleDeps); + versions +}); + +#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +pub enum DependentProgram { + EsLint, + Git, + Npm, + ModuleDeps, +} + +impl DependentProgram { + pub fn check_version(&self, version: &str) -> Result { + let version = parse_version(*self, version)?; + let min_version = self + .min_version() + .ok_or_else(|| hc_error!("failed to get min version for {}", self))?; + + if &version >= min_version { + Ok(true) + } else { + Err(hc_error!( + "{} version is {}; must be >= {}", + self, + version, + min_version + )) + } + } + + pub fn min_version<'v>(&self) -> Option<&'v Version> { + MIN_VERSIONS.get(self) + } + + fn min_version_str(&self) -> &'static str { + match self { + // https://github.com/eslint/eslint/blob/main/CHANGELOG.md + EsLint => "7.0.0", + + // https://github.com/git/git/search?q="flag-goes-here"+in%3Afile+filename%3A*.txt+path%3ADocumentation%2FRelNotes%2F + Git => "2.14.0", + + // https://docs.npmjs.com/cli/v6/commands + Npm => "6.0.0", + + // `module-deps` doesn't report a version number, so we just lie here. + ModuleDeps => "0.0.0", + } + } +} + +impl Display for DependentProgram { + fn fmt(&self, f: &mut Formatter) -> fmt::Result { + let name = match self { + EsLint => "eslint", + Git => "git", + Npm => "npm", + ModuleDeps => "module-deps", + }; + + write!(f, "{}", name) + } +} + +fn parse_version(program: DependentProgram, version: &str) -> Result { + // Typical version strings, at least on MacOS: + // + // - git: `git version 2.30.1 (Apple Git-130)` + // - eslint: `v7.32.0` + // - npm: `6.14.15` + + let re = Regex::new(r"(\d+\.\d+\.\d+)").context("failed to build version regex")?; + + let cap = re + .captures(version) + .ok_or_else(|| hc_error!("failed to capture {} version output", program))?; + + let version = cap + .get(1) + .ok_or_else(|| hc_error!("failed to find a {} version", program))? + .as_str(); + + log::debug!("{} version detected [version='{}']", program, version); + + Ok(Version::parse(version)?) +} + +/// Print command line args as well as commands and args for git commands +pub fn log_git_args(repo_path: &str, args: I, git_path: &str) +where + I: IntoIterator + Copy, + S: AsRef, +{ + let program = Git; + + log::debug!("logging {} CLI args", program); + + for arg in env::args() { + log::debug!("{} CLI environment arg [arg='{}']", program, arg); + } + + log::debug!("{} CLI executable location [path='{}']", program, git_path); + + log::debug!("{} CLI repository location [path='{}']", program, repo_path); + + log_each_arg(args, program); + + log::debug!("done logging {} CLI args", DependentProgram::Git); +} + +/// print command line args as well as commands and args for npm and other non git commands +pub fn log_args(command_path: &str, args: I, program: DependentProgram) +where + I: IntoIterator + Copy, + S: AsRef, +{ + log::debug!("logging {} CLI args", &program); + + // https://doc.rust-lang.org/std/env/fn.args.html + for arg in env::args() { + log::debug!("{} CLI environment arg [arg='{}']", program, arg); + } + + log::debug!( + "{} CLI executable location [path='{}']", + program, + command_path + ); + + log_each_arg(args, program); + + log::debug!("done logging {} CLI args", &program); +} + +pub fn log_each_arg(args: I, program: DependentProgram) +where + I: IntoIterator, + S: AsRef, +{ + for (index, val) in args.into_iter().enumerate() { + let arg_val = val + .as_ref() + .to_str() + .unwrap_or("argument for command could not be logged."); + + log::debug!( + "{} CLI argument [name='{}', value='{}']", + program, + index, + arg_val + ); + } +} diff --git a/libs/hc_common/src/config.rs b/hipcheck/src/config.rs similarity index 98% rename from libs/hc_common/src/config.rs rename to hipcheck/src/config.rs index 5a53b9cc..dccbe005 100644 --- a/libs/hc_common/src/config.rs +++ b/hipcheck/src/config.rs @@ -2,11 +2,18 @@ //! Defines the configuration file format. -use crate::{ - context::Context, error::Result, filesystem as file, pathbuf, salsa, BINARY_CONFIG_FILE, F64, - LANGS_FILE, ORGS_FILE, TYPO_FILE, -}; -use serde::{self, Deserialize, Serialize}; +use crate::context::Context; +use crate::error::Result; +use crate::filesystem as file; +use crate::pathbuf; +use crate::BINARY_CONFIG_FILE; +use crate::F64; +use crate::LANGS_FILE; +use crate::ORGS_FILE; +use crate::TYPO_FILE; +use serde::Deserialize; +use serde::Serialize; +use serde::{self}; use smart_default::SmartDefault; use std::default::Default; use std::path::Path; @@ -419,9 +426,12 @@ pub struct FuzzConfig { /// Inner module for deserialization helpers. mod de { - use super::serde::de::{self, Deserializer, Visitor}; + use super::serde::de::Deserializer; + use super::serde::de::Visitor; + use super::serde::de::{self}; use super::F64; - use std::fmt::{self, Formatter}; + use std::fmt::Formatter; + use std::fmt::{self}; /// Deserialize a float, ensuring it's between 0.0 and 1.0 inclusive. pub(super) fn percent<'de, D>(deserializer: D) -> Result diff --git a/libs/hc_common/src/context.rs b/hipcheck/src/context.rs similarity index 95% rename from libs/hc_common/src/context.rs rename to hipcheck/src/context.rs index e1c6d0b9..2cce5058 100644 --- a/libs/hc_common/src/context.rs +++ b/hipcheck/src/context.rs @@ -3,7 +3,8 @@ //! A duplicate of the `anyhow::Context` extension trait intended to //! make error propagation less verbose. -use crate::error::{Error, Introspect}; +use crate::error::Error; +use crate::error::Introspect; use std::error::Error as StdError; /// Functions for adding context to an error result @@ -69,7 +70,8 @@ where // Restricts implementations of `Context` only to those contained in // this module mod sealed { - use super::{Error, StdError}; + use super::Error; + use super::StdError; pub trait Sealed {} diff --git a/libs/hc_common/src/data.rs b/hipcheck/src/data.rs similarity index 96% rename from libs/hc_common/src/data.rs rename to hipcheck/src/data.rs index 0d4f9432..1a088836 100644 --- a/libs/hc_common/src/data.rs +++ b/hipcheck/src/data.rs @@ -16,13 +16,22 @@ pub mod source; pub use query::*; use std::collections::HashSet; -use crate::{context::Context, error::Error, error::Result, hc_error, log, pathbuf}; -use git::{get_commits_for_file, Commit, CommitContributor, Contributor, Diff}; +use crate::context::Context; +use crate::error::Error; +use crate::error::Result; +use crate::hc_error; +use crate::pathbuf; +use git::get_commits_for_file; +use git::Commit; +use git::CommitContributor; +use git::Contributor; +use git::Diff; use github::*; use modules::RawModule; use petgraph::visit::Dfs; use petgraph::Graph; -use serde::{self, Serialize}; +use serde::Serialize; +use serde::{self}; use std::path::Path; use std::rc::Rc; @@ -207,6 +216,7 @@ pub fn get_single_pull_request_review_from_github( // Module structs/enums +#[allow(unused)] #[derive(Debug, PartialEq, Eq, Copy, Clone, Serialize)] #[serde(crate = "self::serde")] pub enum Relationship { diff --git a/libs/hc_common/src/data/code_quality.rs b/hipcheck/src/data/code_quality.rs similarity index 92% rename from libs/hc_common/src/data/code_quality.rs rename to hipcheck/src/data/code_quality.rs index da472e6e..04f573ae 100644 --- a/libs/hc_common/src/data/code_quality.rs +++ b/hipcheck/src/data/code_quality.rs @@ -1,10 +1,13 @@ // SPDX-License-Identifier: Apache-2.0 -use std::path::{Path, PathBuf}; +use std::path::Path; +use std::path::PathBuf; -use crate::data::es_lint::data::{ESLintMessage, ESLintReports}; +use crate::data::es_lint::data::ESLintMessage; +use crate::data::es_lint::data::ESLintReports; use crate::data::es_lint::get_eslint_reports; -use crate::{error::Result, hc_error}; +use crate::error::Result; +use crate::hc_error; pub type CodeQualityReport = Vec; diff --git a/libs/hc_common/src/data/es_lint/command.rs b/hipcheck/src/data/es_lint/command.rs similarity index 91% rename from libs/hc_common/src/data/es_lint/command.rs rename to hipcheck/src/data/es_lint/command.rs index 576e424d..4fb4ba51 100644 --- a/libs/hc_common/src/data/es_lint/command.rs +++ b/hipcheck/src/data/es_lint/command.rs @@ -3,12 +3,11 @@ use std::ffi::OsStr; use std::process::Command; -use crate::{ - command_util::{log_args, DependentProgram}, - context::Context as _, - error::Result, - hc_error, log, which, -}; +use crate::command_util::log_args; +use crate::command_util::DependentProgram; +use crate::context::Context as _; +use crate::error::Result; +use crate::hc_error; #[derive(Debug)] pub struct ESLintCommand { diff --git a/libs/hc_common/src/data/es_lint/data.rs b/hipcheck/src/data/es_lint/data.rs similarity index 94% rename from libs/hc_common/src/data/es_lint/data.rs rename to hipcheck/src/data/es_lint/data.rs index 5e03b9e4..fc5b6c4a 100644 --- a/libs/hc_common/src/data/es_lint/data.rs +++ b/hipcheck/src/data/es_lint/data.rs @@ -4,7 +4,12 @@ /// https://eslint.org/docs/user-guide/formatters/#json /// /// This parser has been tested with the output from ESLint v7.31.0 -use serde::{self, Deserialize}; +use serde::Deserialize; +/// ESLint's JSON output is demonstrated here: +/// https://eslint.org/docs/user-guide/formatters/#json +/// +/// This parser has been tested with the output from ESLint v7.31.0 +use serde::{self}; pub type ESLintReports = Vec; @@ -43,7 +48,6 @@ pub struct ESLintMessage { #[cfg(test)] mod test { use super::*; - use crate::serde_json; #[test] fn parse_message() { diff --git a/libs/hc_common/src/data/es_lint/mod.rs b/hipcheck/src/data/es_lint/mod.rs similarity index 97% rename from libs/hc_common/src/data/es_lint/mod.rs rename to hipcheck/src/data/es_lint/mod.rs index 8c9e54f7..cfa80f13 100644 --- a/libs/hc_common/src/data/es_lint/mod.rs +++ b/hipcheck/src/data/es_lint/mod.rs @@ -3,9 +3,11 @@ use std::ffi::OsStr; use std::path::Path; -use crate::{context::Context as _, error::Result, semver::Version, serde_json}; +use crate::context::Context as _; +use crate::error::Result; use command::ESLintCommand; use data::ESLintReports; +use semver::Version; pub mod command; pub mod data; diff --git a/libs/hc_common/src/data/git/data.rs b/hipcheck/src/data/git/data.rs similarity index 96% rename from libs/hc_common/src/data/git/data.rs rename to hipcheck/src/data/git/data.rs index 2eb8c475..70ca33d3 100644 --- a/libs/hc_common/src/data/git/data.rs +++ b/hipcheck/src/data/git/data.rs @@ -1,8 +1,13 @@ // SPDX-License-Identifier: Apache-2.0 -use crate::chrono::{DateTime, FixedOffset}; -use serde::{self, Deserialize, Serialize}; -use std::fmt::{self, Display, Formatter}; +use chrono::DateTime; +use chrono::FixedOffset; +use serde::Deserialize; +use serde::Serialize; +use serde::{self}; +use std::fmt::Display; +use std::fmt::Formatter; +use std::fmt::{self}; use std::rc::Rc; /// Commits as they come directly out of `git log`. diff --git a/libs/hc_common/src/data/git/mod.rs b/hipcheck/src/data/git/mod.rs similarity index 96% rename from libs/hc_common/src/data/git/mod.rs rename to hipcheck/src/data/git/mod.rs index ede0afea..47de9162 100644 --- a/libs/hc_common/src/data/git/mod.rs +++ b/hipcheck/src/data/git/mod.rs @@ -8,12 +8,10 @@ pub use data::*; use parse::*; pub use query::*; +use crate::context::Context as _; pub use crate::data::git_command::*; -use crate::{ - context::Context as _, - error::{Error, Result}, - log, -}; +use crate::error::Error; +use crate::error::Result; use std::path::Path; pub fn get_git_version() -> Result { @@ -62,6 +60,7 @@ pub fn get_commits_from_date(repo: &Path, date: &str) -> Result> git_log(&raw_output) } +#[allow(unused)] pub fn get_last_commit(repo: &Path) -> Result { let mut raw_commits = get_commits(repo)?; diff --git a/libs/hc_common/src/data/git/parse.rs b/hipcheck/src/data/git/parse.rs similarity index 97% rename from libs/hc_common/src/data/git/parse.rs rename to hipcheck/src/data/git/parse.rs index 3fa8d369..e95f6a36 100644 --- a/libs/hc_common/src/data/git/parse.rs +++ b/hipcheck/src/data/git/parse.rs @@ -2,22 +2,34 @@ #![allow(dead_code)] -use crate::data::git::{Contributor, Diff, FileDiff, RawCommit}; -use crate::{ - chrono::{DateTime, FixedOffset}, - context::Context as _, - error::{Error, Result}, - log, -}; -use nom::{ - branch::alt, - character::complete::{char as character, digit1, not_line_ending, one_of, space1}, - combinator::{opt, peek, recognize}, - error::{Error as NomError, ErrorKind}, - multi::{fold_many0, many0, many1, many_m_n}, - sequence::{preceded, terminated, tuple}, - IResult, -}; +use crate::context::Context as _; +use crate::data::git::Contributor; +use crate::data::git::Diff; +use crate::data::git::FileDiff; +use crate::data::git::RawCommit; +use crate::error::Error; +use crate::error::Result; +use chrono::DateTime; +use chrono::FixedOffset; +use nom::branch::alt; +use nom::character::complete::char as character; +use nom::character::complete::digit1; +use nom::character::complete::not_line_ending; +use nom::character::complete::one_of; +use nom::character::complete::space1; +use nom::combinator::opt; +use nom::combinator::peek; +use nom::combinator::recognize; +use nom::error::Error as NomError; +use nom::error::ErrorKind; +use nom::multi::fold_many0; +use nom::multi::many0; +use nom::multi::many1; +use nom::multi::many_m_n; +use nom::sequence::preceded; +use nom::sequence::terminated; +use nom::sequence::tuple; +use nom::IResult; use std::iter::Iterator; use std::rc::Rc; use std::result::Result as StdResult; diff --git a/libs/hc_common/src/data/git/query/impls.rs b/hipcheck/src/data/git/query/impls.rs similarity index 94% rename from libs/hc_common/src/data/git/query/impls.rs rename to hipcheck/src/data/git/query/impls.rs index 6aedfd6b..6c277689 100644 --- a/libs/hc_common/src/data/git/query/impls.rs +++ b/hipcheck/src/data/git/query/impls.rs @@ -3,16 +3,27 @@ //! Derived query implementations for the `GitProvider` query group. use super::GitProvider; -use crate::data::git::{ - get_commits, get_commits_from_date, get_diffs, Commit, CommitContributor, - CommitContributorView, CommitDiff, CommitSigner, CommitSignerView, Contributor, - ContributorView, Diff, GitCommand, RawCommit, SignerKeyView, SignerNameView, SignerView, -}; -use crate::{ - chrono::prelude::*, - context::Context, - error::{Error, Result}, -}; +use crate::context::Context; +use crate::data::git::get_commits; +use crate::data::git::get_commits_from_date; +use crate::data::git::get_diffs; +use crate::data::git::Commit; +use crate::data::git::CommitContributor; +use crate::data::git::CommitContributorView; +use crate::data::git::CommitDiff; +use crate::data::git::CommitSigner; +use crate::data::git::CommitSignerView; +use crate::data::git::Contributor; +use crate::data::git::ContributorView; +use crate::data::git::Diff; +use crate::data::git::GitCommand; +use crate::data::git::RawCommit; +use crate::data::git::SignerKeyView; +use crate::data::git::SignerNameView; +use crate::data::git::SignerView; +use crate::error::Error; +use crate::error::Result; +use chrono::prelude::*; use std::rc::Rc; pub(crate) fn raw_commits(db: &dyn GitProvider) -> Result>> { diff --git a/libs/hc_common/src/data/git/query/mod.rs b/hipcheck/src/data/git/query/mod.rs similarity index 85% rename from libs/hc_common/src/data/git/query/mod.rs rename to hipcheck/src/data/git/query/mod.rs index 70d59ea9..58b8e695 100644 --- a/libs/hc_common/src/data/git/query/mod.rs +++ b/hipcheck/src/data/git/query/mod.rs @@ -4,15 +4,23 @@ mod impls; -use crate::data::{ - git::{ - Commit, CommitContributor, CommitContributorView, CommitDiff, CommitSigner, - CommitSignerView, Contributor, ContributorView, Diff, RawCommit, SignerKeyView, - SignerNameView, SignerView, - }, - source::SourceQuery, -}; -use crate::{chrono::prelude::*, error::Result, salsa, version::VersionQuery}; +use crate::data::git::Commit; +use crate::data::git::CommitContributor; +use crate::data::git::CommitContributorView; +use crate::data::git::CommitDiff; +use crate::data::git::CommitSigner; +use crate::data::git::CommitSignerView; +use crate::data::git::Contributor; +use crate::data::git::ContributorView; +use crate::data::git::Diff; +use crate::data::git::RawCommit; +use crate::data::git::SignerKeyView; +use crate::data::git::SignerNameView; +use crate::data::git::SignerView; +use crate::data::source::SourceQuery; +use crate::error::Result; +use crate::version::VersionQuery; +use chrono::prelude::*; use std::rc::Rc; /// Queries about Git objects diff --git a/libs/hc_common/src/data/git_command.rs b/hipcheck/src/data/git_command.rs similarity index 94% rename from libs/hc_common/src/data/git_command.rs rename to hipcheck/src/data/git_command.rs index 52b59d7a..113b6802 100644 --- a/libs/hc_common/src/data/git_command.rs +++ b/hipcheck/src/data/git_command.rs @@ -1,6 +1,9 @@ // SPDX-License-Identifier: Apache-2.0 -use crate::{command_util::log_git_args, context::Context as _, error::Result, hc_error, which}; +use crate::command_util::log_git_args; +use crate::context::Context as _; +use crate::error::Result; +use crate::hc_error; use std::convert::AsRef; use std::ffi::OsStr; use std::iter::IntoIterator; diff --git a/libs/hc_common/src/data/github/authenticated_agent.rs b/hipcheck/src/data/github/authenticated_agent.rs similarity index 97% rename from libs/hc_common/src/data/github/authenticated_agent.rs rename to hipcheck/src/data/github/authenticated_agent.rs index b3bd1af5..e6544b79 100644 --- a/libs/hc_common/src/data/github/authenticated_agent.rs +++ b/hipcheck/src/data/github/authenticated_agent.rs @@ -1,7 +1,8 @@ //! Defines an authenticated [`Agent`] type that adds token auth to all requests. use crate::data::github::hidden::Hidden; -use ureq::{Agent, Request}; +use ureq::Agent; +use ureq::Request; /// An [`Agent`] which authenticates requests with token auth. /// diff --git a/libs/hc_common/src/data/github/code_search.rs b/hipcheck/src/data/github/code_search.rs similarity index 94% rename from libs/hc_common/src/data/github/code_search.rs rename to hipcheck/src/data/github/code_search.rs index b8ecbf85..a51c7a12 100644 --- a/libs/hc_common/src/data/github/code_search.rs +++ b/hipcheck/src/data/github/code_search.rs @@ -1,11 +1,10 @@ // SPDX-License-Identifier: Apache-2.0 use crate::data::github::authenticated_agent::AuthenticatedAgent; -use crate::{ - error::{Error, Result}, - hc_error, - serde_json::Value, -}; +use crate::error::Error; +use crate::error::Result; +use crate::hc_error; +use serde_json::Value; use std::rc::Rc; const GH_API_V4_SEARCH: &str = "https://api.github.com/search/code"; diff --git a/libs/hc_common/src/data/github/data.rs b/hipcheck/src/data/github/data.rs similarity index 88% rename from libs/hc_common/src/data/github/data.rs rename to hipcheck/src/data/github/data.rs index 493e06bf..5750ffec 100644 --- a/libs/hc_common/src/data/github/data.rs +++ b/hipcheck/src/data/github/data.rs @@ -1,6 +1,7 @@ // SPDX-License-Identifier: Apache-2.0 -use crate::data::git::{Diff, RawCommit}; +use crate::data::git::Diff; +use crate::data::git::RawCommit; use serde::Deserialize; #[derive(Debug, Deserialize)] diff --git a/libs/hc_common/src/data/github/gh_query.graphql b/hipcheck/src/data/github/gh_query.graphql similarity index 100% rename from libs/hc_common/src/data/github/gh_query.graphql rename to hipcheck/src/data/github/gh_query.graphql diff --git a/libs/hc_common/src/data/github/gh_schema.graphql b/hipcheck/src/data/github/gh_schema.graphql similarity index 100% rename from libs/hc_common/src/data/github/gh_schema.graphql rename to hipcheck/src/data/github/gh_schema.graphql diff --git a/libs/hc_common/src/data/github/graphql.rs b/hipcheck/src/data/github/graphql.rs similarity index 88% rename from libs/hc_common/src/data/github/graphql.rs rename to hipcheck/src/data/github/graphql.rs index 1d65ad5e..3082523f 100644 --- a/libs/hc_common/src/data/github/graphql.rs +++ b/hipcheck/src/data/github/graphql.rs @@ -2,14 +2,19 @@ use std::convert::TryInto; -use self::reviews::{ResponseData, ReviewsRepositoryPullRequestsNodes as RawPull, Variables}; -use crate::data::github::{authenticated_agent::AuthenticatedAgent, data::*}; -use crate::{ - error::{Error, Result}, - hc_error, - serde_json::{from_value as from_json_value, to_value as to_json_value}, -}; -use graphql_client::{GraphQLQuery, QueryBody, Response}; +use self::reviews::ResponseData; +use self::reviews::ReviewsRepositoryPullRequestsNodes as RawPull; +use self::reviews::Variables; +use crate::data::github::authenticated_agent::AuthenticatedAgent; +use crate::data::github::data::*; +use crate::error::Error; +use crate::error::Result; +use crate::hc_error; +use graphql_client::GraphQLQuery; +use graphql_client::QueryBody; +use graphql_client::Response; +use serde_json::from_value as from_json_value; +use serde_json::to_value as to_json_value; /// The URL of the GitHub GraphQL API. const GH_API_V4: &str = "https://api.github.com/graphql"; diff --git a/libs/hc_common/src/data/github/graphql_pr.rs b/hipcheck/src/data/github/graphql_pr.rs similarity index 91% rename from libs/hc_common/src/data/github/graphql_pr.rs rename to hipcheck/src/data/github/graphql_pr.rs index ac77bb9e..7d7fc294 100644 --- a/libs/hc_common/src/data/github/graphql_pr.rs +++ b/hipcheck/src/data/github/graphql_pr.rs @@ -1,21 +1,23 @@ // SPDX-License-Identifier: Apache-2.0 -use self::review::{ - ResponseData, ReviewRepositoryPullRequest as RawPull, - ReviewRepositoryPullRequestCommitsNodes as RawPullCommit, Variables, -}; -use crate::data::{ - git::{Contributor, RawCommit}, - github::{authenticated_agent::AuthenticatedAgent, data::*}, -}; -use crate::{ - chrono::DateTime, - context::Context, - error::{Error, Result}, - hc_error, - serde_json::{from_value as from_json_value, to_value as to_json_value}, -}; -use graphql_client::{GraphQLQuery, QueryBody, Response}; +use self::review::ResponseData; +use self::review::ReviewRepositoryPullRequest as RawPull; +use self::review::ReviewRepositoryPullRequestCommitsNodes as RawPullCommit; +use self::review::Variables; +use crate::context::Context; +use crate::data::git::Contributor; +use crate::data::git::RawCommit; +use crate::data::github::authenticated_agent::AuthenticatedAgent; +use crate::data::github::data::*; +use crate::error::Error; +use crate::error::Result; +use crate::hc_error; +use chrono::DateTime; +use graphql_client::GraphQLQuery; +use graphql_client::QueryBody; +use graphql_client::Response; +use serde_json::from_value as from_json_value; +use serde_json::to_value as to_json_value; use std::convert::TryFrom; /// The URL of the GitHub GraphQL API. diff --git a/libs/hc_common/src/data/github/hidden.rs b/hipcheck/src/data/github/hidden.rs similarity index 85% rename from libs/hc_common/src/data/github/hidden.rs rename to hipcheck/src/data/github/hidden.rs index 3577f01c..a8de4eeb 100644 --- a/libs/hc_common/src/data/github/hidden.rs +++ b/hipcheck/src/data/github/hidden.rs @@ -1,4 +1,6 @@ -use std::fmt::{Debug, Formatter, Result as FmtResult}; +use std::fmt::Debug; +use std::fmt::Formatter; +use std::fmt::Result as FmtResult; /// Helper container to ensure a value isn't printed. pub struct Hidden(T); diff --git a/libs/hc_common/src/data/github/mod.rs b/hipcheck/src/data/github/mod.rs similarity index 98% rename from libs/hc_common/src/data/github/mod.rs rename to hipcheck/src/data/github/mod.rs index 775a2b92..a07a2208 100644 --- a/libs/hc_common/src/data/github/mod.rs +++ b/hipcheck/src/data/github/mod.rs @@ -14,7 +14,7 @@ use crate::data::github::authenticated_agent::AuthenticatedAgent; use crate::data::github::data::*; use crate::data::github::graphql::get_all_reviews; use crate::data::github::graphql_pr::get_all_pr_reviews; -use crate::{error::Result, log}; +use crate::error::Result; use std::rc::Rc; pub struct GitHub<'a> { diff --git a/libs/hc_common/src/data/hash.rs b/hipcheck/src/data/hash.rs similarity index 94% rename from libs/hc_common/src/data/hash.rs rename to hipcheck/src/data/hash.rs index 0dace2c2..2949a4bd 100644 --- a/libs/hc_common/src/data/hash.rs +++ b/hipcheck/src/data/hash.rs @@ -24,7 +24,8 @@ macro_rules! hash { mod tests { use crate::hash; use std::collections::hash_map::DefaultHasher; - use std::hash::{Hash, Hasher}; + use std::hash::Hash; + use std::hash::Hasher; #[test] fn it_works() { diff --git a/libs/hc_common/src/data/modules.rs b/hipcheck/src/data/modules.rs similarity index 92% rename from libs/hc_common/src/data/modules.rs rename to hipcheck/src/data/modules.rs index c66fd3c0..0597d0e9 100644 --- a/libs/hc_common/src/data/modules.rs +++ b/hipcheck/src/data/modules.rs @@ -1,12 +1,14 @@ // SPDX-License-Identifier: Apache-2.0 -use crate::{ - command_util::{log_args, DependentProgram}, - context::Context as _, - error::{Error, Result}, - hc_error, pathbuf, serde_json, -}; -use serde::{self, Deserialize}; +use crate::command_util::log_args; +use crate::command_util::DependentProgram; +use crate::context::Context as _; +use crate::error::Error; +use crate::error::Result; +use crate::hc_error; +use crate::pathbuf; +use serde::Deserialize; +use serde::{self}; use serde_json::Value as JsonValue; use std::collections::HashMap; use std::convert::AsRef; @@ -14,7 +16,8 @@ use std::ffi::OsStr; use std::fs; use std::iter::IntoIterator; use std::ops::Not as _; -use std::path::{Path, PathBuf}; +use std::path::Path; +use std::path::PathBuf; use std::process::Command; pub fn generate_module_model(repo_dir: &Path, module_deps: &Path) -> Result> { diff --git a/libs/hc_common/src/data/npm.rs b/hipcheck/src/data/npm.rs similarity index 94% rename from libs/hc_common/src/data/npm.rs rename to hipcheck/src/data/npm.rs index 0514bd37..bc1737f0 100644 --- a/libs/hc_common/src/data/npm.rs +++ b/hipcheck/src/data/npm.rs @@ -1,18 +1,24 @@ // SPDX-License-Identifier: Apache-2.0 -use crate::{ - command_util::{log_args, DependentProgram}, - context::Context, - error::Result, - filesystem as file, hc_error, log, pathbuf, which, -}; -use serde::{self, Deserialize}; +use crate::command_util::log_args; +use crate::command_util::DependentProgram; +use crate::context::Context; +use crate::error::Result; +use crate::filesystem as file; +use crate::hc_error; +use crate::pathbuf; +use serde::Deserialize; +use serde::{self}; +use std::collections::HashMap; use std::convert::AsRef; use std::ffi::OsStr; use std::iter::IntoIterator; -use std::path::{Path, PathBuf}; -use std::process::{Child, Command, Stdio}; -use std::{collections::HashMap, ops::Not}; +use std::ops::Not; +use std::path::Path; +use std::path::PathBuf; +use std::process::Child; +use std::process::Command; +use std::process::Stdio; #[derive(Debug, Clone, PartialEq, Eq, Deserialize)] #[serde(crate = "self::serde")] diff --git a/libs/hc_common/src/data/query/code_quality.rs b/hipcheck/src/data/query/code_quality.rs similarity index 80% rename from libs/hc_common/src/data/query/code_quality.rs rename to hipcheck/src/data/query/code_quality.rs index ee311d52..b9e7c1e1 100644 --- a/libs/hc_common/src/data/query/code_quality.rs +++ b/hipcheck/src/data/query/code_quality.rs @@ -4,9 +4,11 @@ use std::rc::Rc; -use crate::data::code_quality::{get_eslint_report, CodeQualityReport}; +use crate::data::code_quality::get_eslint_report; +use crate::data::code_quality::CodeQualityReport; use crate::data::source::SourceQuery; -use crate::{error::Result, salsa, version::VersionQuery}; +use crate::error::Result; +use crate::version::VersionQuery; /// Queries about code quality #[salsa::query_group(CodeQualityProviderStorage)] diff --git a/libs/hc_common/src/data/query/dependencies.rs b/hipcheck/src/data/query/dependencies.rs similarity index 89% rename from libs/hc_common/src/data/query/dependencies.rs rename to hipcheck/src/data/query/dependencies.rs index e4155db4..bb3f102d 100644 --- a/libs/hc_common/src/data/query/dependencies.rs +++ b/hipcheck/src/data/query/dependencies.rs @@ -2,10 +2,12 @@ //! Query group for dependencies information. -use crate::data::npm::{get_package_file, PackageFile}; +use crate::data::npm::get_package_file; +use crate::data::npm::PackageFile; use crate::data::source::SourceQuery; use crate::data::Dependencies; -use crate::{error::Result, salsa, version::VersionQuery}; +use crate::error::Result; +use crate::version::VersionQuery; use std::rc::Rc; /// Queries about dependencies diff --git a/libs/hc_common/src/data/query/fuzz.rs b/hipcheck/src/data/query/fuzz.rs similarity index 86% rename from libs/hc_common/src/data/query/fuzz.rs rename to hipcheck/src/data/query/fuzz.rs index e8907d57..4c1898b7 100644 --- a/libs/hc_common/src/data/query/fuzz.rs +++ b/hipcheck/src/data/query/fuzz.rs @@ -3,12 +3,11 @@ //! Query group for fuzzing checks. use super::github::GitHubProvider; -use crate::data::{get_fuzz_check, Fuzz}; -use crate::{ - config::ConfigSource, - error::{Error, Result}, - log, salsa, -}; +use crate::config::ConfigSource; +use crate::data::get_fuzz_check; +use crate::data::Fuzz; +use crate::error::Error; +use crate::error::Result; /// A query that provides a fuzz check #[salsa::query_group(FuzzProviderStorage)] diff --git a/libs/hc_common/src/data/query/github.rs b/hipcheck/src/data/query/github.rs similarity index 94% rename from libs/hc_common/src/data/query/github.rs rename to hipcheck/src/data/query/github.rs index ab777468..fcb93d63 100644 --- a/libs/hc_common/src/data/query/github.rs +++ b/hipcheck/src/data/query/github.rs @@ -2,11 +2,10 @@ //! Query group for data pertaining to a remote GitHub source. -use crate::data::source::{Remote, SourceQuery}; -use crate::{ - error::{Error, Result}, - salsa, -}; +use crate::data::source::Remote; +use crate::data::source::SourceQuery; +use crate::error::Error; +use crate::error::Result; use std::rc::Rc; /// Queries about a remote GitHub source diff --git a/hipcheck/src/data/query/mod.rs b/hipcheck/src/data/query/mod.rs new file mode 100644 index 00000000..0e5af7df --- /dev/null +++ b/hipcheck/src/data/query/mod.rs @@ -0,0 +1,26 @@ +// SPDX-License-Identifier: Apache-2.0 + +//! A collection of Salsa query groups for accessing the data used in +//! Hipcheck's analyses. + +mod code_quality; +mod dependencies; +mod fuzz; +mod github; +mod module; +mod pr_review; + +#[allow(unused)] +pub use code_quality::CodeQualityProvider; +pub use code_quality::CodeQualityProviderStorage; +pub use dependencies::DependenciesProvider; +pub use dependencies::DependenciesProviderStorage; +pub use fuzz::FuzzProvider; +pub use fuzz::FuzzProviderStorage; +pub use github::GitHubProvider; +pub use github::GitHubProviderStorage; +pub use module::ModuleCommitMap; +pub use module::ModuleProvider; +pub use module::ModuleProviderStorage; +pub use pr_review::PullRequestReviewProvider; +pub use pr_review::PullRequestReviewProviderStorage; diff --git a/libs/hc_common/src/data/query/module.rs b/hipcheck/src/data/query/module.rs similarity index 89% rename from libs/hc_common/src/data/query/module.rs rename to hipcheck/src/data/query/module.rs index 9309dfdc..1d381baf 100644 --- a/libs/hc_common/src/data/query/module.rs +++ b/hipcheck/src/data/query/module.rs @@ -2,18 +2,18 @@ //! Query group for module information. -use std::{path::PathBuf, rc::Rc}; - -use crate::data::{ - associate_modules_and_commits, - git::{Commit, GitProvider}, - Module, ModuleGraph, -}; - -use crate::{ - error::{Error, Result}, - pathbuf, salsa, -}; +use std::path::PathBuf; +use std::rc::Rc; + +use crate::data::associate_modules_and_commits; +use crate::data::git::Commit; +use crate::data::git::GitProvider; +use crate::data::Module; +use crate::data::ModuleGraph; + +use crate::error::Error; +use crate::error::Result; +use crate::pathbuf; /// A module and an associated commit pub type ModuleCommitMap = Rc, Rc)>>; diff --git a/libs/hc_common/src/data/query/pr_review.rs b/hipcheck/src/data/query/pr_review.rs similarity index 90% rename from libs/hc_common/src/data/query/pr_review.rs rename to hipcheck/src/data/query/pr_review.rs index e9a8907d..c8f18935 100644 --- a/libs/hc_common/src/data/query/pr_review.rs +++ b/hipcheck/src/data/query/pr_review.rs @@ -3,17 +3,19 @@ //! Query group for GitHub pull request reviews. use super::github::GitHubProvider; -use crate::data::{ - get_pull_request_reviews_from_github, get_single_pull_request_review_from_github, - git::{Commit, CommitContributorView, CommitDiff, Contributor, ContributorView}, - PullRequest, SinglePullRequest, -}; -use crate::{ - config::ConfigSource, - context::Context, - error::{Error, Result}, - salsa, -}; +use crate::config::ConfigSource; +use crate::context::Context; +use crate::data::get_pull_request_reviews_from_github; +use crate::data::get_single_pull_request_review_from_github; +use crate::data::git::Commit; +use crate::data::git::CommitContributorView; +use crate::data::git::CommitDiff; +use crate::data::git::Contributor; +use crate::data::git::ContributorView; +use crate::data::PullRequest; +use crate::data::SinglePullRequest; +use crate::error::Error; +use crate::error::Result; use std::rc::Rc; /// A query that provides GitHub pull request reviews diff --git a/libs/hc_common/src/data/source/mod.rs b/hipcheck/src/data/source/mod.rs similarity index 98% rename from libs/hc_common/src/data/source/mod.rs rename to hipcheck/src/data/source/mod.rs index c0e03f29..8a863719 100644 --- a/libs/hc_common/src/data/source/mod.rs +++ b/hipcheck/src/data/source/mod.rs @@ -4,20 +4,23 @@ mod query; pub use query::*; +use crate::context::Context; use crate::data::git_command::GitCommand; -use crate::{ - context::Context, - error::{Error, Result}, - hc_error, - log::{self, debug}, - pathbuf, - shell::Phase, - url::Url, -}; +use crate::error::Error; +use crate::error::Result; +use crate::hc_error; +use crate::pathbuf; +use crate::shell::Phase; +use log::debug; use std::ffi::OsStr; -use std::fmt::{self, Debug, Display, Formatter}; +use std::fmt::Debug; +use std::fmt::Display; +use std::fmt::Formatter; +use std::fmt::{self}; use std::fs; -use std::path::{Path, PathBuf}; +use std::path::Path; +use std::path::PathBuf; +use url::Url; // Right now our only subject of analysis is a repository, represented by the // `Source` type. It may optionally include a `Remote` component, in which diff --git a/libs/hc_common/src/data/source/query.rs b/hipcheck/src/data/source/query.rs similarity index 96% rename from libs/hc_common/src/data/source/query.rs rename to hipcheck/src/data/source/query.rs index c489cc5b..6ae6c186 100644 --- a/libs/hc_common/src/data/source/query.rs +++ b/hipcheck/src/data/source/query.rs @@ -2,9 +2,10 @@ //! A query group for accessing Git repository data. -use crate::data::source::{Remote, Source}; +use crate::data::source::Remote; +use crate::data::source::Source; use crate::hash; -use crate::{pathbuf, salsa}; +use crate::pathbuf; use std::path::PathBuf; use std::rc::Rc; diff --git a/libs/hc_common/src/error.rs b/hipcheck/src/error.rs similarity index 98% rename from libs/hc_common/src/error.rs rename to hipcheck/src/error.rs index 1212e2e5..b778e85e 100644 --- a/libs/hc_common/src/error.rs +++ b/hipcheck/src/error.rs @@ -10,10 +10,11 @@ //! which error out aren't retried, as it always compares as equal to //! any other error. -use log; use std::borrow::Cow; use std::error::Error as StdError; -use std::fmt::{self, Debug, Display}; +use std::fmt::Debug; +use std::fmt::Display; +use std::fmt::{self}; use std::rc::Rc; pub type Result = std::result::Result; @@ -75,11 +76,13 @@ impl Error { } } + #[allow(unused)] /// Get the next error in the chain. pub fn source(&self) -> Option<&(dyn StdError + 'static)> { self.head.source() } + #[allow(unused)] /// Get the root error of the chain. pub fn root_cause(&self) -> Error { let mut current = &self.head; diff --git a/libs/hc_common/src/filesystem.rs b/hipcheck/src/filesystem.rs similarity index 95% rename from libs/hc_common/src/filesystem.rs rename to hipcheck/src/filesystem.rs index 1a2d5349..49e21a26 100644 --- a/libs/hc_common/src/filesystem.rs +++ b/hipcheck/src/filesystem.rs @@ -1,9 +1,12 @@ // SPDX-License-Identifier: Apache-2.0 use crate::context::Context as _; -use crate::{error::Result, hc_error, serde_json}; -use serde::{de::DeserializeOwned, Serialize}; -use std::fs::{self, File}; +use crate::error::Result; +use crate::hc_error; +use serde::de::DeserializeOwned; +use serde::Serialize; +use std::fs::File; +use std::fs::{self}; use std::ops::Not; use std::path::Path; @@ -53,6 +56,7 @@ pub fn write, C: AsRef<[u8]>>(path: P, contents: C) -> Result<()> } /// Write JSON to a file. +#[allow(unused)] pub fn write_json, T: ?Sized + Serialize>(path: P, value: &T) -> Result<()> { // The non-generic inner function (NGIF) trick is useless here, since T would still be generic, // so instead we do this conversion up-front to avoid borrowing issues with the `with_context` diff --git a/hipcheck/src/main.rs b/hipcheck/src/main.rs index d85e17a8..13491a0c 100644 --- a/hipcheck/src/main.rs +++ b/hipcheck/src/main.rs @@ -1,21 +1,57 @@ // SPDX-License-Identifier: Apache-2.0 -use clap::{Arg, ArgAction, Command}; -use env_logger::{Builder, Env}; -use hc_common::{ - analysis::session::{Check, CheckType}, - context::Context, - error::Result, - hc_error, print_error, resolve_config, resolve_data, resolve_home, run, - schemars::schema_for, - serde_json, version, AnyReport, CheckKind, ColorChoice, Format, Outcome, Output, PrReport, - Report, Verbosity, -}; +mod analysis; +mod command_util; +mod config; +mod context; +mod data; +mod error; +mod filesystem; +mod pathbuf; +mod report; +mod shell; +mod test_util; +#[cfg(test)] +mod tests; +mod try_any; +mod try_filter; +mod version; + +use crate::analysis::report_builder::build_pr_report; +use crate::analysis::report_builder::build_report; +use crate::analysis::report_builder::AnyReport; +use crate::analysis::report_builder::Format; +use crate::analysis::report_builder::PrReport; +use crate::analysis::report_builder::Report; +use crate::analysis::score::score_pr_results; +use crate::analysis::score::score_results; +use crate::analysis::session::resolve_config; +use crate::analysis::session::resolve_data; +use crate::analysis::session::resolve_home; +use crate::analysis::session::Check; +use crate::analysis::session::CheckType; +use crate::analysis::session::Session; +use crate::context::Context as _; +use crate::error::Error; +use crate::error::Result; +use crate::shell::ColorChoice; +use crate::shell::Output; +use crate::shell::Shell; +use crate::shell::Verbosity; +use clap::Arg; +use clap::ArgAction; +use clap::Command; +use env_logger::Builder; +use env_logger::Env; +use schemars::schema_for; +use std::env; use std::ffi::OsString; +use std::path::Path; use std::path::PathBuf; use std::process::exit; use std::str::FromStr; -use std::{env, path::Path}; +use try_any::TryAny; +use try_filter::TryFilter; /// Entry point for Hipcheck. /// @@ -727,3 +763,233 @@ fn print_missing() -> ! { let exit_code = Outcome::Ok.exit_code(); exit(exit_code) } + +/// An `f64` that is never `NaN`. +type F64 = ordered_float::NotNan; + +// Global variables for toml files per issue 157 config updates +const LANGS_FILE: &str = "Langs.toml"; +const BINARY_CONFIG_FILE: &str = "Binary.toml"; +const TYPO_FILE: &str = "Typos.toml"; +const ORGS_FILE: &str = "Orgs.toml"; +const HIPCHECK_TOML_FILE: &str = "Hipcheck.toml"; + +// Constants for exiting with error codes. +/// Indicates the program failed. +const EXIT_FAILURE: i32 = 1; + +#[allow(unused)] +/// Indicates the program succeeded. +const EXIT_SUCCESS: i32 = 0; + +//used in hc_session::pm and main.rs, global variables for hc check CheckKindHere node-ipc@9.2.1 +enum CheckKind { + Repo, + Request, + Patch, + Maven, + Npm, + Pypi, + Spdx, +} + +impl CheckKind { + const fn name(&self) -> &'static str { + match self { + CheckKind::Repo => "repo", + CheckKind::Request => "request", + CheckKind::Patch => "patch", + CheckKind::Maven => "maven", + CheckKind::Npm => "npm", + CheckKind::Pypi => "pypi", + CheckKind::Spdx => "spdx", + } + } +} + +/// Run Hipcheck. +/// +/// Parses arguments, sets up shell output, and then runs the main logic. +#[allow(clippy::too_many_arguments)] +fn run( + output: Output, + error_output: Output, + verbosity: Verbosity, + check: Check, + config_path: Option, + data_path: Option, + home_dir: Option, + format: Format, + raw_version: &str, +) -> (Shell, Result) { + // Setup wrapper for shell output. + let shell = Shell::new(output, error_output, verbosity); + + // Run and print / report errors. + run_with_shell( + shell, + check, + config_path, + data_path, + home_dir, + format, + raw_version, + ) +} + +// This is for testing purposes. +/// Now that we're fully-initialized, run Hipcheck's analyses. +#[allow(clippy::too_many_arguments)] +#[doc(hidden)] +fn run_with_shell( + shell: Shell, + check: Check, + config_path: Option, + data_path: Option, + home_dir: Option, + format: Format, + raw_version: &str, +) -> (Shell, Result) { + // Initialize the session. + let session = match Session::new( + shell, + &check, + &check.check_value, + config_path, + data_path, + home_dir, + format, + raw_version, + ) { + Ok(session) => session, + Err((shell, err)) => return (shell, Err(err)), + }; + + match check.check_type { + CheckType::RepoSource | CheckType::SpdxDocument => { + // Run analyses against a repo and score the results (score calls analyses that call metrics). + let mut phase = match session.shell.phase("analyzing and scoring results") { + Ok(phase) => phase, + Err(err) => return (session.end(), Err(err)), + }; + + let scoring = match score_results(&mut phase, &session) { + Ok(scoring) => scoring, + _ => { + return ( + session.end(), + Err(Error::msg("Trouble scoring and analyzing results")), + ) + } + }; + + match phase.finish() { + Ok(()) => {} + Err(err) => return (session.end(), Err(err)), + }; + + // Build the final report. + let report = + match build_report(&session, &scoring).context("failed to build final report") { + Ok(report) => report, + Err(err) => return (session.end(), Err(err)), + }; + + (session.end(), Ok(AnyReport::Report(report))) + } + CheckType::PackageVersion => { + // Run analyses against a repo and score the results (score calls analyses that call metrics). + let mut phase = match session.shell.phase("analyzing and scoring results") { + Ok(phase) => phase, + Err(err) => return (session.end(), Err(err)), + }; + + let scoring = match score_results(&mut phase, &session) { + Ok(scoring) => scoring, + _ => { + return ( + session.end(), + Err(Error::msg("Trouble scoring and analyzing results")), + ) + } + }; + + match phase.finish() { + Ok(()) => {} + Err(err) => return (session.end(), Err(err)), + }; + + // Build the final report. + let report = + match build_report(&session, &scoring).context("failed to build final report") { + Ok(report) => report, + Err(err) => return (session.end(), Err(err)), + }; + + (session.end(), Ok(AnyReport::Report(report))) + } + CheckType::PrUri => { + // Run analyses against a pull request and score the results (score calls analyses that call metrics). + let mut phase = match session.shell.phase("scoring and analyzing results") { + Ok(phase) => phase, + Err(err) => return (session.end(), Err(err)), + }; + + let score = match score_pr_results(&mut phase, &session) { + Ok(score) => score, + _ => { + return ( + session.end(), + Err(Error::msg("Trouble scoring and analyzing results")), + ) + } + }; + + match phase.finish() { + Ok(()) => {} + Err(err) => return (session.end(), Err(err)), + }; + + // Build the final report. + let pr_report = + match build_pr_report(&session, &score).context("failed to build final report") { + Ok(pr_report) => pr_report, + Err(err) => return (session.end(), Err(err)), + }; + + (session.end(), Ok(AnyReport::PrReport(pr_report))) + } + _ => ( + session.end(), + Err(Error::msg( + "Hipcheck attempted to analyze an unsupported type", + )), + ), + } +} + +/// Print errors which occur before the `Shell` type can be setup. +fn print_error(err: &Error) { + let mut chain = err.chain(); + + // PANIC: First error is guaranteed to be present. + eprintln!("error: {}", chain.next().unwrap()); + + for err in chain { + eprintln!(" {}", err); + } +} + +enum Outcome { + Ok, + Err, +} + +impl Outcome { + fn exit_code(&self) -> i32 { + match self { + Outcome::Ok => 0, + Outcome::Err => 1, + } + } +} diff --git a/libs/hc_common/src/pathbuf.rs b/hipcheck/src/pathbuf.rs similarity index 100% rename from libs/hc_common/src/pathbuf.rs rename to hipcheck/src/pathbuf.rs diff --git a/libs/hc_common/src/report.rs b/hipcheck/src/report.rs similarity index 96% rename from libs/hc_common/src/report.rs rename to hipcheck/src/report.rs index 3c271238..0e15e17d 100644 --- a/libs/hc_common/src/report.rs +++ b/hipcheck/src/report.rs @@ -9,18 +9,21 @@ // The report serves double-duty, because it's both the thing used to print user-friendly // results on the CLI, and the type that's serialized out to JSON for machine-friendly output. -use crate::{ - chrono::prelude::*, - error::{Error, Result}, - hc_error, log, salsa, - schemars::{self, JsonSchema}, - version::VersionQuery, -}; +use crate::error::Error; +use crate::error::Result; +use crate::hc_error; +use crate::version::VersionQuery; +use chrono::prelude::*; use paste::paste; -use serde::{Serialize, Serializer}; +use schemars::JsonSchema; +use serde::Serialize; +use serde::Serializer; use std::default::Default; -use std::fmt::{self, Display, Formatter}; -use std::hash::{Hash, Hasher}; +use std::fmt::Display; +use std::fmt::Formatter; +use std::fmt::{self}; +use std::hash::Hash; +use std::hash::Hasher; use std::iter::Iterator; use std::ops::Not as _; use std::rc::Rc; @@ -54,7 +57,7 @@ pub enum AnyReport { /// The report output to the user. #[derive(Debug, Serialize, JsonSchema)] -#[schemars(crate = "self::schemars")] +#[schemars(crate = "schemars")] pub struct Report { /// The name of the repository being analyzed. pub repo_name: Rc, @@ -126,7 +129,7 @@ impl Report { /// An analysis which passed. #[derive(Debug, Serialize, JsonSchema)] #[serde(transparent)] -#[schemars(crate = "self::schemars")] +#[schemars(crate = "schemars")] pub struct PassingAnalysis( /// The analysis which passed. Analysis, @@ -140,7 +143,7 @@ impl PassingAnalysis { /// An analysis which failed, including potential specific concerns. #[derive(Debug, Serialize, JsonSchema)] -#[schemars(crate = "self::schemars")] +#[schemars(crate = "schemars")] pub struct FailingAnalysis { /// The analysis. #[serde(flatten)] @@ -219,7 +222,7 @@ fn no_concerns(concerns: &[Concern]) -> bool { /// An analysis that did _not_ succeed. #[derive(Debug, Serialize, JsonSchema)] -#[schemars(crate = "self::schemars")] +#[schemars(crate = "schemars")] pub struct ErroredAnalysis { analysis: AnalysisIdent, error: ErrorReport, @@ -256,7 +259,7 @@ fn try_add_msg(msgs: &mut Vec, error_report: &Option>) /// The name of the analyses. #[derive(Debug, Serialize, JsonSchema)] -#[schemars(crate = "self::schemars")] +#[schemars(crate = "schemars")] pub enum AnalysisIdent { Activity, Affiliation, @@ -291,7 +294,7 @@ impl Display for AnalysisIdent { /// A simple, serializable version of `Error`. #[derive(Debug, Serialize, JsonSchema)] -#[schemars(crate = "self::schemars")] +#[schemars(crate = "schemars")] pub struct ErrorReport { msg: String, #[serde(skip_serializing_if = "source_is_none")] @@ -346,7 +349,7 @@ impl From<&(dyn std::error::Error + 'static)> for ErrorReport { /// An analysis, with score and threshold. #[derive(Debug, Serialize, JsonSchema, Clone, Copy)] #[serde(tag = "analysis")] -#[schemars(crate = "self::schemars")] +#[schemars(crate = "schemars")] pub enum Analysis { /// Activity analysis. Activity { @@ -654,7 +657,7 @@ impl Analysis { /// top-level information. #[derive(Clone, Debug, Serialize, JsonSchema)] #[serde(untagged)] -#[schemars(crate = "self::schemars")] +#[schemars(crate = "schemars")] pub enum Concern { /// Commits with affiliated contributor(s) Affiliation { contributor: String, count: i64 }, @@ -786,7 +789,7 @@ impl Eq for Concern {} /// The pull request report output to the user. #[derive(Debug, Serialize, JsonSchema)] -#[schemars(crate = "self::schemars")] +#[schemars(crate = "schemars")] pub struct PrReport { /// The URI of the pull request being analyzed. pub pr_uri: Rc, @@ -858,7 +861,7 @@ impl PrReport { /// An analysis which passed. #[derive(Debug, Serialize, JsonSchema)] #[serde(transparent)] -#[schemars(crate = "self::schemars")] +#[schemars(crate = "schemars")] pub struct PrPassingAnalysis( /// The analysis which passed. PrAnalysis, @@ -872,7 +875,7 @@ impl PrPassingAnalysis { /// An analysis which failed, including potential specific concerns. #[derive(Debug, Serialize, JsonSchema)] -#[schemars(crate = "self::schemars")] +#[schemars(crate = "schemars")] pub struct PrFailingAnalysis { /// The analysis. #[serde(flatten)] @@ -935,7 +938,7 @@ fn pr_no_concerns(concerns: &[PrConcern]) -> bool { /// An analysis that did _not_ succeed. #[derive(Debug, Serialize, JsonSchema)] -#[schemars(crate = "self::schemars")] +#[schemars(crate = "schemars")] pub struct PrErroredAnalysis { analysis: PrAnalysisIdent, error: ErrorReport, @@ -971,8 +974,9 @@ fn pr_try_add_msg(msgs: &mut Vec, error_report: &Option } /// The name of the analyses. +#[allow(clippy::enum_variant_names)] #[derive(Debug, Serialize, JsonSchema)] -#[schemars(crate = "self::schemars")] +#[schemars(crate = "schemars")] pub enum PrAnalysisIdent { PrAffiliation, PrContributorTrust, @@ -994,9 +998,10 @@ impl Display for PrAnalysisIdent { } /// An analysis, with score and threshold. +#[allow(clippy::enum_variant_names)] #[derive(Debug, Serialize, JsonSchema, Clone, Copy)] #[serde(tag = "analysis")] -#[schemars(crate = "self::schemars")] +#[schemars(crate = "schemars")] pub enum PrAnalysis { /// Pull request affiliation analysis. PrAffiliation { @@ -1143,7 +1148,7 @@ impl PrAnalysis { /// top-level information. #[derive(Clone, Debug, Serialize, JsonSchema)] #[serde(untagged)] -#[schemars(crate = "self::schemars")] +#[schemars(crate = "schemars")] pub enum PrConcern { /// Commits with affiliated contributor(s) PrAffiliation { contributor: String, count: i64 }, @@ -1213,7 +1218,7 @@ impl<'opt, T, E> From<&'opt Option>> for AnalysisResult<&'opt T, /// Value and threshold for counting-based analyses. #[derive(Debug, Serialize, JsonSchema, Clone, Copy)] -#[schemars(crate = "self::schemars")] +#[schemars(crate = "schemars")] pub struct Count { value: u64, threshold: u64, @@ -1221,14 +1226,14 @@ pub struct Count { /// Value for binary-based analyses. #[derive(Debug, Serialize, JsonSchema, Clone, Copy)] -#[schemars(crate = "self::schemars")] +#[schemars(crate = "schemars")] pub struct Exists { value: bool, } /// Value and threshold for percentage-based analyses. #[derive(Debug, Serialize, JsonSchema, Clone, Copy)] -#[schemars(crate = "self::schemars")] +#[schemars(crate = "schemars")] pub struct Percent { value: f64, threshold: f64, @@ -1237,7 +1242,7 @@ pub struct Percent { /// A final recommendation of whether to use or investigate a piece of software, /// including the risk threshold associated with that decision. #[derive(Debug, Serialize, JsonSchema, Clone, Copy)] -#[schemars(crate = "self::schemars")] +#[schemars(crate = "schemars")] pub struct Recommendation { pub kind: RecommendationKind, risk_score: RiskScore, @@ -1266,7 +1271,7 @@ impl Recommendation { /// The kind of recommendation being made. #[derive(Debug, Serialize, JsonSchema, Clone, Copy)] -#[schemars(crate = "self::schemars")] +#[schemars(crate = "schemars")] pub enum RecommendationKind { Pass, Investigate, @@ -1285,18 +1290,18 @@ impl RecommendationKind { /// The overall final risk score for a repo. #[derive(Debug, Serialize, JsonSchema, Clone, Copy)] #[serde(transparent)] -#[schemars(crate = "self::schemars")] +#[schemars(crate = "schemars")] pub struct RiskScore(pub f64); /// The risk threshold configured for the Hipcheck session. #[derive(Debug, Serialize, JsonSchema, Clone, Copy)] #[serde(transparent)] -#[schemars(crate = "self::schemars")] +#[schemars(crate = "schemars")] pub struct RiskThreshold(pub f64); /// A serializable and printable wrapper around a datetime with the local timezone. #[derive(Debug, JsonSchema)] -#[schemars(crate = "self::schemars")] +#[schemars(crate = "schemars")] pub struct Timestamp(DateTime); impl From> for Timestamp { diff --git a/libs/hc_common/src/shell.rs b/hipcheck/src/shell.rs similarity index 98% rename from libs/hc_common/src/shell.rs rename to hipcheck/src/shell.rs index 7bcde02a..ba1f009c 100644 --- a/libs/hc_common/src/shell.rs +++ b/hipcheck/src/shell.rs @@ -84,23 +84,32 @@ #![deny(missing_docs)] -use crate::{ - error::{Error, Result}, - hc_error, log, - report::{Format, PrReport, RecommendationKind, Report}, - serde_json, -}; +use crate::error::Error; +use crate::error::Result; +use crate::hc_error; +use crate::report::Format; +use crate::report::PrReport; +use crate::report::RecommendationKind; +use crate::report::Report; use std::cell::Cell; -use std::fmt::{self, Debug, Formatter}; +use std::fmt::Debug; +use std::fmt::Formatter; +use std::fmt::{self}; use std::io::stderr; use std::io::stdout; use std::io::IsTerminal as _; use std::io::Write; use std::ops::Not as _; use std::str::FromStr; -use std::time::{Duration, Instant}; +use std::time::Duration; +use std::time::Instant; +use termcolor::Color; use termcolor::Color::*; -use termcolor::{self, Color, ColorSpec, NoColor, StandardStream, WriteColor}; +use termcolor::ColorSpec; +use termcolor::NoColor; +use termcolor::StandardStream; +use termcolor::WriteColor; +use termcolor::{self}; /// The interface used throughout Hipcheck to print things out to the user. pub struct Shell { @@ -155,6 +164,7 @@ impl Shell { /// Print the prelude header for Hipcheck's run. pub fn prelude(source: &str) + #[allow(unused)] /// Print a warning to the user. pub fn warn(message: &str) @@ -175,6 +185,7 @@ impl Shell { /// Print the in-progress line for a phase. fn status(msg: &str) + #[allow(unused)] /// Print a warning during a phase. fn warn_in_phase(msg: &str) @@ -767,6 +778,7 @@ impl<'sec, 'desc> Phase<'sec, 'desc> { }) } + #[allow(unused)] /// Warn the user. pub fn warn(&mut self, msg: &str) -> Result<()> { self.shell.warn_in_phase(msg) @@ -821,6 +833,7 @@ impl Output { } } + #[allow(unused)] /// Create a new Output wrapping an arbitrary Write. pub fn from_writer(write: impl Write + 'static) -> Output { Output { @@ -985,11 +998,13 @@ pub enum Verbosity { } impl Verbosity { + #[allow(unused)] /// Check if verbosity is quiet. pub fn is_quiet(&self) -> bool { matches!(self, Verbosity::Quiet) } + #[allow(unused)] /// Check if verbosity is normal. pub fn is_normal(&self) -> bool { matches!(self, Verbosity::Normal) @@ -1523,8 +1538,11 @@ enum TtyWidth { #[cfg(unix)] mod imp { use super::TtyWidth; - use crate::{error::Result, log}; - use libc::{ioctl, winsize, STDOUT_FILENO, TIOCGWINSZ}; + use crate::error::Result; + use libc::ioctl; + use libc::winsize; + use libc::STDOUT_FILENO; + use libc::TIOCGWINSZ; use std::mem::zeroed; use termcolor::WriteColor; @@ -1561,9 +1579,11 @@ mod imp { #[cfg(windows)] mod imp { use super::TtyWidth; - use crate::{error::Result, log}; + use crate::error::Result; + use crate::log; + use std::cmp; use std::mem::zeroed; - use std::{cmp, ptr}; + use std::ptr; use termcolor::WriteColor; use winapi::um::fileapi::*; use winapi::um::handleapi::*; diff --git a/libs/hc_common/src/test_util.rs b/hipcheck/src/test_util.rs similarity index 88% rename from libs/hc_common/src/test_util.rs rename to hipcheck/src/test_util.rs index fe6140ea..de9bec46 100644 --- a/libs/hc_common/src/test_util.rs +++ b/hipcheck/src/test_util.rs @@ -2,11 +2,14 @@ //! Utilities for unit testing. -use std::env::{self, VarError}; -use std::panic::{self, RefUnwindSafe, UnwindSafe}; +use std::env::VarError; +use std::env::{self}; +use std::panic::RefUnwindSafe; +use std::panic::UnwindSafe; +use std::panic::{self}; use std::sync::Mutex; -use crate::lazy_static::lazy_static; +use lazy_static::lazy_static; lazy_static! { static ref SERIAL_TEST: Mutex<()> = Default::default(); @@ -17,6 +20,7 @@ lazy_static! { /// before unwinding the panic. /// /// Credit: Fabian Braun at https://stackoverflow.com/a/67433684 +#[allow(unused)] pub fn with_env_vars(kvs: Vec<(&str, Option<&str>)>, closure: F) where F: Fn() + UnwindSafe + RefUnwindSafe, diff --git a/libs/hc_common/src/tests.rs b/hipcheck/src/tests.rs similarity index 98% rename from libs/hc_common/src/tests.rs rename to hipcheck/src/tests.rs index f87cce31..60eb57f2 100644 --- a/libs/hc_common/src/tests.rs +++ b/hipcheck/src/tests.rs @@ -4,7 +4,8 @@ use crate::error::Error; use crate::hc_error; -use std::io::{self, ErrorKind}; +use std::io::ErrorKind; +use std::io::{self}; // Message source root error with no context #[test] diff --git a/libs/hc_common/src/try_any.rs b/hipcheck/src/try_any.rs similarity index 100% rename from libs/hc_common/src/try_any.rs rename to hipcheck/src/try_any.rs diff --git a/libs/hc_common/src/try_filter.rs b/hipcheck/src/try_filter.rs similarity index 100% rename from libs/hc_common/src/try_filter.rs rename to hipcheck/src/try_filter.rs diff --git a/libs/hc_common/src/version.rs b/hipcheck/src/version.rs similarity index 95% rename from libs/hc_common/src/version.rs rename to hipcheck/src/version.rs index 8876ee90..7d8f357e 100644 --- a/libs/hc_common/src/version.rs +++ b/hipcheck/src/version.rs @@ -1,6 +1,8 @@ // SPDX-License-Identifier: Apache-2.0 -use crate::{context::Context, error::Result, log, salsa, semver::Version}; +use crate::context::Context; +use crate::error::Result; +use semver::Version; use std::ops::Not as _; use std::rc::Rc; diff --git a/libs/hc_common/Cargo.toml b/libs/hc_common/Cargo.toml deleted file mode 100644 index d291b538..00000000 --- a/libs/hc_common/Cargo.toml +++ /dev/null @@ -1,75 +0,0 @@ -[package] -name = "hc_common" -version = "0.1.0" -edition = "2021" -license = "Apache-2.0" -publish = false - -[dependencies] - -content_inspector = "0.2.4" -dotenv = "0.15.0" -curl = "0.4.38" -glob = "0.3.0" -maplit = "1.0.2" -serde_derive = "1.0.137" -spdx-rs = "0.5.0" -unicode-normalization = "0.1.19" -unicode-segmentation = "1.9.0" -walkdir = "2" -xml-rs = "0.8" -chrono = { version = "0.4.19", features = ["serde"] } -lazy_static = "1.4.0" -log = "0.4.16" -once_cell = "1.10.0" -ordered-float = { version = "4.2.0", features = ["serde"] } -paste = "1.0.7" -regex = "1.5.5" -salsa = "0.16.1" -schemars = { version = "0.8.17", default-features = false, features = [ - "derive", - "preserve_order", - "chrono", -] } -semver = "1.0.9" -serde = { version = "1.0.200", features = ["derive", "rc"] } -serde_json = "1.0.80" -smart-default = "0.7.1" -toml = "0.8.12" -url = "2.2.2" -which = { version = "6.0.1", default-features = false } -libc = "0.2.154" -termcolor = "1.1.3" -duct = "0.13.5" -dirs = "5.0.1" -graphql_client = "0.14.0" -nom = "7.1.3" -petgraph = { version = "0.6.0", features = ["serde-1"] } -ureq = { version = "2.9.7", default-features = false, features = [ - "json", - "native-tls", -] } - -[target.'cfg(windows)'.dependencies.winapi] -version = "0.3" -features = ["handleapi", "processenv", "winbase", "wincon", "winnt"] - -[build-dependencies] -anyhow = "1.0.83" -which = { version = "6.0.1", default-features = false } - -[dev-dependencies] -dirs = "5.0.1" -tempfile = "3.10.1" -duct = "0.13.7" -criterion = "0.5.1" - - -[[bench]] -name = "basic" -harness = false -path = "../../benches/basic.rs" - -[[test]] -name = "can_run" -path = "../../tests/can_run.rs" diff --git a/libs/hc_common/src/analysis.rs b/libs/hc_common/src/analysis.rs deleted file mode 100644 index bb575653..00000000 --- a/libs/hc_common/src/analysis.rs +++ /dev/null @@ -1,11 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 - -pub mod analysis; -pub mod metric; -pub mod report_builder; -pub mod score; -pub mod session; - -pub use analysis::{AnalysisProvider, AnalysisProviderStorage}; -pub use metric::{MetricProvider, MetricProviderStorage}; -pub use score::{ScoringProvider, ScoringProviderStorage}; diff --git a/libs/hc_common/src/data/query/mod.rs b/libs/hc_common/src/data/query/mod.rs deleted file mode 100644 index 91eb2b6f..00000000 --- a/libs/hc_common/src/data/query/mod.rs +++ /dev/null @@ -1,18 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 - -//! A collection of Salsa query groups for accessing the data used in -//! Hipcheck's analyses. - -mod code_quality; -mod dependencies; -mod fuzz; -mod github; -mod module; -mod pr_review; - -pub use code_quality::{CodeQualityProvider, CodeQualityProviderStorage}; -pub use dependencies::{DependenciesProvider, DependenciesProviderStorage}; -pub use fuzz::{FuzzProvider, FuzzProviderStorage}; -pub use github::{GitHubProvider, GitHubProviderStorage}; -pub use module::{ModuleCommitMap, ModuleProvider, ModuleProviderStorage}; -pub use pr_review::{PullRequestReviewProvider, PullRequestReviewProviderStorage}; diff --git a/libs/hc_common/src/lib.rs b/libs/hc_common/src/lib.rs deleted file mode 100644 index 4b3e6c04..00000000 --- a/libs/hc_common/src/lib.rs +++ /dev/null @@ -1,279 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 - -//! Provides common access to third-party crates and other -//! functionality used widely throughout Hipcheck. - -pub mod analysis; -pub mod command_util; -pub mod config; -pub mod context; -pub mod data; -pub mod error; -pub mod filesystem; -pub mod pathbuf; -pub mod report; -pub mod shell; -pub mod test_util; -#[cfg(test)] -mod tests; -mod try_any; -mod try_filter; -pub mod version; - -pub use chrono; -pub use lazy_static; -pub use log; -pub use ordered_float; -pub use salsa; -pub use schemars; -pub use semver; -pub use serde_json; -pub use try_any::TryAny; -pub use try_filter::{FallibleFilter, TryFilter}; -pub use url; -pub use which; - -use crate::analysis::{ - report_builder::{build_pr_report, build_report}, - score::{score_pr_results, score_results}, - session::Session, -}; -pub use crate::analysis::{ - report_builder::{AnyReport, Format, PrReport, Report}, - session::{resolve_config, resolve_data, resolve_home, Check, CheckType}, -}; -pub use crate::shell::{ColorChoice, Output, Shell, Verbosity}; -use crate::{ - context::Context as _, - error::{Error, Result}, -}; -use std::path::PathBuf; - -/// An `f64` that is never `NaN`. -pub type F64 = ordered_float::NotNan; - -//Global variables for toml files per issue 157 config updates -pub const LANGS_FILE: &str = "Langs.toml"; -pub const BINARY_CONFIG_FILE: &str = "Binary.toml"; -pub const TYPO_FILE: &str = "Typos.toml"; -pub const ORGS_FILE: &str = "Orgs.toml"; -pub const HIPCHECK_TOML_FILE: &str = "Hipcheck.toml"; - -// Constants for exiting with error codes. -/// Indicates the program failed. -pub const EXIT_FAILURE: i32 = 1; - -/// Indicates the program succeeded. -pub const EXIT_SUCCESS: i32 = 0; - -//used in hc_session::pm and main.rs, global variables for hc check CheckKindHere node-ipc@9.2.1 -pub enum CheckKind { - Repo, - Request, - Patch, - Maven, - Npm, - Pypi, - Spdx, -} - -impl CheckKind { - pub const fn name(&self) -> &'static str { - match self { - CheckKind::Repo => "repo", - CheckKind::Request => "request", - CheckKind::Patch => "patch", - CheckKind::Maven => "maven", - CheckKind::Npm => "npm", - CheckKind::Pypi => "pypi", - CheckKind::Spdx => "spdx", - } - } -} - -/// Run Hipcheck. -/// -/// Parses arguments, sets up shell output, and then runs the main logic. -#[allow(clippy::too_many_arguments)] -pub fn run( - output: Output, - error_output: Output, - verbosity: Verbosity, - check: Check, - config_path: Option, - data_path: Option, - home_dir: Option, - format: Format, - raw_version: &str, -) -> (Shell, Result) { - // Setup wrapper for shell output. - let shell = Shell::new(output, error_output, verbosity); - - // Run and print / report errors. - run_with_shell( - shell, - check, - config_path, - data_path, - home_dir, - format, - raw_version, - ) -} - -// This is pub for testing purposes. -/// Now that we're fully-initialized, run Hipcheck's analyses. -#[allow(clippy::too_many_arguments)] -#[doc(hidden)] -pub fn run_with_shell( - shell: Shell, - check: Check, - config_path: Option, - data_path: Option, - home_dir: Option, - format: Format, - raw_version: &str, -) -> (Shell, Result) { - // Initialize the session. - let session = match Session::new( - shell, - &check, - &check.check_value, - config_path, - data_path, - home_dir, - format, - raw_version, - ) { - Ok(session) => session, - Err((shell, err)) => return (shell, Err(err)), - }; - - match check.check_type { - CheckType::RepoSource | CheckType::SpdxDocument => { - // Run analyses against a repo and score the results (score calls analyses that call metrics). - let mut phase = match session.shell.phase("analyzing and scoring results") { - Ok(phase) => phase, - Err(err) => return (session.end(), Err(err)), - }; - - let scoring = match score_results(&mut phase, &session) { - Ok(scoring) => scoring, - _ => { - return ( - session.end(), - Err(Error::msg("Trouble scoring and analyzing results")), - ) - } - }; - - match phase.finish() { - Ok(()) => {} - Err(err) => return (session.end(), Err(err)), - }; - - // Build the final report. - let report = - match build_report(&session, &scoring).context("failed to build final report") { - Ok(report) => report, - Err(err) => return (session.end(), Err(err)), - }; - - (session.end(), Ok(AnyReport::Report(report))) - } - CheckType::PackageVersion => { - // Run analyses against a repo and score the results (score calls analyses that call metrics). - let mut phase = match session.shell.phase("analyzing and scoring results") { - Ok(phase) => phase, - Err(err) => return (session.end(), Err(err)), - }; - - let scoring = match score_results(&mut phase, &session) { - Ok(scoring) => scoring, - _ => { - return ( - session.end(), - Err(Error::msg("Trouble scoring and analyzing results")), - ) - } - }; - - match phase.finish() { - Ok(()) => {} - Err(err) => return (session.end(), Err(err)), - }; - - // Build the final report. - let report = - match build_report(&session, &scoring).context("failed to build final report") { - Ok(report) => report, - Err(err) => return (session.end(), Err(err)), - }; - - (session.end(), Ok(AnyReport::Report(report))) - } - CheckType::PrUri => { - // Run analyses against a pull request and score the results (score calls analyses that call metrics). - let mut phase = match session.shell.phase("scoring and analyzing results") { - Ok(phase) => phase, - Err(err) => return (session.end(), Err(err)), - }; - - let score = match score_pr_results(&mut phase, &session) { - Ok(score) => score, - _ => { - return ( - session.end(), - Err(Error::msg("Trouble scoring and analyzing results")), - ) - } - }; - - match phase.finish() { - Ok(()) => {} - Err(err) => return (session.end(), Err(err)), - }; - - // Build the final report. - let pr_report = - match build_pr_report(&session, &score).context("failed to build final report") { - Ok(pr_report) => pr_report, - Err(err) => return (session.end(), Err(err)), - }; - - (session.end(), Ok(AnyReport::PrReport(pr_report))) - } - _ => ( - session.end(), - Err(Error::msg( - "Hipcheck attempted to analyze an unsupported type", - )), - ), - } -} - -/// Print errors which occur before the `Shell` type can be setup. -pub fn print_error(err: &Error) { - let mut chain = err.chain(); - - // PANIC: First error is guaranteed to be present. - eprintln!("error: {}", chain.next().unwrap()); - - for err in chain { - eprintln!(" {}", err); - } -} - -pub enum Outcome { - Ok, - Err, -} - -impl Outcome { - pub fn exit_code(&self) -> i32 { - match self { - Outcome::Ok => 0, - Outcome::Err => 1, - } - } -} diff --git a/tests/can_run.rs b/tests/can_run.rs index 1892f28d..a5a312fa 100644 --- a/tests/can_run.rs +++ b/tests/can_run.rs @@ -1,4 +1,5 @@ -use hc_common::{error::Result, CheckKind}; +use hc_common::error::Result; +use hc_common::CheckKind; use hc_core::*; use std::ffi::OsString; use tempfile::tempdir; diff --git a/xtask/Cargo.toml b/xtask/Cargo.toml index d956babb..2e2f3ada 100644 --- a/xtask/Cargo.toml +++ b/xtask/Cargo.toml @@ -7,8 +7,12 @@ edition = "2021" publish = false [dependencies] -hc_common = { path = "../libs/hc_common" } -clap = { version = "4.5.4", default-features = false, features = ["cargo", "std"] } +clap = { version = "4.5.4", default-features = false, features = [ + "cargo", + "std", +] } +anyhow = "1.0.83" +pathbuf = "1.0.0" glob = "0.3.0" serde = { version = "1.0.133", features = ["derive"] } toml = "0.8.12" diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 51bb08e5..0553647a 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -4,10 +4,16 @@ mod exit; mod task; mod workspace; -use crate::exit::{EXIT_FAILURE, EXIT_SUCCESS}; +use crate::exit::EXIT_FAILURE; +use crate::exit::EXIT_SUCCESS; use crate::task::doc::OpenDoc; -use clap::{crate_version, Arg, ArgAction, ArgMatches, Command}; -use hc_common::error::{Error, Result}; +use anyhow::Error; +use anyhow::Result; +use clap::crate_version; +use clap::Arg; +use clap::ArgAction; +use clap::ArgMatches; +use clap::Command; use std::process::exit; fn main() { diff --git a/xtask/src/task/bench.rs b/xtask/src/task/bench.rs index 21e5c882..ed0cfaf5 100644 --- a/xtask/src/task/bench.rs +++ b/xtask/src/task/bench.rs @@ -4,11 +4,10 @@ use crate::exit::EXIT_SUCCESS; use crate::task::ci::Printer; +use anyhow::anyhow as hc_error; +use anyhow::Error; +use anyhow::Result; use duct::cmd; -use hc_common::{ - error::{Error, Result}, - hc_error, -}; use std::io; use std::mem::drop; use std::process::exit; diff --git a/xtask/src/task/ci.rs b/xtask/src/task/ci.rs index 9306d93c..77b7e669 100644 --- a/xtask/src/task/ci.rs +++ b/xtask/src/task/ci.rs @@ -3,12 +3,14 @@ //! A task to simulate a CI run locally. use crate::exit::EXIT_SUCCESS; +use anyhow::anyhow as hc_error; +use anyhow::Error; +use anyhow::Result; use duct::cmd; -use hc_common::{ - error::{Error, Result}, - hc_error, -}; -use std::io::{self, Stderr, Stdout, Write as _}; +use std::io::Stderr; +use std::io::Stdout; +use std::io::Write as _; +use std::io::{self}; use std::mem::drop; use std::ops::Not as _; use std::process::exit; @@ -201,7 +203,7 @@ fn run_fmt(printer: &mut Printer) -> Result<()> { .run() .map(drop) .map_err(reason( - "call to cargo fmt failed. To automatically fix cargo fmt issues most likely due to white space or tab issues, run + "call to cargo fmt failed. To automatically fix cargo fmt issues most likely due to white space or tab issues, run cargo fmt --all", )) } diff --git a/xtask/src/task/doc.rs b/xtask/src/task/doc.rs index 5c1f1f2a..a90b3354 100644 --- a/xtask/src/task/doc.rs +++ b/xtask/src/task/doc.rs @@ -3,11 +3,11 @@ //! A task to simulate a CI run locally. use crate::exit::EXIT_SUCCESS; +use anyhow::anyhow as hc_error; +use anyhow::Error; +use anyhow::Result; use duct::cmd; -use hc_common::{ - error::{Error, Result}, - hc_error, pathbuf, -}; +use pathbuf::pathbuf; use std::io; use std::mem::drop; use std::path::PathBuf; diff --git a/xtask/src/task/install.rs b/xtask/src/task/install.rs index 82deac3e..43024f9c 100644 --- a/xtask/src/task/install.rs +++ b/xtask/src/task/install.rs @@ -3,11 +3,10 @@ //! Installs binaries from the workspace. use crate::exit::EXIT_SUCCESS; +use anyhow::anyhow as hc_error; +use anyhow::Error; +use anyhow::Result; use duct::cmd; -use hc_common::{ - error::{Error, Result}, - hc_error, -}; use std::io; use std::mem::drop; use std::process::exit; diff --git a/xtask/src/task/validate.rs b/xtask/src/task/validate.rs index 25a21a17..d4f8110d 100644 --- a/xtask/src/task/validate.rs +++ b/xtask/src/task/validate.rs @@ -2,20 +2,29 @@ //! Validate the configuration of all Hipcheck crates. -use crate::exit::{EXIT_FAILURE, EXIT_SUCCESS}; +use crate::exit::EXIT_FAILURE; +use crate::exit::EXIT_SUCCESS; use crate::workspace; +use anyhow::anyhow as hc_error; +use anyhow::Context as _; +use anyhow::Result; use glob::glob; -use hc_common::{error::Result, filesystem::read_toml, hc_error, pathbuf}; +use pathbuf::pathbuf; +use serde::de::DeserializeOwned; use serde::Deserialize; -use std::fmt::{self, Debug, Display, Formatter}; +use std::collections::BTreeSet; +use std::fmt::Debug; +use std::fmt::Display; +use std::fmt::Formatter; +use std::fmt::{self}; +use std::fs::File; +use std::fs::{self}; +use std::io::BufRead; +use std::io::BufReader; use std::ops::Not as _; -use std::path::{Path, PathBuf}; +use std::path::Path; +use std::path::PathBuf; use std::process::exit; -use std::{ - collections::BTreeSet, - fs::File, - io::{BufRead, BufReader}, -}; /// Print list of validation failures for crates in the workspace. pub fn run() -> Result<()> { @@ -532,3 +541,21 @@ fn resolve_configs(dir: &Path) -> Result> { Ok(configs) } + +/// Read file to a struct that can be deserialized from TOML format. +fn read_toml, T: DeserializeOwned>(path: P) -> Result { + let path = path.as_ref(); + let contents = read_string(path)?; + toml::de::from_str(&contents) + .with_context(|| format!("failed to read as TOML '{}'", path.display())) +} + +/// Read a file to a string. +fn read_string>(path: P) -> Result { + fn inner(path: &Path) -> Result { + fs::read_to_string(path) + .with_context(|| format!("failed to read as UTF-8 string '{}'", path.display())) + } + + inner(path.as_ref()) +} diff --git a/xtask/src/workspace.rs b/xtask/src/workspace.rs index 964184e9..16277e40 100644 --- a/xtask/src/workspace.rs +++ b/xtask/src/workspace.rs @@ -1,7 +1,9 @@ // SPDX-License-Identifier: Apache-2.0 -use hc_common::{error::Result, hc_error}; -use std::path::{Path, PathBuf}; +use anyhow::anyhow as hc_error; +use anyhow::Result; +use std::path::Path; +use std::path::PathBuf; pub fn root() -> Result { Path::new(&env!("CARGO_MANIFEST_DIR")) From c820c37cff45e49615c40c642a0460bf5dc74524 Mon Sep 17 00:00:00 2001 From: Andrew Lilley Brinker Date: Mon, 6 May 2024 15:42:46 -0700 Subject: [PATCH 09/14] chore: Remove weird `self` imports. It looks like Rustfmt had created some weird `::{self}`-imports. This commit replaces them. Signed-off-by: Andrew Lilley Brinker --- hipcheck/src/analysis/analysis.rs | 2 +- hipcheck/src/analysis/metric/affiliation.rs | 11 ------- hipcheck/src/analysis/metric/binary.rs | 2 -- .../analysis/metric/binary_detector/mod.rs | 5 +--- hipcheck/src/analysis/metric/churn.rs | 3 -- hipcheck/src/analysis/metric/entropy.rs | 3 -- hipcheck/src/analysis/metric/fuzz.rs | 2 -- hipcheck/src/analysis/metric/identity.rs | 3 -- hipcheck/src/analysis/metric/linguist/mod.rs | 5 +--- hipcheck/src/analysis/metric/module.rs | 2 -- .../analysis/metric/module_contributors.rs | 3 -- hipcheck/src/analysis/metric/review.rs | 3 -- hipcheck/src/analysis/metric/typo.rs | 9 +----- hipcheck/src/command_util.rs | 2 +- hipcheck/src/config.rs | 29 +++---------------- hipcheck/src/data.rs | 7 ----- hipcheck/src/data/es_lint/data.rs | 12 ++++---- hipcheck/src/data/git/data.rs | 17 +---------- hipcheck/src/data/modules.rs | 2 -- hipcheck/src/data/npm.rs | 4 --- hipcheck/src/data/source/mod.rs | 2 +- hipcheck/src/error.rs | 2 +- hipcheck/src/filesystem.rs | 2 +- hipcheck/src/report.rs | 2 +- hipcheck/src/shell.rs | 4 +-- hipcheck/src/test_util.rs | 4 +-- hipcheck/src/tests.rs | 2 +- xtask/src/task/ci.rs | 2 +- xtask/src/task/validate.rs | 4 +-- 29 files changed, 27 insertions(+), 123 deletions(-) diff --git a/hipcheck/src/analysis/analysis.rs b/hipcheck/src/analysis/analysis.rs index 28d7aae0..bd90e98a 100644 --- a/hipcheck/src/analysis/analysis.rs +++ b/hipcheck/src/analysis/analysis.rs @@ -16,9 +16,9 @@ use chrono::Duration; use std::collections::HashMap; use std::collections::HashSet; use std::default::Default; +use std::fmt; use std::fmt::Display; use std::fmt::Formatter; -use std::fmt::{self}; use std::ops::Not; use std::rc::Rc; diff --git a/hipcheck/src/analysis/metric/affiliation.rs b/hipcheck/src/analysis/metric/affiliation.rs index f265811a..a77e1e73 100644 --- a/hipcheck/src/analysis/metric/affiliation.rs +++ b/hipcheck/src/analysis/metric/affiliation.rs @@ -13,7 +13,6 @@ use serde::de::Visitor; use serde::Deserialize; use serde::Deserializer; use serde::Serialize; -use serde::{self}; use std::cell::RefCell; use std::collections::HashMap; use std::convert::TryFrom; @@ -25,20 +24,17 @@ use std::rc::Rc; use std::result::Result as StdResult; #[derive(Debug, Eq, PartialEq, Serialize)] -#[serde(crate = "self::serde")] pub struct AffiliationOutput { pub affiliations: Vec, } #[derive(Debug, Eq, PartialEq, Serialize)] -#[serde(crate = "self::serde")] pub struct Affiliation { pub commit: Rc, pub affiliated_type: AffiliatedType, } #[derive(Debug, Eq, PartialEq, Serialize, Clone, Copy)] -#[serde(crate = "self::serde")] pub enum AffiliatedType { Author, Committer, @@ -208,7 +204,6 @@ impl<'haystack> Matcher<'haystack> { /// An overall organization metric specification, with a strategy for how the /// metric will be performed, and a list of organizations. #[derive(Deserialize)] -#[serde(crate = "self::serde")] struct OrgSpec { strategy: Strategy, orgs: Vec, @@ -263,7 +258,6 @@ impl OrgSpec { /// An organization metric strategy. It either implicitly includes _all_ /// organizations in the Orgs struct, or has a more detailed custom specification. #[derive(Deserialize)] -#[serde(crate = "self::serde")] enum Strategy { All(Mode), Specified(Spec), @@ -273,7 +267,6 @@ enum Strategy { /// commits which are independent of the listed orgs, or all commits which are /// affiliated with the listed orgs. #[derive(Deserialize, Clone, Copy)] -#[serde(crate = "self::serde")] enum Mode { Independent, Affiliated, @@ -287,7 +280,6 @@ enum Mode { /// specifiers may be combined (for example, analyzing all commits from some /// country, plus commits from an organization not from that country). #[derive(Deserialize)] -#[serde(crate = "self::serde")] struct Spec { mode: Mode, list: Vec, @@ -339,7 +331,6 @@ fn get_by_name<'spec>(name: &str, list: &'spec [Org]) -> Result> /// A single organization, with a name, a list of hosts (which form the basis /// for the hosts used in the analyzer), and an affiliated country. #[derive(Clone, Deserialize, Debug)] -#[serde(crate = "self::serde")] struct Org { name: String, hosts: Vec, @@ -415,7 +406,6 @@ impl<'de> Visitor<'de> for ReferenceVisitor { } #[derive(Deserialize, Debug)] -#[serde(crate = "self::serde")] struct RawOrgSpec { strategy: Option, strategy_spec: Option, @@ -423,7 +413,6 @@ struct RawOrgSpec { } #[derive(Deserialize, Debug)] -#[serde(crate = "self::serde")] struct RawSpec { mode: String, list: Vec, diff --git a/hipcheck/src/analysis/metric/binary.rs b/hipcheck/src/analysis/metric/binary.rs index fb77fddd..86606a98 100644 --- a/hipcheck/src/analysis/metric/binary.rs +++ b/hipcheck/src/analysis/metric/binary.rs @@ -5,11 +5,9 @@ use crate::analysis::MetricProvider; use crate::error::Result; use crate::TryFilter; use serde::Serialize; -use serde::{self}; use std::rc::Rc; #[derive(Debug, Eq, PartialEq, Serialize)] -#[serde(crate = "self::serde")] pub struct BinaryOutput { pub binary_files: Vec>, } diff --git a/hipcheck/src/analysis/metric/binary_detector/mod.rs b/hipcheck/src/analysis/metric/binary_detector/mod.rs index 29dd9fb2..b6e57fa4 100644 --- a/hipcheck/src/analysis/metric/binary_detector/mod.rs +++ b/hipcheck/src/analysis/metric/binary_detector/mod.rs @@ -13,9 +13,8 @@ use content_inspector::ContentType; use serde::de::Visitor; use serde::Deserialize; use serde::Deserializer; -use serde::{self}; +use std::fmt; use std::fmt::Formatter; -use std::fmt::{self}; use std::fs::File; use std::io::prelude::Read; use std::io::BufReader; @@ -66,13 +65,11 @@ impl BinaryFileDetector { } #[derive(Debug, Deserialize)] -#[serde(crate = "self::serde")] struct ExtensionsFile { formats: Vec, } #[derive(Debug, Deserialize)] -#[serde(crate = "self::serde")] struct BinaryExtensions { #[serde(default = "missing_bin_type")] r#type: BinaryType, diff --git a/hipcheck/src/analysis/metric/churn.rs b/hipcheck/src/analysis/metric/churn.rs index d22b3482..f5767d1d 100644 --- a/hipcheck/src/analysis/metric/churn.rs +++ b/hipcheck/src/analysis/metric/churn.rs @@ -11,18 +11,15 @@ use crate::TryAny; use crate::TryFilter; use crate::F64; use serde::Serialize; -use serde::{self}; use std::collections::HashMap; use std::rc::Rc; #[derive(Debug, Eq, PartialEq, Serialize)] -#[serde(crate = "self::serde")] pub struct ChurnOutput { pub commit_churn_freqs: Vec, } #[derive(Debug, Eq, PartialEq, Serialize)] -#[serde(crate = "self::serde")] pub struct CommitChurnFreq { pub commit: Rc, pub churn: F64, diff --git a/hipcheck/src/analysis/metric/entropy.rs b/hipcheck/src/analysis/metric/entropy.rs index ed338280..9fcbe945 100644 --- a/hipcheck/src/analysis/metric/entropy.rs +++ b/hipcheck/src/analysis/metric/entropy.rs @@ -13,7 +13,6 @@ use crate::TryAny; use crate::TryFilter; use crate::F64; use serde::Serialize; -use serde::{self}; use std::collections::HashMap; use std::iter::Iterator; use std::ops::Not as _; @@ -81,7 +80,6 @@ pub fn entropy_metric(db: &dyn MetricProvider) -> Result> { /// The final output for entropy metric, containing an entropy score for /// every commit. #[derive(Debug, Eq, PartialEq, Serialize)] -#[serde(crate = "self::serde")] pub struct EntropyOutput { /// The set of commit entropies. pub commit_entropies: Vec, @@ -96,7 +94,6 @@ impl EntropyOutput { /// The entropy of a single commit. #[derive(Debug, Eq, PartialEq, Serialize)] -#[serde(crate = "self::serde")] pub struct CommitEntropy { /// The commit pub commit: Rc, diff --git a/hipcheck/src/analysis/metric/fuzz.rs b/hipcheck/src/analysis/metric/fuzz.rs index 7c1d8bf5..170d0614 100644 --- a/hipcheck/src/analysis/metric/fuzz.rs +++ b/hipcheck/src/analysis/metric/fuzz.rs @@ -5,11 +5,9 @@ use crate::context::Context as _; use crate::data::Fuzz; use crate::error::Result; use serde::Serialize; -use serde::{self}; use std::rc::Rc; #[derive(Debug, Eq, PartialEq, Serialize)] -#[serde(crate = "self::serde")] pub struct FuzzOutput { pub fuzz_result: Fuzz, } diff --git a/hipcheck/src/analysis/metric/identity.rs b/hipcheck/src/analysis/metric/identity.rs index c3979f08..b90d6da0 100644 --- a/hipcheck/src/analysis/metric/identity.rs +++ b/hipcheck/src/analysis/metric/identity.rs @@ -5,17 +5,14 @@ use crate::context::Context as _; use crate::data::git::Commit; use crate::error::Result; use serde::Serialize; -use serde::{self}; use std::rc::Rc; #[derive(Debug, Eq, PartialEq, Serialize)] -#[serde(crate = "self::serde")] pub struct IdentityOutput { pub matches: Vec, } #[derive(Debug, Eq, PartialEq, Serialize)] -#[serde(crate = "self::serde")] pub struct Match { pub commit: Rc, pub identities_match: bool, diff --git a/hipcheck/src/analysis/metric/linguist/mod.rs b/hipcheck/src/analysis/metric/linguist/mod.rs index 366e3627..c080f87e 100644 --- a/hipcheck/src/analysis/metric/linguist/mod.rs +++ b/hipcheck/src/analysis/metric/linguist/mod.rs @@ -10,10 +10,9 @@ use crate::filesystem::read_toml; use serde::de::Visitor; use serde::Deserialize; use serde::Deserializer; -use serde::{self}; use std::convert::AsRef; +use std::fmt; use std::fmt::Formatter; -use std::fmt::{self}; use std::path::Path; use std::result::Result as StdResult; @@ -66,13 +65,11 @@ impl SourceFileDetector { } #[derive(Debug, Deserialize)] -#[serde(crate = "self::serde")] struct LanguageFile { languages: Vec, } #[derive(Debug, Deserialize)] -#[serde(crate = "self::serde")] struct LanguageExtensions { #[serde(default = "missing_lang_type")] r#type: LanguageType, diff --git a/hipcheck/src/analysis/metric/module.rs b/hipcheck/src/analysis/metric/module.rs index 3f5bb75b..a53b0a8f 100644 --- a/hipcheck/src/analysis/metric/module.rs +++ b/hipcheck/src/analysis/metric/module.rs @@ -5,11 +5,9 @@ use crate::context::Context as _; use crate::data::ModuleGraph; use crate::error::Result; use serde::Serialize; -use serde::{self}; use std::rc::Rc; #[derive(Debug, Eq, PartialEq, Serialize)] -#[serde(crate = "self::serde")] pub struct ModuleOutput { pub module_graph: Rc, pub is_modular: bool, diff --git a/hipcheck/src/analysis/metric/module_contributors.rs b/hipcheck/src/analysis/metric/module_contributors.rs index efbb94ca..52a3d894 100644 --- a/hipcheck/src/analysis/metric/module_contributors.rs +++ b/hipcheck/src/analysis/metric/module_contributors.rs @@ -6,18 +6,15 @@ use crate::data::git::Contributor; use crate::data::Module; use crate::error::Result; use serde::Serialize; -use serde::{self}; use std::collections::HashMap; use std::rc::Rc; #[derive(Debug, Eq, PartialEq, Serialize)] -#[serde(crate = "self::serde")] pub struct ModuleContributorsOutput { pub contributors_map: Rc, Vec>>, } #[derive(Debug, Eq, PartialEq, Serialize)] -#[serde(crate = "self::serde")] pub struct ContributedModule { pub module: Rc, pub new_contributor: bool, diff --git a/hipcheck/src/analysis/metric/review.rs b/hipcheck/src/analysis/metric/review.rs index 5a0637bc..aae5d72e 100644 --- a/hipcheck/src/analysis/metric/review.rs +++ b/hipcheck/src/analysis/metric/review.rs @@ -5,17 +5,14 @@ use crate::context::Context as _; use crate::data::PullRequest; use crate::error::Result; use serde::Serialize; -use serde::{self}; use std::rc::Rc; #[derive(Debug, Eq, PartialEq, Serialize)] -#[serde(crate = "self::serde")] pub struct ReviewOutput { pub pull_reviews: Vec, } #[derive(Debug, Eq, PartialEq, Serialize)] -#[serde(crate = "self::serde")] pub struct PullReview { pub pull_request: Rc, pub has_review: bool, diff --git a/hipcheck/src/analysis/metric/typo.rs b/hipcheck/src/analysis/metric/typo.rs index 92709633..893a89a1 100644 --- a/hipcheck/src/analysis/metric/typo.rs +++ b/hipcheck/src/analysis/metric/typo.rs @@ -9,24 +9,21 @@ use crate::filesystem as file; use maplit::hashmap; use serde::Deserialize; use serde::Serialize; -use serde::{self}; use std::cmp::Ordering; use std::collections::HashMap; use std::convert::AsRef; +use std::fmt; use std::fmt::Display; -use std::fmt::{self}; use std::path::Path; use std::rc::Rc; use std::str; #[derive(Debug, Eq, PartialEq, Serialize)] -#[serde(crate = "self::serde")] pub struct TypoOutput { pub typos: Vec, } #[derive(Debug, Eq, PartialEq, Serialize)] -#[serde(crate = "self::serde")] pub struct TypoDep { pub dependency: Rc, pub typo: Typo, @@ -74,13 +71,11 @@ fn typos_for_javascript( } #[derive(Debug, Deserialize)] -#[serde(crate = "self::serde")] struct TypoFile { languages: Languages, } #[derive(Debug, Deserialize)] -#[serde(crate = "self::serde")] struct Languages { javascript: Vec, } @@ -402,7 +397,6 @@ fn get_homoglyph_typos(results: &mut Vec, name: &str, homoglyphs: &[Homogl } #[derive(Debug, Clone, PartialEq, Eq, Serialize)] -#[serde(crate = "self::serde")] pub struct Typo { kind: TypoKind, typo: String, @@ -532,7 +526,6 @@ impl PartialEq for &Typo { } #[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize)] -#[serde(crate = "self::serde")] enum TypoKind { Addition, Bitsquatting, diff --git a/hipcheck/src/command_util.rs b/hipcheck/src/command_util.rs index ca7e2fd4..cbca67a4 100644 --- a/hipcheck/src/command_util.rs +++ b/hipcheck/src/command_util.rs @@ -10,9 +10,9 @@ use std::collections::HashMap; use std::convert::AsRef; use std::env; use std::ffi::OsStr; +use std::fmt; use std::fmt::Display; use std::fmt::Formatter; -use std::fmt::{self}; use std::iter::IntoIterator; use DependentProgram::*; diff --git a/hipcheck/src/config.rs b/hipcheck/src/config.rs index dccbe005..626cbc85 100644 --- a/hipcheck/src/config.rs +++ b/hipcheck/src/config.rs @@ -13,7 +13,6 @@ use crate::ORGS_FILE; use crate::TYPO_FILE; use serde::Deserialize; use serde::Serialize; -use serde::{self}; use smart_default::SmartDefault; use std::default::Default; use std::path::Path; @@ -32,7 +31,6 @@ impl Config { /// Represents the configuration of Hipcheck's analyses. #[derive(Debug, Deserialize, Serialize, Default, PartialEq, Eq)] -#[serde(crate = "self::serde")] pub struct Config { /// The configuration of overall project risk tolerance. #[serde(default)] @@ -49,7 +47,6 @@ pub struct Config { /// Represents configuration of the overall risk threshold of an assessment. #[derive(Debug, Serialize, Deserialize, SmartDefault, PartialEq, Eq)] -#[serde(default, crate = "self::serde")] pub struct RiskConfig { /// The risk tolerance threshold, a value between 0 and 1. #[default(_code = "F64::new(0.5).unwrap()")] @@ -59,7 +56,6 @@ pub struct RiskConfig { /// Defines configuration for all of Hipcheck's analyses. #[derive(Debug, Deserialize, Serialize, Default, PartialEq, Eq)] -#[serde(default, crate = "self::serde")] pub struct AnalysisConfig { /// Defines configuration for practices analysis. #[serde(default)] @@ -72,7 +68,6 @@ pub struct AnalysisConfig { /// Configuration of analyses on a repo's development practices. #[derive(Debug, Deserialize, Serialize, SmartDefault, PartialEq, Eq)] -#[serde(default, crate = "self::serde")] pub struct PracticesConfig { /// Whether the analysis is active. #[default = true] @@ -105,7 +100,6 @@ pub struct PracticesConfig { /// Configuration of analyses on potential attacks against a repo. #[derive(Debug, Deserialize, Serialize, SmartDefault, PartialEq, Eq)] -#[serde(default, crate = "self::serde")] pub struct AttacksConfig { /// Whether the analysis is active. #[default = true] @@ -126,7 +120,6 @@ pub struct AttacksConfig { /// Configuration of analyses on individual commits. #[derive(Debug, Deserialize, Serialize, SmartDefault, PartialEq, Eq)] -#[serde(default, crate = "self::serde")] pub struct CommitConfig { /// Whether the analysis is active. #[default = true] @@ -167,7 +160,6 @@ pub struct CommitConfig { /// Defines configuration for activity analysis. #[derive(Debug, Deserialize, Serialize, SmartDefault, PartialEq, Eq)] -#[serde(default, crate = "self::serde")] pub struct ActivityConfig { /// Whether the analysis is active. #[default = true] @@ -184,7 +176,6 @@ pub struct ActivityConfig { /// Defines configuration for affiliation analysis. #[derive(Debug, Deserialize, Serialize, SmartDefault, PartialEq, Eq)] -#[serde(default, crate = "self::serde")] pub struct AffiliationConfig { /// Whether the analysis is active. #[default = true] @@ -205,7 +196,6 @@ pub struct AffiliationConfig { /// Defines configuration for binary file analysis. #[derive(Debug, Deserialize, Serialize, SmartDefault, PartialEq, Eq)] -#[serde(default, crate = "self::serde")] pub struct BinaryConfig { /// Binary file extension configuration file. #[default = "Binary.toml"] @@ -226,7 +216,6 @@ pub struct BinaryConfig { /// Defines configuration for churn analysis. #[derive(Debug, Deserialize, Serialize, SmartDefault, PartialEq, Eq)] -#[serde(default, crate = "self::serde")] pub struct ChurnConfig { /// Whether the analysis is active. #[default = true] @@ -248,7 +237,6 @@ pub struct ChurnConfig { /// Defines configuration for commit trust analysis. #[derive(Debug, Deserialize, Serialize, SmartDefault, PartialEq, Eq)] -#[serde(default, crate = "self::serde")] pub struct CommitTrustConfig { /// Whether the analysis is active. #[default = true] @@ -261,7 +249,6 @@ pub struct CommitTrustConfig { /// Defines configuration for contributor trust analysis. #[derive(Debug, Deserialize, Serialize, SmartDefault, PartialEq, Eq)] -#[serde(default, crate = "self::serde")] pub struct ContributorTrustConfig { /// Whether the analysis is active. #[default = true] @@ -287,7 +274,6 @@ pub struct ContributorTrustConfig { /// Defines configuration for entropy analysis. #[derive(Debug, Deserialize, Serialize, SmartDefault, PartialEq, Eq)] -#[serde(default, crate = "self::serde")] pub struct EntropyConfig { /// Whether the analysis is active. #[default = true] @@ -309,7 +295,6 @@ pub struct EntropyConfig { /// Defines configuration for identity analysis. #[derive(Debug, Deserialize, Serialize, SmartDefault, PartialEq, Eq)] -#[serde(default, crate = "self::serde")] pub struct IdentityConfig { /// Whether the analysis is active. #[default = true] @@ -328,7 +313,6 @@ pub struct IdentityConfig { /// Defines configuration for review analysis. #[derive(Debug, Deserialize, Serialize, SmartDefault, PartialEq, Eq)] -#[serde(default, crate = "self::serde")] pub struct ReviewConfig { /// Whether the analysis is active. #[default = true] @@ -347,7 +331,6 @@ pub struct ReviewConfig { /// Defines configuration for typo analysis. #[derive(Debug, Deserialize, Serialize, SmartDefault, PartialEq, Eq)] -#[serde(default, crate = "self::serde")] pub struct TypoConfig { /// Whether the analysis is active. #[default = true] @@ -369,7 +352,6 @@ pub struct TypoConfig { /// Defines configuration for pull request affiliation analysis. #[derive(Debug, Deserialize, Serialize, SmartDefault, PartialEq, Eq)] -#[serde(default, crate = "self::serde")] pub struct PrAffiliationConfig { /// Whether the analysis is active. #[default = true] @@ -386,7 +368,6 @@ pub struct PrAffiliationConfig { /// Defines configuration for pull request module committers analysis. #[derive(Debug, Deserialize, Serialize, SmartDefault, PartialEq, Eq)] -#[serde(default, crate = "self::serde")] pub struct PrModuleContributorsConfig { /// Whether the analysis is active. #[default = true] @@ -404,7 +385,6 @@ pub struct PrModuleContributorsConfig { /// Defines the configuration of language-specific info. #[derive(Debug, Deserialize, Serialize, SmartDefault, PartialEq, Eq)] -#[serde(crate = "self::serde")] pub struct LanguagesConfig { /// The file to pull language information from. #[default = "Langs.toml"] @@ -413,7 +393,6 @@ pub struct LanguagesConfig { /// Defines configuration for fuzz analysis. #[derive(Debug, Deserialize, Serialize, SmartDefault, PartialEq, Eq)] -#[serde(default, crate = "self::serde")] pub struct FuzzConfig { /// Whether the analysis is active. #[default = true] @@ -426,12 +405,12 @@ pub struct FuzzConfig { /// Inner module for deserialization helpers. mod de { - use super::serde::de::Deserializer; - use super::serde::de::Visitor; - use super::serde::de::{self}; use super::F64; + use serde::de; + use serde::de::Deserializer; + use serde::de::Visitor; + use std::fmt; use std::fmt::Formatter; - use std::fmt::{self}; /// Deserialize a float, ensuring it's between 0.0 and 1.0 inclusive. pub(super) fn percent<'de, D>(deserializer: D) -> Result diff --git a/hipcheck/src/data.rs b/hipcheck/src/data.rs index 1a088836..1e479f49 100644 --- a/hipcheck/src/data.rs +++ b/hipcheck/src/data.rs @@ -31,7 +31,6 @@ use modules::RawModule; use petgraph::visit::Dfs; use petgraph::Graph; use serde::Serialize; -use serde::{self}; use std::path::Path; use std::rc::Rc; @@ -75,7 +74,6 @@ impl Lang { } #[derive(Clone, Debug, Serialize, PartialEq, Eq)] -#[serde(crate = "self::serde")] pub struct Fuzz { pub exists: bool, } @@ -95,14 +93,12 @@ pub fn get_fuzz_check(token: &str, repo_uri: Rc) -> Result { } #[derive(Debug, Serialize, PartialEq, Eq)] -#[serde(crate = "self::serde")] pub struct PullRequest { pub id: u64, pub reviews: u64, } #[derive(Debug, Serialize, PartialEq, Eq)] -#[serde(crate = "self::serde")] pub struct SinglePullRequest { pub id: u64, pub reviews: u64, @@ -218,20 +214,17 @@ pub fn get_single_pull_request_review_from_github( #[allow(unused)] #[derive(Debug, PartialEq, Eq, Copy, Clone, Serialize)] -#[serde(crate = "self::serde")] pub enum Relationship { Child, Import, } #[derive(Debug, Clone, Eq, Hash, PartialEq, Serialize)] -#[serde(crate = "self::serde")] pub struct Module { pub file: String, } #[derive(Clone, Debug, Serialize)] -#[serde(crate = "self::serde")] pub struct ModuleGraph { pub connections: Graph, } diff --git a/hipcheck/src/data/es_lint/data.rs b/hipcheck/src/data/es_lint/data.rs index fc5b6c4a..e6ddf498 100644 --- a/hipcheck/src/data/es_lint/data.rs +++ b/hipcheck/src/data/es_lint/data.rs @@ -5,16 +5,15 @@ /// /// This parser has been tested with the output from ESLint v7.31.0 use serde::Deserialize; -/// ESLint's JSON output is demonstrated here: -/// https://eslint.org/docs/user-guide/formatters/#json -/// -/// This parser has been tested with the output from ESLint v7.31.0 -use serde::{self}; + +// ESLint's JSON output is demonstrated here: +// https://eslint.org/docs/user-guide/formatters/#json +// +// This parser has been tested with the output from ESLint v7.31.0 pub type ESLintReports = Vec; #[derive(Debug, Clone, Deserialize)] -#[serde(crate = "self::serde")] pub struct ESLintReport { #[serde(rename = "filePath")] pub file_path: String, @@ -31,7 +30,6 @@ pub struct ESLintReport { } #[derive(Debug, Clone, Deserialize)] -#[serde(crate = "self::serde")] pub struct ESLintMessage { #[serde(rename = "ruleId")] pub rule_id: String, diff --git a/hipcheck/src/data/git/data.rs b/hipcheck/src/data/git/data.rs index 70ca33d3..9c8a58d2 100644 --- a/hipcheck/src/data/git/data.rs +++ b/hipcheck/src/data/git/data.rs @@ -4,15 +4,13 @@ use chrono::DateTime; use chrono::FixedOffset; use serde::Deserialize; use serde::Serialize; -use serde::{self}; +use std::fmt; use std::fmt::Display; use std::fmt::Formatter; -use std::fmt::{self}; use std::rc::Rc; /// Commits as they come directly out of `git log`. #[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)] -#[serde(crate = "self::serde")] pub struct RawCommit { pub hash: String, @@ -28,7 +26,6 @@ pub struct RawCommit { /// Commits as understood in Hipcheck's data model. #[derive(Debug, Serialize, Clone, PartialEq, Eq, Hash)] -#[serde(crate = "self::serde")] pub struct Commit { pub hash: String, @@ -45,7 +42,6 @@ impl Display for Commit { /// Authors or committers of a commit. #[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone, Hash, PartialOrd, Ord)] -#[serde(crate = "self::serde")] pub struct Contributor { pub name: String, pub email: String, @@ -59,7 +55,6 @@ impl Display for Contributor { /// "Joim struct" for commits and contributors. #[derive(Debug, PartialEq, Eq, Serialize, Clone)] -#[serde(crate = "self::serde")] pub struct CommitContributor { // Index of commit cache pub commit_id: usize, @@ -70,7 +65,6 @@ pub struct CommitContributor { /// "Join struct" for commits and signature data. #[derive(Debug, PartialEq, Eq, Serialize, Clone)] -#[serde(crate = "self::serde")] pub struct CommitSigner { // Index of commit cache pub commit_id: usize, @@ -82,7 +76,6 @@ pub struct CommitSigner { /// Temporary data structure for looking up the contributors of a commit #[derive(Debug, Serialize, Clone, PartialEq, Eq)] -#[serde(crate = "self::serde")] pub struct CommitContributorView { pub commit: Rc, pub author: Rc, @@ -91,7 +84,6 @@ pub struct CommitContributorView { /// Temporary data structure for looking up the commits associated with a contributor #[derive(Debug, Serialize, Clone, PartialEq, Eq)] -#[serde(crate = "self::serde")] pub struct ContributorView { pub contributor: Rc, pub commits: Vec>, @@ -99,7 +91,6 @@ pub struct ContributorView { /// Temporary data structure for looking up the signer of a commit #[derive(Debug, Serialize, Clone, PartialEq, Eq)] -#[serde(crate = "self::serde")] pub struct CommitSignerView { pub commit: Rc, pub signer_name: Option>, @@ -108,7 +99,6 @@ pub struct CommitSignerView { /// Temporary data structure for looking up the commits associated with a signer name #[derive(Debug, Serialize, Clone, PartialEq, Eq)] -#[serde(crate = "self::serde")] pub struct SignerNameView { pub signer_name: Rc, pub commits: Vec>, @@ -116,7 +106,6 @@ pub struct SignerNameView { /// Temporary data structure for looking up the commits associated with a signer key #[derive(Debug, Serialize, Clone, PartialEq, Eq)] -#[serde(crate = "self::serde")] pub struct SignerKeyView { pub signer_key: Rc, pub commits: Vec>, @@ -124,7 +113,6 @@ pub struct SignerKeyView { /// Temporary data structure for looking up the keys associated with a signer name #[derive(Debug, Serialize, Clone, PartialEq, Eq)] -#[serde(crate = "self::serde")] pub struct SignerView { pub signer_name: Rc, pub signer_keys: Vec>, @@ -132,7 +120,6 @@ pub struct SignerView { /// View into commits and diffs joined together. #[derive(Debug, Serialize, PartialEq, Eq)] -#[serde(crate = "self::serde")] pub struct CommitDiff { pub commit: Rc, pub diff: Rc, @@ -160,7 +147,6 @@ impl Display for CommitDiff { /// A set of changes in a commit. #[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)] -#[serde(crate = "self::serde")] pub struct Diff { pub additions: Option, pub deletions: Option, @@ -169,7 +155,6 @@ pub struct Diff { /// A set of changes to a specific file in a commit. #[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)] -#[serde(crate = "self::serde")] pub struct FileDiff { pub file_name: Rc, pub additions: Option, diff --git a/hipcheck/src/data/modules.rs b/hipcheck/src/data/modules.rs index 0597d0e9..b476e699 100644 --- a/hipcheck/src/data/modules.rs +++ b/hipcheck/src/data/modules.rs @@ -8,7 +8,6 @@ use crate::error::Result; use crate::hc_error; use crate::pathbuf; use serde::Deserialize; -use serde::{self}; use serde_json::Value as JsonValue; use std::collections::HashMap; use std::convert::AsRef; @@ -56,7 +55,6 @@ fn detect_npm_package_root(pkg_file: &Path) -> Result { } #[derive(Debug, Deserialize)] -#[serde(crate = "self::serde")] pub struct RawModule { pub file: String, pub entry: bool, diff --git a/hipcheck/src/data/npm.rs b/hipcheck/src/data/npm.rs index bc1737f0..04674e43 100644 --- a/hipcheck/src/data/npm.rs +++ b/hipcheck/src/data/npm.rs @@ -8,7 +8,6 @@ use crate::filesystem as file; use crate::hc_error; use crate::pathbuf; use serde::Deserialize; -use serde::{self}; use std::collections::HashMap; use std::convert::AsRef; use std::ffi::OsStr; @@ -21,7 +20,6 @@ use std::process::Command; use std::process::Stdio; #[derive(Debug, Clone, PartialEq, Eq, Deserialize)] -#[serde(crate = "self::serde")] pub struct PackageFile { pub main: String, } @@ -116,7 +114,6 @@ fn generate_package_lock_file(package_dir: &Path, version: String) -> Result<()> } #[derive(Deserialize)] -#[serde(crate = "self::serde")] struct PackageLockFile { dependencies: Option>>, } @@ -151,7 +148,6 @@ fn resolve_deps(name: &str, detail: &Dependency) -> Vec { } #[derive(Deserialize)] -#[serde(crate = "self::serde")] struct Dependency { dependencies: Option>>, } diff --git a/hipcheck/src/data/source/mod.rs b/hipcheck/src/data/source/mod.rs index 8a863719..33dee983 100644 --- a/hipcheck/src/data/source/mod.rs +++ b/hipcheck/src/data/source/mod.rs @@ -13,10 +13,10 @@ use crate::pathbuf; use crate::shell::Phase; use log::debug; use std::ffi::OsStr; +use std::fmt; use std::fmt::Debug; use std::fmt::Display; use std::fmt::Formatter; -use std::fmt::{self}; use std::fs; use std::path::Path; use std::path::PathBuf; diff --git a/hipcheck/src/error.rs b/hipcheck/src/error.rs index b778e85e..31bc1432 100644 --- a/hipcheck/src/error.rs +++ b/hipcheck/src/error.rs @@ -12,9 +12,9 @@ use std::borrow::Cow; use std::error::Error as StdError; +use std::fmt; use std::fmt::Debug; use std::fmt::Display; -use std::fmt::{self}; use std::rc::Rc; pub type Result = std::result::Result; diff --git a/hipcheck/src/filesystem.rs b/hipcheck/src/filesystem.rs index 49e21a26..0904ddbf 100644 --- a/hipcheck/src/filesystem.rs +++ b/hipcheck/src/filesystem.rs @@ -5,8 +5,8 @@ use crate::error::Result; use crate::hc_error; use serde::de::DeserializeOwned; use serde::Serialize; +use std::fs; use std::fs::File; -use std::fs::{self}; use std::ops::Not; use std::path::Path; diff --git a/hipcheck/src/report.rs b/hipcheck/src/report.rs index 0e15e17d..ebd3cebf 100644 --- a/hipcheck/src/report.rs +++ b/hipcheck/src/report.rs @@ -19,9 +19,9 @@ use schemars::JsonSchema; use serde::Serialize; use serde::Serializer; use std::default::Default; +use std::fmt; use std::fmt::Display; use std::fmt::Formatter; -use std::fmt::{self}; use std::hash::Hash; use std::hash::Hasher; use std::iter::Iterator; diff --git a/hipcheck/src/shell.rs b/hipcheck/src/shell.rs index ba1f009c..dc40af7a 100644 --- a/hipcheck/src/shell.rs +++ b/hipcheck/src/shell.rs @@ -92,9 +92,9 @@ use crate::report::PrReport; use crate::report::RecommendationKind; use crate::report::Report; use std::cell::Cell; +use std::fmt; use std::fmt::Debug; use std::fmt::Formatter; -use std::fmt::{self}; use std::io::stderr; use std::io::stdout; use std::io::IsTerminal as _; @@ -103,13 +103,13 @@ use std::ops::Not as _; use std::str::FromStr; use std::time::Duration; use std::time::Instant; +use termcolor; use termcolor::Color; use termcolor::Color::*; use termcolor::ColorSpec; use termcolor::NoColor; use termcolor::StandardStream; use termcolor::WriteColor; -use termcolor::{self}; /// The interface used throughout Hipcheck to print things out to the user. pub struct Shell { diff --git a/hipcheck/src/test_util.rs b/hipcheck/src/test_util.rs index de9bec46..0638fe09 100644 --- a/hipcheck/src/test_util.rs +++ b/hipcheck/src/test_util.rs @@ -2,11 +2,11 @@ //! Utilities for unit testing. +use std::env; use std::env::VarError; -use std::env::{self}; +use std::panic; use std::panic::RefUnwindSafe; use std::panic::UnwindSafe; -use std::panic::{self}; use std::sync::Mutex; use lazy_static::lazy_static; diff --git a/hipcheck/src/tests.rs b/hipcheck/src/tests.rs index 60eb57f2..44828965 100644 --- a/hipcheck/src/tests.rs +++ b/hipcheck/src/tests.rs @@ -4,8 +4,8 @@ use crate::error::Error; use crate::hc_error; +use std::io; use std::io::ErrorKind; -use std::io::{self}; // Message source root error with no context #[test] diff --git a/xtask/src/task/ci.rs b/xtask/src/task/ci.rs index 77b7e669..8873fc91 100644 --- a/xtask/src/task/ci.rs +++ b/xtask/src/task/ci.rs @@ -7,10 +7,10 @@ use anyhow::anyhow as hc_error; use anyhow::Error; use anyhow::Result; use duct::cmd; +use std::io; use std::io::Stderr; use std::io::Stdout; use std::io::Write as _; -use std::io::{self}; use std::mem::drop; use std::ops::Not as _; use std::process::exit; diff --git a/xtask/src/task/validate.rs b/xtask/src/task/validate.rs index d4f8110d..c646873a 100644 --- a/xtask/src/task/validate.rs +++ b/xtask/src/task/validate.rs @@ -13,12 +13,12 @@ use pathbuf::pathbuf; use serde::de::DeserializeOwned; use serde::Deserialize; use std::collections::BTreeSet; +use std::fmt; use std::fmt::Debug; use std::fmt::Display; use std::fmt::Formatter; -use std::fmt::{self}; +use std::fs; use std::fs::File; -use std::fs::{self}; use std::io::BufRead; use std::io::BufReader; use std::ops::Not as _; From 14c55ba6f166c632d615f234ae3a57c0fca3f387 Mon Sep 17 00:00:00 2001 From: Andrew Lilley Brinker Date: Mon, 6 May 2024 15:44:52 -0700 Subject: [PATCH 10/14] fix: Remove broken integration test and benchmark. This commit removes the broken (and already minimally-useful) integration testing and benchmarking code. Those relied on the Hipcheck library interface, which no longer exists. We'll want to create new ones based on the new stable interface for Hipcheck, the CLI. Signed-off-by: Andrew Lilley Brinker --- benches/basic.rs | 59 -------------------------------------- hipcheck/Cargo.toml | 10 ------- tests/README.md | 5 ---- tests/can_run.rs | 70 --------------------------------------------- 4 files changed, 144 deletions(-) delete mode 100644 benches/basic.rs delete mode 100644 tests/README.md delete mode 100644 tests/can_run.rs diff --git a/benches/basic.rs b/benches/basic.rs deleted file mode 100644 index 0572f012..00000000 --- a/benches/basic.rs +++ /dev/null @@ -1,59 +0,0 @@ -use criterion::criterion_group; -use criterion::criterion_main; -use criterion::Criterion; -use criterion::PlottingBackend; -use hc_common::CheckKind; -use hc_core::*; -use std::time::Duration; - -fn criterion_benchmark(c: &mut Criterion) { - c.bench_function("hc check repo https://github.com/expressjs/express", |b| { - b.iter(|| { - let repo = "https://github.com/expressjs/express"; - - let shell = { - let verbosity = Verbosity::Quiet; - let color_choice = ColorChoice::Auto; - - Shell::new( - Output::stdout(color_choice), - Output::stderr(color_choice), - verbosity, - ) - }; - - let check = Check { - check_type: CheckType::RepoSource, - check_value: repo.into(), - parent_command_value: CheckKind::Repo.name().to_string(), - }; - - let config_path = None; - let data_path = None; - let home_dir = None; - let format = Format::Human; - let raw_version = "3.0.0"; - - run_with_shell( - shell, - check, - config_path, - data_path, - home_dir, - format, - raw_version, - ) - }) - }); -} - -criterion_group! { - name = benches; - config = Criterion::default() - .sample_size(10) - .measurement_time(Duration::from_secs(150)) - .plotting_backend(PlottingBackend::Plotters); - targets = criterion_benchmark -} - -criterion_main!(benches); diff --git a/hipcheck/Cargo.toml b/hipcheck/Cargo.toml index ed4e2aec..dc0f2d2c 100644 --- a/hipcheck/Cargo.toml +++ b/hipcheck/Cargo.toml @@ -73,13 +73,3 @@ dirs = "5.0.1" tempfile = "3.10.1" duct = "0.13.7" criterion = "0.5.1" - - -[[bench]] -name = "basic" -harness = false -path = "../benches/basic.rs" - -[[test]] -name = "can_run" -path = "../tests/can_run.rs" diff --git a/tests/README.md b/tests/README.md deleted file mode 100644 index 7ca328be..00000000 --- a/tests/README.md +++ /dev/null @@ -1,5 +0,0 @@ - -# Hipcheck Integration Tests - -The tests in this folder are integration tests for all of Hipcheck. Any new tests -here need to be added to `libs/hc_core` as a new `[[test]]`. diff --git a/tests/can_run.rs b/tests/can_run.rs deleted file mode 100644 index a5a312fa..00000000 --- a/tests/can_run.rs +++ /dev/null @@ -1,70 +0,0 @@ -use hc_common::error::Result; -use hc_common::CheckKind; -use hc_core::*; -use std::ffi::OsString; -use tempfile::tempdir; - -// Don't run these tests by default, since they're slow. - -/// Check if Hipcheck can run against its own repository. -#[test] -#[ignore] -fn hc_can_run() { - // Run Hipcheck on its own repo. - check_can_run(".").unwrap(); -} - -/// Check if Hipcheck can run against an empty repository. -#[test] -#[should_panic( - expected = "called `Result::unwrap()` on an `Err` value: can't get head commit for local source" -)] -#[ignore] -fn hc_properly_errors_on_empty_repo() { - // Create an empty git repo. - let dir = tempdir().unwrap(); - let _ = duct::cmd!("git", "init", dir.path()); - let result = check_can_run(dir.path()); - dir.close().unwrap(); - result.unwrap(); -} - -fn check_can_run>(repo: S) -> Result<()> { - let shell = { - // Silent mode to ensure no output at all. - let verbosity = Verbosity::Silent; - let color_choice = ColorChoice::Never; - - Shell::new( - Output::stdout(color_choice), - Output::stderr(color_choice), - verbosity, - ) - }; - - let check = Check { - check_type: CheckType::RepoSource, - check_value: repo.into(), - parent_command_value: CheckKind::Repo.name().to_string(), - }; - - let config_path = None; - let data_path = None; - let home_dir = None; - let format = Format::Human; - let raw_version = "0.0.0"; - - // Get the result, drop the `Shell`. - let (_, result) = run_with_shell( - shell, - check, - config_path, - data_path, - home_dir, - format, - raw_version, - ); - - // Ignore contents of Result::Ok - result.map(|_| ()) -} From c754fac71a0f690ba5b084557dc5fc7da4f47ce7 Mon Sep 17 00:00:00 2001 From: Andrew Lilley Brinker Date: Mon, 6 May 2024 15:49:14 -0700 Subject: [PATCH 11/14] chore: Put `hipcheck` dependencies in order. This commit puts Hipcheck's dependencies in alphabetical order, which makes them much easier to work with in the future since there are so many of them. Signed-off-by: Andrew Lilley Brinker --- hipcheck/Cargo.toml | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/hipcheck/Cargo.toml b/hipcheck/Cargo.toml index dc0f2d2c..64df3c89 100644 --- a/hipcheck/Cargo.toml +++ b/hipcheck/Cargo.toml @@ -14,21 +14,26 @@ path = "src/main.rs" content_inspector = "0.2.4" dotenv = "0.15.0" +chrono = { version = "0.4.19", features = ["serde"] } +clap = { version = "4.5.4", default-features = false, features = [ + "string", + "std", +] } curl = "0.4.38" +dirs = "5.0.1" +duct = "0.13.5" +env_logger = { version = "0.11.3" } glob = "0.3.0" -maplit = "1.0.2" -serde_derive = "1.0.137" -spdx-rs = "0.5.0" -unicode-normalization = "0.1.19" -unicode-segmentation = "1.9.0" -walkdir = "2" -xml-rs = "0.8" -chrono = { version = "0.4.19", features = ["serde"] } +graphql_client = "0.14.0" lazy_static = "1.4.0" log = "0.4.16" +libc = "0.2.154" +maplit = "1.0.2" +nom = "7.1.3" once_cell = "1.10.0" ordered-float = { version = "4.2.0", features = ["serde"] } paste = "1.0.7" +petgraph = { version = "0.6.0", features = ["serde-1"] } regex = "1.5.5" salsa = "0.16.1" schemars = { version = "0.8.17", default-features = false, features = [ @@ -38,27 +43,22 @@ schemars = { version = "0.8.17", default-features = false, features = [ ] } semver = "1.0.9" serde = { version = "1.0.200", features = ["derive", "rc"] } +serde_derive = "1.0.137" serde_json = "1.0.80" smart-default = "0.7.1" -toml = "0.8.12" -url = "2.2.2" -which = { version = "6.0.1", default-features = false } -libc = "0.2.154" +spdx-rs = "0.5.0" termcolor = "1.1.3" -duct = "0.13.5" -dirs = "5.0.1" -graphql_client = "0.14.0" -nom = "7.1.3" -petgraph = { version = "0.6.0", features = ["serde-1"] } +toml = "0.8.12" +unicode-normalization = "0.1.19" +unicode-segmentation = "1.9.0" ureq = { version = "2.9.7", default-features = false, features = [ "json", "native-tls", ] } -clap = { version = "4.5.4", default-features = false, features = [ - "string", - "std", -] } -env_logger = { version = "0.11.3" } +url = "2.2.2" +walkdir = "2" +which = { version = "6.0.1", default-features = false } +xml-rs = "0.8" [target.'cfg(windows)'.dependencies.winapi] version = "0.3" From 13b27d52f0c2c33bf8cbb039f82ddd50c91e96c9 Mon Sep 17 00:00:00 2001 From: Andrew Lilley Brinker Date: Tue, 7 May 2024 09:06:02 -0700 Subject: [PATCH 12/14] fix: return missing 'default' annotations on config types. I'd accidentally deleted the `#[serde(default)]` annotations on all of the configuration types, causing parsing to fail for config files if any fields were missing. This commit brings them back, and also resolves a clippy warning about a useless import. Signed-off-by: Andrew Lilley Brinker --- hipcheck/src/config.rs | 20 ++++++++++++++++++++ hipcheck/src/shell.rs | 1 - 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/hipcheck/src/config.rs b/hipcheck/src/config.rs index 626cbc85..9951146e 100644 --- a/hipcheck/src/config.rs +++ b/hipcheck/src/config.rs @@ -31,6 +31,7 @@ impl Config { /// Represents the configuration of Hipcheck's analyses. #[derive(Debug, Deserialize, Serialize, Default, PartialEq, Eq)] +#[serde(default)] pub struct Config { /// The configuration of overall project risk tolerance. #[serde(default)] @@ -47,6 +48,7 @@ pub struct Config { /// Represents configuration of the overall risk threshold of an assessment. #[derive(Debug, Serialize, Deserialize, SmartDefault, PartialEq, Eq)] +#[serde(default)] pub struct RiskConfig { /// The risk tolerance threshold, a value between 0 and 1. #[default(_code = "F64::new(0.5).unwrap()")] @@ -56,6 +58,7 @@ pub struct RiskConfig { /// Defines configuration for all of Hipcheck's analyses. #[derive(Debug, Deserialize, Serialize, Default, PartialEq, Eq)] +#[serde(default)] pub struct AnalysisConfig { /// Defines configuration for practices analysis. #[serde(default)] @@ -68,6 +71,7 @@ pub struct AnalysisConfig { /// Configuration of analyses on a repo's development practices. #[derive(Debug, Deserialize, Serialize, SmartDefault, PartialEq, Eq)] +#[serde(default)] pub struct PracticesConfig { /// Whether the analysis is active. #[default = true] @@ -100,6 +104,7 @@ pub struct PracticesConfig { /// Configuration of analyses on potential attacks against a repo. #[derive(Debug, Deserialize, Serialize, SmartDefault, PartialEq, Eq)] +#[serde(default)] pub struct AttacksConfig { /// Whether the analysis is active. #[default = true] @@ -120,6 +125,7 @@ pub struct AttacksConfig { /// Configuration of analyses on individual commits. #[derive(Debug, Deserialize, Serialize, SmartDefault, PartialEq, Eq)] +#[serde(default)] pub struct CommitConfig { /// Whether the analysis is active. #[default = true] @@ -160,6 +166,7 @@ pub struct CommitConfig { /// Defines configuration for activity analysis. #[derive(Debug, Deserialize, Serialize, SmartDefault, PartialEq, Eq)] +#[serde(default)] pub struct ActivityConfig { /// Whether the analysis is active. #[default = true] @@ -176,6 +183,7 @@ pub struct ActivityConfig { /// Defines configuration for affiliation analysis. #[derive(Debug, Deserialize, Serialize, SmartDefault, PartialEq, Eq)] +#[serde(default)] pub struct AffiliationConfig { /// Whether the analysis is active. #[default = true] @@ -196,6 +204,7 @@ pub struct AffiliationConfig { /// Defines configuration for binary file analysis. #[derive(Debug, Deserialize, Serialize, SmartDefault, PartialEq, Eq)] +#[serde(default)] pub struct BinaryConfig { /// Binary file extension configuration file. #[default = "Binary.toml"] @@ -216,6 +225,7 @@ pub struct BinaryConfig { /// Defines configuration for churn analysis. #[derive(Debug, Deserialize, Serialize, SmartDefault, PartialEq, Eq)] +#[serde(default)] pub struct ChurnConfig { /// Whether the analysis is active. #[default = true] @@ -237,6 +247,7 @@ pub struct ChurnConfig { /// Defines configuration for commit trust analysis. #[derive(Debug, Deserialize, Serialize, SmartDefault, PartialEq, Eq)] +#[serde(default)] pub struct CommitTrustConfig { /// Whether the analysis is active. #[default = true] @@ -249,6 +260,7 @@ pub struct CommitTrustConfig { /// Defines configuration for contributor trust analysis. #[derive(Debug, Deserialize, Serialize, SmartDefault, PartialEq, Eq)] +#[serde(default)] pub struct ContributorTrustConfig { /// Whether the analysis is active. #[default = true] @@ -274,6 +286,7 @@ pub struct ContributorTrustConfig { /// Defines configuration for entropy analysis. #[derive(Debug, Deserialize, Serialize, SmartDefault, PartialEq, Eq)] +#[serde(default)] pub struct EntropyConfig { /// Whether the analysis is active. #[default = true] @@ -295,6 +308,7 @@ pub struct EntropyConfig { /// Defines configuration for identity analysis. #[derive(Debug, Deserialize, Serialize, SmartDefault, PartialEq, Eq)] +#[serde(default)] pub struct IdentityConfig { /// Whether the analysis is active. #[default = true] @@ -313,6 +327,7 @@ pub struct IdentityConfig { /// Defines configuration for review analysis. #[derive(Debug, Deserialize, Serialize, SmartDefault, PartialEq, Eq)] +#[serde(default)] pub struct ReviewConfig { /// Whether the analysis is active. #[default = true] @@ -331,6 +346,7 @@ pub struct ReviewConfig { /// Defines configuration for typo analysis. #[derive(Debug, Deserialize, Serialize, SmartDefault, PartialEq, Eq)] +#[serde(default)] pub struct TypoConfig { /// Whether the analysis is active. #[default = true] @@ -352,6 +368,7 @@ pub struct TypoConfig { /// Defines configuration for pull request affiliation analysis. #[derive(Debug, Deserialize, Serialize, SmartDefault, PartialEq, Eq)] +#[serde(default)] pub struct PrAffiliationConfig { /// Whether the analysis is active. #[default = true] @@ -368,6 +385,7 @@ pub struct PrAffiliationConfig { /// Defines configuration for pull request module committers analysis. #[derive(Debug, Deserialize, Serialize, SmartDefault, PartialEq, Eq)] +#[serde(default)] pub struct PrModuleContributorsConfig { /// Whether the analysis is active. #[default = true] @@ -385,6 +403,7 @@ pub struct PrModuleContributorsConfig { /// Defines the configuration of language-specific info. #[derive(Debug, Deserialize, Serialize, SmartDefault, PartialEq, Eq)] +#[serde(default)] pub struct LanguagesConfig { /// The file to pull language information from. #[default = "Langs.toml"] @@ -393,6 +412,7 @@ pub struct LanguagesConfig { /// Defines configuration for fuzz analysis. #[derive(Debug, Deserialize, Serialize, SmartDefault, PartialEq, Eq)] +#[serde(default)] pub struct FuzzConfig { /// Whether the analysis is active. #[default = true] diff --git a/hipcheck/src/shell.rs b/hipcheck/src/shell.rs index dc40af7a..0f63914b 100644 --- a/hipcheck/src/shell.rs +++ b/hipcheck/src/shell.rs @@ -103,7 +103,6 @@ use std::ops::Not as _; use std::str::FromStr; use std::time::Duration; use std::time::Instant; -use termcolor; use termcolor::Color; use termcolor::Color::*; use termcolor::ColorSpec; From adb66b8f62b3d38c9ade7dd5d5561fe1e90beffd Mon Sep 17 00:00:00 2001 From: Andrew Lilley Brinker Date: Tue, 7 May 2024 09:35:57 -0700 Subject: [PATCH 13/14] fix: Fix broken ureq TLS configuration This commit fixes broken ureq TLS configuration. It turns out when you tell ureq to use native TLS certificate stores, it doesn't set those up in the request agent automatically the way it does for the default TLS configuration. Rather, it requires you to add the `native_tls` dependency and set them up yourself. This commit does that. Signed-off-by: Andrew Lilley Brinker --- Cargo.lock | 1 + Cargo.toml | 3 --- hipcheck/Cargo.toml | 7 ++++--- hipcheck/src/analysis/session/pm.rs | 17 +++++++++++++---- hipcheck/src/data.rs | 6 +++--- .../src/data/github/authenticated_agent.rs | 18 +++++++++++++----- hipcheck/src/data/github/mod.rs | 16 ++++++++-------- 7 files changed, 42 insertions(+), 26 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7eecefcd..ca95898b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -618,6 +618,7 @@ dependencies = [ "libc", "log", "maplit", + "native-tls", "nom", "once_cell", "ordered-float", diff --git a/Cargo.toml b/Cargo.toml index ac22f87d..6eca65bb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,3 @@ -# Necessary for 'cargo outdated' -cargo-features = ["resolver"] - [workspace] # Use the newer, better feature resolver. resolver = "2" diff --git a/hipcheck/Cargo.toml b/hipcheck/Cargo.toml index 64df3c89..5a83e8fe 100644 --- a/hipcheck/Cargo.toml +++ b/hipcheck/Cargo.toml @@ -56,12 +56,13 @@ ureq = { version = "2.9.7", default-features = false, features = [ "native-tls", ] } url = "2.2.2" -walkdir = "2" +walkdir = "2.5.0" which = { version = "6.0.1", default-features = false } -xml-rs = "0.8" +xml-rs = "0.8.20" +native-tls = "0.2.11" [target.'cfg(windows)'.dependencies.winapi] -version = "0.3" +version = "0.3.9" features = ["handleapi", "processenv", "winbase", "wincon", "winnt"] [build-dependencies] diff --git a/hipcheck/src/analysis/session/pm.rs b/hipcheck/src/analysis/session/pm.rs index cfd95334..30302161 100644 --- a/hipcheck/src/analysis/session/pm.rs +++ b/hipcheck/src/analysis/session/pm.rs @@ -11,11 +11,11 @@ use serde_json::Value; use std::cmp::max; use std::cmp::Ordering; use std::process::exit; +use std::sync::Arc; use url::Host; use url::Url; use xml::reader::EventReader; use xml::reader::XmlEvent; -//This entire module was largely copied from https://gitlab.mitre.org/software-assurance/repofinder const MAVEN: &str = CheckKind::Maven.name(); const NPM: &str = CheckKind::Npm.name(); @@ -364,7 +364,10 @@ fn extract_repo_for_npm(raw_package: &str) -> Result { }; // Make an HTTP request to that URL. - let response = ureq::get(®istry) + let response = ureq::AgentBuilder::new() + .tls_connector(Arc::new(native_tls::TlsConnector::new()?)) + .build() + .get(®istry) .call() .context("request to npm API failed, make sure the package name is correct as well as the project version")?; @@ -412,7 +415,10 @@ fn extract_repo_for_pypi(raw_package: &str) -> Result { }; // Make an HTTP request to that URL. - let response = ureq::get(®istry) + let response = ureq::AgentBuilder::new() + .tls_connector(Arc::new(native_tls::TlsConnector::new()?)) + .build() + .get(®istry) .call() .context("request to PYPI API failed, make sure the project name is correct (case matters) as well as the project version")?; @@ -444,7 +450,10 @@ fn extract_repo_for_pypi(raw_package: &str) -> Result { fn extract_repo_for_maven(url: &str) -> Result { // Make an HTTP request to that URL to get the POM file. - let response = ureq::get(url) + let response = ureq::AgentBuilder::new() + .tls_connector(Arc::new(native_tls::TlsConnector::new()?)) + .build() + .get(url) .call() .context("request to Maven API failed")?; diff --git a/hipcheck/src/data.rs b/hipcheck/src/data.rs index 1e479f49..6971d2c2 100644 --- a/hipcheck/src/data.rs +++ b/hipcheck/src/data.rs @@ -79,7 +79,7 @@ pub struct Fuzz { } pub fn get_fuzz_check(token: &str, repo_uri: Rc) -> Result { - let github = GitHub::new("google", "oss-fuzz", token); + let github = GitHub::new("google", "oss-fuzz", token)?; let github_result = github .fuzz_check(repo_uri) @@ -113,7 +113,7 @@ pub fn get_pull_request_reviews_from_github( repo: &str, token: &str, ) -> Result> { - let github = GitHub::new(owner, repo, token); + let github = GitHub::new(owner, repo, token)?; let results = github .get_reviews_for_pr() @@ -134,7 +134,7 @@ pub fn get_single_pull_request_review_from_github( pull_request: &u64, token: &str, ) -> Result { - let github_pr = GitHubPr::new(owner, repo, pull_request, token); + let github_pr = GitHubPr::new(owner, repo, pull_request, token)?; let github_result = github_pr .get_review_for_single_pr() diff --git a/hipcheck/src/data/github/authenticated_agent.rs b/hipcheck/src/data/github/authenticated_agent.rs index e6544b79..bfaabe08 100644 --- a/hipcheck/src/data/github/authenticated_agent.rs +++ b/hipcheck/src/data/github/authenticated_agent.rs @@ -1,7 +1,12 @@ //! Defines an authenticated [`Agent`] type that adds token auth to all requests. +use std::sync::Arc; + use crate::data::github::hidden::Hidden; +use crate::error::Result; +use native_tls::TlsConnector; use ureq::Agent; +use ureq::AgentBuilder; use ureq::Request; /// An [`Agent`] which authenticates requests with token auth. @@ -18,11 +23,14 @@ pub struct AuthenticatedAgent<'token> { impl<'token> AuthenticatedAgent<'token> { /// Construct a new authenticated agent. - pub fn new(token: &'token str) -> AuthenticatedAgent<'token> { - AuthenticatedAgent { - agent: Agent::new(), - token: Hidden::new(token), - } + pub fn new(token: &'token str) -> Result> { + let agent = AgentBuilder::new() + .tls_connector(Arc::new(TlsConnector::new()?)) + .build(); + + let token = Hidden::new(token); + + Ok(AuthenticatedAgent { agent, token }) } /// Make an authenticated GET request. diff --git a/hipcheck/src/data/github/mod.rs b/hipcheck/src/data/github/mod.rs index a07a2208..fd83990f 100644 --- a/hipcheck/src/data/github/mod.rs +++ b/hipcheck/src/data/github/mod.rs @@ -24,12 +24,12 @@ pub struct GitHub<'a> { } impl<'a> GitHub<'a> { - pub fn new(owner: &'a str, repo: &'a str, token: &'a str) -> GitHub<'a> { - GitHub { + pub fn new(owner: &'a str, repo: &'a str, token: &'a str) -> Result> { + Ok(GitHub { owner, repo, - agent: AuthenticatedAgent::new(token), - } + agent: AuthenticatedAgent::new(token)?, + }) } pub fn fuzz_check(&self, repo_uri: Rc) -> Result { @@ -54,13 +54,13 @@ impl<'a> GitHubPr<'a> { repo: &'a str, pull_request: &'a u64, token: &'a str, - ) -> GitHubPr<'a> { - GitHubPr { + ) -> Result> { + Ok(GitHubPr { owner, repo, pull_request, - agent: AuthenticatedAgent::new(token), - } + agent: AuthenticatedAgent::new(token)?, + }) } pub fn get_review_for_single_pr(&self) -> Result { From 6ffe55d1cb6b1aefbc821c84513795096104aecc Mon Sep 17 00:00:00 2001 From: Andrew Lilley Brinker Date: Tue, 7 May 2024 09:40:35 -0700 Subject: [PATCH 14/14] fix: Remove broken Windows import. This is why we have cross-platform CI testing haha. This commit removes a broken import in some Windows-specific code. We'd previously done a weird thing of re-exporting external dependencies under crate-local pathnames. We no longer do that, but had an import laying around still that expected this kind of structure. Signed-off-by: Andrew Lilley Brinker --- hipcheck/src/shell.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/hipcheck/src/shell.rs b/hipcheck/src/shell.rs index 0f63914b..a748673f 100644 --- a/hipcheck/src/shell.rs +++ b/hipcheck/src/shell.rs @@ -1579,7 +1579,6 @@ mod imp { mod imp { use super::TtyWidth; use crate::error::Result; - use crate::log; use std::cmp; use std::mem::zeroed; use std::ptr;