|
@@ -0,0 +1,71 @@
|
|
|
|
|
+package release
|
|
|
|
|
+
|
|
|
|
|
+import (
|
|
|
|
|
+ "net/http"
|
|
|
|
|
+
|
|
|
|
|
+ "github.com/porter-dev/porter/api/server/handlers"
|
|
|
|
|
+ "github.com/porter-dev/porter/api/server/shared"
|
|
|
|
|
+ "github.com/porter-dev/porter/api/server/shared/apierrors"
|
|
|
|
|
+ "github.com/porter-dev/porter/api/server/shared/config"
|
|
|
|
|
+ "github.com/porter-dev/porter/api/server/shared/requestutils"
|
|
|
|
|
+ "github.com/porter-dev/porter/api/types"
|
|
|
|
|
+ "github.com/porter-dev/porter/internal/models"
|
|
|
|
|
+ "gorm.io/gorm"
|
|
|
|
|
+)
|
|
|
|
|
+
|
|
|
|
|
+type UpdateActionConfigHandler struct {
|
|
|
|
|
+ handlers.PorterHandlerReadWriter
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+func NewUpdateActionConfigHandler(
|
|
|
|
|
+ config *config.Config,
|
|
|
|
|
+ decoderValidator shared.RequestDecoderValidator,
|
|
|
|
|
+ writer shared.ResultWriter,
|
|
|
|
|
+) *UpdateActionConfigHandler {
|
|
|
|
|
+ return &UpdateActionConfigHandler{
|
|
|
|
|
+ PorterHandlerReadWriter: handlers.NewDefaultPorterHandler(config, decoderValidator, writer),
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+func (c *UpdateActionConfigHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
+ cluster, _ := r.Context().Value(types.ClusterScope).(*models.Cluster)
|
|
|
|
|
+ name, _ := requestutils.GetURLParamString(r, types.URLParamReleaseName)
|
|
|
|
|
+ namespace := r.Context().Value(types.NamespaceScope).(string)
|
|
|
|
|
+
|
|
|
|
|
+ request := &types.UpdateActionConfigRequest{}
|
|
|
|
|
+
|
|
|
|
|
+ if ok := c.DecodeAndValidate(w, r, request); !ok {
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ release, err := c.Repo().Release().ReadRelease(cluster.ID, name, namespace)
|
|
|
|
|
+
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ if err == gorm.ErrRecordNotFound {
|
|
|
|
|
+ w.WriteHeader(http.StatusNotFound)
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ c.HandleAPIError(w, r, apierrors.NewErrInternal(err))
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ actionConfig, err := c.Repo().GitActionConfig().ReadGitActionConfig(release.ID)
|
|
|
|
|
+
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ if err == gorm.ErrRecordNotFound {
|
|
|
|
|
+ w.WriteHeader(http.StatusNotFound)
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ c.HandleAPIError(w, r, apierrors.NewErrInternal(err))
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ actionConfig.GitBranch = request.GitActionConfig.GitBranch
|
|
|
|
|
+
|
|
|
|
|
+ if err := c.Repo().GitActionConfig().UpdateGitActionConfig(actionConfig); err != nil {
|
|
|
|
|
+ c.HandleAPIError(w, r, apierrors.NewErrInternal(err))
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ w.WriteHeader(http.StatusOK)
|
|
|
|
|
+}
|