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: several optimize for VCS SQL review (#3001)
ecmadao95af32954fff
diff --git a/frontend/src/components/RepositoryPanel.vue b/frontend/src/components/RepositoryPanel.vueindex a410889c05..1340ca3f92 100644--- a/frontend/src/components/RepositoryPanel.vue+++ b/frontend/src/components/RepositoryPanel.vue@@ -67,7 +67,7 @@:ok-text="$t('common.restore')":confirm-title="$t('repository.restore-to-ui-workflow') + '?'":confirm-description="$t('repository.restore-ui-workflow-description')"- @confirm="restoreToUIWorkflowType"+ @confirm="() => restoreToUIWorkflowType(true)"/><div><button@@ -138,7 +138,7 @@v-if="state.showRemoveSQLReviewCIModal"class="relative overflow-hidden":title="$t('repository.sql-review-ci-remove')"- @close="state.showRemoveSQLReviewCIModal = false"+ @close="onSQLReviewCIModalClose"><div class="space-y-4 max-w-[32rem]"><div class="whitespace-pre-wrap">@@ -149,7 +149,7 @@<buttontype="button"class="btn-normal"- @click.prevent="state.showRemoveSQLReviewCIModal = false"+ @click.prevent="onSQLReviewCIModalClose">{{ $t("common.close") }}</button>@@ -283,12 +283,17 @@ export default defineComponent({);});- const restoreToUIWorkflowType = () => {- const removeSQLReview = removeSQLReviewCI.value;+ const onSQLReviewCIModalClose = () => {+ state.showRemoveSQLReviewCIModal = false;+ restoreToUIWorkflowType(false);+ };++ const restoreToUIWorkflowType = (checkSQLReviewCI: boolean) => {+ if (checkSQLReviewCI && props.repository.enableSQLReviewCI) {+ state.showRemoveSQLReviewCIModal = true;+ return;+ }repositoryStore.deleteRepositoryByProjectId(props.project.id).then(() => {- if (removeSQLReview) {- state.showRemoveSQLReviewCIModal = true;- }pushNotification({module: "bytebase",style: "SUCCESS",@@ -396,6 +401,7 @@ export default defineComponent({repositoryInfo,allowUpdate,restoreToUIWorkflowType,+ onSQLReviewCIModalClose,doUpdate,};},diff --git a/plugin/vcs/github/sql-review.yml b/plugin/vcs/github/bytebase-sql-review.ymlsimilarity index 98%rename from plugin/vcs/github/sql-review.ymlrename to plugin/vcs/github/bytebase-sql-review.ymlindex f855ca951a..fd4be6b225 100644--- a/plugin/vcs/github/sql-review.yml+++ b/plugin/vcs/github/bytebase-sql-review.yml@@ -1,6 +1,6 @@on: [pull_request]jobs:- sql-review:+ bytebase-sql-review:runs-on: ubuntu-latestname: SQL Reviewsteps:diff --git a/plugin/vcs/github/sql_review.go b/plugin/vcs/github/sql_review.goindex fe6952fa3c..49f04172e3 100644--- a/plugin/vcs/github/sql_review.go+++ b/plugin/vcs/github/sql_review.go@@ -9,12 +9,12 @@ import (// sqlReviewAction is the GitHub action for SQL review in VCS workflow.//-//go:embed sql-review.yml+//go:embed bytebase-sql-review.ymlvar sqlReviewAction stringconst (// SQLReviewActionFilePath is the SQL review action file path.- SQLReviewActionFilePath = ".github/workflows/sql-review.yml"+ SQLReviewActionFilePath = ".github/workflows/bytebase-sql-review.yml")// SetupSQLReviewCI will setup the SQL review CI content with SQL review endpoint.diff --git a/plugin/vcs/gitlab/sql-review.yml b/plugin/vcs/gitlab/bytebase-sql-review.ymlsimilarity index 90%rename from plugin/vcs/gitlab/sql-review.ymlrename to plugin/vcs/gitlab/bytebase-sql-review.ymlindex a57558e98e..0579134233 100644--- a/plugin/vcs/gitlab/sql-review.yml+++ b/plugin/vcs/gitlab/bytebase-sql-review.yml@@ -1,4 +1,4 @@-sql-review:+bytebase-sql-review:only:refs:- merge_requests@@ -17,11 +17,11 @@ sql-review:- len=$(echo $content | jq '. | length')- if [ $len == 0 ]; then exit 0; fi- msg=$(echo $content | jq -r '.[0]')- - echo $msg >> sql-review.xml+ - echo $msg >> bytebase-sql-review.xml- status=$(echo $response | jq -r '.status')- if [ "$status" == "ERROR" ]; then exit 1; fiartifacts:when: alwaysreports:junit:- - sql-review.xml+ - bytebase-sql-review.xmldiff --git a/plugin/vcs/gitlab/sql_review.go b/plugin/vcs/gitlab/sql_review.goindex 1d0d3ac8bd..db17cb635d 100644--- a/plugin/vcs/gitlab/sql_review.go+++ b/plugin/vcs/gitlab/sql_review.go@@ -13,7 +13,7 @@ const (// CIFilePath is the local path for GitLab ci file.CIFilePath = ".gitlab-ci.yml"// SQLReviewCIFilePath is the local path for SQL review CI in GitLab repo.- SQLReviewCIFilePath = ".gitlab/sql-review.yml"+ SQLReviewCIFilePath = ".gitlab/bytebase-sql-review.yml"// sqlReviewCIFileRelativePathInGitLabCI is the keyword for relative path for SQL review CI file in .gitlab-ci.yml.sqlReviewCIFileRelativePathKeywordInGitLabCI = "local"// gitlabCIIncludeKeyword is the keyword for "include" in .gitlab-ci.yml@@ -23,7 +23,7 @@ const (// sqlReviewCI is the GitLab CI for SQL review in VCS workflow.//-//go:embed sql-review.yml+//go:embed bytebase-sql-review.ymlvar sqlReviewCI string// SetupSQLReviewCI will setup the SQL review CI content with SQL review endpoint.diff --git a/server/flight.go b/server/flight.gonew file mode 100644index 0000000000..c7603fb6a0--- /dev/null+++ b/server/flight.go@@ -0,0 +1,12 @@+package server++import (+ "github.com/bytebase/bytebase/api"+ "github.com/bytebase/bytebase/common"+)++// flight returns if the feature is enabled.+// By default, the feature is always enabled in dev mode, and you can decide if is available in the release mode.+func (s *Server) flight(feature api.FeatureType) bool {+ return api.FeatureFlight[feature] || s.profile.Mode == common.ReleaseModeDev+}diff --git a/server/project.go b/server/project.goindex 0ec5b0020f..bf370065f8 100644--- a/server/project.go+++ b/server/project.go@@ -318,7 +318,7 @@ func (s *Server) registerProjectRoutes(g *echo.Group) {}// Setup SQL review CI for VCS- if repository.EnableSQLReviewCI && api.FeatureFlight[api.FeatureVCSSQLReviewWorkflow] && s.feature(api.FeatureVCSSQLReviewWorkflow) {+ if repository.EnableSQLReviewCI && s.flight(api.FeatureVCSSQLReviewWorkflow) && s.feature(api.FeatureVCSSQLReviewWorkflow) {pullRequest, err := s.setupVCSSQLReviewCI(ctx, repository)if err != nil {return echo.NewHTTPError(http.StatusInternalServerError, "Failed to create SQL review CI").SetInternal(err)@@ -444,7 +444,7 @@ func (s *Server) registerProjectRoutes(g *echo.Group) {}// Setup SQL review CI for VCS- if !repo.EnableSQLReviewCI && updatedRepo.EnableSQLReviewCI && api.FeatureFlight[api.FeatureVCSSQLReviewWorkflow] && s.feature(api.FeatureVCSSQLReviewWorkflow) {+ if !repo.EnableSQLReviewCI && updatedRepo.EnableSQLReviewCI && s.flight(api.FeatureVCSSQLReviewWorkflow) && s.feature(api.FeatureVCSSQLReviewWorkflow) {pullRequest, err := s.setupVCSSQLReviewCI(ctx, updatedRepo)if err != nil {return echo.NewHTTPError(http.StatusInternalServerError, "Failed to create SQL review CI").SetInternal(err)diff --git a/server/webhook.go b/server/webhook.goindex b9e228d666..ceb0bd7f7b 100644--- a/server/webhook.go+++ b/server/webhook.go@@ -168,6 +168,13 @@ func (s *Server) registerWebhookRoutes(g *echo.Group) {}filter := func(repo *api.Repository) (bool, error) {+ if repo.Project.RowStatus == api.Archived {+ log.Debug("Skip repository as the associated project is archived",+ zap.Int("repository_id", repo.ID),+ zap.String("repository_external_id", repo.ExternalID),+ )+ return false, nil+ }return c.Request().Header.Get("X-SQL-Review-Token") == repo.WebhookSecretToken && strings.HasPrefix(repo.WebURL, request.WebURL), nil}ctx := c.Request().Context()@@ -350,7 +357,15 @@ func (s *Server) sqlAdviceForFile(return adviceList, nil}- return nil, nil+ return []advisor.Advice{+ {+ Status: advisor.Warn,+ Code: advisor.NotFound,+ Title: "SQL review policy not found",+ Content: fmt.Sprintf("You can configure the SQL review policy on %s/setting/sql-review", s.profile.ExternalURL),+ Line: 1,+ },+ }, nil}type repositoryFilter func(*api.Repository) (bool, error)