Jelajahi Sumber

implemented release scope on update git action config

jnfrati 3 tahun lalu
induk
melakukan
c7db522d5e

+ 1 - 15
api/server/handlers/release/update_git_action_config.go

@@ -7,7 +7,6 @@ import (
 	"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"
@@ -28,9 +27,7 @@ func NewUpdateGitActionConfigHandler(
 }
 
 func (c *UpdateGitActionConfigHandler) 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)
+	release, _ := r.Context().Value(types.ReleaseScope).(*models.Release)
 
 	request := &types.UpdateGitActionConfigRequest{}
 
@@ -38,17 +35,6 @@ func (c *UpdateGitActionConfigHandler) ServeHTTP(w http.ResponseWriter, r *http.
 		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.GitActionConfig.ID)
 
 	if err != nil {

+ 3 - 2
api/server/router/release.go

@@ -815,20 +815,21 @@ func getReleaseRoutes(
 		Router:   r,
 	})
 
-	// PATCH /api/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/releases/{name}/git_action_config -> release.NewUpdateGitActionConfigHandler
+	// PATCH /api/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/releases/{name}/{version}/git_action_config -> release.NewUpdateGitActionConfigHandler
 	updateGitActionConfigEndpoint := factory.NewAPIEndpoint(
 		&types.APIRequestMetadata{
 			Verb:   types.APIVerbUpdate,
 			Method: types.HTTPVerbPatch,
 			Path: &types.Path{
 				Parent:       basePath,
-				RelativePath: "/releases/{name}/git_action_config",
+				RelativePath: "/releases/{name}/{version}/git_action_config",
 			},
 			Scopes: []types.PermissionScope{
 				types.UserScope,
 				types.ProjectScope,
 				types.ClusterScope,
 				types.NamespaceScope,
+				types.ReleaseScope,
 			},
 		},
 	)

+ 6 - 3
dashboard/src/shared/api.tsx

@@ -1808,18 +1808,21 @@ const updateBuildConfig = baseApi<
 
 const updateGitActionConfig = baseApi<
   {
-    git_action_config: FullActionConfigType;
+    git_action_config: {
+      git_branch: string;
+    };
   },
   {
     project_id: number;
     cluster_id: number;
     namespace: string;
     release_name: string;
+    revision?: 0; // Always update latest
   }
 >(
   "PATCH",
-  ({ project_id, cluster_id, namespace, release_name }) =>
-    `/api/projects/${project_id}/clusters/${cluster_id}/namespaces/${namespace}/releases/${release_name}/git_action_config`
+  ({ project_id, cluster_id, namespace, release_name, revision = 0 }) =>
+    `/api/projects/${project_id}/clusters/${cluster_id}/namespaces/${namespace}/releases/${release_name}/${revision}/git_action_config`
 );
 
 const reRunGHWorkflow = baseApi<