Jelajahi Sumber

fixing bug where buildpacks aren't deleted properly and adding end time for build event (#3204)

Feroze Mohideen 2 tahun lalu
induk
melakukan
9304495d54

+ 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"`

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

@@ -210,7 +210,7 @@ const ExpandedApp: React.FC<Props> = ({ ...props }) => {
       setPorterJson(porterJson);
       setAppData(newAppData);
       // annoying that we have to parse buildpacks like this but alas
-      const parsedPorterApp = { ...resPorterApp?.data, buildpacks: newAppData.app.buildpacks?.split(",") };
+      const parsedPorterApp = { ...resPorterApp?.data, buildpacks: newAppData.app.buildpacks?.split(",") ?? [] };
       setPorterApp(parsedPorterApp);
       setTempPorterApp(parsedPorterApp);
 
@@ -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;