Skip to content

Commit f56f485

Browse files
committed
wip fixing filtering
1 parent 16c4169 commit f56f485

File tree

1 file changed

+51
-12
lines changed

1 file changed

+51
-12
lines changed

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

Lines changed: 51 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -60,33 +60,72 @@ fn add_header(report: &mut String, repository: &str, base_branch: &str, head_bra
6060
}
6161

6262
/// Add summary table by rule
63-
/// Add summary table by rule
64-
fn add_rule_summary(report: &mut String, analysis: &AnalysisResult, rules: &[String], ignored_crate: &str) {
63+
fn add_rule_summary(
64+
report: &mut String,
65+
analysis: &AnalysisResult,
66+
rules: &[String],
67+
ignored_crate: &str,
68+
) {
6569
report.push_str("### Summary by Rule\n\n");
6670
report.push_str("| Rule | Base Branch | PR Branch | Change |\n");
6771
report.push_str("|------|------------|-----------|--------|\n");
6872

6973
let mut total_base = 0;
7074
let mut total_head = 0;
7175

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);
76+
// If we're ignoring a crate, we need to filter and recalculate counts
77+
if !ignored_crate.is_empty() {
78+
// Filter out annotations from the ignored crate
79+
let filtered_base_annotations: Vec<&ClippyAnnotation> = analysis
80+
.base_annotations
81+
.iter()
82+
.filter(|anno| {
83+
let file_path = anno.file.as_str();
84+
!file_path.contains(&format!(".github/actions/{}/", ignored_crate))
85+
})
86+
.collect();
87+
88+
let filtered_head_annotations: Vec<&ClippyAnnotation> = analysis
89+
.head_annotations
90+
.iter()
91+
.filter(|anno| {
92+
let file_path = anno.file.as_str();
93+
!file_path.contains(&format!(".github/actions/{}/", ignored_crate))
94+
})
95+
.collect();
96+
97+
// Count by rule
98+
let filtered_base_counts = count_annotations_by_rule_refs(&filtered_base_annotations);
99+
let filtered_head_counts = count_annotations_by_rule_refs(&filtered_head_annotations);
100+
101+
// Generate the rule summary
102+
for rule_str in rules {
103+
let base_count = filtered_base_counts.get(rule_str).copied().unwrap_or(0);
104+
let head_count = filtered_head_counts.get(rule_str).copied().unwrap_or(0);
105+
106+
total_base += base_count;
107+
total_head += head_count;
108+
109+
add_table_row(report, rule_str, base_count, head_count);
110+
}
111+
} else {
112+
// Use the original counts - this is the test path
113+
for rule_str in rules {
114+
let rule = Rc::new(rule_str.clone());
115+
let base_count = *analysis.base_counts.get(&rule).unwrap_or(&0);
116+
let head_count = *analysis.head_counts.get(&rule).unwrap_or(&0);
78117

79-
total_base += base_count;
80-
total_head += head_count;
118+
total_base += base_count;
119+
total_head += head_count;
81120

82-
add_table_row(report, rule_str, base_count, head_count);
121+
add_table_row(report, rule_str, base_count, head_count);
122+
}
83123
}
84124

85125
// Add total row
86126
add_table_row(report, "**Total**", total_base, total_head);
87127
report.push('\n');
88128
}
89-
90129
// Helper function to count annotations by rule from references
91130
fn count_annotations_by_rule_refs(annotations: &[&ClippyAnnotation]) -> HashMap<Rc<String>, usize> {
92131
let mut counts = HashMap::new();

0 commit comments

Comments
 (0)