Skip to content

Commit

Permalink
feat(pipeline): inject project/org default namespace for ci/cd pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
chengjoey committed Sep 25, 2024
1 parent cb68cd8 commit a113a8e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
19 changes: 19 additions & 0 deletions internal/apps/dop/endpoints/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ func (e *Endpoints) pipelineCreate(ctx context.Context, r *http.Request, vars ma
if err != nil {
return errorresp.ErrResp(err)
}

// also add project/org default config namespace
reqPipeline.ConfigManageNamespaces = append(reqPipeline.ConfigManageNamespaces, makeOrgDefaultLevelCmsNs(app.OrgID)...)
reqPipeline.ConfigManageNamespaces = append(reqPipeline.ConfigManageNamespaces, makeProjectDefaultLevelCmsNs(app.ProjectID)...)

rules, err := e.branchRule.Query(apistructs.ProjectScope, int64(app.ProjectID))
if err != nil {
return errorresp.ErrResp(err)
Expand Down Expand Up @@ -167,6 +172,20 @@ func (e *Endpoints) pipelineDetail(ctx context.Context, r *http.Request, vars ma
return httpserver.OkResp(result)
}

func makeProjectDefaultLevelCmsNs(projectID uint64) []string {
// default need be added before custom
return []string{
fmt.Sprintf("project-%d-default", projectID),
}
}

func makeOrgDefaultLevelCmsNs(orgID uint64) []string {
// default need be added before custom
return []string{
fmt.Sprintf("org-%d-default", orgID),
}
}

func getPipelineDetailAndCheckPermission(svc pipelinepb.PipelineServiceServer, permission *permission.Permission, req apistructs.CICDPipelineDetailRequest, identityInfo apistructs.IdentityInfo) (*pipelinepb.PipelineDetailDTO, error) {
result, err := svc.PipelineDetail(apis.WithInternalClientContext(context.Background(), discover.DOP()), &pipelinepb.PipelineDetailRequest{
PipelineID: req.PipelineID,
Expand Down
16 changes: 16 additions & 0 deletions internal/apps/dop/endpoints/pipeline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,3 +182,19 @@ func Test_pipelineList(t *testing.T) {
_, err = e.pipelineList(context.Background(), r, nil)
assert.NoError(t, err)
}

func Test_makeProjectDefaultLevelCmsNs(t *testing.T) {
projectNamespace1 := makeProjectDefaultLevelCmsNs(1)
assert.Equal(t, "project-1-default", projectNamespace1[0])

projectNamespace2 := makeProjectDefaultLevelCmsNs(2)
assert.Equal(t, "project-2-default", projectNamespace2[0])
}

func Test_makeOrgDefaultLevelCmsNs(t *testing.T) {
orgNamespace1 := makeOrgDefaultLevelCmsNs(1)
assert.Equal(t, "org-1-default", orgNamespace1[0])

orgNamespace2 := makeOrgDefaultLevelCmsNs(2)
assert.Equal(t, "org-2-default", orgNamespace2[0])
}

0 comments on commit a113a8e

Please sign in to comment.