Skip to content

Commit

Permalink
Merge pull request #924 from cloudflare/dedup
Browse files Browse the repository at this point in the history
Fix dedup on reports with same body
  • Loading branch information
prymitive authored Mar 22, 2024
2 parents d14c85f + bb8f00e commit 685d77b
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

- [query/cost](checks/query/cost.md) will now only create reports if a query is more
expensive than any of the configured limits.
- Fixed duplicated reports when using BitBucket reporter.

## v0.56.1

Expand Down
4 changes: 4 additions & 0 deletions internal/reporter/bitbucket_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,10 @@ func dedupReports(src []Report) (dst [][]Report) {
dst = append(dst, []Report{report})
continue
}
// Skip this report if we have exact same message already
if dst[index][0].Problem.Text == report.Problem.Text && dst[index][0].Problem.Details == report.Problem.Details {
continue
}
dst[index] = append(dst[index], report)
}
return dst
Expand Down
56 changes: 56 additions & 0 deletions internal/reporter/bitbucket_comments_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,62 @@ func TestBitBucketMakeComments(t *testing.T) {
},
},
},
{
description: "dedup identical reports",
summary: Summary{reports: []Report{
{
ReportedPath: "rule.yaml",
SourcePath: "rule.yaml",
ModifiedLines: []int{2, 3},
Problem: checks.Problem{
Severity: checks.Bug,
Lines: parser.LineRange{
First: 2,
Last: 2,
},
Text: "my error",
Details: "my details",
Reporter: "r1",
},
},
{
ReportedPath: "rule.yaml",
SourcePath: "rule.yaml",
ModifiedLines: []int{2, 3},
Problem: checks.Problem{
Severity: checks.Bug,
Lines: parser.LineRange{
First: 2,
Last: 2,
},
Text: "my error",
Details: "my details",
Reporter: "r1",
},
},
}},
changes: &bitBucketPRChanges{
pathModifiedLines: map[string][]int{
"rule.yaml": {2, 3},
},
pathLineMapping: map[string]map[int]int{
"rule.yaml": {2: 2, 3: 3},
},
},
comments: []BitBucketPendingComment{
{
Text: commentBody("stop_sign", "Bug", "r1", "my error\n\nmy details"),
Severity: "BLOCKER",
Anchor: BitBucketPendingCommentAnchor{
Path: "rule.yaml",
Line: 2,
LineType: "ADDED",
FileType: "TO",
DiffType: "EFFECTIVE",
},
},
},
},
}

for _, tc := range testCases {
Expand Down
2 changes: 1 addition & 1 deletion internal/reporter/bitbucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1677,7 +1677,7 @@ func TestBitBucketReporter(t *testing.T) {
},
pullRequestComments: []reporter.BitBucketPendingComment{
{
Text: ":stop_sign: **Bug** reported by [pint](https://cloudflare.github.io/pint/) **mock** check.\n\n------\n\nthis should be ignored, line is not part of the diff\n\n------\n\nthis should be ignored, line is not part of the diff\n\n------\n\n:information_source: To see documentation covering this check and instructions on how to resolve it [click here](https://cloudflare.github.io/pint/checks/mock.html).\n",
Text: ":stop_sign: **Bug** reported by [pint](https://cloudflare.github.io/pint/) **mock** check.\n\n------\n\nthis should be ignored, line is not part of the diff\n\n------\n\n:information_source: To see documentation covering this check and instructions on how to resolve it [click here](https://cloudflare.github.io/pint/checks/mock.html).\n",
Severity: "BLOCKER",
Anchor: reporter.BitBucketPendingCommentAnchor{
Path: "foo.txt",
Expand Down

0 comments on commit 685d77b

Please sign in to comment.