Răsfoiți Sursa

return workflow filename and installation ID

Mohammed Nafees 4 ani în urmă
părinte
comite
7d0641e485

+ 18 - 5
api/server/handlers/environment/list_deployments_by_cluster.go

@@ -59,10 +59,16 @@ func (c *ListDeploymentsByClusterHandler) ServeHTTP(w http.ResponseWriter, r *ht
 
 			env, err := c.Repo().Environment().ReadEnvironmentByID(project.ID, cluster.ID, deployment.EnvironmentID)
 
-			if err == nil {
-				updateDeploymentWithGithubWorkflowRunStatus(r.Context(), c.Config(), env, deployment)
+			if err != nil {
+				c.HandleAPIError(w, r, apierrors.NewErrInternal(err))
+				return
 			}
 
+			updateDeploymentWithGithubWorkflowRunStatus(r.Context(), c.Config(), env, deployment)
+
+			deployment.InstallationID = env.GitInstallationID
+			deployment.WorkflowFilename = fmt.Sprintf("porter_%s_env.yml", env.Name)
+
 			deployments = append(deployments, deployment)
 		}
 
@@ -108,6 +114,9 @@ func (c *ListDeploymentsByClusterHandler) ServeHTTP(w http.ResponseWriter, r *ht
 
 			updateDeploymentWithGithubWorkflowRunStatus(r.Context(), c.Config(), env, deployment)
 
+			deployment.InstallationID = env.GitInstallationID
+			deployment.WorkflowFilename = fmt.Sprintf("porter_%s_env.yml", env.Name)
+
 			deployments = append(deployments, deployment)
 		}
 
@@ -140,6 +149,10 @@ func updateDeploymentWithGithubWorkflowRunStatus(
 			ctx, deployment.RepoOwner, deployment.RepoName,
 			fmt.Sprintf("porter_%s_env.yml", env.Name), &github.ListWorkflowRunsOptions{
 				Branch: deployment.PRBranchFrom,
+				ListOptions: github.ListOptions{
+					Page:    1,
+					PerPage: 1,
+				},
 			},
 		)
 
@@ -148,9 +161,9 @@ func updateDeploymentWithGithubWorkflowRunStatus(
 
 			deployment.LastWorkflowRunURL = latestWorkflowRun.GetHTMLURL()
 
-			if deployment.Status != types.DeploymentStatusCreating &&
-				(latestWorkflowRun.GetStatus() == "in_progress" ||
-					latestWorkflowRun.GetStatus() == "queued") {
+			if (latestWorkflowRun.GetStatus() == "in_progress" ||
+				latestWorkflowRun.GetStatus() == "queued") &&
+				deployment.Status != types.DeploymentStatusCreating {
 				deployment.Status = types.DeploymentStatusUpdating
 			} else if latestWorkflowRun.GetStatus() == "completed" {
 				if latestWorkflowRun.GetConclusion() == "failed" {

+ 6 - 1
api/server/handlers/gitinstallation/rerun_workflow.go

@@ -85,7 +85,12 @@ func (c *RerunWorkflowHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
 
 func getLatestWorkflowRun(client *github.Client, owner, repo, filename string) (*github.WorkflowRun, error) {
 	workflowRuns, _, err := client.Actions.ListWorkflowRunsByFileName(
-		context.Background(), owner, repo, filename, &github.ListWorkflowRunsOptions{},
+		context.Background(), owner, repo, filename, &github.ListWorkflowRunsOptions{
+			ListOptions: github.ListOptions{
+				Page:    1,
+				PerPage: 1,
+			},
+		},
 	)
 
 	if err != nil {

+ 9 - 8
api/types/environment.go

@@ -22,13 +22,15 @@ type CreateEnvironmentRequest struct {
 }
 
 type GitHubMetadata struct {
-	DeploymentID int64  `json:"gh_deployment_id"`
-	PRName       string `json:"gh_pr_name"`
-	RepoName     string `json:"gh_repo_name"`
-	RepoOwner    string `json:"gh_repo_owner"`
-	CommitSHA    string `json:"gh_commit_sha"`
-	PRBranchFrom string `json:"gh_pr_branch_from"`
-	PRBranchInto string `json:"gh_pr_branch_into"`
+	DeploymentID     int64  `json:"gh_deployment_id"`
+	PRName           string `json:"gh_pr_name"`
+	RepoName         string `json:"gh_repo_name"`
+	RepoOwner        string `json:"gh_repo_owner"`
+	CommitSHA        string `json:"gh_commit_sha"`
+	PRBranchFrom     string `json:"gh_pr_branch_from"`
+	PRBranchInto     string `json:"gh_pr_branch_into"`
+	WorkflowFilename string `json:"gh_workflow_filename"`
+	InstallationID   uint   `json:"gh_installation_id"`
 }
 
 type DeploymentStatus string
@@ -48,7 +50,6 @@ type Deployment struct {
 	ID                 uint             `json:"id"`
 	CreatedAt          time.Time        `json:"created_at"`
 	UpdatedAt          time.Time        `json:"updated_at"`
-	GitInstallationID  uint             `json:"git_installation_id"`
 	EnvironmentID      uint             `json:"environment_id"`
 	Namespace          string           `json:"namespace"`
 	Status             DeploymentStatus `json:"status"`

+ 0 - 39
internal/models/environment.go

@@ -79,42 +79,3 @@ func (d *Deployment) ToDeploymentType() *types.Deployment {
 		GitHubMetadata: ghMetadata,
 	}
 }
-
-type DeploymentWithEnvironment struct {
-	gorm.Model
-
-	Environment    *Environment
-	Namespace      string
-	Status         types.DeploymentStatus
-	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{
-		CreatedAt:         d.CreatedAt,
-		UpdatedAt:         d.UpdatedAt,
-		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,
-	}
-}