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: update the comment if the sql review check passed (#13786)
ecmadao2c9992a02e69
diff --git a/backend/api/gitops/common.go b/backend/api/gitops/common.goindex e4f6ec6f4a..b091065ab4 100644--- a/backend/api/gitops/common.go+++ b/backend/api/gitops/common.go@@ -111,8 +111,9 @@ func getPullRequestID(url string) string {}const (- commentPrefixBytebaseBot = "**[Bytebase Bot]**"- commentPrefixSQLReview = "**[Bytebase SQL Review]**"+ commentPrefixBytebaseBot = "**[Bytebase Bot]**"+ commentPrefixSQLReview = "**[Bytebase SQL Review]**"+ commentPrefixSQLReviewPassed = "SQL Review Check Passed")func getPullRequestComment(externalURL, issue string) string {diff --git a/backend/api/gitops/webhook.go b/backend/api/gitops/webhook.goindex 8c1b3899d5..d5b8ffc401 100644--- a/backend/api/gitops/webhook.go+++ b/backend/api/gitops/webhook.go@@ -167,6 +167,7 @@ func (s *Service) RegisterWebhookRoutes(g *echo.Group) {var comment stringvar commentPrefix string+ var createCommentIfNotExist boolswitch prInfo.action {case webhookActionCreateIssue:issue, err := s.createIssueFromPRInfo(childCtx, project, vcsProvider, vcsConnector, prInfo)@@ -175,6 +176,7 @@ func (s *Service) RegisterWebhookRoutes(g *echo.Group) {}comment = getPullRequestComment(setting.ExternalUrl, issue.Name)commentPrefix = commentPrefixBytebaseBot+ createCommentIfNotExist = truecase webhookActionSQLReview:comment, err = s.sqlReviewWithPRInfo(childCtx, project, vcsConnector, vcsProvider.Type, prInfo)if err != nil {@@ -184,6 +186,11 @@ func (s *Service) RegisterWebhookRoutes(g *echo.Group) {comment = fmt.Sprintf("%s\n\n---\n\nClick [here](%s) to check the SQL review config", comment, fmt.Sprintf("%s/sql-review", setting.ExternalUrl))}commentPrefix = commentPrefixSQLReview+ // We don't have the "Enable SQL review" option for VCS connection.+ // It's confused that projects may not have the active SQL review policy but will get "SQL Reivew Check Passed" comment.+ // So in order to not to always trigger the SQL review comment for PRs,+ // we will not create the comment for "SQL Reivew Check Passed" comment, but we can still update existed comment (from errors/warnings to passed).+ createCommentIfNotExist = !strings.HasPrefix(comment, commentPrefixSQLReviewPassed)default:}@@ -195,6 +202,7 @@ func (s *Service) RegisterWebhookRoutes(g *echo.Group) {prInfo,fmt.Sprintf("%s\n\n%s", commentPrefix, comment),func(content string) bool { return strings.HasPrefix(content, commentPrefix) },+ createCommentIfNotExist,); err != nil {slog.Error("failed to upsert comment", slog.String("pr", prInfo.url), log.BBError(err))return c.String(http.StatusOK, fmt.Sprintf("failed to create pull request comment, error %v", err))@@ -279,7 +287,7 @@ func (s *Service) sqlReviewWithPRInfo(ctx context.Context, project *store.Projec}if len(content) == 0 {- return "", nil+ return commentPrefixSQLReviewPassed, nil}return fmt.Sprintf("\n%d errors, %d warnings\n\n---\n\n%s", errorCount, warnCount, strings.Join(content, "\n")), nil@@ -401,6 +409,7 @@ func upsertPullRequestComment(prInfo *pullRequestInfo,comment string,checkComment isTargetComment,+ createIfNotExist bool,) error {pullRequestID := getPullRequestID(prInfo.url)provider := vcs.Get(@@ -422,6 +431,10 @@ func upsertPullRequestComment(return nil}+ if !createIfNotExist {+ return nil+ }+if err := provider.CreatePullRequestComment(ctx, vcsConnector.Payload.ExternalId, pullRequestID, comment); err != nil {return errors.Wrapf(err, `failed to create comment for PR "%s"`, prInfo.url)}