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: Patch branch api #3722

Merged
merged 11 commits into from
Aug 3, 2023
7 changes: 7 additions & 0 deletions api/restHandler/app/BuildPipelineRestHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,11 +280,18 @@ func (handler PipelineConfigRestHandlerImpl) PatchCiMaterialSourceWithAppIdAndEn
patchRequest, userId, err := handler.parseSourceChangeRequest(w, r)
if err != nil {
handler.Logger.Errorw("Parse error, PatchCiMaterialSource", "err", err, "PatchCiMaterialSource", patchRequest)
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
return
}
if !(patchRequest.Source.Type == pipelineConfig.SOURCE_TYPE_BRANCH_FIXED || patchRequest.Source.Type == pipelineConfig.SOURCE_TYPE_BRANCH_REGEX) {
handler.Logger.Errorw("Unsupported source type, PatchCiMaterialSource", "err", err, "PatchCiMaterialSource", patchRequest)
common.WriteJsonResp(w, err, "source.type not supported", http.StatusBadRequest)
return
}
token := r.Header.Get("token")
if err = handler.authorizeCiSourceChangeRequest(w, patchRequest, token); err != nil {
handler.Logger.Errorw("Authorization error, PatchCiMaterialSource", "err", err, "PatchCiMaterialSource", patchRequest)
common.WriteJsonResp(w, err, nil, http.StatusUnauthorized)
return
}

Expand Down
2 changes: 1 addition & 1 deletion api/restHandler/app/BuildPipelineRestHandler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func TestPipelineConfigRestHandlerImpl_PatchCiMaterialSource(t *testing.T) {
fields: fields{
validator: validator.New(),
},
body: "{\"appId\":4, \"id\": 5 ,\"ciMaterial\":[{\"gitMaterialId\":4,\"id\":5,\"source\":{\"type\":\"SOURCE_TYPE_BRANCH_FIXED\",\"value\":\"main3\",\"regex\":\"\"}}]}",
body: "{\"appId\":4, \"id\": 5 ,\"source\":{\"type\":\"SOURCE_TYPE_BRANCH_FIXED\",\"value\":\"main3\",\"regex\":\"\"}}",
setup: func(fields2 *fields) {
ctrl := gomock.NewController(t)
fields2.pipelineBuilder = mock_pipeline.NewMockPipelineBuilder(ctrl)
Expand Down
44 changes: 44 additions & 0 deletions specs/ci-pipeline/ci-pipeline-change-source.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
openapi: "3.0.0"
info:
version: 1.0.0
title: CiPipeline material change source
paths:
/orchestrator/app/ci-pipeline/patch-source:
patch:
description: update source of a ci-matrial
requestBody:
content:
application/json:
schema:
$ref: "#/components/schemas/RequestBody"
responses:
"200":
description: Successfully fetched commit info. if CommitInfo is null, then commit is not found.
content:
application/json:
schema:
type: object

#{"appId": 16, "environmentId": 1, "source": {"type":"SOURCE_TYPE_BRANCH_FIXED", "value": "main1", "regex":""}}
# Components
components:
schemas:
RequestBody:
type: object
properties:
appId:
type: integer
environmentId:
type: integer
source:
type: object
properties:
type:
type: string
description: "SOURCE_TYPE_BRANCH_FIXED / SOURCE_TYPE_BRANCH_REGEX"
value:
type: string
description: "name of the branch"
regex:
type: string
description: "regular expression when type is SOURCE_TYPE_BRANCH_REGEX"