Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

chore: bitbucket risk report (#15841)

Danny Xua9def65b2938
diff --git a/action/bitbucket.go b/action/bitbucket.go
index bd25f862a8..fbde179fd3 100644
--- a/action/bitbucket.go
+++ b/action/bitbucket.go
@@ -14,6 +14,15 @@ import (
v1pb "github.com/bytebase/bytebase/proto/generated-go/v1"
)
+// Define a struct for the report data
+type Report struct {
+ Title string `json:"title"`
+ Details string `json:"details"`
+ ReportType string `json:"report_type"`
+ Reporter string `json:"reporter"`
+ Result string `json:"result"`
+}
+
// Annotation represents the structure of a Bitbucket Code Insights annotation.
// https://developer.atlassian.com/cloud/bitbucket/rest/api-group-reports/#api-repositories-workspace-repo-slug-commit-commit-reports-reportid-annotations-post
type Annotation struct {
@@ -57,20 +66,36 @@ func createBitbucketReport(checkResponse *v1pb.CheckReleaseResponse) error {
}
}
}
- result, details := "PASSED", "This pull request has passed all checks."
+ var riskDetail string
+ switch checkResponse.RiskLevel {
+ case v1pb.CheckReleaseResponse_LOW:
+ riskDetail = "🟢 Low"
+ case v1pb.CheckReleaseResponse_MODERATE:
+ riskDetail = "🟡 Moderate"
+ case v1pb.CheckReleaseResponse_HIGH:
+ riskDetail = "🔴 High"
+ default:
+ riskDetail = "⚪ None"
+ }
+ details := fmt.Sprintf(`• Total Affected Rows: %d
+• Overall Risk Level: %s
+• Advices Statistics: %d Error(s), %d Warning(s)`, checkResponse.GetAffectedRows(), riskDetail, errorCount, warningCount)
+ result := "PASSED"
if errorCount > 0 {
- result, details = "FAILED", fmt.Sprintf("This pull request introduces %d errors and %d warnings.", errorCount, warningCount)
- } else if warningCount > 0 {
- details = fmt.Sprintf("This pull request introduces %d warnings.", warningCount)
+ result = "FAILED"
+ }
+ report := Report{
+ Title: "Bytebase SQL Review",
+ Details: details,
+ ReportType: "TEST",
+ Reporter: "bytebase",
+ Result: result,
+ }
+ reportDataBytes, err := json.Marshal(report)
+ if err != nil {
+ return errors.Wrap(err, "failed to marshal report data")
}
- reportData := fmt.Sprintf(`{
- "title": "Bytebase SQL Review",
- "details": "%s",
- "report_type": "TEST",
- "reporter": "bytebase",
- "result": "%s",
- "data": []
- }`, details, result)
+ reportData := string(reportDataBytes)
if err := sendPutRequest(client, http.MethodPut, reportURL, reportData); err != nil {
return err
}
diff --git a/action/gitlab.go b/action/gitlab.go
index 3d5a914257..1ec45494ef 100644
--- a/action/gitlab.go
+++ b/action/gitlab.go
@@ -32,13 +32,46 @@ type Finding struct {
func writeReleaseCheckToCodeQualityJSON(resp *v1pb.CheckReleaseResponse) error {
var data []Finding
+ var warningCount, errorCount int
+ for _, result := range resp.Results {
+ for _, advice := range result.Advices {
+ switch advice.Status {
+ case v1pb.Advice_WARNING:
+ warningCount++
+ case v1pb.Advice_ERROR:
+ errorCount++
+ default:
+ continue
+ }
+ }
+ }
+ var riskDetail string
+ switch resp.RiskLevel {
+ case v1pb.CheckReleaseResponse_LOW:
+ riskDetail = "🟢 Low"
+ case v1pb.CheckReleaseResponse_MODERATE:
+ riskDetail = "🟡 Moderate"
+ case v1pb.CheckReleaseResponse_HIGH:
+ riskDetail = "🔴 High"
+ default:
+ riskDetail = "⚪ None"
+ }
+ details := fmt.Sprintf(`Summary: • Total Affected Rows: %d
+• Overall Risk Level: %s
+• Advices Statistics: %d Error(s), %d Warning(s)`, resp.GetAffectedRows(), riskDetail, errorCount, warningCount)
+ data = append(data, Finding{
+ Description: details,
+ CheckName: "Summary",
+ Fingerprint: "summary",
+ Severity: "info",
+ })
for _, result := range resp.Results {
for _, advice := range result.Advices {
var severity string
// Valid values are info, minor, major, critical, or blocker.
switch advice.Status {
case v1pb.Advice_WARNING:
- severity = "info"
+ severity = "minor"
case v1pb.Advice_ERROR:
severity = "critical"
default: