diff --git a/docs/changelog.md b/docs/changelog.md index 2e1ea50c..5c022c69 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -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 diff --git a/internal/reporter/bitbucket_api.go b/internal/reporter/bitbucket_api.go index 1979d8b2..62488758 100644 --- a/internal/reporter/bitbucket_api.go +++ b/internal/reporter/bitbucket_api.go @@ -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 diff --git a/internal/reporter/bitbucket_comments_test.go b/internal/reporter/bitbucket_comments_test.go index e4592bdb..0046b008 100644 --- a/internal/reporter/bitbucket_comments_test.go +++ b/internal/reporter/bitbucket_comments_test.go @@ -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 { diff --git a/internal/reporter/bitbucket_test.go b/internal/reporter/bitbucket_test.go index f7d4baef..e1e7eeb3 100644 --- a/internal/reporter/bitbucket_test.go +++ b/internal/reporter/bitbucket_test.go @@ -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",