Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
feat: impl issue releasers (#9301)
p0nye1e64ff5921d
diff --git a/backend/api/v1/issue_service.go b/backend/api/v1/issue_service.goindex ac39dcbba3..89f32129c0 100644--- a/backend/api/v1/issue_service.go+++ b/backend/api/v1/issue_service.go@@ -1525,6 +1525,11 @@ func convertToIssue(ctx context.Context, s *store.Store, issue *store.IssueMessareturn nil, errors.Wrapf(err, "failed to convert GrantRequest")}+ releasers, err := convertToIssueReleasers(ctx, s, issue)+ if err != nil {+ return nil, errors.Wrapf(err, "failed to get issue releasers")+ }+issueV1 := &v1pb.Issue{Name: fmt.Sprintf("%s%s/%s%d", common.ProjectNamePrefix, issue.Project.ResourceID, common.IssuePrefix, issue.UID),Uid: fmt.Sprintf("%d", issue.UID),@@ -1544,6 +1549,7 @@ func convertToIssue(ctx context.Context, s *store.Store, issue *store.IssueMessaPlan: "",Rollout: "",GrantRequest: convertedGrantRequest,+ Releasers: releasers,}if issue.PlanUID != nil {@@ -1580,6 +1586,77 @@ func convertToIssue(ctx context.Context, s *store.Store, issue *store.IssueMessareturn issueV1, nil}+func convertToIssueReleasers(ctx context.Context, s *store.Store, issue *store.IssueMessage) ([]string, error) {+ if issue.Type != api.IssueDatabaseGeneral {+ return nil, nil+ }+ if issue.Status != api.IssueOpen {+ return nil, nil+ }+ if issue.PipelineUID == nil {+ return nil, nil+ }+ stages, err := s.ListStageV2(ctx, *issue.PipelineUID)+ if err != nil {+ return nil, errors.Wrapf(err, "failed to list issue stages")+ }+ var activeStage *store.StageMessage+ for _, stage := range stages {+ if stage.Active {+ activeStage = stage+ break+ }+ }+ if activeStage == nil {+ return nil, nil+ }+ policy, err := s.GetRolloutPolicy(ctx, activeStage.EnvironmentID)+ if err != nil {+ return nil, errors.Wrapf(err, "failed to get rollout policy")+ }++ var releasers []string+ if policy.Automatic {+ releasers = append(releasers, "roles/projectOwner", common.FormatUserEmail(issue.Creator.Email))+ return releasers, nil+ }++ for _, role := range policy.WorkspaceRoles {+ switch role {+ case "roles/OWNER":+ releasers = append(releasers, "roles/workspaceOwner")+ case "roles/DBA":+ releasers = append(releasers, "roles/workspaceDBA")+ }+ }+ for _, role := range policy.ProjectRoles {+ switch role {+ case "roles/OWNER":+ releasers = append(releasers, "roles/projectOwner")+ case "roles/RELEASER":+ releasers = append(releasers, "roles/projectReleaser")+ }+ }+ for _, role := range policy.IssueRoles {+ switch role {+ case "roles/CREATOR":+ releasers = append(releasers, common.FormatUserEmail(issue.Creator.Email))+ case "roles/LAST_APPROVER":+ approvers := issue.Payload.GetApproval().GetApprovers()+ if len(approvers) > 0 {+ lastApproverUID := approvers[len(approvers)-1].GetPrincipalId()+ user, err := s.GetUserByID(ctx, int(lastApproverUID))+ if err != nil {+ return nil, errors.Wrapf(err, "failed to get last approver uid %d", lastApproverUID)+ }+ releasers = append(releasers, common.FormatUserEmail(user.Email))+ }+ }+ }++ return releasers, nil+}+func convertToIssueType(t api.IssueType) v1pb.Issue_Type {switch t {case api.IssueDatabaseGeneral:diff --git a/backend/store/stage.go b/backend/store/stage.goindex b193e0c120..76263afc67 100644--- a/backend/store/stage.go+++ b/backend/store/stage.go@@ -15,7 +15,8 @@ type StageMessage struct {TaskList []*TaskMessage// Output only.- ID int+ ID int+ Active bool// TODO(d): this is used to create the tasks.TaskIndexDAGList []TaskIndexDAG@@ -109,7 +110,29 @@ func (s *Store) ListStageV2(ctx context.Context, pipelineUID int) ([]*StageMessastage.id,stage.pipeline_id,stage.environment_id,- stage.name+ stage.name,+ (+ SELECT EXISTS (+ SELECT 1 FROM task+ LEFT JOIN LATERAL (+ SELECT COALESCE(+ (SELECT+ task_run.status+ FROM task_run+ WHERE task_run.task_id = task.id+ ORDER BY task_run.id DESC+ LIMIT 1+ ), 'NOT_STARTED'+ ) AS status+ ) AS latest_task_run ON TRUE+ WHERE task.pipeline_id = stage.pipeline_id+ AND task.stage_id <= stage.id+ AND (+ COALESCE((task.payload->>'skipped')::BOOLEAN, FALSE) IS FALSE+ OR latest_task_run.status = 'DONE'+ )+ )+ ) AS activeFROM stageWHERE %s ORDER BY id ASC`, strings.Join(where, " AND ")),args...,@@ -127,6 +150,7 @@ func (s *Store) ListStageV2(ctx context.Context, pipelineUID int) ([]*StageMessa&stage.PipelineID,&stage.EnvironmentID,&stage.Name,+ &stage.Active,); err != nil {return nil, err}diff --git a/frontend/src/types/proto/v1/issue_service.ts b/frontend/src/types/proto/v1/issue_service.tsindex 6c6cc50245..954644f61f 100644--- a/frontend/src/types/proto/v1/issue_service.ts+++ b/frontend/src/types/proto/v1/issue_service.ts@@ -223,8 +223,15 @@ export interface Issue {| GrantRequest| undefined;/**- * The releasers.- * Format: roles/{role}+ * The releasers of the pending stage of the issue rollout, judging+ * from the rollout policy.+ * If the policy is auto rollout, the releasers are the project owners and the issue creator.+ * Format:+ * - roles/workspaceOwner+ * - roles/workspaceDBA+ * - roles/projectOwner+ * - roles/projectReleaser+ * - users/{email}*/releasers: string[];}diff --git a/proto/gen/grpc-doc/v1/README.md b/proto/gen/grpc-doc/v1/README.mdindex 6c7a22020c..0dce178392 100644--- a/proto/gen/grpc-doc/v1/README.md+++ b/proto/gen/grpc-doc/v1/README.md@@ -5700,7 +5700,7 @@ The instance's `name` field is used to identify the instance to update. Form| plan | [string](#string) | | The plan associated with the issue. Can be empty. Format: projects/{project}/plans/{plan} || rollout | [string](#string) | | The rollout associated with the issue. Can be empty. Format: projects/{project}/rollouts/{rollout} || grant_request | [GrantRequest](#bytebase-v1-GrantRequest) | | Used if the issue type is GRANT_REQUEST. |-| releasers | [string](#string) | repeated | The releasers. Format: roles/{role} |+| releasers | [string](#string) | repeated | The releasers of the pending stage of the issue rollout, judging from the rollout policy. If the policy is auto rollout, the releasers are the project owners and the issue creator. Format: - roles/workspaceOwner - roles/workspaceDBA - roles/projectOwner - roles/projectReleaser - users/{email} |diff --git a/proto/generated-go/v1/issue_service.pb.go b/proto/generated-go/v1/issue_service.pb.goindex f2533c71fa..5f123f01da 100644--- a/proto/generated-go/v1/issue_service.pb.go+++ b/proto/generated-go/v1/issue_service.pb.go@@ -993,8 +993,15 @@ type Issue struct {Rollout string `protobuf:"bytes,18,opt,name=rollout,proto3" json:"rollout,omitempty"`// Used if the issue type is GRANT_REQUEST.GrantRequest *GrantRequest `protobuf:"bytes,19,opt,name=grant_request,json=grantRequest,proto3" json:"grant_request,omitempty"`- // The releasers.- // Format: roles/{role}+ // The releasers of the pending stage of the issue rollout, judging+ // from the rollout policy.+ // If the policy is auto rollout, the releasers are the project owners and the issue creator.+ // Format:+ // - roles/workspaceOwner+ // - roles/workspaceDBA+ // - roles/projectOwner+ // - roles/projectReleaser+ // - users/{email}Releasers []string `protobuf:"bytes,20,rep,name=releasers,proto3" json:"releasers,omitempty"`}diff --git a/proto/v1/issue_service.proto b/proto/v1/issue_service.protoindex 8326a002d3..ddd54aaa32 100644--- a/proto/v1/issue_service.proto+++ b/proto/v1/issue_service.proto@@ -259,8 +259,15 @@ message Issue {// Used if the issue type is GRANT_REQUEST.GrantRequest grant_request = 19;- // The releasers.- // Format: roles/{role}+ // The releasers of the pending stage of the issue rollout, judging+ // from the rollout policy.+ // If the policy is auto rollout, the releasers are the project owners and the issue creator.+ // Format:+ // - roles/workspaceOwner+ // - roles/workspaceDBA+ // - roles/projectOwner+ // - roles/projectReleaser+ // - users/{email}repeated string releasers = 20;}