Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
chore: support sql review ci for bitbucket (#10809)
ecmadao459204ff2b6a
diff --git a/backend/api/gitops/webhook.go b/backend/api/gitops/webhook.goindex e0cebe9725..5134d2b73f 100644--- a/backend/api/gitops/webhook.go+++ b/backend/api/gitops/webhook.go@@ -615,14 +615,6 @@ func (s *Service) RegisterWebhookRoutes(g *echo.Group) {return false, nil}- if !strings.HasPrefix(repo.WebURL, request.WebURL) {- slog.Debug("Skip repository as the web URL is not matched.",- slog.String("request_web_url", request.WebURL),- slog.String("repo_web_url", repo.WebURL),- )- return false, nil- }-// We will use workspace id as token in integration test for skipping the check.return token == workspaceID || token == repo.WebhookSecretToken, nil}@@ -2281,6 +2273,8 @@ func convertSQLAdviceToGitLabCIResult(adviceMap map[string][]advisor.Advice) *appathes := strings.Split(filePath, "/")filename := pathes[len(pathes)-1]+ errorCount := 0+ failureCount := 0for _, advice := range adviceList {if advice.Code == 0 {continue@@ -2293,8 +2287,12 @@ func convertSQLAdviceToGitLabCIResult(adviceMap map[string][]advisor.Advice) *apif advice.Status == advisor.Error {status = advice.Status- } else if advice.Status == advisor.Warn && status != advisor.Error {- status = advice.Status+ errorCount+++ } else if advice.Status == advisor.Warn {+ failureCount+++ if status != advisor.Error {+ status = advice.Status+ }}content := fmt.Sprintf("Error: %s.\nPlease check the docs at %s#%d",@@ -2318,7 +2316,7 @@ func convertSQLAdviceToGitLabCIResult(adviceMap map[string][]advisor.Advice) *apif len(testcaseList) > 0 {testsuiteList = append(testsuiteList,- fmt.Sprintf("<testsuite name=\"%s\">\n%s\n</testsuite>", filePath, strings.Join(testcaseList, "\n")),+ fmt.Sprintf("<testsuite errors=\"%d\" failures=\"%d\" tests=\"%d\" name=\"%s\">\n%s\n</testsuite>", errorCount, failureCount, len(adviceList), filePath, strings.Join(testcaseList, "\n")),)}}diff --git a/backend/api/gitops/webhook_test.go b/backend/api/gitops/webhook_test.goindex 328b1c01f2..e08faf27b1 100644--- a/backend/api/gitops/webhook_test.go+++ b/backend/api/gitops/webhook_test.go@@ -139,7 +139,7 @@ func TestVCSSQLReview_ConvertSQLAdviceToGitLabCIResult(t *testing.T) {expect :=`<?xml version="1.0" encoding="UTF-8"?><testsuites name="SQL Review">-<testsuite name="file1.sql">+<testsuite errors="1" failures="1" tests="3" name="file1.sql"><testcase name="[WARN] file1.sql#L1: column.no-null" classname="file1.sql" file="file1.sql#L1"><failure>Error: Column "id" in "public"."book" cannot have NULL value.@@ -153,7 +153,7 @@ Please check the docs at https://www.bytebase.com/docs/reference/error-code/advi</failure></testcase></testsuite>-<testsuite name="file2.sql">+<testsuite errors="1" failures="1" tests="3" name="file2.sql"><testcase name="[WARN] 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]+)*$".diff --git a/backend/api/v1/project_service.go b/backend/api/v1/project_service.goindex c76bd3b407..fbdb3eea8b 100644--- a/backend/api/v1/project_service.go+++ b/backend/api/v1/project_service.go@@ -1253,6 +1253,7 @@ func (s *ProjectService) setupVCSSQLReviewCI(ctx context.Context, repository *streturn nil, err}case vcsplugin.Bitbucket:+ // TODO(ed): we need to call the API to enable the pipeline.if err := setupVCSSQLReviewCIForBitBucket(ctx, oauthContext, repository, vcs, branch, sqlReviewEndpoint, repository.WebhookSecretToken); err != nil {return nil, err}diff --git a/backend/plugin/vcs/bitbucket/bytebase-sql-review.sh b/backend/plugin/vcs/bitbucket/bytebase-sql-review.shindex d418827f92..c7f12958ea 100644--- a/backend/plugin/vcs/bitbucket/bytebase-sql-review.sh+++ b/backend/plugin/vcs/bitbucket/bytebase-sql-review.sh@@ -51,8 +51,13 @@ response=$(curl -s --show-error -X POST $API_URL \echo "response: $response"content=$(echo "$response" | jq -r '.content')+status=$(echo "$response" | jq -r '.status')+len=$(echo "$content" | jq '. | length')if [[ $len == 0 ]]; then exit 0; fimsg=$(echo "$content" | jq -r '.[0]')+mkdir test-resultsecho $msg >> test-results/bytebase-sql-review.xml++if [ "$status" != "SUCCESS" ]; then exit 1; fidiff --git a/backend/plugin/vcs/bitbucket/pipeline-step.yml b/backend/plugin/vcs/bitbucket/pipeline-step.ymlindex 076597db54..20035475a7 100644--- a/backend/plugin/vcs/bitbucket/pipeline-step.yml+++ b/backend/plugin/vcs/bitbucket/pipeline-step.yml@@ -1,4 +1,4 @@name: %simage: atlassian/default-image:4script:- - bash %s --pull-request-id="$BITBUCKET_PR_ID" --repo-id="$BITBUCKET_REPO_UUID" --repo-url="$BITBUCKET_GIT_HTTP_ORIGIN" --api="%s" --token="%s"+ - bash %s --pull-request-id="$BITBUCKET_PR_ID" --repo-id="$BITBUCKET_REPO_FULL_NAME" --repo-url="$BITBUCKET_GIT_HTTP_ORIGIN" --api="%s" --token="%s"diff --git a/backend/tests/schema_update_test.go b/backend/tests/schema_update_test.goindex 0ea9573d90..f25d92b3a7 100644--- a/backend/tests/schema_update_test.go+++ b/backend/tests/schema_update_test.go@@ -1307,7 +1307,7 @@ func TestVCS_SQL_Review(t *testing.T) {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=\"[WARN] %s#L1: SQL review is disabled\" classname=\"%s\" file=\"%s#L1\">\n<failure>\nError: Cannot found SQL review policy or instance license. You can configure the SQL review policy on %s/setting/sql-review, and assign license to the instance.\nPlease check the docs at https://www.bytebase.com/docs/reference/error-code/advisor#3\n</failure>\n</testcase>\n</testsuite>\n</testsuites>",+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<testsuites name=\"SQL Review\">\n<testsuite errors=\"0\" failures=\"1\" tests=\"1\" name=\"%s\">\n<testcase name=\"[WARN] %s#L1: SQL review is disabled\" classname=\"%s\" file=\"%s#L1\">\n<failure>\nError: Cannot found SQL review policy or instance license. You can configure the SQL review policy on %s/setting/sql-review, and assign license to the instance.\nPlease check the docs at https://www.bytebase.com/docs/reference/error-code/advisor#3\n</failure>\n</testcase>\n</testsuite>\n</testsuites>",filePath,pathes[len(pathes)-1],filePath,@@ -1324,7 +1324,7 @@ func TestVCS_SQL_Review(t *testing.T) {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=\"[WARN] %s#L1: column.required\" classname=\"%s\" file=\"%s#L1\">\n<failure>\nError: Table \"book\" requires columns: created_ts, creator_id, updated_ts, updater_id.\nPlease check the docs at https://www.bytebase.com/docs/reference/error-code/advisor#401\n</failure>\n</testcase>\n<testcase name=\"[WARN] %s#L1: column.no-null\" classname=\"%s\" file=\"%s#L1\">\n<failure>\nError: Column \"name\" in \"public\".\"book\" cannot have NULL value.\nPlease 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 errors=\"0\" failures=\"2\" tests=\"27\" name=\"%s\">\n<testcase name=\"[WARN] %s#L1: column.required\" classname=\"%s\" file=\"%s#L1\">\n<failure>\nError: Table \"book\" requires columns: created_ts, creator_id, updated_ts, updater_id.\nPlease check the docs at https://www.bytebase.com/docs/reference/error-code/advisor#401\n</failure>\n</testcase>\n<testcase name=\"[WARN] %s#L1: column.no-null\" classname=\"%s\" file=\"%s#L1\">\n<failure>\nError: Column \"name\" in \"public\".\"book\" cannot have NULL value.\nPlease 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,diff --git a/frontend/src/bbkit/BBSpin.vue b/frontend/src/bbkit/BBSpin.vueindex 73d5ae59f4..b5a72c2d21 100644--- a/frontend/src/bbkit/BBSpin.vue+++ b/frontend/src/bbkit/BBSpin.vue@@ -12,7 +12,7 @@ import { NSpin } from "naive-ui";withDefaults(defineProps<{- size?: "small" | "medium" | "large";+ size?: "small" | "medium" | "large" | number;}>(),{size: "small",diff --git a/frontend/src/components/InstanceForm/InstanceForm.vue b/frontend/src/components/InstanceForm/InstanceForm.vueindex 23ec6188c8..2ee3815320 100644--- a/frontend/src/components/InstanceForm/InstanceForm.vue+++ b/frontend/src/components/InstanceForm/InstanceForm.vue@@ -189,7 +189,7 @@<MaximumConnectionsInputv-if="!isCreating"ref="maximumConnectionsInputRef"- :maximum-connections="basicInfo.options?.maximumConnections"+ :maximum-connections="basicInfo.options?.maximumConnections ?? 0":allow-edit="allowEdit"@update:maximum-connections="changeMaximumConnections"/>@@ -253,11 +253,11 @@<div class="mt-6 pt-0 border-none"><div class="flex flex-row space-x-2"><NButton- class="whitespace-nowrap flex items-center gap-x-1"+ class="whitespace-nowrap flex items-center"+ :loading="state.isTestingConnection":disabled="!allowCreate || state.isRequesting || !allowEdit"@click.prevent="testConnection(false /* !silent */)">- <BBSpin v-if="state.isTestingConnection" /><span>{{ $t("instance.test-connection") }}</span></NButton></div>