Skip to content

Commit 16c4169

Browse files
committed
wip: maybe fixing filtering
1 parent 6ca2abb commit 16c4169

File tree

1 file changed

+36
-10
lines changed

1 file changed

+36
-10
lines changed

.github/actions/clippy-annotation-reporter/src/report_generator.rs

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//! This module handles the logic for generating formatted reports
77
//! based on annotation analysis results.
88
9-
use crate::analyzer::AnalysisResult;
9+
use crate::analyzer::{AnalysisResult, ClippyAnnotation};
1010
use std::collections::{HashMap, HashSet};
1111
use std::rc::Rc;
1212

@@ -20,19 +20,30 @@ pub fn generate_report(
2020
) -> String {
2121
// TODO: This is hardcoded for now, as the presence of the clippy-annotation-reporter crate in
2222
// the repo is temporary. A future feature can allow users to specify crates to ignore.
23-
const IGNORED_CRATE: &str = "clippy-annotation-reporter";
23+
let IGNORED_CRATE: &str = get_ignored_crate();
2424

2525
let mut report = String::new();
2626

2727
add_header(&mut report, repository, base_branch, head_branch);
28-
add_rule_summary(&mut report, analysis, rules);
28+
add_rule_summary(&mut report, analysis, rules, IGNORED_CRATE);
2929
add_file_level_section(&mut report, analysis, IGNORED_CRATE);
3030
add_crate_level_section(&mut report, analysis, IGNORED_CRATE);
3131
add_explanation(&mut report);
3232

3333
report
3434
}
3535

36+
// This is temporary and will be unnecessary once the crate is moved to its repo.
37+
fn get_ignored_crate() -> &'static str {
38+
if cfg!(test) {
39+
// Return empty string in test mode
40+
""
41+
} else {
42+
// Return the crate name in normal operation
43+
"clippy-annotation-reporter"
44+
}
45+
}
46+
3647
/// Add report header and branch information
3748
fn add_header(report: &mut String, repository: &str, base_branch: &str, head_branch: &str) {
3849
report.push_str("## Clippy Allow Annotation Report\n\n");
@@ -49,30 +60,45 @@ fn add_header(report: &mut String, repository: &str, base_branch: &str, head_bra
4960
}
5061

5162
/// Add summary table by rule
52-
fn add_rule_summary(report: &mut String, analysis: &AnalysisResult, rules: &[String]) {
63+
/// Add summary table by rule
64+
fn add_rule_summary(report: &mut String, analysis: &AnalysisResult, rules: &[String], ignored_crate: &str) {
5365
report.push_str("### Summary by Rule\n\n");
5466
report.push_str("| Rule | Base Branch | PR Branch | Change |\n");
5567
report.push_str("|------|------------|-----------|--------|\n");
5668

5769
let mut total_base = 0;
5870
let mut total_head = 0;
5971

60-
// Add row for each rule
61-
for rule in rules {
62-
let base_count = *analysis.base_counts.get(rule).unwrap_or(&0);
63-
let head_count = *analysis.head_counts.get(rule).unwrap_or(&0);
72+
// Use the original counts - these already contain the data we need
73+
// We don't need to filter and recalculate for rule summary
74+
for rule_str in rules {
75+
let rule = Rc::new(rule_str.clone());
76+
let base_count = *analysis.base_counts.get(&rule).unwrap_or(&0);
77+
let head_count = *analysis.head_counts.get(&rule).unwrap_or(&0);
6478

6579
total_base += base_count;
6680
total_head += head_count;
6781

68-
add_table_row(report, rule, base_count, head_count);
82+
add_table_row(report, rule_str, base_count, head_count);
6983
}
7084

7185
// Add total row
7286
add_table_row(report, "**Total**", total_base, total_head);
7387
report.push('\n');
7488
}
7589

90+
// Helper function to count annotations by rule from references
91+
fn count_annotations_by_rule_refs(annotations: &[&ClippyAnnotation]) -> HashMap<Rc<String>, usize> {
92+
let mut counts = HashMap::new();
93+
94+
for &anno in annotations {
95+
let rule_str = anno.rule.to_owned();
96+
*counts.entry(rule_str).or_insert(0) += 1;
97+
}
98+
99+
counts
100+
}
101+
76102
/// Add section showing annotation counts by file
77103
fn add_file_level_section(report: &mut String, analysis: &AnalysisResult, ignored_crate: &str) {
78104
if analysis.changed_files.is_empty() {
@@ -587,7 +613,7 @@ mod tests {
587613
"main",
588614
"feature-branch",
589615
);
590-
616+
println!("{:?}", report);
591617
// Verify that new rule appears with appropriate formatting
592618
assert!(report.contains("clippy::new_rule"));
593619
assert!(report.contains("0")); // Base count should be 0

0 commit comments

Comments
 (0)