Skip to content

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

fix: azure sql review ci issues (#8814)

ecmadao42d468391a9d
diff --git a/backend/api/gitops/webhook.go b/backend/api/gitops/webhook.go
index 566c9e6bd7..cec14275a1 100644
--- a/backend/api/gitops/webhook.go
+++ b/backend/api/gitops/webhook.go
@@ -503,8 +503,14 @@ func (s *Service) RegisterWebhookRoutes(g *echo.Group) {
}
if len(backfillCommits) == 1 && len(backfillCommits[0].AddedList) == 1 && strings.HasSuffix(backfillCommits[0].AddedList[0], azure.SQLReviewPipelineFilePath) {
+ slog.Debug("start to setup pipeline", slog.String("repository", repositoryList[0].repository.ExternalID))
+ // Use workspaceID instead of repo secret as SQL review pipeline token, so that we don't need to re-create the pipeline if users disable then enable the CI.
+ workspaceID, err := s.store.GetWorkspaceID(ctx)
+ if err != nil {
+ return echo.NewHTTPError(http.StatusInternalServerError, "Failed to get workspace id with error").SetInternal(err)
+ }
// Setup SQL review pipeline and policy.
- if err := azure.EnableSQLReviewCI(ctx, oauthContext, repositoryList[0].repository.ExternalID, repositoryList[0].repository.BranchFilter, repositoryList[0].repository.WebhookSecretToken); err != nil {
+ if err := azure.EnableSQLReviewCI(ctx, oauthContext, repositoryList[0].repository.Title, repositoryList[0].repository.ExternalID, repositoryList[0].repository.BranchFilter, workspaceID); err != nil {
slog.Error("failed to setup pipeline", log.BBError(err), slog.String("repository", repositoryList[0].repository.ExternalID))
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to setup SQL review pipeline").SetInternal(err)
}
@@ -596,11 +602,7 @@ func (s *Service) RegisterWebhookRoutes(g *echo.Group) {
}
// We will use workspace id as token in integration test for skipping the check.
- if token == workspaceID {
- return true, nil
- }
-
- return token == repo.WebhookSecretToken, nil
+ return token == workspaceID || token == repo.WebhookSecretToken, nil
}
repositoryList, err := s.filterRepository(ctx, c.Param("id"), request.RepositoryID, filter)
diff --git a/backend/plugin/vcs/azure/sql_review.go b/backend/plugin/vcs/azure/sql_review.go
index 7d0c1a44ef..0d099cb8ca 100644
--- a/backend/plugin/vcs/azure/sql_review.go
+++ b/backend/plugin/vcs/azure/sql_review.go
@@ -26,7 +26,7 @@ const (
// SQLReviewPipelineFilePath is the SQL review pipeline file path.
SQLReviewPipelineFilePath = ".pipelines/pipeline.bytebase-sql-review.yml"
// sqlReviewPipelineName is the pipeline name for SQL review.
- sqlReviewPipelineName = "Bytebase SQL Review"
+ sqlReviewPipelineName = "Bytebase SQL Review Pipeline"
)
// SetupSQLReviewCI will setup the SQL review CI content with SQL review endpoint.
@@ -98,8 +98,8 @@ type policy struct {
}
// EnableSQLReviewCI enables the SQL review pipeline and policy.
-func EnableSQLReviewCI(ctx context.Context, oauthCtx common.OauthContext, repositoryID, branch, token string) error {
- pipeline, err := createSQLReviewPipeline(ctx, oauthCtx, repositoryID, token)
+func EnableSQLReviewCI(ctx context.Context, oauthCtx common.OauthContext, repositoryTitle, repositoryID, branch, token string) error {
+ pipeline, err := createSQLReviewPipeline(ctx, oauthCtx, repositoryTitle, repositoryID, token)
if err != nil {
return err
}
@@ -109,7 +109,7 @@ func EnableSQLReviewCI(ctx context.Context, oauthCtx common.OauthContext, reposi
// createSQLReviewPipeline creates the SQL Review pipeline.
//
// Docs: https://learn.microsoft.com/en-us/rest/api/azure/devops/pipelines/pipelines/create?view=azure-devops-rest-7.1
-func createSQLReviewPipeline(ctx context.Context, oauthCtx common.OauthContext, repositoryID, token string) (*pipeline, error) {
+func createSQLReviewPipeline(ctx context.Context, oauthCtx common.OauthContext, repositoryTitle, repositoryID, token string) (*pipeline, error) {
parts := strings.Split(repositoryID, "/")
if len(parts) != 3 {
return nil, errors.Errorf("invalid repository ID %q", repositoryID)
@@ -122,7 +122,7 @@ func createSQLReviewPipeline(ctx context.Context, oauthCtx common.OauthContext,
client := &http.Client{}
apiURL := fmt.Sprintf("https://dev.azure.com/%s/%s/_apis/pipelines?%s", url.PathEscape(organizationName), url.PathEscape(projectName), values.Encode())
payload := &pipelineCreate{
- Name: sqlReviewPipelineName,
+ Name: fmt.Sprintf("%s for %s", sqlReviewPipelineName, repositoryTitle),
Configuration: &pipelineConfig{
Type: "yaml",
Path: SQLReviewPipelineFilePath,