Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
lsegal committed Jan 15, 2025
1 parent 3144502 commit 2d44500
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 17 deletions.
7 changes: 3 additions & 4 deletions qlty-cli/src/commands/coverage/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use anyhow::Result;
use clap::Args;
use console::style;
use indicatif::HumanBytes;
use qlty_analysis::utils::fs::path_to_string;
use qlty_config::version::LONG_VERSION;
use qlty_config::{QltyConfig, Workspace};
use qlty_coverage::eprintln_unless;
Expand Down Expand Up @@ -51,7 +50,8 @@ pub struct Publish {
pub transform_add_prefix: Option<String>,

#[arg(long)]
/// The prefix to remove from absolute paths in coverage payloads, to make them relative to the project root. This is usually the directory in which the tests were run. Defaults to current working directory.
/// The prefix to remove from absolute paths in coverage payloads to make them relative to the project root.
/// This is usually the directory in which the tests were run. Defaults to the root of the git repository.
pub transform_strip_prefix: Option<String>,

#[arg(long, short)]
Expand All @@ -76,7 +76,6 @@ pub struct Publish {
impl Publish {
// TODO: Use CommandSuccess and CommandError, which is not straight forward since those types aren't available here.
pub fn execute(&self, _args: &crate::Arguments) -> Result<CommandSuccess, CommandError> {
let root = path_to_string(Workspace::assert_within_git_directory()?);
self.print_initial_messages();

let token = match self.load_auth_token() {
Expand All @@ -96,7 +95,7 @@ impl Publish {
override_branch: self.override_branch.clone(),
override_pull_request_number: self.override_pr_number.clone(),
add_prefix: self.transform_add_prefix.clone(),
strip_prefix: self.transform_strip_prefix.clone().unwrap_or(root),
strip_prefix: self.transform_strip_prefix.clone(),
tag: self.tag.clone(),
report_format: self.report_format,
paths: self.paths.clone(),
Expand Down
9 changes: 4 additions & 5 deletions qlty-cli/src/commands/coverage/transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ use crate::{CommandError, CommandSuccess};
use anyhow::Result;
use clap::Args;
use console::style;
use qlty_analysis::utils::fs::path_to_string;
use qlty_cloud::format::JsonEachRowFormatter;
use qlty_config::{version::LONG_VERSION, Workspace};
use qlty_config::version::LONG_VERSION;
use qlty_coverage::{
eprintln_unless,
formats::Formats,
Expand All @@ -29,7 +28,8 @@ pub struct Transform {
pub add_prefix: Option<String>,

#[arg(long)]
/// The prefix to remove from absolute paths in coverage payloads. This makes paths relative to the project root, typically the directory where tests were run. Defaults to the current working directory.
/// The prefix to remove from absolute paths in coverage payloads to make them relative to the project root.
/// This is usually the directory in which the tests were run. Defaults to the root of the git repository.
pub strip_prefix: Option<String>,

#[arg(long)]
Expand All @@ -54,7 +54,6 @@ pub struct Transform {

impl Transform {
pub fn execute(&self, _args: &crate::Arguments) -> Result<CommandSuccess, CommandError> {
let root = path_to_string(Workspace::assert_within_git_directory()?);
self.print_initial_messages();

if !self.quiet {
Expand All @@ -64,7 +63,7 @@ impl Transform {
let settings = Settings {
report_format: self.report_format,
add_prefix: self.add_prefix.clone(),
strip_prefix: self.strip_prefix.clone().unwrap_or(root),
strip_prefix: self.strip_prefix.clone(),
path: self.path.clone(),
};

Expand Down
10 changes: 7 additions & 3 deletions qlty-coverage/src/publish/planner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,13 @@ impl Planner {
let mut transformers: Vec<Box<dyn Transformer>> = vec![];

transformers.push(Box::new(ComputeSummary::new()));
transformers.push(Box::new(StripPrefix::new(
self.settings.strip_prefix.clone(),
)));

if let Some(prefix) = self.settings.strip_prefix.clone() {
transformers.push(Box::new(StripPrefix::new(prefix)));
} else {
transformers.push(Box::new(StripPrefix::new_from_git_root()?));
}

transformers.push(Box::new(StripDotSlashPrefix));

if self.config.coverage.ignores.is_some() {
Expand Down
2 changes: 1 addition & 1 deletion qlty-coverage/src/publish/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ pub struct Settings {
pub report_format: Option<Formats>,

pub add_prefix: Option<String>,
pub strip_prefix: String,
pub strip_prefix: Option<String>,
}
9 changes: 6 additions & 3 deletions qlty-coverage/src/transform/planner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,12 @@ impl Planner {
fn compute_transformers(&self) -> Result<Vec<Box<dyn Transformer>>> {
let mut transformers: Vec<Box<dyn Transformer>> = vec![];

transformers.push(Box::new(StripPrefix::new(
self.settings.strip_prefix.clone(),
)));
if let Some(prefix) = self.settings.strip_prefix.clone() {
transformers.push(Box::new(StripPrefix::new(prefix)));
} else {
transformers.push(Box::new(StripPrefix::new_from_git_root()?));
}

transformers.push(Box::new(StripDotSlashPrefix));

if let Some(prefix) = self.settings.add_prefix.clone() {
Expand Down
2 changes: 1 addition & 1 deletion qlty-coverage/src/transform/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ pub struct Settings {
pub path: String,
pub report_format: Option<Formats>,
pub add_prefix: Option<String>,
pub strip_prefix: String,
pub strip_prefix: Option<String>,
}
7 changes: 7 additions & 0 deletions qlty-coverage/src/transformer.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use anyhow::Result;
use globset::{Glob, GlobSet, GlobSetBuilder};
use qlty_config::Workspace;
use qlty_types::tests::v1::{CoverageMetadata, CoverageSummary, FileCoverage};
use std::{fmt::Debug, path::PathBuf};

Expand Down Expand Up @@ -157,6 +158,12 @@ impl StripPrefix {
prefix: PathBuf::from(prefix),
}
}

pub fn new_from_git_root() -> Result<Self> {
Ok(Self {
prefix: Workspace::assert_within_git_directory()?,
})
}
}

impl Transformer for StripPrefix {
Expand Down

0 comments on commit 2d44500

Please sign in to comment.