Skip to content

Commit 276f538

Browse files
committed
fixing warning for cicd
1 parent 3f07a34 commit 276f538

5 files changed

Lines changed: 69 additions & 58 deletions

File tree

src/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub enum PatrolError {
3030
Regex(#[from] regex::Error),
3131

3232
#[error("fancy-regex error: {0}")]
33-
FancyRegex(#[from] fancy_regex::Error),
33+
FancyRegex(#[from] Box<fancy_regex::Error>),
3434
}
3535

3636
pub type Result<T> = std::result::Result<T, PatrolError>;

src/main.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ use diffcatcher::error::{PatrolError, Result};
1717
use diffcatcher::extraction::ExtractionOptions;
1818
use diffcatcher::extraction::plugins::{ExtractorPlugin, load_extractor_plugins};
1919
use diffcatcher::git::commands::run_git_expect_stdout;
20-
use diffcatcher::processor::{ProcessorConfig, process_diff_refs, process_repository};
20+
use diffcatcher::processor::{
21+
DiffRefsConfig, ProcessorConfig, process_diff_refs, process_repository,
22+
};
2123
use diffcatcher::progress::{ProgressReporter, Verbosity};
2224
use diffcatcher::report::writer::{prepare_report_dir, write_repo_report, write_top_level_reports};
2325
use diffcatcher::scanner::{ScanOptions, discover_repositories};
@@ -269,18 +271,16 @@ fn run_diff_mode(
269271
plugin_extractors: extractor_plugins.to_vec(),
270272
};
271273

272-
let mut result = process_diff_refs(
273-
repo_path,
274-
report_dir,
275-
base,
276-
head,
277-
settings.timeout,
278-
&extraction,
279-
settings.no_security_tags,
280-
settings.include_test_security,
274+
let config = DiffRefsConfig {
275+
timeout_secs: settings.timeout,
276+
extraction: &extraction,
277+
no_security_tags: settings.no_security_tags,
278+
include_test_security: settings.include_test_security,
281279
tag_definitions,
282-
settings.verbose,
283-
);
280+
verbose: settings.verbose,
281+
};
282+
283+
let mut result = process_diff_refs(repo_path, report_dir, base, head, &config);
284284

285285
write_repo_report(report_dir, &mut result, &settings.summary_formats)?;
286286

src/processor.rs

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,22 @@ pub struct ProcessorConfig {
4545
pub verbose: bool,
4646
}
4747

48+
#[derive(Debug, Clone)]
49+
pub struct DiffRefsConfig<'a> {
50+
pub timeout_secs: u64,
51+
pub extraction: &'a ExtractionOptions,
52+
pub no_security_tags: bool,
53+
pub include_test_security: bool,
54+
pub tag_definitions: &'a [SecurityTagDefinition],
55+
pub verbose: bool,
56+
}
57+
4858
pub fn process_diff_refs(
4959
repo_path: &Path,
5060
report_dir: &Path,
5161
base_ref: &str,
5262
head_ref: &str,
53-
timeout_secs: u64,
54-
extraction: &ExtractionOptions,
55-
no_security_tags: bool,
56-
include_test_security: bool,
57-
tag_definitions: &[SecurityTagDefinition],
58-
_verbose: bool,
63+
config: &DiffRefsConfig,
5964
) -> RepoResult {
6065
let repo_name = repo_path
6166
.file_name()
@@ -66,7 +71,7 @@ pub fn process_diff_refs(
6671
let report_folder_name = repo_name.clone();
6772
let mut errors = Vec::new();
6873

69-
let base_commit = match capture_commit(repo_path, timeout_secs, base_ref) {
74+
let base_commit = match capture_commit(repo_path, config.timeout_secs, base_ref) {
7075
Ok(c) => c,
7176
Err(err) => {
7277
return RepoResult {
@@ -87,7 +92,7 @@ pub fn process_diff_refs(
8792
}
8893
};
8994

90-
let head_commit = match capture_commit(repo_path, timeout_secs, head_ref) {
95+
let head_commit = match capture_commit(repo_path, config.timeout_secs, head_ref) {
9196
Ok(c) => c,
9297
Err(err) => {
9398
return RepoResult {
@@ -125,7 +130,7 @@ pub fn process_diff_refs(
125130
let mut diffs = Vec::new();
126131
let mut retrieval_cache = ShowFileCache::new(SHOW_FILE_CACHE_CAPACITY);
127132

128-
match generate_diff_artifacts(repo_path, &diff_dir, timeout_secs, &pair) {
133+
match generate_diff_artifacts(repo_path, &diff_dir, config.timeout_secs, &pair) {
129134
Ok(artifacts) => {
130135
let patch_path = diff_dir.join(&artifacts.patch_filename);
131136
let patch_bytes = fs::read(&patch_path).unwrap_or_default();
@@ -145,27 +150,27 @@ pub fn process_diff_refs(
145150
&artifacts.name_status,
146151
&base_commit.hash,
147152
&head_commit.hash,
148-
extraction,
153+
config.extraction,
149154
)
150155
})) {
151156
Ok((mut file_changes, element_summary)) => {
152157
apply_git_show_diffonly_fallback(
153158
repo_path,
154-
timeout_secs,
159+
config.timeout_secs,
155160
&base_commit.hash,
156161
&head_commit.hash,
157162
&mut file_changes,
158163
&mut retrieval_cache,
159164
&mut errors,
160165
);
161166

162-
let security_review = if no_security_tags {
167+
let security_review = if config.no_security_tags {
163168
None
164169
} else {
165170
match tag_file_changes(
166171
&mut file_changes,
167-
tag_definitions,
168-
include_test_security,
172+
config.tag_definitions,
173+
config.include_test_security,
169174
) {
170175
Ok(review) => Some(review),
171176
Err(err) => {
@@ -560,20 +565,23 @@ pub fn process_repository<'a>(
560565
}
561566
}
562567

563-
emit(if errors.is_empty()
564-
&& !matches!(
568+
emit(
569+
if errors.is_empty()
570+
&& !matches!(
571+
status,
572+
RepoStatus::FetchFailed { .. } | RepoStatus::PullFailed { .. }
573+
)
574+
{
575+
ProcessingState::Complete
576+
} else if matches!(
565577
status,
566578
RepoStatus::FetchFailed { .. } | RepoStatus::PullFailed { .. }
567579
) {
568-
ProcessingState::Complete
569-
} else if matches!(
570-
status,
571-
RepoStatus::FetchFailed { .. } | RepoStatus::PullFailed { .. }
572-
) {
573-
ProcessingState::Failed
574-
} else {
575-
ProcessingState::Complete
576-
});
580+
ProcessingState::Failed
581+
} else {
582+
ProcessingState::Complete
583+
},
584+
);
577585

578586
RepoResult {
579587
repo_path: repo_path.to_path_buf(),

src/progress.rs

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
use std::fmt;
2-
use std::sync::atomic::{AtomicU32, Ordering};
32
use std::sync::Mutex;
3+
use std::sync::atomic::{AtomicU32, Ordering};
44
use std::time::{Duration, Instant};
55

66
use indicatif::{MultiProgress, ProgressBar, ProgressStyle};
77

8-
use crate::types::{
9-
ChangeType, GlobalSummary, RepoResult, RepoStatus,
10-
};
8+
use crate::types::{ChangeType, GlobalSummary, RepoResult, RepoStatus};
119

1210
// ── Processing states ──────────────────────────────────────────────────────
1311

@@ -71,8 +69,7 @@ impl RepoStats {
7169

7270
if let Some(es) = &diff.element_summary {
7371
stats.elements_total += es.total_elements;
74-
stats.elements_added +=
75-
*es.by_change_type.get(&ChangeType::Added).unwrap_or(&0);
72+
stats.elements_added += *es.by_change_type.get(&ChangeType::Added).unwrap_or(&0);
7673
stats.elements_modified +=
7774
*es.by_change_type.get(&ChangeType::Modified).unwrap_or(&0);
7875
stats.elements_removed +=
@@ -187,13 +184,9 @@ impl ProgressReporter {
187184
state.repo_times.push(elapsed);
188185

189186
if let RepoStatus::FetchFailed { ref error } = result.status {
190-
state
191-
.errors
192-
.push((result.repo_name.clone(), error.clone()));
187+
state.errors.push((result.repo_name.clone(), error.clone()));
193188
} else if let RepoStatus::PullFailed { ref error } = result.status {
194-
state
195-
.errors
196-
.push((result.repo_name.clone(), error.clone()));
189+
state.errors.push((result.repo_name.clone(), error.clone()));
197190
}
198191
for err in &result.errors {
199192
if !matches!(
@@ -364,9 +357,18 @@ impl ProgressReporter {
364357

365358
// Aggregate statistics
366359
out.push_str(" Statistics:\n");
367-
out.push_str(&format!(" Files changed: {}\n", total_files_changed));
368-
out.push_str(&format!(" Elements extracted: {}\n", total_elements));
369-
out.push_str(&format!(" Security-tagged elements: {}\n", total_security));
360+
out.push_str(&format!(
361+
" Files changed: {}\n",
362+
total_files_changed
363+
));
364+
out.push_str(&format!(
365+
" Elements extracted: {}\n",
366+
total_elements
367+
));
368+
out.push_str(&format!(
369+
" Security-tagged elements: {}\n",
370+
total_security
371+
));
370372
if high_attention > 0 {
371373
out.push_str(&format!(
372374
" \x1b[31mHigh-attention items: {}\x1b[0m\n",
@@ -426,10 +428,11 @@ impl ProgressReporter {
426428
.errors
427429
.iter()
428430
.any(|(_, e)| e.contains("timeout") || e.contains("Timeout"));
429-
let has_auth = state
430-
.errors
431-
.iter()
432-
.any(|(_, e)| e.contains("Authentication") || e.contains("authentication") || e.contains("could not read Username"));
431+
let has_auth = state.errors.iter().any(|(_, e)| {
432+
e.contains("Authentication")
433+
|| e.contains("authentication")
434+
|| e.contains("could not read Username")
435+
});
433436

434437
if has_permission || has_timeout || has_auth {
435438
out.push('\n');

src/security/tagger.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ fn compile_pattern(pattern: &str, kind: Option<PatternKind>) -> Result<CompiledP
6262
let pat = format!("(?i){}", pattern);
6363
match kind {
6464
Some(PatternKind::FancyRegex) => {
65-
let re = FancyRegex::new(&pat)?;
65+
let re = FancyRegex::new(&pat).map_err(Box::new)?;
6666
Ok(CompiledPattern::Fancy(re))
6767
}
6868
_ => {

0 commit comments

Comments
 (0)