Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(pipeline): inject project/org default namespace for ci/cd pipeline #6443

Merged
merged 1 commit into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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)...)

Check warning on line 101 in internal/apps/dop/endpoints/pipeline.go

View check run for this annotation

Codecov / codecov/patch

internal/apps/dop/endpoints/pipeline.go#L100-L101

Added lines #L100 - L101 were not covered by tests

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 @@
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])
}
Loading