Skip to content

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

chore: comment for GitHub PR (#13009)

ecmadao43c950687025
diff --git a/backend/api/gitops/common.go b/backend/api/gitops/common.go
index eaa8309714..a518d60dd9 100644
--- a/backend/api/gitops/common.go
+++ b/backend/api/gitops/common.go
@@ -108,8 +108,13 @@ func getPullRequestID(url string) string {
return fields[len(fields)-1]
}
+const (
+ commentPrefixBytebaseBot = "[Bytebase Bot]"
+ commentPrefixSQLReview = "[Bytebase SQL Review]"
+)
+
func getPullRequestComment(externalURL, issue string) string {
- return fmt.Sprintf("Bytebase Bot: this pull request has triggered a Bytebase rollout 🚀. Check out the status at %s/%s.", externalURL, issue)
+ return fmt.Sprintf("This pull request has triggered a Bytebase rollout 🚀. Check out the status at %s/%s.", externalURL, issue)
}
func convertFileContentToUTF8String(content string) string {
diff --git a/backend/api/gitops/gitops.go b/backend/api/gitops/gitops.go
index 6e62f4ff00..2dfa292195 100644
--- a/backend/api/gitops/gitops.go
+++ b/backend/api/gitops/gitops.go
@@ -3,7 +3,6 @@ package gitops
import (
v1pb "github.com/bytebase/bytebase/backend/api/v1"
- "github.com/bytebase/bytebase/backend/component/dbfactory"
"github.com/bytebase/bytebase/backend/component/sheet"
"github.com/bytebase/bytebase/backend/component/state"
enterprise "github.com/bytebase/bytebase/backend/enterprise/api"
@@ -13,34 +12,34 @@ import (
// Service is the API endpoint for handling GitOps requests.
type Service struct {
store *store.Store
- dbFactory *dbfactory.DBFactory
stateCfg *state.State
licenseService enterprise.LicenseService
planService *v1pb.PlanService
rolloutService *v1pb.RolloutService
issueService *v1pb.IssueService
+ sqlService *v1pb.SQLService
sheetManager *sheet.Manager
}
// NewService creates a GitOps service.
func NewService(
store *store.Store,
- dbFactory *dbfactory.DBFactory,
stateCfg *state.State,
licenseService enterprise.LicenseService,
planService *v1pb.PlanService,
rolloutService *v1pb.RolloutService,
issueService *v1pb.IssueService,
+ sqlService *v1pb.SQLService,
sheetManager *sheet.Manager,
) *Service {
return &Service{
store: store,
- dbFactory: dbFactory,
stateCfg: stateCfg,
licenseService: licenseService,
planService: planService,
rolloutService: rolloutService,
issueService: issueService,
+ sqlService: sqlService,
sheetManager: sheetManager,
}
}
diff --git a/backend/api/gitops/webhook.go b/backend/api/gitops/webhook.go
index 89ae87a779..621365a27e 100644
--- a/backend/api/gitops/webhook.go
+++ b/backend/api/gitops/webhook.go
@@ -152,26 +152,49 @@ func (s *Service) RegisterWebhookRoutes(g *echo.Group) {
return c.String(http.StatusOK, fmt.Sprintf("no relevant file change directly under the base directory %q for pull request %q", vcsConnector.Payload.BaseDirectory, prInfo.url))
}
+ user := func() *store.UserMessage {
+ user, err := s.store.GetUserByEmail(ctx, prInfo.email)
+ if err != nil {
+ slog.Error("failed to find user by email", slog.String("email", prInfo.email), log.BBError(err))
+ return s.store.GetSystemBotUser(ctx)
+ }
+ if user == nil {
+ return s.store.GetSystemBotUser(ctx)
+ }
+ return user
+ }()
+ childCtx := context.WithValue(ctx, common.PrincipalIDContextKey, user.ID)
+ childCtx = context.WithValue(childCtx, common.UserContextKey, user)
+ childCtx = context.WithValue(childCtx, common.LoopbackContextKey, true)
+
var comment string
+ var commentPrefix string
switch prInfo.action {
case webhookActionCreateIssue:
- issue, err := s.createIssueFromPRInfo(ctx, project, vcsProvider, vcsConnector, prInfo)
+ issue, err := s.createIssueFromPRInfo(childCtx, project, vcsProvider, vcsConnector, prInfo)
if err != nil {
return c.String(http.StatusOK, fmt.Sprintf("failed to create issue from pull request %s, error %v", prInfo.url, err))
}
comment = getPullRequestComment(setting.ExternalUrl, issue.Name)
+ commentPrefix = commentPrefixBytebaseBot
case webhookActionSQLReview:
- // TODO(ed): sql review.
+ comment, err = s.sqlReviewWithPRInfo(childCtx, project, vcsConnector, prInfo)
+ if err != nil {
+ return c.String(http.StatusOK, fmt.Sprintf("failed to exec sql review for pull request %s, error %v", prInfo.url, err))
+ }
+ commentPrefix = commentPrefixSQLReview
default:
}
if comment != "" {
- pullRequestID := getPullRequestID(prInfo.url)
- // TODO(ed): upsert the commont.
- if err := vcs.Get(
- vcsProvider.Type,
- vcs.ProviderConfig{InstanceURL: vcsProvider.InstanceURL, AuthToken: vcsProvider.AccessToken},
- ).CreatePullRequestComment(ctx, vcsConnector.Payload.ExternalId, pullRequestID, comment); err != nil {
+ if err := upsertPullRequestComment(
+ ctx,
+ vcsProvider,
+ vcsConnector,
+ prInfo,
+ fmt.Sprintf("%s\n\n%s", commentPrefix, comment),
+ func(content string) bool { return strings.HasPrefix(content, commentPrefix) },
+ ); err != nil {
return c.String(http.StatusOK, fmt.Sprintf("failed to create pull request comment, error %v", err))
}
}
@@ -196,24 +219,60 @@ func validateGitHubWebhookSignature256(signature, key string, body []byte) (bool
return subtle.ConstantTimeCompare([]byte(signature), []byte(got)) == 1, nil
}
-func (s *Service) createIssueFromPRInfo(ctx context.Context, project *store.ProjectMessage, vcsProvider *store.VCSProviderMessage, vcsConnector *store.VCSConnectorMessage, prInfo *pullRequestInfo) (*v1pb.Issue, error) {
- user := func() *store.UserMessage {
- user, err := s.store.GetUserByEmail(ctx, prInfo.email)
+func (s *Service) sqlReviewWithPRInfo(ctx context.Context, project *store.ProjectMessage, vcsConnector *store.VCSConnectorMessage, prInfo *pullRequestInfo) (string, error) {
+ instance, database, err := s.getDatabaseSample(ctx, project, vcsConnector)
+ if err != nil {
+ return "", errors.Wrapf(err, "failed to get database sample")
+ }
+
+ content := []string{}
+ for _, change := range prInfo.changes {
+ adviceStatus, advices, err := s.sqlService.SQLReviewCheck(
+ ctx,
+ change.content,
+ v1pb.CheckRequest_CHANGE_TYPE_UNSPECIFIED,
+ instance,
+ database,
+ nil, /* Override Metadata */
+ )
if err != nil {
- slog.Error("failed to find user by email", slog.String("email", prInfo.email), log.BBError(err))
- return s.store.GetSystemBotUser(ctx)
+ slog.Error("failed to exec sql review", slog.String("instance", instance.ResourceID), slog.String("database", database.DatabaseName), log.BBError(err))
+ continue
}
- if user == nil {
- return s.store.GetSystemBotUser(ctx)
+ if adviceStatus == storepb.Advice_SUCCESS || adviceStatus == storepb.Advice_STATUS_UNSPECIFIED {
+ continue
}
- return user
- }()
+
+ // TODO(ed): better message format. Maybe add links for files?
+ adviceMessage := []string{}
+ for _, advice := range advices {
+ message := fmt.Sprintf("- [%d] %s (line: %d)", advice.Code, advice.Title, advice.Line)
+ adviceMessage = append(adviceMessage, message)
+ }
+
+ if len(adviceMessage) > 0 {
+ if len(content) > 0 {
+ content = append(content, "\n")
+ }
+ content = append(content, fmt.Sprintf("SQL review for %s", change.path))
+ content = append(content, strings.Join(adviceMessage, "\n"))
+ }
+ }
+
+ return strings.Join(content, "\n"), nil
+}
+
+func (s *Service) createIssueFromPRInfo(ctx context.Context, project *store.ProjectMessage, vcsProvider *store.VCSProviderMessage, vcsConnector *store.VCSConnectorMessage, prInfo *pullRequestInfo) (*v1pb.Issue, error) {
+ user, ok := ctx.Value(common.UserContextKey).(*store.UserMessage)
+ if !ok {
+ return nil, errors.Errorf("cannot found user in context")
+ }
creatorID := user.ID
creatorName := common.FormatUserUID(user.ID)
- engine, err := s.getDatabaseEngineSample(ctx, project, vcsConnector)
+ instance, _, err := s.getDatabaseSample(ctx, project, vcsConnector)
if err != nil {
- return nil, errors.Wrapf(err, "failed to get database engine")
+ return nil, errors.Wrapf(err, "failed to get database sample")
}
var sheets []int
@@ -225,7 +284,7 @@ func (s *Service) createIssueFromPRInfo(ctx context.Context, project *store.Proj
Statement: change.content,
Payload: &storepb.SheetPayload{
- Engine: engine,
+ Engine: instance.Engine,
},
})
if err != nil {
@@ -239,10 +298,7 @@ func (s *Service) createIssueFromPRInfo(ctx context.Context, project *store.Proj
return nil, err
}
- childCtx := context.WithValue(ctx, common.PrincipalIDContextKey, creatorID)
- childCtx = context.WithValue(childCtx, common.UserContextKey, user)
- childCtx = context.WithValue(childCtx, common.LoopbackContextKey, true)
- plan, err := s.planService.CreatePlan(childCtx, &v1pb.CreatePlanRequest{
+ plan, err := s.planService.CreatePlan(ctx, &v1pb.CreatePlanRequest{
Parent: common.FormatProject(project.ResourceID),
Plan: &v1pb.Plan{
Title: prInfo.title,
@@ -257,7 +313,7 @@ func (s *Service) createIssueFromPRInfo(ctx context.Context, project *store.Proj
if err != nil {
return nil, errors.Wrapf(err, "failed to create plan")
}
- issue, err := s.issueService.CreateIssue(childCtx, &v1pb.CreateIssueRequest{
+ issue, err := s.issueService.CreateIssue(ctx, &v1pb.CreateIssueRequest{
Parent: common.FormatProject(project.ResourceID),
Issue: &v1pb.Issue{
Title: prInfo.title,
@@ -270,7 +326,7 @@ func (s *Service) createIssueFromPRInfo(ctx context.Context, project *store.Proj
if err != nil {
return nil, errors.Wrapf(err, "failed to create issue")
}
- if _, err := s.rolloutService.CreateRollout(childCtx, &v1pb.CreateRolloutRequest{
+ if _, err := s.rolloutService.CreateRollout(ctx, &v1pb.CreateRolloutRequest{
Parent: common.FormatProject(project.ResourceID),
Rollout: &v1pb.Rollout{
Plan: plan.Name,
@@ -300,11 +356,61 @@ func (s *Service) createIssueFromPRInfo(ctx context.Context, project *store.Proj
return issue, nil
}
-func (s *Service) getDatabaseEngineSample(
+type isTargetComment func(string) bool
+
+func getCommentIDByContent(ctx context.Context, provider vcs.Provider, repositoryID, pullRequestID string, checkComment isTargetComment) (string, error) {
+ comments, err := provider.ListPullRequestComments(ctx, repositoryID, pullRequestID)
+ if err != nil {
+ return "", errors.Wrapf(err, "failed to list comments for PR %s", pullRequestID)
+ }
+
+ for _, comment := range comments {
+ if checkComment(comment.Content) {
+ return comment.ID, nil
+ }
+ }
+ return "", nil
+}
+
+func upsertPullRequestComment(
+ ctx context.Context,
+ vcsProvider *store.VCSProviderMessage,
+ vcsConnector *store.VCSConnectorMessage,
+ prInfo *pullRequestInfo,
+ comment string,
+ checkComment isTargetComment,
+) error {
+ pullRequestID := getPullRequestID(prInfo.url)
+ provider := vcs.Get(
+ vcsProvider.Type,
+ vcs.ProviderConfig{InstanceURL: vcsProvider.InstanceURL, AuthToken: vcsProvider.AccessToken},
+ )
+
+ existedCommentID, err := getCommentIDByContent(ctx, provider, vcsConnector.Payload.ExternalId, pullRequestID, checkComment)
+ if err != nil {
+ return err
+ }
+ if existedCommentID != "" {
+ if err := provider.UpdatePullRequestComment(ctx, vcsConnector.Payload.ExternalId, pullRequestID, &vcs.PullRequestComment{
+ ID: existedCommentID,
+ Content: comment,
+ }); err != nil {
+ return errors.Wrapf(err, `failed to update comment for PR "%s"`, prInfo.url)
+ }
+ 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)
+ }
+ return nil
+}
+
+func (s *Service) getDatabaseSample(
ctx context.Context,
project *store.ProjectMessage,
vcsConnector *store.VCSConnectorMessage,
-) (storepb.Engine, error) {
+) (*store.InstanceMessage, *store.DatabaseMessage, error) {
sample, err := func() (*store.DatabaseMessage, error) {
if dbg := vcsConnector.Payload.GetDatabaseGroup(); dbg != "" {
projectID, databaseGroupID, err := common.GetProjectIDDatabaseGroupID(dbg)
@@ -345,17 +451,17 @@ func (s *Service) getDatabaseEngineSample(
return allDatabases[0], nil
}()
if err != nil {
- return 0, errors.Wrapf(err, "failed to get sample database")
+ return nil, nil, errors.Wrapf(err, "failed to get sample database")
}
instance, err := s.store.GetInstanceV2(ctx, &store.FindInstanceMessage{ResourceID: &sample.InstanceID})
if err != nil {
- return 0, errors.Wrapf(err, "failed to get instance")
+ return nil, nil, errors.Wrapf(err, "failed to get instance")
}
if instance == nil {
- return 0, errors.Errorf("instance not found")
+ return nil, nil, errors.Errorf("instance not found")
}
- return instance.Engine, nil
+ return instance, sample, nil
}
func (s *Service) getChangeSteps(
diff --git a/backend/api/v1/sql_service.go b/backend/api/v1/sql_service.go
index dcf8fa231a..c107791237 100644
--- a/backend/api/v1/sql_service.go
+++ b/backend/api/v1/sql_service.go
@@ -185,7 +185,7 @@ func (s *SQLService) Execute(ctx context.Context, request *v1pb.ExecuteRequest)
statement := request.Statement
// Run SQL review.
- adviceStatus, advices, err := s.sqlReviewCheck(ctx, statement, v1pb.CheckRequest_CHANGE_TYPE_UNSPECIFIED, instance, database, nil /* Override Metadata */)
+ adviceStatus, advices, err := s.SQLReviewCheck(ctx, statement, v1pb.CheckRequest_CHANGE_TYPE_UNSPECIFIED, instance, database, nil /* Override Metadata */)
if err != nil {
return nil, err
}
@@ -333,7 +333,7 @@ func (s *SQLService) Export(ctx context.Context, request *v1pb.ExportRequest) (*
}
// Run SQL review.
- if _, _, err = s.sqlReviewCheck(ctx, statement, v1pb.CheckRequest_CHANGE_TYPE_UNSPECIFIED, instance, database, nil /* Override Metadata */); err != nil {
+ if _, _, err = s.SQLReviewCheck(ctx, statement, v1pb.CheckRequest_CHANGE_TYPE_UNSPECIFIED, instance, database, nil /* Override Metadata */); err != nil {
return nil, err
}
@@ -709,7 +709,7 @@ func (s *SQLService) Query(ctx context.Context, request *v1pb.QueryRequest) (*v1
}
// Run SQL review.
- adviceStatus, advices, err := s.sqlReviewCheck(ctx, statement, v1pb.CheckRequest_CHANGE_TYPE_UNSPECIFIED, instance, database, nil /* Override Metadata */)
+ adviceStatus, advices, err := s.SQLReviewCheck(ctx, statement, v1pb.CheckRequest_CHANGE_TYPE_UNSPECIFIED, instance, database, nil /* Override Metadata */)
if err != nil {
return nil, err
}
@@ -1178,7 +1178,7 @@ func (s *SQLService) Check(ctx context.Context, request *v1pb.CheckRequest) (*v1
return nil, err
}
}
- _, adviceList, err := s.sqlReviewCheck(ctx, request.Statement, request.ChangeType, instance, database, overideMetadata)
+ _, adviceList, err := s.SQLReviewCheck(ctx, request.Statement, request.ChangeType, instance, database, overideMetadata)
if err != nil {
return nil, err
}
@@ -1188,10 +1188,10 @@ func (s *SQLService) Check(ctx context.Context, request *v1pb.CheckRequest) (*v1
}, nil
}
-// sqlReviewCheck checks the SQL statement against the SQL review policy bind to given environment,
+// SQLReviewCheck checks the SQL statement against the SQL review policy bind to given environment,
// against the database schema bind to the given database, if the overrideMetadata is provided,
// it will be used instead of fetching the database schema from the store.
-func (s *SQLService) sqlReviewCheck(
+func (s *SQLService) SQLReviewCheck(
ctx context.Context,
statement string,
changeType v1pb.CheckRequest_ChangeType,
@@ -1199,39 +1199,27 @@ func (s *SQLService) sqlReviewCheck(
database *store.DatabaseMessage,
overrideMetadata *storepb.DatabaseSchemaMetadata,
) (storepb.Advice_Status, []*v1pb.Advice, error) {
- if !IsSQLReviewSupported(instance.Engine) || database == nil {
+ if !isSQLReviewSupported(instance.Engine) || database == nil {
return storepb.Advice_SUCCESS, nil, nil
}
dbMetadata := overrideMetadata
if dbMetadata == nil {
- dbSchema, err := s.store.GetDBSchema(ctx, database.UID)
+ metadata, err := getDatabaseMetadata(ctx, s.store, s.schemaSyncer, database)
if err != nil {
- return storepb.Advice_ERROR, nil, status.Errorf(codes.Internal, "failed to fetch database schema: %v", err)
+ return storepb.Advice_ERROR, nil, status.Errorf(codes.Internal, err.Error())
}
- if dbSchema == nil {
- if err := s.schemaSyncer.SyncDatabaseSchema(ctx, database, true /* force */); err != nil {
- return storepb.Advice_ERROR, nil, status.Errorf(codes.Internal, "failed to sync database schema: %v", err)
- }
- dbSchema, err = s.store.GetDBSchema(ctx, database.UID)
- if err != nil {
- return storepb.Advice_ERROR, nil, status.Errorf(codes.Internal, "failed to fetch database schema: %v", err)
- }
- if dbSchema == nil {
- return storepb.Advice_ERROR, nil, status.Errorf(codes.NotFound, "database schema not found: %v", database.UID)
- }
- }
- dbMetadata = dbSchema.GetMetadata()
+ dbMetadata = metadata
}
catalog, err := catalog.NewCatalog(ctx, s.store, database.UID, instance.Engine, store.IgnoreDatabaseAndTableCaseSensitive(instance), overrideMetadata)
if err != nil {
- return storepb.Advice_ERROR, nil, status.Errorf(codes.Internal, "Failed to create a catalog: %v", err)
+ return storepb.Advice_ERROR, nil, status.Errorf(codes.Internal, "failed to create a catalog: %v", err)
}
driver, err := s.dbFactory.GetAdminDatabaseDriver(ctx, instance, database, db.ConnectionContext{UseDatabaseOwner: true})
if err != nil {
- return storepb.Advice_ERROR, nil, status.Errorf(codes.Internal, "Failed to get database driver: %v", err)
+ return storepb.Advice_ERROR, nil, status.Errorf(codes.Internal, "failed to get database driver: %v", err)
}
defer driver.Close(ctx)
connection := driver.GetDB()
@@ -1248,35 +1236,46 @@ func (s *SQLService) sqlReviewCheck(
CurrentDatabase: database.DatabaseName,
}
- adviceLevel, adviceList, err := s.sqlCheck(
+ return s.sqlCheck(
ctx,
statement,
database,
context,
)
+}
+
+func getDatabaseMetadata(ctx context.Context, stores *store.Store, schemaSyncer *schemasync.Syncer, database *store.DatabaseMessage) (*storepb.DatabaseSchemaMetadata, error) {
+ dbSchema, err := stores.GetDBSchema(ctx, database.UID)
if err != nil {
- return storepb.Advice_ERROR, nil, status.Errorf(codes.Internal, "Failed to check SQL review policy: %v", err)
+ return nil, errors.Wrapf(err, "failed to fetch database schema for database %v", database.UID)
}
-
- return adviceLevel, convertAdviceList(adviceList), nil
+ if dbSchema == nil {
+ if err := schemaSyncer.SyncDatabaseSchema(ctx, database, true /* force */); err != nil {
+ return nil, errors.Wrapf(err, "failed to sync database schema for database %v", database.UID)
+ }
+ dbSchema, err = stores.GetDBSchema(ctx, database.UID)
+ if err != nil {
+ return nil, errors.Wrapf(err, "failed to fetch database schema for database %v", database.UID)
+ }
+ if dbSchema == nil {
+ return nil, errors.Wrapf(err, "cannot found schema for database %v", database.UID)
+ }
+ }
+ return dbSchema.GetMetadata(), nil
}
-func convertAdviceList(list []*storepb.Advice) []*v1pb.Advice {
- var result []*v1pb.Advice
- for _, advice := range list {
- result = append(result, &v1pb.Advice{
- Status: convertAdviceStatus(advice.Status),
- Code: int32(advice.Code),
- Title: advice.Title,
- Content: advice.Content,
- Line: int32(advice.GetStartPosition().GetLine()),
- Column: int32(advice.GetStartPosition().GetColumn()),
- Detail: advice.Detail,
- StartPosition: convertToPosition(advice.StartPosition),
- EndPosition: convertToPosition(advice.EndPosition),
- })
+func convertToV1Advice(advice *storepb.Advice) *v1pb.Advice {
+ return &v1pb.Advice{
+ Status: convertAdviceStatus(advice.Status),
+ Code: int32(advice.Code),
+ Title: advice.Title,
+ Content: advice.Content,
+ Line: int32(advice.GetStartPosition().GetLine()),
+ Column: int32(advice.GetStartPosition().GetColumn()),
+ Detail: advice.Detail,
+ StartPosition: convertToPosition(advice.StartPosition),
+ EndPosition: convertToPosition(advice.EndPosition),
}
- return result
}
func convertAdviceStatus(status storepb.Advice_Status) v1pb.Advice_Status {
@@ -1297,19 +1296,19 @@ func (s *SQLService) sqlCheck(
statement string,
database *store.DatabaseMessage,
context advisor.SQLReviewCheckContext,
-) (storepb.Advice_Status, []*storepb.Advice, error) {
- var adviceList []*storepb.Advice
+) (storepb.Advice_Status, []*v1pb.Advice, error) {
+ var adviceList []*v1pb.Advice
reviewConfig, err := s.store.GetReviewConfigForDatabase(ctx, database)
if err != nil {
if e, ok := err.(*common.Error); ok && e.Code == common.NotFound {
return storepb.Advice_SUCCESS, nil, nil
}
- return storepb.Advice_ERROR, nil, err
+ return storepb.Advice_ERROR, nil, status.Errorf(codes.Internal, "failed to get SQL review policy with error: %v", err)
}
res, err := advisor.SQLReviewCheck(s.sheetManager, statement, reviewConfig.SqlReviewRules, context)
if err != nil {
- return storepb.Advice_ERROR, nil, err
+ return storepb.Advice_ERROR, nil, status.Errorf(codes.Internal, "failed to exec SQL review with error: %v", err)
}
adviceLevel := storepb.Advice_SUCCESS
@@ -1321,11 +1320,11 @@ func (s *SQLService) sqlCheck(
}
case storepb.Advice_ERROR:
adviceLevel = storepb.Advice_ERROR
- case storepb.Advice_SUCCESS:
+ case storepb.Advice_SUCCESS, storepb.Advice_STATUS_UNSPECIFIED:
continue
}
- adviceList = append(adviceList, advice)
+ adviceList = append(adviceList, convertToV1Advice(advice))
}
return adviceLevel, adviceList, nil
diff --git a/backend/api/v1/sql_service_test.go b/backend/api/v1/sql_service_test.go
index 9bca08fafb..0b75cfc553 100644
--- a/backend/api/v1/sql_service_test.go
+++ b/backend/api/v1/sql_service_test.go
@@ -189,37 +189,6 @@ func TestExportSQL(t *testing.T) {
}
}
-func TestEncodeToBase64String(t *testing.T) {
- tests := []struct {
- input string
- want string
- }{
- {
- input: "",
- want: "",
- },
- {
- input: "select * from employee",
- want: "c2VsZWN0ICogZnJvbSBlbXBsb3llZQ==",
- },
- {
- input: "select name as 姓名 from employee",
- want: "c2VsZWN0IG5hbWUgYXMg5aeT5ZCNIGZyb20gZW1wbG95ZWU=",
- },
- {
- input: "Hello 哈喽 👋",
- want: "SGVsbG8g5ZOI5Za9IPCfkYs=",
- },
- }
-
- for _, test := range tests {
- got := encodeToBase64String(test.input)
- if got != test.want {
- t.Errorf("encodeToBase64String(%q) = %q, want %q", test.input, got, test.want)
- }
- }
-}
-
func TestGetExcelColumnName(t *testing.T) {
a := assert.New(t)
diff --git a/backend/api/v1/sql_service_utils.go b/backend/api/v1/sql_service_utils.go
index 10b632873c..72129ebf15 100644
--- a/backend/api/v1/sql_service_utils.go
+++ b/backend/api/v1/sql_service_utils.go
@@ -1,14 +1,12 @@
package v1
import (
- "encoding/base64"
-
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
v1pb "github.com/bytebase/bytebase/proto/generated-go/v1"
)
-// IsSQLReviewSupported checks the engine type if SQL review supports it.
-func IsSQLReviewSupported(dbType storepb.Engine) bool {
+// isSQLReviewSupported checks the engine type if SQL review supports it.
+func isSQLReviewSupported(dbType storepb.Engine) bool {
switch dbType {
case storepb.Engine_POSTGRES, storepb.Engine_MYSQL, storepb.Engine_TIDB, storepb.Engine_MARIADB, storepb.Engine_ORACLE, storepb.Engine_OCEANBASE_ORACLE, storepb.Engine_OCEANBASE, storepb.Engine_SNOWFLAKE, storepb.Engine_DM, storepb.Engine_MSSQL:
return true
@@ -17,12 +15,6 @@ func IsSQLReviewSupported(dbType storepb.Engine) bool {
}
}
-// encodeToBase64String encodes the statement to base64 string.
-func encodeToBase64String(statement string) string {
- base64Encoded := base64.StdEncoding.EncodeToString([]byte(statement))
- return base64Encoded
-}
-
func convertChangeType(t v1pb.CheckRequest_ChangeType) storepb.PlanCheckRunConfig_ChangeDatabaseType {
switch t {
case v1pb.CheckRequest_DDL:
diff --git a/backend/plugin/vcs/azure/azure.go b/backend/plugin/vcs/azure/azure.go
index 8e33efe526..fe281c046e 100644
--- a/backend/plugin/vcs/azure/azure.go
+++ b/backend/plugin/vcs/azure/azure.go
@@ -427,6 +427,18 @@ func (p *Provider) CreatePullRequestComment(ctx context.Context, repositoryID, p
return nil
}
+// ListPullRequestComments lists comments in a pull request.
+// TODO(ed): implement.
+func (*Provider) ListPullRequestComments(_ context.Context, _, _ string) ([]*vcs.PullRequestComment, error) {
+ return nil, nil
+}
+
+// UpdatePullRequestComment updates a comment in a pull request.
+// TODO(ed): implement.
+func (*Provider) UpdatePullRequestComment(_ context.Context, _, _ string, _ *vcs.PullRequestComment) error {
+ return nil
+}
+
// CreateWebhook creates a webhook in the organization, and returns the webhook ID which can be used in PatchWebhook.
// API Version 7.0 do not specify the OAuth scope for creating webhook explicitly, but it works.
//
diff --git a/backend/plugin/vcs/bitbucket/bitbucket.go b/backend/plugin/vcs/bitbucket/bitbucket.go
index 7fb799f5bb..b08bcb4e13 100644
--- a/backend/plugin/vcs/bitbucket/bitbucket.go
+++ b/backend/plugin/vcs/bitbucket/bitbucket.go
@@ -316,6 +316,7 @@ func (p *Provider) ListPullRequestFile(ctx context.Context, repositoryID, pullRe
}
type Comment struct {
+ ID int64 `json:"id,omitempty"`
Content CommentContent `json:"content"`
}
@@ -324,6 +325,8 @@ type CommentContent struct {
}
// CreatePullRequestComment creates a pull request comment.
+//
+// Docs: https://developer.atlassian.com/cloud/bitbucket/rest/api-group-pullrequests/#api-repositories-workspace-repo-slug-pullrequests-pull-request-id-comments-post
func (p *Provider) CreatePullRequestComment(ctx context.Context, repositoryID, pullRequestID, comment string) error {
commentMessage := Comment{Content: CommentContent{Raw: comment}}
commentCreatePayload, err := json.Marshal(commentMessage)
@@ -340,7 +343,8 @@ func (p *Provider) CreatePullRequestComment(ctx context.Context, repositoryID, p
return common.Errorf(common.NotFound, "failed to create pull request comment through URL %s", url)
}
- // GitHub returns 201 HTTP status codes upon successful issue comment creation,
+ // Bitbucket returns 201 HTTP status codes upon successful issue comment creation
+ // https://developer.atlassian.com/cloud/bitbucket/rest/api-group-pullrequests/#api-repositories-workspace-repo-slug-pullrequests-pull-request-id-comments-post-response
if code != http.StatusCreated {
return errors.Errorf("failed to create pull request comment through URL %s, status code: %d, body: %s",
url,
@@ -351,6 +355,76 @@ func (p *Provider) CreatePullRequestComment(ctx context.Context, repositoryID, p
return nil
}
+// ListPullRequestComments lists comments in a pull request.
+//
+// Docs: https://developer.atlassian.com/cloud/bitbucket/rest/api-group-pullrequests/#api-repositories-workspace-repo-slug-pullrequests-pull-request-id-comments-get
+func (p *Provider) ListPullRequestComments(ctx context.Context, repositoryID, pullRequestID string) ([]*vcs.PullRequestComment, error) {
+ url := fmt.Sprintf("%s/repositories/%s/pullrequests/%s/comments", p.APIURL(p.instanceURL), repositoryID, pullRequestID)
+ code, body, err := internal.Get(ctx, url, p.getAuthorization())
+ if err != nil {
+ return nil, errors.Wrapf(err, "GET %s", url)
+ }
+
+ if code == http.StatusNotFound {
+ return nil, common.Errorf(common.NotFound, "failed to list pull request comments through URL %s", url)
+ } else if code >= 300 {
+ return nil, errors.Errorf("failed to list pull request comments from URL %s, status code: %d, body: %s",
+ url,
+ code,
+ body,
+ )
+ }
+
+ var resp struct {
+ Values []*Comment `json:"values"`
+ }
+
+ if err := json.Unmarshal([]byte(body), &resp); err != nil {
+ return nil, errors.Wrap(err, "unmarshal")
+ }
+
+ var res []*vcs.PullRequestComment
+
+ for _, v := range resp.Values {
+ res = append(res,
+ &vcs.PullRequestComment{
+ ID: fmt.Sprintf("%d", v.ID),
+ Content: v.Content.Raw,
+ },
+ )
+ }
+ return res, nil
+}
+
+// UpdatePullRequestComment updates a comment in a pull request.
+//
+// Docs: https://developer.atlassian.com/cloud/bitbucket/rest/api-group-pullrequests/#api-repositories-workspace-repo-slug-pullrequests-pull-request-id-comments-comment-id-put
+func (p *Provider) UpdatePullRequestComment(ctx context.Context, repositoryID, pullRequestID string, comment *vcs.PullRequestComment) error {
+ commentMessage := Comment{Content: CommentContent{Raw: comment.Content}}
+ commentCreatePayload, err := json.Marshal(commentMessage)
+ if err != nil {
+ return errors.Wrap(err, "failed to marshal request body for updating pull request comment")
+ }
+
+ url := fmt.Sprintf("%s/repositories/%s/pullrequests/%s/comments/%s", p.APIURL(p.instanceURL), repositoryID, pullRequestID, comment.ID)
+ code, body, err := internal.Put(ctx, url, p.getAuthorization(), commentCreatePayload)
+ if err != nil {
+ return errors.Wrapf(err, "PUT %s", url)
+ }
+
+ if code == http.StatusNotFound {
+ return common.Errorf(common.NotFound, "cannot found pull request comment through URL %s", url)
+ } else if code >= 300 {
+ return errors.Errorf("failed to update pull request comment through URL %s, status code: %d, body: %s",
+ url,
+ code,
+ body,
+ )
+ }
+
+ return nil
+}
+
// Link is the API message for link.
type Link struct {
Href string `json:"href"`
diff --git a/backend/plugin/vcs/github/github.go b/backend/plugin/vcs/github/github.go
index c4b1115207..311c9f41a3 100644
--- a/backend/plugin/vcs/github/github.go
+++ b/backend/plugin/vcs/github/github.go
@@ -330,6 +330,7 @@ func (p *Provider) listPaginatedPullRequestFile(ctx context.Context, repositoryI
}
type Comment struct {
+ ID int `json:"id,omitempty"`
Body string `json:"body"`
}
@@ -366,6 +367,71 @@ func (p *Provider) CreatePullRequestComment(ctx context.Context, repositoryID, p
return nil
}
+// ListPullRequestComments lists comments in a pull request.
+//
+// Docs: https://docs.github.com/en/rest/issues/comments?apiVersion=2022-11-28#list-issue-comments-for-a-repository
+func (p *Provider) ListPullRequestComments(ctx context.Context, repositoryID, pullRequestID string) ([]*vcs.PullRequestComment, error) {
+ // No need to fetch comments page by page.
+ url := fmt.Sprintf("%s/repos/%s/issues/%s/comments?per_page=100", p.APIURL(p.instanceURL), repositoryID, pullRequestID)
+
+ code, body, err := internal.Get(ctx, url, p.getAuthorization())
+ if err != nil {
+ return nil, errors.Wrapf(err, "GET %s", url)
+ }
+ if code == http.StatusNotFound {
+ return nil, common.Errorf(common.NotFound, "failed to list pull request comments from URL %s", url)
+ } else if code >= 300 {
+ return nil, errors.Errorf("failed to list pull request comments from URL %s, status code: %d, body: %s",
+ url,
+ code,
+ body,
+ )
+ }
+
+ var comments []Comment
+ if err := json.Unmarshal([]byte(body), &comments); err != nil {
+ return nil, err
+ }
+
+ var res []*vcs.PullRequestComment
+ for _, comment := range comments {
+ res = append(res, &vcs.PullRequestComment{
+ ID: fmt.Sprintf("%d", comment.ID),
+ Content: comment.Body,
+ })
+ }
+ return res, nil
+}
+
+// UpdatePullRequestComment updates a comment in a pull request.
+//
+// Docs: https://docs.github.com/en/rest/issues/comments?apiVersion=2022-11-28#update-an-issue-comment
+func (p *Provider) UpdatePullRequestComment(ctx context.Context, repositoryID, _ string, comment *vcs.PullRequestComment) error {
+ url := fmt.Sprintf("%s/repos/%s/issues/comments/%s", p.APIURL(p.instanceURL), repositoryID, comment.ID)
+ commentMessage := Comment{Body: comment.Content}
+ commentCreatePayload, err := json.Marshal(commentMessage)
+ if err != nil {
+ return errors.Wrap(err, "failed to marshal request body for creating pull request comment")
+ }
+
+ code, body, err := internal.Patch(ctx, url, p.getAuthorization(), commentCreatePayload)
+ if err != nil {
+ return errors.Wrapf(err, "PATCH %s", url)
+ }
+
+ if code == http.StatusNotFound {
+ return common.Errorf(common.NotFound, "cannot found pull request comment through URL %s", url)
+ } else if code >= 300 {
+ return errors.Errorf("failed to update pull request comment through URL %s, status code: %d, body: %s",
+ url,
+ code,
+ body,
+ )
+ }
+
+ return nil
+}
+
// Branch is the API message for GitHub branch.
type Branch struct {
Ref string `json:"ref"`
diff --git a/backend/plugin/vcs/gitlab/gitlab.go b/backend/plugin/vcs/gitlab/gitlab.go
index a254a4b407..9d60927d1a 100644
--- a/backend/plugin/vcs/gitlab/gitlab.go
+++ b/backend/plugin/vcs/gitlab/gitlab.go
@@ -289,7 +289,14 @@ func (p *Provider) ListPullRequestFile(ctx context.Context, repositoryID, pullRe
return res, nil
}
+type Comment struct {
+ ID int64 `json:"id"`
+ Body string `json:"body"`
+}
+
// CreatePullRequestComment creates a pull request comment.
+//
+// Docs: https://docs.gitlab.com/ee/api/notes.html#create-new-merge-request-note
func (p *Provider) CreatePullRequestComment(ctx context.Context, repositoryID, pullRequestID, comment string) error {
url := fmt.Sprintf("%s/projects/%s/merge_requests/%s/notes?body=%s", p.APIURL(p.instanceURL), repositoryID, pullRequestID, url.QueryEscape(comment))
code, body, err := internal.Post(ctx, url, p.getAuthorization(), nil)
@@ -312,6 +319,66 @@ func (p *Provider) CreatePullRequestComment(ctx context.Context, repositoryID, p
return nil
}
+// ListPullRequestComments lists comments in a pull request.
+//
+// Docs: https://docs.gitlab.com/ee/api/notes.html#list-all-merge-request-notes
+func (p *Provider) ListPullRequestComments(ctx context.Context, repositoryID, pullRequestID string) ([]*vcs.PullRequestComment, error) {
+ url := fmt.Sprintf("%s/projects/%s/merge_requests/%s/notes", p.APIURL(p.instanceURL), repositoryID, pullRequestID)
+ code, body, err := internal.Get(ctx, url, p.getAuthorization())
+ if err != nil {
+ return nil, errors.Wrapf(err, "GET %s", url)
+ }
+
+ if code == http.StatusNotFound {
+ return nil, common.Errorf(common.NotFound, "failed to list pull request comments through URL %s", url)
+ } else if code >= 300 {
+ return nil, errors.Errorf("failed to list pull request comments from URL %s, status code: %d, body: %s",
+ url,
+ code,
+ body,
+ )
+ }
+
+ var repos []*Comment
+ if err := json.Unmarshal([]byte(body), &repos); err != nil {
+ return nil, errors.Wrap(err, "unmarshal pull request comments failed")
+ }
+
+ var resp []*vcs.PullRequestComment
+ for _, v := range repos {
+ resp = append(resp,
+ &vcs.PullRequestComment{
+ ID: fmt.Sprintf("%d", v.ID),
+ Content: v.Body,
+ },
+ )
+ }
+ return resp, nil
+}
+
+// UpdatePullRequestComment updates a comment in a pull request.
+//
+// Docs: https://docs.gitlab.com/ee/api/notes.html#modify-existing-merge-request-note
+func (p *Provider) UpdatePullRequestComment(ctx context.Context, repositoryID, pullRequestID string, comment *vcs.PullRequestComment) error {
+ url := fmt.Sprintf("%s/projects/%s/merge_requests/%s/notes/%s?body=%s", p.APIURL(p.instanceURL), repositoryID, pullRequestID, comment.ID, url.QueryEscape(comment.Content))
+ code, body, err := internal.Put(ctx, url, p.getAuthorization(), nil)
+ if err != nil {
+ return errors.Wrapf(err, "PUT %s", url)
+ }
+
+ if code == http.StatusNotFound {
+ return common.Errorf(common.NotFound, "cannot found pull request comment through URL %s", url)
+ } else if code >= 300 {
+ return errors.Errorf("failed to update pull request comment through URL %s, status code: %d, body: %s",
+ url,
+ code,
+ body,
+ )
+ }
+
+ return nil
+}
+
// Branch is the API message for GitLab branch.
type Branch struct {
Name string `json:"name"`
diff --git a/backend/plugin/vcs/internal/request.go b/backend/plugin/vcs/internal/request.go
index d01b8d3fb2..f59f066cbc 100644
--- a/backend/plugin/vcs/internal/request.go
+++ b/backend/plugin/vcs/internal/request.go
@@ -15,6 +15,16 @@ func Post(ctx context.Context, url string, authorization string, body []byte) (c
return request(ctx, http.MethodPost, url, authorization, nil, bytes.NewReader(body))
}
+// Patch makes a HTTP PATCH request to the given URL.
+func Patch(ctx context.Context, url string, authorization string, body []byte) (code int, respBody string, err error) {
+ return request(ctx, http.MethodPatch, url, authorization, nil, bytes.NewReader(body))
+}
+
+// Put makes a HTTP PUT request to the given URL.
+func Put(ctx context.Context, url string, authorization string, body []byte) (code int, respBody string, err error) {
+ return request(ctx, http.MethodPut, url, authorization, nil, bytes.NewReader(body))
+}
+
// Get makes a HTTP GET request to the given URL.
func Get(ctx context.Context, url string, authorization string) (code int, respBody string, err error) {
return request(ctx, http.MethodGet, url, authorization, nil, bytes.NewReader(nil))
diff --git a/backend/plugin/vcs/vcs.go b/backend/plugin/vcs/vcs.go
index 93e060af5f..799c86810d 100644
--- a/backend/plugin/vcs/vcs.go
+++ b/backend/plugin/vcs/vcs.go
@@ -68,6 +68,11 @@ type BranchInfo struct {
LastCommitID string
}
+type PullRequestComment struct {
+ ID string
+ Content string
+}
+
// Provider is the interface for VCS provider.
type Provider interface {
// Returns the API URL for a given VCS instance URL
@@ -88,6 +93,12 @@ type Provider interface {
// CreatePullRequestComment creates a pull request comment.
CreatePullRequestComment(ctx context.Context, repositoryID, pullRequestID, comment string) error
+ // UpdatePullRequestComment updates a pull request comment.
+ UpdatePullRequestComment(ctx context.Context, repositoryID, pullRequestID string, comment *PullRequestComment) error
+
+ // ListPullRequestComments lists comments in a pull request.
+ ListPullRequestComments(ctx context.Context, repositoryID, pullRequestID string) ([]*PullRequestComment, error)
+
// Creates a webhook. Returns the created webhook ID on success.
CreateWebhook(ctx context.Context, repositoryID string, payload []byte) (string, error)
diff --git a/backend/server/grpc_routes.go b/backend/server/grpc_routes.go
index b002c45c72..8b8b41dac0 100644
--- a/backend/server/grpc_routes.go
+++ b/backend/server/grpc_routes.go
@@ -46,11 +46,11 @@ func configureGrpcRouters(
postCreateUser apiv1.CreateUserFunc,
secret string,
errorRecordRing *api.ErrorRecordRing,
- tokenDuration time.Duration) (*apiv1.PlanService, *apiv1.RolloutService, *apiv1.IssueService, error) {
+ tokenDuration time.Duration) (*apiv1.PlanService, *apiv1.RolloutService, *apiv1.IssueService, *apiv1.SQLService, error) {
// Register services.
authService, err := apiv1.NewAuthService(stores, secret, tokenDuration, licenseService, metricReporter, profile, stateCfg, iamManager, postCreateUser)
if err != nil {
- return nil, nil, nil, err
+ return nil, nil, nil, nil, err
}
v1pb.RegisterAuditLogServiceServer(grpcServer, apiv1.NewAuditLogService(stores, iamManager, licenseService))
v1pb.RegisterAuthServiceServer(grpcServer, authService)
@@ -78,7 +78,8 @@ func configureGrpcRouters(
v1pb.RegisterIdentityProviderServiceServer(grpcServer, apiv1.NewIdentityProviderService(stores, licenseService))
v1pb.RegisterSettingServiceServer(grpcServer, apiv1.NewSettingService(stores, profile, licenseService, stateCfg))
v1pb.RegisterAnomalyServiceServer(grpcServer, apiv1.NewAnomalyService(stores))
- v1pb.RegisterSQLServiceServer(grpcServer, apiv1.NewSQLService(stores, sheetManager, schemaSyncer, dbFactory, licenseService, profile, iamManager))
+ sqlService := apiv1.NewSQLService(stores, sheetManager, schemaSyncer, dbFactory, licenseService, profile, iamManager)
+ v1pb.RegisterSQLServiceServer(grpcServer, sqlService)
v1pb.RegisterVCSProviderServiceServer(grpcServer, apiv1.NewVCSProviderService(stores))
v1pb.RegisterRiskServiceServer(grpcServer, apiv1.NewRiskService(stores, licenseService))
planService := apiv1.NewPlanService(stores, sheetManager, licenseService, dbFactory, planCheckScheduler, stateCfg, profile, iamManager)
@@ -108,86 +109,86 @@ func configureGrpcRouters(
),
)
if err != nil {
- return nil, nil, nil, err
+ return nil, nil, nil, nil, err
}
if err := v1pb.RegisterAuthServiceHandler(ctx, mux, grpcConn); err != nil {
- return nil, nil, nil, err
+ return nil, nil, nil, nil, err
}
if err := v1pb.RegisterActuatorServiceHandler(ctx, mux, grpcConn); err != nil {
- return nil, nil, nil, err
+ return nil, nil, nil, nil, err
}
if err := v1pb.RegisterSubscriptionServiceHandler(ctx, mux, grpcConn); err != nil {
- return nil, nil, nil, err
+ return nil, nil, nil, nil, err
}
if err := v1pb.RegisterEnvironmentServiceHandler(ctx, mux, grpcConn); err != nil {
- return nil, nil, nil, err
+ return nil, nil, nil, nil, err
}
if err := v1pb.RegisterInstanceServiceHandler(ctx, mux, grpcConn); err != nil {
- return nil, nil, nil, err
+ return nil, nil, nil, nil, err
}
if err := v1pb.RegisterProjectServiceHandler(ctx, mux, grpcConn); err != nil {
- return nil, nil, nil, err
+ return nil, nil, nil, nil, err
}
if err := v1pb.RegisterDatabaseServiceHandler(ctx, mux, grpcConn); err != nil {
- return nil, nil, nil, err
+ return nil, nil, nil, nil, err
}
if err := v1pb.RegisterInstanceRoleServiceHandler(ctx, mux, grpcConn); err != nil {
- return nil, nil, nil, err
+ return nil, nil, nil, nil, err
}
if err := v1pb.RegisterOrgPolicyServiceHandler(ctx, mux, grpcConn); err != nil {
- return nil, nil, nil, err
+ return nil, nil, nil, nil, err
}
if err := v1pb.RegisterWorkspaceServiceHandler(ctx, mux, grpcConn); err != nil {
- return nil, nil, nil, err
+ return nil, nil, nil, nil, err
}
if err := v1pb.RegisterIdentityProviderServiceHandler(ctx, mux, grpcConn); err != nil {
- return nil, nil, nil, err
+ return nil, nil, nil, nil, err
}
if err := v1pb.RegisterSettingServiceHandler(ctx, mux, grpcConn); err != nil {
- return nil, nil, nil, err
+ return nil, nil, nil, nil, err
}
if err := v1pb.RegisterAnomalyServiceHandler(ctx, mux, grpcConn); err != nil {
- return nil, nil, nil, err
+ return nil, nil, nil, nil, err
}
if err := v1pb.RegisterSQLServiceHandler(ctx, mux, grpcConn); err != nil {
- return nil, nil, nil, err
+ return nil, nil, nil, nil, err
}
if err := v1pb.RegisterVCSProviderServiceHandler(ctx, mux, grpcConn); err != nil {
- return nil, nil, nil, err
+ return nil, nil, nil, nil, err
}
if err := v1pb.RegisterRoleServiceHandler(ctx, mux, grpcConn); err != nil {
- return nil, nil, nil, err
+ return nil, nil, nil, nil, err
}
if err := v1pb.RegisterSheetServiceHandler(ctx, mux, grpcConn); err != nil {
- return nil, nil, nil, err
+ return nil, nil, nil, nil, err
}
if err := v1pb.RegisterWorksheetServiceHandler(ctx, mux, grpcConn); err != nil {
- return nil, nil, nil, err
+ return nil, nil, nil, nil, err
}
if err := v1pb.RegisterPlanServiceHandler(ctx, mux, grpcConn); err != nil {
- return nil, nil, nil, err
+ return nil, nil, nil, nil, err
}
if err := v1pb.RegisterRolloutServiceHandler(ctx, mux, grpcConn); err != nil {
- return nil, nil, nil, err
+ return nil, nil, nil, nil, err
}
if err := v1pb.RegisterIssueServiceHandler(ctx, mux, grpcConn); err != nil {
- return nil, nil, nil, err
+ return nil, nil, nil, nil, err
}
if err := v1pb.RegisterDatabaseGroupServiceHandler(ctx, mux, grpcConn); err != nil {
- return nil, nil, nil, err
+ return nil, nil, nil, nil, err
}
if err := v1pb.RegisterChangelistServiceHandler(ctx, mux, grpcConn); err != nil {
- return nil, nil, nil, err
+ return nil, nil, nil, nil, err
}
if err := v1pb.RegisterVCSConnectorServiceHandler(ctx, mux, grpcConn); err != nil {
- return nil, nil, nil, err
+ return nil, nil, nil, nil, err
}
if err := v1pb.RegisterUserGroupServiceHandler(ctx, mux, grpcConn); err != nil {
- return nil, nil, nil, err
+ return nil, nil, nil, nil, err
}
if err := v1pb.RegisterReviewConfigServiceHandler(ctx, mux, grpcConn); err != nil {
- return nil, nil, nil, err
+ return nil, nil, nil, nil, err
}
- return planService, rolloutService, issueService, nil
+ return planService, rolloutService, issueService, sqlService, nil
}
diff --git a/backend/server/server.go b/backend/server/server.go
index e7b3bbde7b..d44ab27d09 100644
--- a/backend/server/server.go
+++ b/backend/server/server.go
@@ -338,13 +338,13 @@ func NewServer(ctx context.Context, profile *config.Profile) (*Server, error) {
}
return nil
}
- planService, rolloutService, issueService, err := configureGrpcRouters(ctx, mux, s.grpcServer, s.store, s.sheetManager, s.dbFactory, s.licenseService, s.profile, s.metricReporter, s.stateCfg, s.schemaSyncer, s.webhookManager, s.iamManager, s.relayRunner, s.planCheckScheduler, postCreateUser, s.secret, &s.errorRecordRing, tokenDuration)
+ planService, rolloutService, issueService, sqlService, err := configureGrpcRouters(ctx, mux, s.grpcServer, s.store, s.sheetManager, s.dbFactory, s.licenseService, s.profile, s.metricReporter, s.stateCfg, s.schemaSyncer, s.webhookManager, s.iamManager, s.relayRunner, s.planCheckScheduler, postCreateUser, s.secret, &s.errorRecordRing, tokenDuration)
if err != nil {
return nil, err
}
s.planService, s.rolloutService, s.issueService = planService, rolloutService, issueService
// GitOps webhook server.
- gitOpsServer := gitops.NewService(s.store, s.dbFactory, s.stateCfg, s.licenseService, planService, rolloutService, issueService, s.sheetManager)
+ gitOpsServer := gitops.NewService(s.store, s.stateCfg, s.licenseService, planService, rolloutService, issueService, sqlService, s.sheetManager)
// Configure echo server routes.
configureEchoRouters(s.echoServer, s.grpcServer, s.lspServer, gitOpsServer, mux, profile)