Преглед изворни кода

Merge branch 'master' of github.com:porter-dev/porter into stacks-improved-debug-flow-pre-deploy

Feroze Mohideen пре 2 година
родитељ
комит
5781b33218

+ 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(

+ 9 - 19
api/server/handlers/porter_app/create.go

@@ -361,6 +361,11 @@ func (c *CreatePorterAppHandler) ServeHTTP(w http.ResponseWriter, r *http.Reques
 			c.HandleAPIError(w, r, apierrors.NewErrPassThroughToClient(err, http.StatusInternalServerError))
 			return
 		}
+		if app == nil {
+			err = telemetry.Error(ctx, span, nil, "app with name does not exist in project")
+			c.HandleAPIError(w, r, apierrors.NewErrPassThroughToClient(err, http.StatusForbidden))
+			return
+		}
 
 		if request.RepoName != "" {
 			app.RepoName = request.RepoName
@@ -371,26 +376,11 @@ func (c *CreatePorterAppHandler) ServeHTTP(w http.ResponseWriter, r *http.Reques
 		if request.BuildContext != "" {
 			app.BuildContext = request.BuildContext
 		}
-		if request.Builder != "" {
-			if request.Builder == "null" {
-				app.Builder = ""
-			} else {
-				app.Builder = request.Builder
-			}
-		}
-		if request.Buildpacks != "" {
-			if request.Buildpacks == "null" {
-				app.Buildpacks = ""
-			} else {
-				app.Buildpacks = request.Buildpacks
-			}
-		}
+		// handles deletion of builder and buildpacks
+		app.Builder = request.Builder
+		app.Buildpacks = request.Buildpacks
 		if request.Dockerfile != "" {
-			if request.Dockerfile == "null" {
-				app.Dockerfile = ""
-			} else {
-				app.Dockerfile = request.Dockerfile
-			}
+			app.Dockerfile = request.Dockerfile
 		}
 		if request.ImageRepoURI != "" {
 			app.ImageRepoURI = request.ImageRepoURI

+ 10 - 0
api/server/handlers/porter_app/list_events.go

@@ -189,16 +189,25 @@ func (p *PorterAppEventListHandler) updateBuildEvent_Github(ctx context.Context,
 	if err != nil {
 		return telemetry.Error(ctx, span, err, "error reading github environment by owner repo name")
 	}
+	if env == nil {
+		return telemetry.Error(ctx, span, nil, "github environment is nil")
+	}
 
 	ghClient, err := getGithubClientFromEnvironment(p.Config(), env.InstallationID)
 	if err != nil {
 		return telemetry.Error(ctx, span, err, "error getting github client using porter application")
 	}
+	if ghClient == nil {
+		return telemetry.Error(ctx, span, nil, "github client is nil")
+	}
 
 	actionRun, _, err := ghClient.Actions.GetWorkflowRunByID(ctx, repoOrg, repoName, int64(actionRunID))
 	if err != nil {
 		return telemetry.Error(ctx, span, err, "error getting github action run by id")
 	}
+	if actionRun == nil {
+		return telemetry.Error(ctx, span, nil, "github action run is nil")
+	}
 
 	if *actionRun.Status == "completed" {
 		if *actionRun.Conclusion == "success" {
@@ -206,6 +215,7 @@ func (p *PorterAppEventListHandler) updateBuildEvent_Github(ctx context.Context,
 		} else {
 			event.Status = "FAILED"
 		}
+		event.Metadata["end_time"] = actionRun.GetUpdatedAt().Time
 	}
 
 	return nil

+ 3 - 1
api/types/porter_app.go

@@ -1,6 +1,8 @@
 package types
 
-import "time"
+import (
+	"time"
+)
 
 type PorterApp struct {
 	ID        uint `json:"id"`

+ 2 - 2
dashboard/src/main/home/app-dashboard/expanded-app/ExpandedApp.tsx

@@ -340,8 +340,8 @@ const ExpandedApp: React.FC<Props> = ({ ...props }) => {
             repo_name: tempPorterApp.repo_name,
             git_branch: tempPorterApp.git_branch,
             build_context: tempPorterApp.build_context,
-            builder: !_.isEmpty(tempPorterApp.dockerfile) || !_.isEmpty(tempPorterApp.image_repo_uri) ? "null" : tempPorterApp.builder,
-            buildpacks: !_.isEmpty(tempPorterApp.dockerfile) || !_.isEmpty(tempPorterApp.image_repo_uri) ? "null" : tempPorterApp.buildpacks.join(","),
+            builder: tempPorterApp.builder,
+            buildpacks: tempPorterApp.buildpacks.join(","),
             dockerfile: tempPorterApp.dockerfile,
             ...options,
             override_release: true,

+ 2 - 2
dashboard/src/main/home/app-dashboard/expanded-app/activity-feed/events/utils.ts

@@ -5,8 +5,8 @@ import loading from "assets/loading.gif";
 import api from "shared/api";
 
 export const getDuration = (event: PorterAppEvent): string => {
-    const startTimeStamp = new Date(event.created_at).getTime();
-    const endTimeStamp = new Date(event.updated_at).getTime();
+    const startTimeStamp = new Date(event.metadata.start_time ?? event.created_at).getTime();
+    const endTimeStamp = new Date(event.metadata.end_time ?? event.updated_at).getTime();
 
     const timeDifferenceMilliseconds = endTimeStamp - startTimeStamp;