Skip to content

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

feat: create release via github (#14279)

p0ny44bbfb36a1e8
diff --git a/backend/api/gitops/common.go b/backend/api/gitops/common.go
index 20f9ea2705..410c48605b 100644
--- a/backend/api/gitops/common.go
+++ b/backend/api/gitops/common.go
@@ -1,6 +1,7 @@
package gitops
import (
+ "context"
"fmt"
"log/slog"
"path/filepath"
@@ -23,6 +24,7 @@ type webhookAction int
const (
webhookActionCreateIssue webhookAction = iota
webhookActionSQLReview
+ webhookActionCreateRelease
)
type pullRequestInfo struct {
@@ -32,6 +34,9 @@ type pullRequestInfo struct {
description string
url string
changes []*fileChange
+
+ // all files directly (non-recursive) under the base directory.
+ getAllFiles func(context.Context) ([]*fileChange, error)
}
type fileChange struct {
@@ -67,6 +72,41 @@ func getChangesByFileList(files []*vcs.PullRequestFile, rootDir string) []*fileC
return changes
}
+func convertVcsFile(f *vcs.File) (*fileChange, error) {
+ if filepath.Ext(f.Name) != ".sql" {
+ return nil, nil
+ }
+
+ matches := versionRE.FindAllString(f.Name, -1)
+ if len(matches) == 0 {
+ return nil, nil
+ }
+ version := matches[0]
+ description := strings.TrimPrefix(f.Name, version)
+ description = strings.TrimLeft(description, "_")
+ changeType := v1pb.Plan_ChangeDatabaseConfig_MIGRATE
+ switch {
+ case strings.HasPrefix(description, "ddl"):
+ description = strings.TrimPrefix(description, "ddl")
+ changeType = v1pb.Plan_ChangeDatabaseConfig_MIGRATE
+ case strings.HasPrefix(description, "dml"):
+ description = strings.TrimPrefix(description, "dml")
+ changeType = v1pb.Plan_ChangeDatabaseConfig_DATA
+ case strings.HasPrefix(description, "ghost"):
+ description = strings.TrimPrefix(description, "ghost")
+ changeType = v1pb.Plan_ChangeDatabaseConfig_MIGRATE_GHOST
+ }
+ description = strings.TrimLeft(description, "_")
+ return &fileChange{
+ path: f.Path,
+ version: version,
+ changeType: changeType,
+ description: description,
+ content: f.Content,
+ webURL: "",
+ }, nil
+}
+
func getFileChange(file *vcs.PullRequestFile) (*fileChange, error) {
filename := filepath.Base(file.Path)
if filepath.Ext(filename) != ".sql" {
diff --git a/backend/api/gitops/github.go b/backend/api/gitops/github.go
index a18d5d1a73..778056fe27 100644
--- a/backend/api/gitops/github.go
+++ b/backend/api/gitops/github.go
@@ -7,13 +7,15 @@ import (
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
+ "github.com/bytebase/bytebase/backend/component/config"
"github.com/bytebase/bytebase/backend/plugin/vcs"
"github.com/bytebase/bytebase/backend/plugin/vcs/github"
"github.com/bytebase/bytebase/backend/store"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
)
-func getGitHubPullRequestInfo(ctx context.Context, vcsProvider *store.VCSProviderMessage, vcsConnector *store.VCSConnectorMessage, body []byte) (*pullRequestInfo, error) {
+func getGitHubPullRequestInfo(ctx context.Context, vcsProvider *store.VCSProviderMessage, vcsConnector *store.VCSConnectorMessage, body []byte, profile *config.Profile) (*pullRequestInfo, error) {
var pushEvent github.PullRequestPushEvent
if err := json.Unmarshal(body, &pushEvent); err != nil {
return nil, errors.Errorf("failed to unmarshal push event, error %v", err)
@@ -27,7 +29,11 @@ func getGitHubPullRequestInfo(ctx context.Context, vcsProvider *store.VCSProvide
if !pushEvent.PullRequest.Merged {
return nil, errors.Errorf("skip pull request close action, pull request is not merged")
}
- actionType = webhookActionCreateIssue
+ if common.IsDev() && profile.DevelopmentVersioned {
+ actionType = webhookActionCreateRelease
+ } else {
+ actionType = webhookActionCreateIssue
+ }
default:
return nil, errors.Errorf(`skip webhook event action "%s"`, pushEvent.Action)
}
@@ -57,5 +63,35 @@ func getGitHubPullRequestInfo(ctx context.Context, vcsProvider *store.VCSProvide
}
file.content = convertFileContentToUTF8String(content)
}
+
+ if actionType == webhookActionCreateRelease {
+ prInfo.getAllFiles = func(ctx context.Context) ([]*fileChange, error) {
+ p, ok := vcs.Get(storepb.VCSType_GITHUB, vcs.ProviderConfig{InstanceURL: vcsProvider.InstanceURL, AuthToken: vcsProvider.AccessToken}).(*github.Provider)
+ if !ok {
+ return nil, errors.Errorf("expect github.Provider, got %T", p)
+ }
+
+ mergeCommitSha, err := p.GetPullRequestMergedCommit(ctx, vcsConnector.Payload.ExternalId, fmt.Sprintf("%d", pushEvent.Number))
+ if err != nil {
+ return nil, errors.Wrapf(err, "failed to get pull request %d", pushEvent.Number)
+ }
+
+ dirFiles, err := p.GetDirectoryFiles(ctx, vcsConnector.Payload.ExternalId, mergeCommitSha, vcsConnector.Payload.BaseDirectory)
+ if err != nil {
+ return nil, errors.Wrapf(err, "failed to get directory files")
+ }
+ var allFiles []*fileChange
+ for _, f := range dirFiles {
+ f.Content = convertFileContentToUTF8String(f.Content)
+ converted, err := convertVcsFile(f)
+ if err != nil {
+ return nil, errors.Wrapf(err, "failed to convert vcs file")
+ }
+ allFiles = append(allFiles, converted)
+ }
+ return allFiles, nil
+ }
+ }
+
return prInfo, nil
}
diff --git a/backend/api/gitops/gitops.go b/backend/api/gitops/gitops.go
index 2ed30af723..ff52c2a37f 100644
--- a/backend/api/gitops/gitops.go
+++ b/backend/api/gitops/gitops.go
@@ -3,6 +3,7 @@ package gitops
import (
v1pb "github.com/bytebase/bytebase/backend/api/v1"
+ "github.com/bytebase/bytebase/backend/component/config"
"github.com/bytebase/bytebase/backend/component/sheet"
enterprise "github.com/bytebase/bytebase/backend/enterprise/api"
"github.com/bytebase/bytebase/backend/store"
@@ -12,30 +13,36 @@ import (
type Service struct {
store *store.Store
licenseService enterprise.LicenseService
+ releaseService *v1pb.ReleaseService
planService *v1pb.PlanService
rolloutService *v1pb.RolloutService
issueService *v1pb.IssueService
sqlService *v1pb.SQLService
sheetManager *sheet.Manager
+ profile *config.Profile
}
// NewService creates a GitOps service.
func NewService(
store *store.Store,
licenseService enterprise.LicenseService,
+ releaseService *v1pb.ReleaseService,
planService *v1pb.PlanService,
rolloutService *v1pb.RolloutService,
issueService *v1pb.IssueService,
sqlService *v1pb.SQLService,
sheetManager *sheet.Manager,
+ profile *config.Profile,
) *Service {
return &Service{
store: store,
licenseService: licenseService,
+ releaseService: releaseService,
planService: planService,
rolloutService: rolloutService,
issueService: issueService,
sqlService: sqlService,
sheetManager: sheetManager,
+ profile: profile,
}
}
diff --git a/backend/api/gitops/webhook.go b/backend/api/gitops/webhook.go
index 89a97c786f..a0e4ccbfa1 100644
--- a/backend/api/gitops/webhook.go
+++ b/backend/api/gitops/webhook.go
@@ -29,6 +29,15 @@ import (
v1pb "github.com/bytebase/bytebase/proto/generated-go/v1"
)
+type createReleaseContext struct {
+ user *store.UserMessage
+ setting *storepb.WorkspaceProfileSetting
+ project *store.ProjectMessage
+ vcsConnector *store.VCSConnectorMessage
+ vcsProvider *store.VCSProviderMessage
+ prInfo *pullRequestInfo
+}
+
func (s *Service) RegisterWebhookRoutes(g *echo.Group) {
g.POST(":id", func(c echo.Context) error {
ctx := c.Request().Context()
@@ -103,7 +112,7 @@ func (s *Service) RegisterWebhookRoutes(g *echo.Group) {
return c.String(http.StatusOK, fmt.Sprintf(`skip webhook event "%v"`, eventType))
}
- prInfo, err = getGitHubPullRequestInfo(ctx, vcsProvider, vcsConnector, body)
+ prInfo, err = getGitHubPullRequestInfo(ctx, vcsProvider, vcsConnector, body, s.profile)
if err != nil {
return c.String(http.StatusOK, fmt.Sprintf("failed to get pr info from pull request, error %v", err))
}
@@ -169,6 +178,16 @@ func (s *Service) RegisterWebhookRoutes(g *echo.Group) {
var commentPrefix string
var createCommentIfNotExist bool
switch prInfo.action {
+ case webhookActionCreateRelease:
+ go s.createRelease(&createReleaseContext{
+ user: user,
+ setting: setting,
+ project: project,
+ vcsConnector: vcsConnector,
+ vcsProvider: vcsProvider,
+ prInfo: prInfo,
+ })
+
case webhookActionCreateIssue:
issue, err := s.createIssueFromPRInfo(childCtx, project, vcsProvider, vcsConnector, prInfo)
if err != nil {
@@ -213,6 +232,38 @@ func (s *Service) RegisterWebhookRoutes(g *echo.Group) {
})
}
+func (s *Service) createRelease(t *createReleaseContext) {
+ ctx := context.Background()
+ ctx = context.WithValue(ctx, common.PrincipalIDContextKey, t.user.ID)
+ ctx = context.WithValue(ctx, common.UserContextKey, t.user)
+
+ err := func() error {
+ release, err := s.createReleaseFromPRInfo(ctx, t.project, t.vcsProvider, t.prInfo)
+ if err != nil {
+ return errors.Wrapf(err, "failed to create release from pull request %s", t.prInfo.url)
+ }
+ comment := fmt.Sprintf("This pull request has created a Bytebase release 🚀. Check out at %s/%s", t.setting.ExternalUrl, release.Name)
+ commentPrefix := commentPrefixBytebaseBot
+ createCommentIfNotExist := true
+
+ if err := upsertPullRequestComment(
+ ctx,
+ t.vcsProvider,
+ t.vcsConnector,
+ t.prInfo,
+ fmt.Sprintf("%s\n\n%s", commentPrefix, comment),
+ func(content string) bool { return strings.HasPrefix(content, commentPrefix) },
+ createCommentIfNotExist,
+ ); err != nil {
+ return errors.Wrapf(err, "failed to upsert comment")
+ }
+ return nil
+ }()
+ if err != nil {
+ slog.Error("failed to create release from pull request", log.BBError(err))
+ }
+}
+
// validateGitHubWebhookSignature256 returns true if the signature matches the
// HMAC hex digested SHA256 hash of the body using the given key.
func validateGitHubWebhookSignature256(signature, key string, body []byte) (bool, error) {
@@ -305,6 +356,70 @@ func (s *Service) sqlReviewWithPRInfo(ctx context.Context, project *store.Projec
return fmt.Sprintf("\n%d errors, %d warnings\n\n---\n\n%s", errorCount, warnCount, strings.Join(content, "\n")), nil
}
+func (s *Service) createReleaseFromPRInfo(ctx context.Context, project *store.ProjectMessage, vcsProvider *store.VCSProviderMessage, prInfo *pullRequestInfo) (*v1pb.Release, error) {
+ user, ok := ctx.Value(common.UserContextKey).(*store.UserMessage)
+ if !ok {
+ return nil, errors.Errorf("cannot found user in context")
+ }
+
+ if prInfo.getAllFiles == nil {
+ return nil, errors.Errorf("getAllFiles is nil")
+ }
+
+ allFiles, err := prInfo.getAllFiles(ctx)
+ if err != nil {
+ return nil, errors.Wrapf(err, "failed to get all files")
+ }
+
+ var sheetNames []string
+ for _, f := range allFiles {
+ sheet, err := s.store.CreateSheet(ctx, &store.SheetMessage{
+ ProjectUID: project.UID,
+ CreatorID: user.ID,
+ UpdaterID: user.ID,
+ Title: "",
+ Statement: f.content,
+ })
+ if err != nil {
+ return nil, errors.Wrapf(err, "failed to create sheet")
+ }
+
+ sheetNames = append(sheetNames, common.FormatSheet(project.ResourceID, sheet.UID))
+ }
+
+ var files []*v1pb.Release_File
+ for i, f := range allFiles {
+ file := &v1pb.Release_File{
+ Id: "",
+ Path: f.path,
+ Sheet: sheetNames[i],
+ SheetSha256: "",
+ Type: v1pb.ReleaseFileType_VERSIONED,
+ Version: f.version,
+ }
+ files = append(files, file)
+ }
+
+ release1 := &v1pb.Release{
+ Title: fmt.Sprintf("release for PR %s", prInfo.title),
+ Files: files,
+ VcsSource: &v1pb.Release_VCSSource{
+ VcsType: v1pb.VCSType(vcsProvider.Type),
+ PullRequestUrl: prInfo.url,
+ },
+ }
+
+ release, err := s.releaseService.CreateRelease(ctx, &v1pb.CreateReleaseRequest{
+ Parent: common.FormatProject(project.ResourceID),
+ Release: release1,
+ })
+ if err != nil {
+ return nil, errors.Wrapf(err, "failed to create release")
+ }
+
+ return release, 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 {
diff --git a/backend/plugin/vcs/github/github.go b/backend/plugin/vcs/github/github.go
index fdab3e3cf1..0f01add829 100644
--- a/backend/plugin/vcs/github/github.go
+++ b/backend/plugin/vcs/github/github.go
@@ -11,6 +11,7 @@ import (
"net/http"
"net/url"
"strconv"
+ "strings"
"time"
"github.com/pkg/errors"
@@ -556,3 +557,139 @@ func (p *Provider) DeleteWebhook(ctx context.Context, repositoryID, webhookID st
func (p *Provider) getAuthorization() string {
return fmt.Sprintf("Bearer %s", p.authToken)
}
+
+// https://docs.github.com/en/rest/pulls/pulls?apiVersion=2022-11-28#get-a-pull-request
+func (p *Provider) GetPullRequestMergedCommit(ctx context.Context, repoID string, prID string) (string, error) {
+ url := fmt.Sprintf("%s/repos/%s/pulls/%s", p.APIURL(p.instanceURL), repoID, prID)
+ code, body, err := internal.Get(ctx, url, p.getAuthorization())
+ if err != nil {
+ return "", errors.Wrapf(err, "GET %s", url)
+ }
+
+ if code == http.StatusNotFound {
+ return "", common.Errorf(common.NotFound, "failed to get pull request from URL %s", url)
+ } else if code >= 300 {
+ return "", errors.Errorf("failed to get pull request from URL %s, status code: %d, body: %s",
+ url,
+ code,
+ body,
+ )
+ }
+
+ var pr struct {
+ MergeCommitSha string `json:"merge_commit_sha"`
+ }
+
+ if err := json.Unmarshal([]byte(body), &pr); err != nil {
+ return "", errors.Wrapf(err, "failed to unmarshal")
+ }
+
+ return pr.MergeCommitSha, nil
+}
+
+func (p *Provider) GetDirectoryFiles(ctx context.Context, repoID string, commitSha string, path string) ([]*vcs.File, error) {
+ path = strings.TrimLeft(path, "/")
+ path = url.PathEscape(path)
+
+ files, err := p.getDirectory(ctx, repoID, commitSha, path)
+ if err != nil {
+ return nil, errors.Wrapf(err, "failed to get directory")
+ }
+
+ for _, f := range files {
+ content, err := p.getBlob(ctx, repoID, f.Sha)
+ if err != nil {
+ return nil, errors.Wrapf(err, "failed to get blob")
+ }
+ f.Content = content
+ }
+
+ return files, nil
+}
+
+// https://docs.github.com/en/rest/git/blobs?apiVersion=2022-11-28#get-a-blob
+func (p *Provider) getBlob(ctx context.Context, repoID string, sha string) (string, error) {
+ url := fmt.Sprintf("%s/repos/%s/git/blobs/%s", p.APIURL(p.instanceURL), repoID, sha)
+ code, body, err := internal.GetWithHeader(ctx, url, p.getAuthorization(),
+ map[string]string{
+ "Accept": "application/vnd.github.raw+json",
+ },
+ )
+ if err != nil {
+ return "", errors.Wrapf(err, "GET %s", url)
+ }
+
+ if code == http.StatusNotFound {
+ return "", common.Errorf(common.NotFound, "failed to get blob from URL %s", url)
+ } else if code >= 300 {
+ return "",
+ errors.Errorf("failed to get blob from URL %s, status code: %d, body: %s",
+ url,
+ code,
+ body,
+ )
+ }
+
+ return body, nil
+}
+
+// https://docs.github.com/en/rest/repos/contents?apiVersion=2022-11-28#get-repository-content
+func (p *Provider) getDirectory(ctx context.Context, repoID string, commitSha string, path string) ([]*vcs.File, error) {
+ path = strings.TrimLeft(path, "/")
+ path = url.PathEscape(path)
+
+ url := fmt.Sprintf("%s/repos/%s/contents/%s?ref=%s", p.APIURL(p.instanceURL), repoID, path, commitSha)
+ code, body, err := internal.GetWithHeader(ctx, url, p.getAuthorization(),
+ map[string]string{
+ "Accept": "application/vnd.github.object+json",
+ },
+ )
+ if err != nil {
+ return nil, errors.Wrapf(err, "GET %s", url)
+ }
+
+ if code == http.StatusNotFound {
+ return nil, common.Errorf(common.NotFound, "failed to get directory from URL %s", url)
+ } else if code >= 300 {
+ return nil,
+ errors.Errorf("failed to get directory from URL %s, status code: %d, body: %s",
+ url,
+ code,
+ body,
+ )
+ }
+
+ var dir struct {
+ Type string `json:"type"`
+ Name string `json:"name"`
+ Path string `json:"path"`
+ Sha string `json:"sha"`
+ Entries []struct {
+ Type string `json:"type"`
+ Name string `json:"name"`
+ Path string `json:"path"`
+ Sha string `json:"sha"`
+ } `json:"entries"`
+ }
+
+ if err := json.Unmarshal([]byte(body), &dir); err != nil {
+ return nil, errors.Wrapf(err, "failed to unmarshal")
+ }
+
+ if dir.Type != "dir" {
+ return nil, errors.Errorf("expecting %q to be of type `dir`, but found %s", path, dir.Type)
+ }
+
+ var files []*vcs.File
+ for _, e := range dir.Entries {
+ if e.Type == "file" {
+ files = append(files, &vcs.File{
+ Path: e.Path,
+ Name: e.Name,
+ Sha: e.Sha,
+ })
+ }
+ }
+
+ return files, nil
+}
diff --git a/backend/plugin/vcs/vcs.go b/backend/plugin/vcs/vcs.go
index 7d9d15cd03..f58ed256e7 100644
--- a/backend/plugin/vcs/vcs.go
+++ b/backend/plugin/vcs/vcs.go
@@ -75,6 +75,13 @@ type PullRequestComment struct {
Content string
}
+type File struct {
+ Path string
+ Name string
+ Sha string
+ Content string
+}
+
// Provider is the interface for VCS provider.
type Provider interface {
// Returns the API URL for a given VCS instance URL
diff --git a/backend/server/grpc_routes.go b/backend/server/grpc_routes.go
index 0015b355d7..20b4cf94bd 100644
--- a/backend/server/grpc_routes.go
+++ b/backend/server/grpc_routes.go
@@ -40,11 +40,11 @@ func configureGrpcRouters(
iamManager *iam.Manager,
relayRunner *relay.Runner,
postCreateUser apiv1.CreateUserFunc,
- secret string) (*apiv1.PlanService, *apiv1.RolloutService, *apiv1.IssueService, *apiv1.SQLService, error) {
+ secret string) (*apiv1.ReleaseService, *apiv1.PlanService, *apiv1.RolloutService, *apiv1.IssueService, *apiv1.SQLService, error) {
// Register services.
authService, err := apiv1.NewAuthService(stores, secret, licenseService, metricReporter, profile, stateCfg, iamManager, postCreateUser)
if err != nil {
- return nil, nil, nil, nil, err
+ return nil, nil, nil, nil, nil, err
}
v1pb.RegisterAuditLogServiceServer(grpcServer, apiv1.NewAuditLogService(stores, iamManager, licenseService))
v1pb.RegisterAuthServiceServer(grpcServer, authService)
@@ -105,103 +105,103 @@ func configureGrpcRouters(
),
)
if err != nil {
- return nil, nil, nil, nil, err
+ return nil, nil, nil, nil, nil, err
}
// Sort by service name, align with api.bytebase.com.
if err := v1pb.RegisterActuatorServiceHandler(ctx, mux, grpcConn); err != nil {
- return nil, nil, nil, nil, err
+ return nil, nil, nil, nil, nil, err
}
if err := v1pb.RegisterAnomalyServiceHandler(ctx, mux, grpcConn); err != nil {
- return nil, nil, nil, nil, err
+ return nil, nil, nil, nil, nil, err
}
if err := v1pb.RegisterAuditLogServiceHandler(ctx, mux, grpcConn); err != nil {
- return nil, nil, nil, nil, err
+ return nil, nil, nil, nil, nil, err
}
if err := v1pb.RegisterAuthServiceHandler(ctx, mux, grpcConn); err != nil {
- return nil, nil, nil, nil, err
+ return nil, nil, nil, nil, nil, err
}
if err := v1pb.RegisterBranchServiceHandler(ctx, mux, grpcConn); err != nil {
- return nil, nil, nil, nil, err
+ return nil, nil, nil, nil, nil, err
}
if err := v1pb.RegisterCelServiceHandler(ctx, mux, grpcConn); err != nil {
- return nil, nil, nil, nil, err
+ return nil, nil, nil, nil, nil, err
}
if err := v1pb.RegisterChangelistServiceHandler(ctx, mux, grpcConn); err != nil {
- return nil, nil, nil, nil, err
+ return nil, nil, nil, nil, nil, err
}
if err := v1pb.RegisterDatabaseGroupServiceHandler(ctx, mux, grpcConn); err != nil {
- return nil, nil, nil, nil, err
+ return nil, nil, nil, nil, nil, err
}
if err := v1pb.RegisterDatabaseServiceHandler(ctx, mux, grpcConn); err != nil {
- return nil, nil, nil, nil, err
+ return nil, nil, nil, nil, nil, err
}
if err := v1pb.RegisterEnvironmentServiceHandler(ctx, mux, grpcConn); err != nil {
- return nil, nil, nil, nil, err
+ return nil, nil, nil, nil, nil, err
}
if err := v1pb.RegisterGroupServiceHandler(ctx, mux, grpcConn); err != nil {
- return nil, nil, nil, nil, err
+ return nil, nil, nil, nil, nil, err
}
if err := v1pb.RegisterIdentityProviderServiceHandler(ctx, mux, grpcConn); err != nil {
- return nil, nil, nil, nil, err
+ return nil, nil, nil, nil, nil, err
}
if err := v1pb.RegisterInstanceRoleServiceHandler(ctx, mux, grpcConn); err != nil {
- return nil, nil, nil, nil, err
+ return nil, nil, nil, nil, nil, err
}
if err := v1pb.RegisterInstanceServiceHandler(ctx, mux, grpcConn); err != nil {
- return nil, nil, nil, nil, err
+ return nil, nil, nil, nil, nil, err
}
if err := v1pb.RegisterIssueServiceHandler(ctx, mux, grpcConn); err != nil {
- return nil, nil, nil, nil, err
+ return nil, nil, nil, nil, nil, err
}
if err := v1pb.RegisterOrgPolicyServiceHandler(ctx, mux, grpcConn); err != nil {
- return nil, nil, nil, nil, err
+ return nil, nil, nil, nil, nil, err
}
if err := v1pb.RegisterPlanServiceHandler(ctx, mux, grpcConn); err != nil {
- return nil, nil, nil, nil, err
+ return nil, nil, nil, nil, nil, err
}
if err := v1pb.RegisterProjectServiceHandler(ctx, mux, grpcConn); err != nil {
- return nil, nil, nil, nil, err
+ return nil, nil, nil, nil, nil, err
}
if err := v1pb.RegisterReviewConfigServiceHandler(ctx, mux, grpcConn); err != nil {
- return nil, nil, nil, nil, err
+ return nil, nil, nil, nil, nil, err
}
if err := v1pb.RegisterRiskServiceHandler(ctx, mux, grpcConn); err != nil {
- return nil, nil, nil, nil, err
+ return nil, nil, nil, nil, nil, err
}
if err := v1pb.RegisterRoleServiceHandler(ctx, mux, grpcConn); err != nil {
- return nil, nil, nil, nil, err
+ return nil, nil, nil, nil, nil, err
}
if err := v1pb.RegisterRolloutServiceHandler(ctx, mux, grpcConn); err != nil {
- return nil, nil, nil, nil, err
+ return nil, nil, nil, nil, nil, err
}
if err := v1pb.RegisterSQLServiceHandler(ctx, mux, grpcConn); err != nil {
- return nil, nil, nil, nil, err
+ return nil, nil, nil, nil, nil, err
}
if err := v1pb.RegisterSettingServiceHandler(ctx, mux, grpcConn); err != nil {
- return nil, nil, nil, nil, err
+ return nil, nil, nil, nil, nil, err
}
if err := v1pb.RegisterSheetServiceHandler(ctx, mux, grpcConn); err != nil {
- return nil, nil, nil, nil, err
+ return nil, nil, nil, nil, nil, err
}
if err := v1pb.RegisterSubscriptionServiceHandler(ctx, mux, grpcConn); err != nil {
- return nil, nil, nil, nil, err
+ return nil, nil, nil, nil, nil, err
}
if err := v1pb.RegisterVCSConnectorServiceHandler(ctx, mux, grpcConn); err != nil {
- return nil, nil, nil, nil, err
+ return nil, nil, nil, nil, nil, err
}
if err := v1pb.RegisterVCSProviderServiceHandler(ctx, mux, grpcConn); err != nil {
- return nil, nil, nil, nil, err
+ return nil, nil, nil, nil, nil, err
}
if err := v1pb.RegisterWorksheetServiceHandler(ctx, mux, grpcConn); err != nil {
- return nil, nil, nil, nil, err
+ return nil, nil, nil, nil, nil, err
}
if err := v1pb.RegisterWorkspaceServiceHandler(ctx, mux, grpcConn); err != nil {
- return nil, nil, nil, nil, err
+ return nil, nil, nil, nil, nil, err
}
if err := v1pb.RegisterReleaseServiceHandler(ctx, mux, grpcConn); err != nil {
- return nil, nil, nil, nil, err
+ return nil, nil, nil, nil, nil, err
}
- return planService, rolloutService, issueService, sqlService, nil
+ return releaseService, planService, rolloutService, issueService, sqlService, nil
}
diff --git a/backend/server/server.go b/backend/server/server.go
index f011f3db22..1f03306d0d 100644
--- a/backend/server/server.go
+++ b/backend/server/server.go
@@ -362,13 +362,13 @@ func NewServer(ctx context.Context, profile *config.Profile) (*Server, error) {
}
return nil
}
- 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, postCreateUser, s.secret)
+ releaseService, 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, postCreateUser, s.secret)
if err != nil {
return nil, err
}
s.planService, s.rolloutService, s.issueService = planService, rolloutService, issueService
// GitOps webhook server.
- gitOpsServer := gitops.NewService(s.store, s.licenseService, planService, rolloutService, issueService, sqlService, s.sheetManager)
+ gitOpsServer := gitops.NewService(s.store, s.licenseService, releaseService, planService, rolloutService, issueService, sqlService, s.sheetManager, profile)
directorySyncServer := directorysync.NewService(s.store, s.licenseService, s.iamManager)
// Configure echo server routes.
diff --git a/backend/store/sheet.go b/backend/store/sheet.go
index 274acffc05..e16ae5edc2 100644
--- a/backend/store/sheet.go
+++ b/backend/store/sheet.go
@@ -238,7 +238,7 @@ func (s *Store) CreateSheet(ctx context.Context, create *SheetMessage) (*SheetMe
payload
)
VALUES ($1, $2, $3, $4, $5, $6, $7)
- RETURNING id, created_ts, updated_ts, OCTET_LENGTH(statement)
+ RETURNING id, created_ts, updated_ts, OCTET_LENGTH(statement), encode(sha256(convert_to(sheet.statement, 'UTF8')), 'hex')
`
tx, err := s.db.BeginTx(ctx, nil)
@@ -260,6 +260,7 @@ func (s *Store) CreateSheet(ctx context.Context, create *SheetMessage) (*SheetMe
&create.createdTs,
&create.updatedTs,
&create.Size,
+ &create.Sha256,
); err != nil {
if err == sql.ErrNoRows {
return nil, common.FormatDBErrorEmptyRowWithQuery(query)