Selaa lähdekoodia

fix merge conflicts

Alexander Belanger 4 vuotta sitten
vanhempi
sitoutus
b9342af797

+ 8 - 8
api/server/router/git_installation.go

@@ -94,8 +94,8 @@ func getGitInstallationRoutes(
 				RelativePath: fmt.Sprintf(
 					"%s/{%s}/{%s}/clusters/{cluster_id}/environment",
 					relPath,
+					types.URLParamGitRepoOwner,
 					types.URLParamGitRepoName,
-					types.URLParamGitBranch,
 				),
 			},
 			Scopes: []types.PermissionScope{
@@ -130,8 +130,8 @@ func getGitInstallationRoutes(
 				RelativePath: fmt.Sprintf(
 					"%s/{%s}/{%s}/clusters/{cluster_id}/deployment",
 					relPath,
+					types.URLParamGitRepoOwner,
 					types.URLParamGitRepoName,
-					types.URLParamGitBranch,
 				),
 			},
 			Scopes: []types.PermissionScope{
@@ -166,8 +166,8 @@ func getGitInstallationRoutes(
 				RelativePath: fmt.Sprintf(
 					"%s/{%s}/{%s}/clusters/{cluster_id}/deployment",
 					relPath,
+					types.URLParamGitRepoOwner,
 					types.URLParamGitRepoName,
-					types.URLParamGitBranch,
 				),
 			},
 			Scopes: []types.PermissionScope{
@@ -202,8 +202,8 @@ func getGitInstallationRoutes(
 				RelativePath: fmt.Sprintf(
 					"%s/{%s}/{%s}/clusters/{cluster_id}/deployments",
 					relPath,
+					types.URLParamGitRepoOwner,
 					types.URLParamGitRepoName,
-					types.URLParamGitBranch,
 				),
 			},
 			Scopes: []types.PermissionScope{
@@ -238,8 +238,8 @@ func getGitInstallationRoutes(
 				RelativePath: fmt.Sprintf(
 					"%s/{%s}/{%s}/clusters/{cluster_id}/deployment/finalize",
 					relPath,
+					types.URLParamGitRepoOwner,
 					types.URLParamGitRepoName,
-					types.URLParamGitBranch,
 				),
 			},
 			Scopes: []types.PermissionScope{
@@ -274,8 +274,8 @@ func getGitInstallationRoutes(
 				RelativePath: fmt.Sprintf(
 					"%s/{%s}/{%s}/clusters/{cluster_id}/deployment/update",
 					relPath,
+					types.URLParamGitRepoOwner,
 					types.URLParamGitRepoName,
-					types.URLParamGitBranch,
 				),
 			},
 			Scopes: []types.PermissionScope{
@@ -310,8 +310,8 @@ func getGitInstallationRoutes(
 				RelativePath: fmt.Sprintf(
 					"%s/{%s}/{%s}/clusters/{cluster_id}/environment",
 					relPath,
+					types.URLParamGitRepoOwner,
 					types.URLParamGitRepoName,
-					types.URLParamGitBranch,
 				),
 			},
 			Scopes: []types.PermissionScope{
@@ -346,8 +346,8 @@ func getGitInstallationRoutes(
 				RelativePath: fmt.Sprintf(
 					"%s/{%s}/{%s}/clusters/{cluster_id}/deployment",
 					relPath,
+					types.URLParamGitRepoOwner,
 					types.URLParamGitRepoName,
-					types.URLParamGitBranch,
 				),
 			},
 			Scopes: []types.PermissionScope{

+ 7 - 6
api/types/environment.go

@@ -26,12 +26,13 @@ type GitHubMetadata struct {
 type Deployment struct {
 	*GitHubMetadata
 
-	ID            uint   `json:"id"`
-	EnvironmentID uint   `json:"environment_id"`
-	Namespace     string `json:"namespace"`
-	Status        string `json:"status"`
-	Subdomain     string `json:"subdomain"`
-	PullRequestID uint   `json:"pull_request_id"`
+	ID                uint   `json:"id"`
+	GitInstallationID uint   `json:"git_installation_id"`
+	EnvironmentID     uint   `json:"environment_id"`
+	Namespace         string `json:"namespace"`
+	Status            string `json:"status"`
+	Subdomain         string `json:"subdomain"`
+	PullRequestID     uint   `json:"pull_request_id"`
 }
 
 type CreateGHDeploymentRequest struct {

+ 51 - 11
dashboard/src/main/home/cluster-dashboard/dashboard/preview-environments/EnvironmentDetail.tsx

@@ -5,7 +5,7 @@ import TitleSection from "components/TitleSection";
 import pr_icon from "assets/pull_request_icon.svg";
 import { useRouteMatch, useLocation } from "react-router";
 import DynamicLink from "components/DynamicLink";
-import { capitalize, PRDeployment } from "./EnvironmentList";
+import { capitalize, PRDeployment, Environment } from "./EnvironmentList";
 import Loading from "components/Loading";
 import { Context } from "shared/Context";
 import api from "shared/api";
@@ -25,17 +25,16 @@ const EnvironmentDetail = () => {
     Context
   );
 
-  const useQuery = () => {
-    const { search } = useLocation();
+  const { search } = useLocation();
+  let searchParams = new URLSearchParams(search);
 
-    return React.useMemo(() => new URLSearchParams(search), [search]);
-  };
+  // const useQuery = () => {
+  //   return React.useMemo(() => , [search]);
+  // };
 
-  useEffect(() => {
-    let query = useQuery();
+  const getDeployment = (environment: Environment) => {
     let isSubscribed = true;
 
-    let git_installation_id = parseInt(query.get("git_installation_id"));
     api
       .getPRDeployment(
         "<token>",
@@ -45,9 +44,9 @@ const EnvironmentDetail = () => {
         {
           project_id: currentProject.id,
           cluster_id: currentCluster.id,
-          git_installation_id: git_installation_id,
-          git_repo_owner: environment.gh_repo_owner,
-          git_repo_name: environment.gh_repo_name,
+          git_installation_id: environment.git_installation_id,
+          git_repo_owner: environment.git_repo_owner,
+          git_repo_name: environment.git_repo_name,
         }
       )
       .then(({ data }) => {
@@ -69,6 +68,47 @@ const EnvironmentDetail = () => {
           setIsLoading(false);
         }
       });
+  };
+
+  useEffect(() => {
+    let isSubscribed = true;
+
+    let environment_id = parseInt(searchParams.get("environment_id"));
+
+    // find the git installation id
+    api
+      .listEnvironments(
+        "<token>",
+        {
+          namespace: params.namespace,
+        },
+        {
+          project_id: currentProject.id,
+          cluster_id: currentCluster.id,
+        }
+      )
+      .then(({ data }) => {
+        if (!isSubscribed) {
+          return;
+        }
+
+        if (!Array.isArray(data)) {
+          throw Error("Data is not an array");
+        }
+
+        data.forEach((d) => {
+          if (d.id == environment_id) {
+            getDeployment(d);
+          }
+        });
+      })
+      .catch((err) => {
+        console.error(err);
+        if (isSubscribed) {
+          setHasError(true);
+          setEnvironment(null);
+        }
+      });
 
     return () => {
       isSubscribed = false;

+ 1 - 2
dashboard/src/main/home/cluster-dashboard/dashboard/preview-environments/EnvironmentList.tsx

@@ -19,7 +19,6 @@ export type PRDeployment = {
   environment_id: number;
   pull_request_id: number;
   namespace: string;
-  git_installation_id?: number;
   gh_pr_name: string;
   gh_repo_owner: string;
   gh_repo_name: string;
@@ -206,7 +205,7 @@ const EnvironmentList = () => {
           </DataContainer>
           <Flex>
             <RowButton
-              to={`${currentUrl}/pr-env-detail/${d.namespace}?git_installation_id=${d.git_installation_id}`}
+              to={`${currentUrl}/pr-env-detail/${d.namespace}?environment_id=${d.environment_id}`}
               key={d.id}
             >
               <i className="material-icons-outlined">info</i>

+ 58 - 21
internal/models/environment.go

@@ -32,35 +32,72 @@ func (e *Environment) ToEnvironmentType() *types.Environment {
 type Deployment struct {
 	gorm.Model
 
-	EnvironmentID      uint
-	Namespace          string
-	Status             string
-	Subdomain          string
-	PullRequestID      uint
-	GHDeploymentID	   int64
-	PRName			   string
-	RepoName     	   string
-	RepoOwner		   string
-	CommitSHA		   string
+	EnvironmentID  uint
+	Namespace      string
+	Status         string
+	Subdomain      string
+	PullRequestID  uint
+	GHDeploymentID int64
+	PRName         string
+	RepoName       string
+	RepoOwner      string
+	CommitSHA      string
 }
 
 func (d *Deployment) ToDeploymentType() *types.Deployment {
 
 	ghMetadata := &types.GitHubMetadata{
 		DeploymentID: d.GHDeploymentID,
-		PRName:		  d.PRName,
-		RepoName:	 d.RepoName,
-		RepoOwner:	 d.RepoOwner,
-		CommitSHA:	 d.CommitSHA,
+		PRName:       d.PRName,
+		RepoName:     d.RepoName,
+		RepoOwner:    d.RepoOwner,
+		CommitSHA:    d.CommitSHA,
 	}
 
 	return &types.Deployment{
-		ID:                 d.Model.ID,
-		EnvironmentID:      d.EnvironmentID,
-		Namespace:          d.Namespace,
-		Status:             d.Status,
-		Subdomain:          d.Subdomain,
-		PullRequestID:      d.PullRequestID,
-		GitHubMetadata: 	ghMetadata,
+		ID:             d.Model.ID,
+		EnvironmentID:  d.EnvironmentID,
+		Namespace:      d.Namespace,
+		Status:         d.Status,
+		Subdomain:      d.Subdomain,
+		PullRequestID:  d.PullRequestID,
+		GitHubMetadata: ghMetadata,
+	}
+}
+
+type DeploymentWithEnvironment struct {
+	gorm.Model
+
+	Environment    *Environment
+	Namespace      string
+	Status         string
+	Subdomain      string
+	PullRequestID  uint
+	GHDeploymentID int64
+	PRName         string
+	RepoName       string
+	RepoOwner      string
+	CommitSHA      string
+}
+
+func (d *DeploymentWithEnvironment) ToDeploymentType() *types.Deployment {
+
+	ghMetadata := &types.GitHubMetadata{
+		DeploymentID: d.GHDeploymentID,
+		PRName:       d.PRName,
+		RepoName:     d.RepoName,
+		RepoOwner:    d.RepoOwner,
+		CommitSHA:    d.CommitSHA,
+	}
+
+	return &types.Deployment{
+		ID:                d.Model.ID,
+		EnvironmentID:     d.Environment.ID,
+		GitInstallationID: d.Environment.GitInstallationID,
+		Namespace:         d.Namespace,
+		Status:            d.Status,
+		Subdomain:         d.Subdomain,
+		PullRequestID:     d.PullRequestID,
+		GitHubMetadata:    ghMetadata,
 	}
 }