Skip to content

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

fix: sql review in gitlab ci (#5078)

ecmadao38f6049ed93a
diff --git a/backend/server/webhook.go b/backend/server/webhook.go
index b3d85466ae..a21939ff56 100644
--- a/backend/server/webhook.go
+++ b/backend/server/webhook.go
@@ -1254,7 +1254,6 @@ func (s *Server) tryUpdateTasksFromModifiedFile(ctx context.Context, databases [
// convertSQLAdviceToGitLabCIResult will convert SQL advice map to GitLab test output format.
// GitLab test report: https://docs.gitlab.com/ee/ci/testing/unit_test_reports.html
// junit XML format: https://llg.cubic.org/docs/junit/
-// nolint:unused
func convertSQLAdviceToGitLabCIResult(adviceMap map[string][]advisor.Advice) *api.VCSSQLReviewResult {
testsuiteList := []string{}
status := advisor.Success
@@ -1268,6 +1267,9 @@ func convertSQLAdviceToGitLabCIResult(adviceMap map[string][]advisor.Advice) *ap
for _, filePath := range fileList {
adviceList := adviceMap[filePath]
testcaseList := []string{}
+ pathes := strings.Split(filePath, "/")
+ filename := pathes[len(pathes)-1]
+
for _, advice := range adviceList {
if advice.Code == 0 {
continue
@@ -1292,7 +1294,7 @@ func convertSQLAdviceToGitLabCIResult(adviceMap map[string][]advisor.Advice) *ap
testcase := fmt.Sprintf(
"<testcase name=\"%s\" classname=\"%s\" file=\"%s#L%d\">\n<failure>\n%s\n</failure>\n</testcase>",
- advice.Title,
+ fmt.Sprintf("%s#L%d: %s", filename, line, advice.Title),
filePath,
filePath,
line,
@@ -1323,7 +1325,6 @@ func convertSQLAdviceToGitLabCIResult(adviceMap map[string][]advisor.Advice) *ap
// convertSQLAdviceToGitHubActionResult will convert SQL advice map to GitHub action output format.
// GitHub action output message: https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions
-// nolint:unused
func convertSQLAdviceToGitHubActionResult(adviceMap map[string][]advisor.Advice) *api.VCSSQLReviewResult {
messageList := []string{}
status := advisor.Success
diff --git a/backend/server/webhook_test.go b/backend/server/webhook_test.go
index 763e35fcea..25187d18c1 100644
--- a/backend/server/webhook_test.go
+++ b/backend/server/webhook_test.go
@@ -137,13 +137,13 @@ func TestVCSSQLReview_ConvertSQLAdviceToGitLabCIResult(t *testing.T) {
`<?xml version="1.0" encoding="UTF-8"?>
<testsuites name="SQL Review">
<testsuite name="file1.sql">
-<testcase name="column.no-null" classname="file1.sql" file="file1.sql#L1">
+<testcase name="file1.sql#L1: column.no-null" classname="file1.sql" file="file1.sql#L1">
<failure>
Error: Column "id" in "public"."book" cannot have NULL value.
You can check the docs at https://www.bytebase.com/docs/reference/error-code/advisor#402
</failure>
</testcase>
-<testcase name="naming.index.idx" classname="file1.sql" file="file1.sql#L2">
+<testcase name="file1.sql#L2: naming.index.idx" classname="file1.sql" file="file1.sql#L2">
<failure>
Error: Index in table "tech_book" mismatches the naming convention, expect "^$|^idx_tech_book_id_name$" but found "tech_book_id_name".
You can check the docs at https://www.bytebase.com/docs/reference/error-code/advisor#303
@@ -151,13 +151,13 @@ You can check the docs at https://www.bytebase.com/docs/reference/error-code/adv
</testcase>
</testsuite>
<testsuite name="file2.sql">
-<testcase name="naming.table" classname="file2.sql" file="file2.sql#L1">
+<testcase name="file2.sql#L1: naming.table" classname="file2.sql" file="file2.sql#L1">
<failure>
Error: "techBook" mismatches table naming convention, naming format should be "^[a-z]+(_[a-z]+)*$".
You can check the docs at https://www.bytebase.com/docs/reference/error-code/advisor#301
</failure>
</testcase>
-<testcase name="naming.index.uk" classname="file2.sql" file="file2.sql#L4">
+<testcase name="file2.sql#L4: naming.index.uk" classname="file2.sql" file="file2.sql#L4">
<failure>
Error: Unique key in table "tech_book" mismatches the naming convention, expect "^$|^uk_tech_book_id_name$" but found "tech_book_id_name".
You can check the docs at https://www.bytebase.com/docs/reference/error-code/advisor#304
diff --git a/backend/tests/schema_update_test.go b/backend/tests/schema_update_test.go
index 33d804f7dd..0d9b4fed4d 100644
--- a/backend/tests/schema_update_test.go
+++ b/backend/tests/schema_update_test.go
@@ -12,6 +12,7 @@ import (
"os"
"path"
"strconv"
+ "strings"
"testing"
"time"
@@ -1401,12 +1402,14 @@ func TestVCS_SQL_Review(t *testing.T) {
externalID: "121",
repositoryFullPath: "test/schemaUpdate",
getEmptySQLReviewResult: func(repo *api.Repository, filePath, rootURL string) *api.VCSSQLReviewResult {
+ pathes := strings.Split(filePath, "/")
return &api.VCSSQLReviewResult{
Status: advisor.Warn,
Content: []string{
fmt.Sprintf(
- "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<testsuites name=\"SQL Review\">\n<testsuite name=\"%s\">\n<testcase name=\"SQL review policy not found\" classname=\"%s\" file=\"%s#L1\">\n<failure>\nError: You can configure the SQL review policy on %s/setting/sql-review.\nYou can check the docs at https://www.bytebase.com/docs/reference/error-code/advisor#2\n</failure>\n</testcase>\n</testsuite>\n</testsuites>",
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<testsuites name=\"SQL Review\">\n<testsuite name=\"%s\">\n<testcase name=\"%s#L1: SQL review policy not found\" classname=\"%s\" file=\"%s#L1\">\n<failure>\nError: You can configure the SQL review policy on %s/setting/sql-review.\nYou can check the docs at https://www.bytebase.com/docs/reference/error-code/advisor#2\n</failure>\n</testcase>\n</testsuite>\n</testsuites>",
filePath,
+ pathes[len(pathes)-1],
filePath,
filePath,
rootURL,
@@ -1415,14 +1418,18 @@ func TestVCS_SQL_Review(t *testing.T) {
}
},
getSQLReviewResult: func(repo *api.Repository, filePath string) *api.VCSSQLReviewResult {
+ pathes := strings.Split(filePath, "/")
+ filename := pathes[len(pathes)-1]
return &api.VCSSQLReviewResult{
Status: advisor.Warn,
Content: []string{
fmt.Sprintf(
- "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<testsuites name=\"SQL Review\">\n<testsuite name=\"%s\">\n<testcase name=\"column.required\" classname=\"%s\" file=\"%s#L1\">\n<failure>\nError: Table \"book\" requires columns: created_ts, creator_id, updated_ts, updater_id.\nYou can check the docs at https://www.bytebase.com/docs/reference/error-code/advisor#401\n</failure>\n</testcase>\n<testcase name=\"column.no-null\" classname=\"%s\" file=\"%s#L1\">\n<failure>\nError: Column \"name\" in \"public\".\"book\" cannot have NULL value.\nYou can check the docs at https://www.bytebase.com/docs/reference/error-code/advisor#402\n</failure>\n</testcase>\n</testsuite>\n</testsuites>",
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<testsuites name=\"SQL Review\">\n<testsuite name=\"%s\">\n<testcase name=\"%s#L1: column.required\" classname=\"%s\" file=\"%s#L1\">\n<failure>\nError: Table \"book\" requires columns: created_ts, creator_id, updated_ts, updater_id.\nYou can check the docs at https://www.bytebase.com/docs/reference/error-code/advisor#401\n</failure>\n</testcase>\n<testcase name=\"%s#L1: column.no-null\" classname=\"%s\" file=\"%s#L1\">\n<failure>\nError: Column \"name\" in \"public\".\"book\" cannot have NULL value.\nYou can check the docs at https://www.bytebase.com/docs/reference/error-code/advisor#402\n</failure>\n</testcase>\n</testsuite>\n</testsuites>",
filePath,
+ filename,
filePath,
filePath,
+ filename,
filePath,
filePath,
),