Skip to content

Commit

Permalink
chore: Move "Context" under "error" module
Browse files Browse the repository at this point in the history
This is part of a general goal I have of simplifying the top-level module
structure of the crate. The "Context" type is in relation to our
error-handling story, so it seems sensible to put it there.

Signed-off-by: Andrew Lilley Brinker <[email protected]>
  • Loading branch information
alilleybrinker authored and j-lanson committed Sep 7, 2024
1 parent b820e28 commit 0ffaf00
Show file tree
Hide file tree
Showing 47 changed files with 101 additions and 79 deletions.
1 change: 0 additions & 1 deletion hipcheck/src/analysis/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// SPDX-License-Identifier: Apache-2.0

pub mod report_builder;
pub mod result;
pub mod score;

Expand Down
6 changes: 2 additions & 4 deletions hipcheck/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
//!
//! A macro is provided to automatically tag timings with the file and line number that they were created on.
use crate::shell::Shell;
pub use print_scope_time;
use std::time::Instant;

/// Structure used to track timing that will print its location and elapsed time when dropped.
Expand Down Expand Up @@ -55,7 +57,3 @@ macro_rules! print_scope_time {
))
};
}

pub(crate) use print_scope_time;

use crate::shell::Shell;
2 changes: 1 addition & 1 deletion hipcheck/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use crate::{
cache::repo_cache::{RepoCacheDeleteScope, RepoCacheListScope, RepoCacheSort},
context::Context,
error::Context,
error::Result,
hc_error,
session::pm,
Expand Down
5 changes: 4 additions & 1 deletion hipcheck/src/command_util.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// SPDX-License-Identifier: Apache-2.0

use crate::{context::Context as _, error::Result, hc_error};
use crate::{
error::{Context as _, Result},
hc_error,
};
use once_cell::sync::Lazy;
use regex::Regex;
use semver::Version;
Expand Down
3 changes: 1 addition & 2 deletions hipcheck/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
use crate::{
analysis::score::*,
context::Context,
engine::HcEngine,
error::Result,
error::{Context, Result},
hc_error,
plugin::QueryResult,
policy::{
Expand Down
3 changes: 1 addition & 2 deletions hipcheck/src/data/es_lint/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ use std::{ffi::OsStr, process::Command};

use crate::{
command_util::{log_args, DependentProgram},
context::Context as _,
error::Result,
error::{Context as _, Result},
hc_error,
};

Expand Down
5 changes: 2 additions & 3 deletions hipcheck/src/data/es_lint/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
// SPDX-License-Identifier: Apache-2.0

use std::{ffi::OsStr, path::Path};

use crate::{context::Context as _, error::Result};
use crate::error::{Context as _, Result};
use command::ESLintCommand;
use data::ESLintReports;
use std::{ffi::OsStr, path::Path};

pub mod command;
pub mod data;
Expand Down
5 changes: 2 additions & 3 deletions hipcheck/src/data/git/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ mod data;
pub mod parse;
mod query;

pub use crate::data::git_command::*;
use crate::error::{Context as _, Result};
pub use data::*;
use parse::*;
pub use query::*;

pub use crate::data::git_command::*;
use crate::{context::Context as _, error::Result};
use std::path::Path;

pub fn get_git_version() -> Result<String> {
Expand Down
3 changes: 1 addition & 2 deletions hipcheck/src/data/git/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
#![allow(dead_code)]

use crate::{
context::Context as _,
data::git::{Contributor, Diff, FileDiff, RawCommit},
error::{Error, Result},
error::{Context as _, Error, Result},
};
use chrono::{DateTime, FixedOffset};
use nom::{
Expand Down
3 changes: 1 addition & 2 deletions hipcheck/src/data/git/query/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@
use super::GitProvider;
use crate::{
context::Context,
data::git::{
get_commits, get_commits_from_date, get_diffs, Commit, CommitContributor,
CommitContributorView, CommitDiff, CommitSigner, CommitSignerView, Contributor,
ContributorView, Diff, GitCommand, RawCommit, SignerKeyView, SignerNameView, SignerView,
},
error::{Error, Result},
error::{Context, Error, Result},
};
use chrono::prelude::*;
use std::sync::Arc;
Expand Down
6 changes: 5 additions & 1 deletion hipcheck/src/data/git_command.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
// SPDX-License-Identifier: Apache-2.0

use crate::{command_util::log_git_args, context::Context as _, error::Result, hc_error};
use crate::{
command_util::log_git_args,
error::{Context as _, Result},
hc_error,
};
use std::{
convert::AsRef, ffi::OsStr, iter::IntoIterator, ops::Not as _, path::Path, process::Command,
};
Expand Down
3 changes: 1 addition & 2 deletions hipcheck/src/data/github/graphql_pr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ use self::review::{
ReviewRepositoryPullRequestCommitsNodes as RawPullCommit, Variables,
};
use crate::{
context::Context,
data::{
git::{Contributor, RawCommit},
github::data::*,
},
error::{Error, Result},
error::{Context, Error, Result},
hc_error,
util::http::authenticated_agent::AuthenticatedAgent,
};
Expand Down
3 changes: 1 addition & 2 deletions hipcheck/src/data/github/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ mod graphql;
mod graphql_pr;

use crate::{
context::Context as _,
data::{
code_search::search_code_request,
git::parse::github_diff,
github::{data::*, graphql::get_all_reviews, graphql_pr::get_all_pr_reviews},
},
error::Result,
error::{Context as _, Result},
util::http::authenticated_agent::AuthenticatedAgent,
};
use std::sync::Arc;
Expand Down
3 changes: 1 addition & 2 deletions hipcheck/src/data/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ mod query;
pub use query::*;

use crate::{
context::Context,
error::{Error, Result},
error::{Context, Error, Result},
hc_error,
};
use git::{get_commits_for_file, Commit, CommitContributor, Contributor, Diff};
Expand Down
3 changes: 1 addition & 2 deletions hipcheck/src/data/modules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

use crate::{
command_util::{log_args, DependentProgram},
context::Context as _,
error::{Error, Result},
error::{Context as _, Error, Result},
hc_error,
};
use pathbuf::pathbuf;
Expand Down
3 changes: 1 addition & 2 deletions hipcheck/src/data/npm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

use crate::{
command_util::{log_args, DependentProgram},
context::Context,
error::Result,
error::{Context, Result},
hc_error,
util::fs as file,
};
Expand Down
3 changes: 1 addition & 2 deletions hipcheck/src/data/query/pr_review.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
use super::github::GitHubProvider;
use crate::{
config::ConfigSource,
context::Context,
data::{
get_pull_request_reviews_from_github, get_single_pull_request_review_from_github,
git::{Commit, CommitContributorView, CommitDiff, Contributor, ContributorView},
PullRequest, SinglePullRequest,
},
error::{Error, Result},
error::{Context, Error, Result},
};
use std::sync::Arc;

Expand Down
File renamed without changes.
3 changes: 3 additions & 0 deletions hipcheck/src/error.rs → hipcheck/src/error/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
//! which error out aren't retried, as it always compares as equal to
//! any other error.
mod context;

pub use crate::error::context::Context;
use std::{
borrow::Cow,
error::Error as StdError,
Expand Down
10 changes: 3 additions & 7 deletions hipcheck/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ mod cache;
mod cli;
mod command_util;
mod config;
mod context;
mod data;
mod engine;
mod error;
Expand All @@ -32,16 +31,13 @@ pub mod hipcheck {
}

use crate::{
analysis::{
report_builder::{build_report, Report},
score::score_results,
},
analysis::score::score_results,
cache::repo_cache::HcRepoCache,
cli::Format,
config::WeightTreeProvider,
context::Context as _,
error::{Error, Result},
error::{Context as _, Error, Result},
plugin::{Plugin, PluginExecutor, PluginWithConfig},
report::report_builder::{build_report, Report},
session::Session,
setup::{resolve_and_transform_source, SourceType},
shell::Shell,
Expand Down
5 changes: 4 additions & 1 deletion hipcheck/src/metric/activity.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// SPDX-License-Identifier: Apache-2.0

use crate::{context::Context as _, error::Result, metric::MetricProvider};
use crate::{
error::{Context as _, Result},
metric::MetricProvider,
};
use chrono::{prelude::*, Duration};
use serde::{ser::SerializeStruct, Serialize, Serializer};
use std::{result::Result as StdResult, sync::Arc};
Expand Down
3 changes: 1 addition & 2 deletions hipcheck/src/metric/affiliation.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
// SPDX-License-Identifier: Apache-2.0

use crate::{
context::Context as _,
data::git::{Commit, CommitContributorView},
error::{Error, Result},
error::{Context as _, Error, Result},
hc_error,
metric::MetricProvider,
util::fs as file,
Expand Down
6 changes: 5 additions & 1 deletion hipcheck/src/metric/binary_detector/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ mod query;

pub use query::*;

use crate::{context::Context, error::Result, hc_error, util::fs::read_toml};
use crate::{
error::{Context, Result},
hc_error,
util::fs::read_toml,
};
use content_inspector::{inspect, ContentType};
use serde::{de::Visitor, Deserialize, Deserializer};
use std::{
Expand Down
3 changes: 2 additions & 1 deletion hipcheck/src/metric/binary_detector/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
//! A query group for binary file detection queries.
use crate::{
config::PracticesConfigQuery, context::Context as _, error::Result,
config::PracticesConfigQuery,
error::{Context as _, Result},
metric::binary_detector::BinaryFileDetector,
};
use std::sync::Arc;
Expand Down
3 changes: 1 addition & 2 deletions hipcheck/src/metric/churn.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
// SPDX-License-Identifier: Apache-2.0

use crate::{
context::Context as _,
data::git::Commit,
error::Result,
error::{Context as _, Result},
hc_error,
metric::{
math::{mean, std_dev},
Expand Down
5 changes: 4 additions & 1 deletion hipcheck/src/metric/commit_trust.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// SPDX-License-Identifier: Apache-2.0

use crate::{context::Context as _, error::Result, metric::MetricProvider};
use crate::{
error::{Context as _, Result},
metric::MetricProvider,
};
use std::{collections::HashMap, sync::Arc};

pub const TRUST_PHASE: &str = "commit trust";
Expand Down
5 changes: 4 additions & 1 deletion hipcheck/src/metric/contributor_trust.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// SPDX-License-Identifier: Apache-2.0

use crate::{context::Context as _, error::Result, metric::MetricProvider};
use crate::{
error::{Context as _, Result},
metric::MetricProvider,
};
use std::{collections::HashMap, sync::Arc};

pub const TRUST_PHASE: &str = "contributor trust";
Expand Down
3 changes: 1 addition & 2 deletions hipcheck/src/metric/entropy.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
// SPDX-License-Identifier: Apache-2.0

use crate::{
context::Context as _,
data::git::{Commit, CommitDiff, FileDiff},
error::Result,
error::{Context as _, Result},
hc_error,
metric::{
math::{mean, std_dev},
Expand Down
6 changes: 5 additions & 1 deletion hipcheck/src/metric/fuzz.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
// SPDX-License-Identifier: Apache-2.0

use crate::{context::Context as _, data::Fuzz, error::Result, metric::MetricProvider};
use crate::{
data::Fuzz,
error::{Context as _, Result},
metric::MetricProvider,
};
use serde::Serialize;
use std::sync::Arc;

Expand Down
6 changes: 5 additions & 1 deletion hipcheck/src/metric/identity.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
// SPDX-License-Identifier: Apache-2.0

use crate::{context::Context as _, data::git::Commit, error::Result, metric::MetricProvider};
use crate::{
data::git::Commit,
error::{Context as _, Result},
metric::MetricProvider,
};
use serde::Serialize;
use std::sync::Arc;

Expand Down
5 changes: 4 additions & 1 deletion hipcheck/src/metric/linguist/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ mod query;

pub use query::*;

use crate::{context::Context as _, error::Result, util::fs::read_toml};
use crate::{
error::{Context as _, Result},
util::fs::read_toml,
};
use serde::{de::Visitor, Deserialize, Deserializer};
use std::{convert::AsRef, fmt, fmt::Formatter, path::Path, result::Result as StdResult};

Expand Down
3 changes: 2 additions & 1 deletion hipcheck/src/metric/linguist/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
//! A query group for source file language detection queries.
use crate::{
config::LanguagesConfigQuery, context::Context, error::Result,
config::LanguagesConfigQuery,
error::{Context, Result},
metric::linguist::SourceFileDetector,
};
use std::sync::Arc;
Expand Down
6 changes: 5 additions & 1 deletion hipcheck/src/metric/module.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
// SPDX-License-Identifier: Apache-2.0

use crate::{context::Context as _, data::ModuleGraph, error::Result, metric::MetricProvider};
use crate::{
data::ModuleGraph,
error::{Context as _, Result},
metric::MetricProvider,
};
use serde::Serialize;
use std::sync::Arc;

Expand Down
Loading

0 comments on commit 0ffaf00

Please sign in to comment.