Selaa lähdekoodia

case on job vs application

Mohammed Nafees 3 vuotta sitten
vanhempi
sitoutus
e16e35abf0

+ 10 - 3
api/server/handlers/environment/finalize_deployment.go

@@ -131,11 +131,18 @@ func (c *FinalizeDeploymentHandler) ServeHTTP(w http.ResponseWriter, r *http.Req
 	)
 
 	if len(request.SuccessfulResources) > 0 {
-		commentBody += "#### Successfully deployed resources\n"
+		commentBody += "\n#### Successfully deployed resources\n"
 
 		for _, res := range request.SuccessfulResources {
-			commentBody += fmt.Sprintf("- [`%s`](%s/applications/%s/%s/%s?project_id=%d)\n",
-				res, c.Config().ServerConf.ServerURL, cluster.Name, depl.Namespace, res, project.ID)
+			if res.ReleaseType == "job" {
+				commentBody += fmt.Sprintf("- [`%s`](%s/jobs/%s/%s/%s?project_id=%d)\n",
+					res.ReleaseName, c.Config().ServerConf.ServerURL, cluster.Name, depl.Namespace,
+					res.ReleaseName, project.ID)
+			} else {
+				commentBody += fmt.Sprintf("- [`%s`](%s/applications/%s/%s/%s?project_id=%d)\n",
+					res.ReleaseName, c.Config().ServerConf.ServerURL, cluster.Name, depl.Namespace,
+					res.ReleaseName, project.ID)
+			}
 		}
 	}
 

+ 9 - 2
api/server/handlers/environment/finalize_deployment_with_errors.go

@@ -127,8 +127,15 @@ func (c *FinalizeDeploymentWithErrorsHandler) ServeHTTP(w http.ResponseWriter, r
 		commentBody += "#### Successfully deployed resources\n"
 
 		for _, res := range request.SuccessfulResources {
-			commentBody += fmt.Sprintf("- [`%s`](%s/applications/%s/%s/%s?project_id=%d)\n",
-				res, c.Config().ServerConf.ServerURL, cluster.Name, depl.Namespace, res, project.ID)
+			if res.ReleaseType == "job" {
+				commentBody += fmt.Sprintf("- [`%s`](%s/jobs/%s/%s/%s?project_id=%d)\n",
+					res.ReleaseName, c.Config().ServerConf.ServerURL, cluster.Name, depl.Namespace,
+					res.ReleaseName, project.ID)
+			} else {
+				commentBody += fmt.Sprintf("- [`%s`](%s/applications/%s/%s/%s?project_id=%d)\n",
+					res.ReleaseName, c.Config().ServerConf.ServerURL, cluster.Name, depl.Namespace,
+					res.ReleaseName, project.ID)
+			}
 		}
 	}
 

+ 11 - 6
api/types/environment.go

@@ -69,16 +69,21 @@ type CreateDeploymentRequest struct {
 	PullRequestID uint   `json:"pull_request_id" form:"required"`
 }
 
+type SuccessfullyDeployedResource struct {
+	ReleaseName string `json:"release_name" form:"required"`
+	ReleaseType string `json:"release_type"`
+}
+
 type FinalizeDeploymentRequest struct {
-	Namespace           string   `json:"namespace" form:"required"`
-	SuccessfulResources []string `json:"successful_resources"`
-	Subdomain           string   `json:"subdomain"`
+	Namespace           string                          `json:"namespace" form:"required"`
+	SuccessfulResources []*SuccessfullyDeployedResource `json:"successful_resources"`
+	Subdomain           string                          `json:"subdomain"`
 }
 
 type FinalizeDeploymentWithErrorsRequest struct {
-	Namespace           string            `json:"namespace" form:"required"`
-	SuccessfulResources []string          `json:"successful_resources"`
-	Errors              map[string]string `json:"errors" form:"required"`
+	Namespace           string                          `json:"namespace" form:"required"`
+	SuccessfulResources []*SuccessfullyDeployedResource `json:"successful_resources"`
+	Errors              map[string]string               `json:"errors" form:"required"`
 }
 
 type UpdateDeploymentRequest struct {

+ 17 - 3
cli/cmd/apply.go

@@ -861,11 +861,14 @@ func (t *DeploymentHook) PostApply(populatedData map[string]interface{}) error {
 
 	req := &types.FinalizeDeploymentRequest{
 		Namespace: t.namespace,
-		Subdomain: strings.Join(subdomains, ","),
+		Subdomain: strings.Join(subdomains, ", "),
 	}
 
 	for _, res := range t.resourceGroup.Resources {
-		req.SuccessfulResources = append(req.SuccessfulResources, getReleaseName(res))
+		req.SuccessfulResources = append(req.SuccessfulResources, &types.SuccessfullyDeployedResource{
+			ReleaseName: getReleaseName(res),
+			ReleaseType: getReleaseType(res),
+		})
 	}
 
 	// finalize the deployment
@@ -923,7 +926,10 @@ func (t *DeploymentHook) OnConsolidatedErrors(allErrors map[string]error) {
 
 		for _, res := range t.resourceGroup.Resources {
 			if _, ok := allErrors[res.Name]; !ok {
-				req.SuccessfulResources = append(req.SuccessfulResources, getReleaseName(res))
+				req.SuccessfulResources = append(req.SuccessfulResources, &types.SuccessfullyDeployedResource{
+					ReleaseName: getReleaseName(res),
+					ReleaseType: getReleaseType(res),
+				})
 			}
 		}
 
@@ -1044,3 +1050,11 @@ func getReleaseName(res *switchboardTypes.Resource) string {
 
 	return res.Name
 }
+
+func getReleaseType(res *switchboardTypes.Resource) string {
+	// can ignore the error because this method is called once
+	// GetSource has alrealy been called and validated previously
+	source, _ := preview.GetSource(res.Source)
+
+	return source.Name
+}