Skip to content

Commit

Permalink
chore: Removes unused module analysis and the unncessary data locatio…
Browse files Browse the repository at this point in the history
…n and scripts folder
  • Loading branch information
mchernicoff authored and alilleybrinker committed Sep 10, 2024
1 parent 0766a6a commit 6a3e49e
Show file tree
Hide file tree
Showing 14 changed files with 23 additions and 1,039 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/hipcheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,13 @@ on:
- "config/**"
- "hipcheck/**"
- "plugins/**"
- "scripts/**"
- "xtask/**"
pull_request:
branches: [main]
paths:
- "config/**"
- "hipcheck/**"
- "plugins/**"
- "scripts/**"
- "xtask/**"

permissions:
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pr-run-mode = "plan"
# Whether to install an updater program
install-updater = true
# Extra static files to include in each App (path relative to this Cargo.toml's dir)
include = ["config/", "scripts/"]
include = ["config/"]
# Path that installers should place binaries in
install-path = "CARGO_HOME"

Expand Down
2 changes: 0 additions & 2 deletions Containerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ WORKDIR /app

COPY --from=builder /build/target/release/hc ./hc
COPY config/ config/
COPY scripts/ scripts/

RUN set -eux && \
apt-get update && \
Expand All @@ -39,7 +38,6 @@ RUN set -eux && \
USER hc_user

ENV HC_CONFIG=./config
ENV HC_DATA=./scripts

ENTRYPOINT ["./hc"]

Expand Down
131 changes: 4 additions & 127 deletions hipcheck/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,6 @@ struct OutputArgs {
/// Arguments configuring paths for Hipcheck to use.
#[derive(Debug, Default, clap::Args, hc::Update)]
struct PathArgs {
/// Path to the data folder.
#[arg(
short = 'd',
long = "data",
global = true,
help_heading = "Path Flags",
long_help = "Path to the data folder. Can also be set with the `HC_DATA` environment variable"
)]
data: Option<PathBuf>,

