Skip to content

Commit 6ca2abb

Browse files
committed
WIP ignore the clippy-annotation-reporter crate
1 parent 2168714 commit 6ca2abb

File tree

2 files changed

+22
-16
lines changed

2 files changed

+22
-16
lines changed

.github/actions/clippy-annotation-reporter/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ clap = { version = "4.3", features = ["derive", "env"] }
99
octocrab = "0.44"
1010
anyhow = "1.0"
1111
regex = "1.9"
12-
# TODO: EK - fix features
1312
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
1413
serde_json = "1.0"
1514
log = "0.4"

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

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,16 @@ pub fn generate_report(
1818
base_branch: &str,
1919
head_branch: &str,
2020
) -> String {
21+
// TODO: This is hardcoded for now, as the presence of the clippy-annotation-reporter crate in
22+
// the repo is temporary. A future feature can allow users to specify crates to ignore.
23+
const IGNORED_CRATE: &str = "clippy-annotation-reporter";
24+
2125
let mut report = String::new();
2226

23-
// Add header and branch information
2427
add_header(&mut report, repository, base_branch, head_branch);
25-
26-
// Add rule summary section
2728
add_rule_summary(&mut report, analysis, rules);
28-
29-
// Add file-level section
30-
add_file_level_section(&mut report, analysis);
31-
32-
// Add crate-level section
33-
add_crate_level_section(&mut report, analysis);
34-
35-
// Add explanation
29+
add_file_level_section(&mut report, analysis, IGNORED_CRATE);
30+
add_crate_level_section(&mut report, analysis, IGNORED_CRATE);
3631
add_explanation(&mut report);
3732

3833
report
@@ -79,7 +74,7 @@ fn add_rule_summary(report: &mut String, analysis: &AnalysisResult, rules: &[Str
7974
}
8075

8176
/// Add section showing annotation counts by file
82-
fn add_file_level_section(report: &mut String, analysis: &AnalysisResult) {
77+
fn add_file_level_section(report: &mut String, analysis: &AnalysisResult, ignored_crate: &str) {
8378
if analysis.changed_files.is_empty() {
8479
return;
8580
}
@@ -98,8 +93,15 @@ fn add_file_level_section(report: &mut String, analysis: &AnalysisResult) {
9893

9994
// Add row for each file
10095
for file in all_files {
101-
let base_count = *base_file_counts.get(&file).unwrap_or(&0);
102-
let head_count = *head_file_counts.get(&file).unwrap_or(&0);
96+
// Skip files that belong to the ignored crate
97+
if !ignored_crate.is_empty()
98+
&& file.contains(&format!(".github/actions/{}/", ignored_crate))
99+
{
100+
continue;
101+
}
102+
103+
let base_count = *base_file_counts.get(&Rc::new(file.clone())).unwrap_or(&0);
104+
let head_count = *head_file_counts.get(&Rc::new(file.clone())).unwrap_or(&0);
103105

104106
// Skip files with no annotations in either branch
105107
if base_count == 0 && head_count == 0 {
@@ -113,7 +115,7 @@ fn add_file_level_section(report: &mut String, analysis: &AnalysisResult) {
113115
}
114116

115117
/// Add section showing annotation stats by crate
116-
fn add_crate_level_section(report: &mut String, analysis: &AnalysisResult) {
118+
fn add_crate_level_section(report: &mut String, analysis: &AnalysisResult, ignored_crate: &str) {
117119
report.push_str("### Annotation Stats by Crate\n\n");
118120
report.push_str("| Crate | Base Branch | PR Branch | Change |\n");
119121
report.push_str("|-------|------------|-----------|--------|\n");
@@ -126,6 +128,11 @@ fn add_crate_level_section(report: &mut String, analysis: &AnalysisResult) {
126128

127129
// Add row for each crate
128130
for crate_name in all_crates {
131+
// Skip the ignored crate
132+
if !ignored_crate.is_empty() && *crate_name == ignored_crate {
133+
continue;
134+
}
135+
129136
let base_count = *analysis.base_crate_counts.get(&crate_name).unwrap_or(&0);
130137
let head_count = *analysis.head_crate_counts.get(&crate_name).unwrap_or(&0);
131138

0 commit comments

Comments
 (0)