diff --git a/api/restHandler/app/BuildPipelineRestHandler.go b/api/restHandler/app/BuildPipelineRestHandler.go index c42740e426b..38e1e94bc93 100644 --- a/api/restHandler/app/BuildPipelineRestHandler.go +++ b/api/restHandler/app/BuildPipelineRestHandler.go @@ -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 } diff --git a/api/restHandler/app/BuildPipelineRestHandler_test.go b/api/restHandler/app/BuildPipelineRestHandler_test.go index d2befef306e..8425b73f053 100644 --- a/api/restHandler/app/BuildPipelineRestHandler_test.go +++ b/api/restHandler/app/BuildPipelineRestHandler_test.go @@ -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) diff --git a/specs/ci-pipeline/ci-pipeline-change-source.yaml b/specs/ci-pipeline/ci-pipeline-change-source.yaml new file mode 100644 index 00000000000..b1a7c7d5b66 --- /dev/null +++ b/specs/ci-pipeline/ci-pipeline-change-source.yaml @@ -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" \ No newline at end of file