mirror of
https://github.com/harness/drone.git
synced 2025-05-05 08:50:31 +08:00
46 lines
1.0 KiB
Go
46 lines
1.0 KiB
Go
package pipeline
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
|
|
"github.com/harness/gitness/internal/api/controller/pipeline"
|
|
"github.com/harness/gitness/internal/api/render"
|
|
"github.com/harness/gitness/internal/api/request"
|
|
)
|
|
|
|
/*
|
|
* Updates an existing pipeline.
|
|
*/
|
|
func HandleUpdate(pipelineCtrl *pipeline.Controller) http.HandlerFunc {
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
ctx := r.Context()
|
|
session, _ := request.AuthSessionFrom(ctx)
|
|
|
|
in := new(pipeline.UpdateInput)
|
|
err := json.NewDecoder(r.Body).Decode(in)
|
|
if err != nil {
|
|
render.BadRequestf(w, "Invalid Request Body: %s.", err)
|
|
return
|
|
}
|
|
|
|
pipelineRef, err := request.GetPipelinePathRefFromPath(r)
|
|
if err != nil {
|
|
render.TranslatedUserError(w, err)
|
|
return
|
|
}
|
|
spaceRef, pipelineUID, err := SplitRef(pipelineRef)
|
|
if err != nil {
|
|
render.TranslatedUserError(w, err)
|
|
}
|
|
|
|
pipeline, err := pipelineCtrl.Update(ctx, session, spaceRef, pipelineUID, in)
|
|
if err != nil {
|
|
render.TranslatedUserError(w, err)
|
|
return
|
|
}
|
|
|
|
render.JSON(w, http.StatusOK, pipeline)
|
|
}
|
|
}
|