Skip to content

Commit

Permalink
feat: Patch branch api (#3722)
Browse files Browse the repository at this point in the history
* add core functions

* added the branch change API

* Add unit tests

* Allow source change only in customApp

* Refactor tests

* Add logs

* Refactor API

* Add source type check

* Add Spec for /orchestrator/app/ci-pipeline/patch-source
  • Loading branch information
avdhesh-devtron committed Aug 3, 2023
1 parent 1dc6a99 commit f1e85af
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
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"

0 comments on commit f1e85af

Please sign in to comment.