/// Path to the cache folder.
#[arg(
short = 'C',
Expand Down Expand Up @@ -131,10 +121,6 @@ struct DeprecatedArgs {
#[arg(long = "print-config", hide = true, global = true)]
print_config: Option<bool>,

/// Print the data folder path for Hipcheck.
#[arg(long = "print-data", hide = true, global = true)]
print_data: Option<bool>,

/// Path to the configuration folder.
#[arg(short = 'c', long = "config", hide = true, global = true)]
config: Option<PathBuf>,
Expand Down Expand Up @@ -164,10 +150,6 @@ impl CliConfig {

/// Get the selected subcommand, if any.
pub fn subcommand(&self) -> Option<FullCommands> {
if self.print_data() {
return Some(FullCommands::PrintData);
}

if self.print_home() {
return Some(FullCommands::PrintCache);
}
Expand Down Expand Up @@ -212,11 +194,6 @@ impl CliConfig {
}
}

/// Get the path to the data directory.
pub fn data(&self) -> Option<&Path> {
self.path_args.data.as_deref()
}

/// Get the path to the cache directory.
pub fn cache(&self) -> Option<&Path> {
match (&self.path_args.cache, &self.deprecated_args.home) {
Expand Down Expand Up @@ -250,11 +227,6 @@ impl CliConfig {
self.deprecated_args.print_config.unwrap_or(false)
}

/// Check if the `--print-data` flag was used.
pub fn print_data(&self) -> bool {
self.deprecated_args.print_data.unwrap_or(false)
}

/// Get an empty configuration object with nothing set.
///
/// This is just an alias for `default()`.
Expand All @@ -280,7 +252,6 @@ impl CliConfig {
format: hc_env_var_value_enum("format"),
},
path_args: PathArgs {
data: hc_env_var("data"),
cache: hc_env_var("cache"),
// For now, we do not get this from the environment, so pass a None to never update this field
policy: None,
Expand All @@ -302,7 +273,6 @@ impl CliConfig {
CliConfig {
path_args: PathArgs {
cache: platform_cache(),
data: platform_data(),
// There is no central per-user or per-system location for the policy file, so pass a None to never update this field
policy: None,
},
Expand All @@ -318,7 +288,6 @@ impl CliConfig {
fn backups() -> CliConfig {
CliConfig {
path_args: PathArgs {
data: dirs::home_dir().map(|dir| pathbuf![&dir, "hipcheck", "data"]),
cache: dirs::home_dir().map(|dir| pathbuf![&dir, "hipcheck", "cache"]),
// TODO: currently if this is set, then when running `hc check`, it errors out
// because policy files are not yet supported
Expand Down Expand Up @@ -347,7 +316,7 @@ fn platform_cache() -> Option<PathBuf> {
fn platform_config() -> Option<PathBuf> {
let base = dirs::config_dir().map(|dir| pathbuf![&dir, "hipcheck"]);

// Config and data paths aren't differentiated on MacOS or Windows,
// Config and (now unused) data paths aren't differentiated on MacOS or Windows,
// so on those platforms we differentiate them ourselves.
if cfg!(target_os = "macos") || cfg!(target_os = "windows") {
base.map(|dir| pathbuf![&dir, "config"])
Expand All @@ -356,21 +325,6 @@ fn platform_config() -> Option<PathBuf> {
}
}

/// Get the platform data directory.
///
/// See: https://docs.rs/dirs/latest/dirs/fn.data_dir.html
fn platform_data() -> Option<PathBuf> {
let base = dirs::data_dir().map(|dir| pathbuf![&dir, "hipcheck"]);

// Config and data paths aren't differentiated on MacOS or Windows,
// so on those platforms we differentiate them ourselves.
if cfg!(target_os = "macos") || cfg!(target_os = "windows") {
base.map(|dir| pathbuf![&dir, "data"])
} else {
base
}
}

/// Get a Hipcheck configuration environment variable.
///
/// This is generic in the return type, to automatically handle
Expand Down Expand Up @@ -400,7 +354,6 @@ pub enum FullCommands {
Cache(CacheArgs),
Plugin(PluginArgs),
PrintConfig,
PrintData,
PrintCache,
Scoring,
}
Expand Down Expand Up @@ -428,13 +381,13 @@ pub enum Commands {
Schema(SchemaArgs),
/// Initialize Hipcheck config file and script file locations.
///
/// The "destination" directories for configuration and data files
/// The "destination" directories for configuration files
/// Hipcheck needs are determined with the following methods, in
/// increasing precedence:
///
/// 1. Platform-specific defaults
/// 2. `HC_CONFIG` and `HC_DATA` environment variables
/// 3. `--config` and `--data` command line flags
/// 2. `HC_CONFIG` environment variable
/// 3. `--config` command line flag
Setup(SetupArgs),
/// Check if Hipcheck is ready to run.
Ready,
Expand Down Expand Up @@ -1158,82 +1111,6 @@ mod tests {
});
}

#[cfg(any(target_os = "linux", target_os = "macos", target_os = "windows"))]
#[test]
fn resolve_data_with_platform() {
let tempdir = TempDir::with_prefix(TEMPDIR_PREFIX).unwrap();

let vars = vec![
("HOME", Some(tempdir.path().to_str().unwrap())),
("XDG_DATA_HOME", None),
("HC_DATA", None),
];

with_env_vars(vars, || {
let config = {
let mut temp = CliConfig::empty();
temp.update(&CliConfig::from_platform());
temp.update(&CliConfig::from_env());
temp
};

assert_eq!(config.data().unwrap(), platform_data().unwrap());
});
}

#[test]
fn resolve_data_with_env_var() {
let tempdir = TempDir::with_prefix(TEMPDIR_PREFIX).unwrap();

let vars = vec![
("HOME", None),
("XDG_DATA_HOME", None),
("HC_DATA", Some(tempdir.path().to_str().unwrap())),
];

with_env_vars(vars, || {
let config = {
let mut temp = CliConfig::empty();
temp.update(&CliConfig::from_platform());
temp.update(&CliConfig::from_env());
temp
};

assert_eq!(config.data().unwrap(), tempdir.path());
});
}

#[test]
fn resolve_data_with_flag() {
let tempdir = TempDir::with_prefix(TEMPDIR_PREFIX).unwrap();

let vars = vec![
("HOME", Some(tempdir.path().to_str().unwrap())),
("XDG_DATA_HOME", None),
("HC_DATA", None),
];

with_env_vars(vars, || {
let expected = pathbuf![tempdir.path(), "hipcheck"];

let config = {
let mut temp = CliConfig::empty();
temp.update(&CliConfig::from_platform());
temp.update(&CliConfig::from_env());
temp.update(&CliConfig {
path_args: PathArgs {
data: Some(expected.clone()),
..Default::default()
},
..Default::default()
});
temp
};

assert_eq!(config.data().unwrap(), expected);
});
}

#[test]
fn resolve_policy_with_flag() {
let tempdir = TempDir::with_prefix(TEMPDIR_PREFIX).unwrap();
Expand Down
13 changes: 0 additions & 13 deletions hipcheck/src/data/git/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,19 +75,6 @@ pub fn get_diffs(repo: &Path) -> Result<Vec<Diff>> {
git_diff(&output)
}

pub fn get_commits_for_file(repo_path: &Path, file: &str) -> Result<String> {
log::debug!("getting commits for file [file = '{}']", file);

let output = GitCommand::for_repo(
repo_path,
["log", "--follow", "--pretty=tformat:%H%n", "--", file],
)?
.output()
.context("git log hash command failed")?;

Ok(output)
}

#[cfg(test)]
mod test {
use super::*;
Expand Down
Loading

0 comments on commit 6a3e49e

Please sign in to comment.