Skip to content

Commit 5a2d8d2

Browse files
authored
Merge pull request #667 from safedep/fix/bitbucket-report-misc
fix: bitbucket report mise issues
2 parents 7ac6301 + 09d990d commit 5a2d8d2

2 files changed

Lines changed: 18 additions & 18 deletions

File tree

pkg/reporter/bitbucket/bitbucket_annotations.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func newBitBucketAnnotationForPackage(pkg *models.Package) []*CodeInsightsAnnota
4747
if malwareInfo.IsMalware {
4848
annotations = append(annotations, &CodeInsightsAnnotation{
4949
Title: fmt.Sprintf("Malware Package %s@%s", pkg.Name, pkg.Version),
50-
AnnotationType: AnnotationTypeBug,
50+
AnnotationType: AnnotationTypeCodeSmell,
5151
Summary: fmt.Sprintf("Package %s@%s is malicious", pkg.Name, pkg.Version),
5252
Severity: AnnotationSeverityCritical,
5353
FilePath: packagePath,
@@ -75,15 +75,21 @@ func newBitBucketAnnotationForAnalyzerEvent(event *analyzer.AnalyzerEvent) *Code
7575

7676
title := event.Filter.GetSummary()
7777
if title == "" {
78-
title = "Filter Matched"
78+
title = fmt.Sprintf("Filter %s matched for %s@%s", event.Filter.Name, event.Package.Name, event.Package.Version)
79+
}
80+
81+
summary := event.Filter.GetDescription()
82+
if summary == "" {
83+
summary = fmt.Sprintf("Source: %s", event.Source)
7984
}
8085

8186
return &CodeInsightsAnnotation{
8287
Title: title,
83-
AnnotationType: AnnotationTypeBug,
84-
Summary: event.Filter.GetDescription(),
88+
AnnotationType: AnnotationTypeCodeSmell,
89+
Summary: summary,
8590
Severity: AnnotationSeverityMedium, // Default severity for policy violations
8691
FilePath: event.Package.Manifest.Source.Path,
92+
ExternalID: utils.NewUniqueId(),
8793
}
8894
}
8995

pkg/reporter/bitbucket/bitbucket_models.go

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,15 @@ const (
99
ReportTypeSecurity ReportType = "SECURITY"
1010
ReportTypeCoverage ReportType = "COVERAGE"
1111
ReportTypeTest ReportType = "TEST"
12-
ReportTypeBug ReportType = "BUG"
1312
)
1413

15-
// ReportResult represents the pass/fail status of the report.
1614
type ReportResult string
1715

1816
const (
19-
ReportResultPassed ReportResult = "PASSED"
20-
ReportResultFailed ReportResult = "FAILED"
21-
ReportResultPending ReportResult = "PENDING"
17+
ReportResultPassed ReportResult = "PASSED"
18+
ReportResultFailed ReportResult = "FAILED"
2219
)
2320

24-
// DataType represents the type of value in the report data fields.
2521
type DataType string
2622

2723
const (
@@ -31,19 +27,17 @@ const (
3127
DataTypeLink DataType = "LINK"
3228
DataTypeNumber DataType = "NUMBER"
3329
DataTypePercentage DataType = "PERCENTAGE"
30+
DataTypeString DataType = "STRING"
3431
DataTypeText DataType = "TEXT"
3532
)
3633

37-
// AnnotationType represents the category of the annotation.
3834
type AnnotationType string
3935

4036
const (
4137
AnnotationTypeVulnerability AnnotationType = "VULNERABILITY"
4238
AnnotationTypeCodeSmell AnnotationType = "CODE_SMELL"
43-
AnnotationTypeBug AnnotationType = "BUG"
4439
)
4540

46-
// AnnotationSeverity represents the severity level of the annotation.
4741
type AnnotationSeverity string
4842

4943
const (
@@ -60,7 +54,7 @@ type CodeInsightsReport struct {
6054
Reporter string `json:"reporter,omitempty"`
6155
Link string `json:"link,omitempty"`
6256
Result ReportResult `json:"result,omitempty"`
63-
Data []*CodeInsightsData `json:"data,omitempty"`
57+
Data []*CodeInsightsData `json:"data,omitempty"` // Max 10 elements
6458
}
6559

6660
type CodeInsightsData struct {
@@ -70,12 +64,12 @@ type CodeInsightsData struct {
7064
}
7165

7266
type CodeInsightsAnnotation struct {
73-
Title string `json:"title"`
67+
ExternalID string `json:"external_id,omitempty"` // Unique ID from your system
68+
Title string `json:"title,omitempty"`
7469
AnnotationType AnnotationType `json:"annotation_type"`
7570
Summary string `json:"summary"`
76-
Severity AnnotationSeverity `json:"severity"`
71+
Severity AnnotationSeverity `json:"severity,omitempty"`
7772
FilePath string `json:"path,omitempty"`
78-
LineNumber uint32 `json:"line,omitempty"`
73+
LineNumber int `json:"line,omitempty"`
7974
Link string `json:"link,omitempty"`
80-
ExternalID string `json:"external_id,omitempty"`
8175
}

0 commit comments

Comments
 (0)