Parcourir la source

remove deploy branch when preview env deleted (#3203)

ianedwards il y a 2 ans
Parent
commit
07ff4dc5be
1 fichiers modifiés avec 19 ajouts et 0 suppressions
  1. 19 0
      api/server/handlers/environment/delete_deployment.go

+ 19 - 0
api/server/handlers/environment/delete_deployment.go

@@ -5,6 +5,7 @@ import (
 	"errors"
 	"fmt"
 	"net/http"
+	"strings"
 
 	"github.com/google/go-github/v41/github"
 	"github.com/porter-dev/porter/api/server/authz"
@@ -110,6 +111,24 @@ func (c *DeleteDeploymentHandler) ServeHTTP(w http.ResponseWriter, r *http.Reque
 		return
 	}
 
+	originalBranches := strings.Split(env.GitDeployBranches, ",")
+	newBranches := []string{}
+
+	for _, branch := range originalBranches {
+		if branch != depl.PRBranchFrom {
+			newBranches = append(newBranches, branch)
+		}
+	}
+
+	env.GitDeployBranches = strings.Join(newBranches, ",")
+
+	_, err = c.Repo().Environment().UpdateEnvironment(env)
+
+	if err != nil {
+		c.HandleAPIError(w, r, apierrors.NewErrInternal(err))
+		return
+	}
+
 	if depl.GHDeploymentID != 0 {
 		// set the GitHub deployment status to be inactive
 		_, _, err := client.Repositories.CreateDeploymentStatus(