Skip to content

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

chore: move codes to corresponding places, sync style with composeXxx (#1259)

Yilong Li6e7f5478753f
diff --git a/store/issue.go b/store/issue.go
index 612b8091a6..e81465605f 100644
--- a/store/issue.go
+++ b/store/issue.go
@@ -224,22 +224,23 @@ func (s *Store) CreatePipelineValidateOnly(ctx context.Context, create *api.Pipe
//
func (s *Store) composeIssueValidateOnly(ctx context.Context, issue *api.Issue) error {
- var err error
-
- issue.Creator, err = s.GetPrincipalByID(ctx, issue.CreatorID)
+ creator, err := s.GetPrincipalByID(ctx, issue.CreatorID)
if err != nil {
return err
}
+ issue.Creator = creator
- issue.Updater, err = s.GetPrincipalByID(ctx, issue.UpdaterID)
+ updater, err := s.GetPrincipalByID(ctx, issue.UpdaterID)
if err != nil {
return err
}
+ issue.Updater = updater
- issue.Assignee, err = s.GetPrincipalByID(ctx, issue.AssigneeID)
+ assignee, err := s.GetPrincipalByID(ctx, issue.AssigneeID)
if err != nil {
return err
}
+ issue.Assignee = assignee
issueSubscriberFind := &api.IssueSubscriberFind{
IssueID: &issue.ID,
@@ -266,50 +267,7 @@ func (s *Store) composeIssueValidateOnly(ctx context.Context, issue *api.Issue)
return nil
}
-func (s *Store) composePipelineValidateOnly(ctx context.Context, pipeline *api.Pipeline) error {
- var err error
-
- pipeline.Creator, err = s.GetPrincipalByID(ctx, pipeline.CreatorID)
- if err != nil {
- return err
- }
-
- pipeline.Updater, err = s.GetPrincipalByID(ctx, pipeline.UpdaterID)
- if err != nil {
- return err
- }
-
- for _, stage := range pipeline.StageList {
- if err := s.composeStageValidateOnly(ctx, stage); err != nil {
- return err
- }
- }
-
- return nil
-}
-
-func (s *Store) composeStageValidateOnly(ctx context.Context, stage *api.Stage) error {
- var err error
- stage.Creator, err = s.GetPrincipalByID(ctx, stage.CreatorID)
- if err != nil {
- return err
- }
-
- stage.Updater, err = s.GetPrincipalByID(ctx, stage.UpdaterID)
- if err != nil {
- return err
- }
-
- stage.Environment, err = s.GetEnvironmentByID(ctx, stage.EnvironmentID)
- if err != nil {
- return err
- }
-
- // Note: stage.TaskList is already composed in CreatePipelineValidateOnly(). Do not need to compose here.
-
- return nil
-}
-
+// Note: MUST keep in sync with composeIssueValidateOnly
func (s *Store) composeIssue(ctx context.Context, raw *issueRaw) (*api.Issue, error) {
issue := raw.toIssue()
diff --git a/store/pipeline.go b/store/pipeline.go
index 7deed13b60..d2628bc9b1 100644
--- a/store/pipeline.go
+++ b/store/pipeline.go
@@ -116,6 +116,29 @@ func (s *Store) PatchPipeline(ctx context.Context, patch *api.PipelinePatch) (*a
// private function
//
+func (s *Store) composePipelineValidateOnly(ctx context.Context, pipeline *api.Pipeline) error {
+ creator, err := s.GetPrincipalByID(ctx, pipeline.CreatorID)
+ if err != nil {
+ return err
+ }
+ pipeline.Creator = creator
+
+ updater, err := s.GetPrincipalByID(ctx, pipeline.UpdaterID)
+ if err != nil {
+ return err
+ }
+ pipeline.Updater = updater
+
+ for _, stage := range pipeline.StageList {
+ if err := s.composeStageValidateOnly(ctx, stage); err != nil {
+ return err
+ }
+ }
+
+ return nil
+}
+
+// Note: MUST keep in sync with composePipelineValidateOnly
func (s *Store) composePipeline(ctx context.Context, raw *pipelineRaw) (*api.Pipeline, error) {
pipeline := raw.toPipeline()
diff --git a/store/stage.go b/store/stage.go
index 4ed42bb25d..04ad3d0951 100644
--- a/store/stage.go
+++ b/store/stage.go
@@ -83,6 +83,31 @@ func (s *Store) FindStage(ctx context.Context, find *api.StageFind) ([]*api.Stag
// private functions
//
+func (s *Store) composeStageValidateOnly(ctx context.Context, stage *api.Stage) error {
+ creator, err := s.GetPrincipalByID(ctx, stage.CreatorID)
+ if err != nil {
+ return err
+ }
+ stage.Creator = creator
+
+ updater, err := s.GetPrincipalByID(ctx, stage.UpdaterID)
+ if err != nil {
+ return err
+ }
+ stage.Updater = updater
+
+ env, err := s.GetEnvironmentByID(ctx, stage.EnvironmentID)
+ if err != nil {
+ return err
+ }
+ stage.Environment = env
+
+ // Note: stage.TaskList is already composed in CreatePipelineValidateOnly(). Do not need to compose here.
+
+ return nil
+}
+
+// Note: MUST keep in sync with composeStageValidateOnly
func (s *Store) composeStage(ctx context.Context, raw *stageRaw) (*api.Stage, error) {
stage := raw.toStage()