Stefan McShane 3 лет назад
Родитель
Сommit
1eb786101b
2 измененных файлов с 26 добавлено и 24 удалено
  1. 2 3
      api/server/handlers/environment/create_deployment.go
  2. 24 21
      cli/cmd/apply.go

+ 2 - 3
api/server/handlers/environment/create_deployment.go

@@ -153,9 +153,8 @@ func createGithubDeployment(
 			RequiredContexts: &requiredContexts,
 		},
 	)
-
 	if err != nil {
-		return nil, fmt.Errorf("%v: %w", errGithubAPI, err)
+		return nil, fmt.Errorf("create deployment failed - %v: %w", errGithubAPI, err)
 	}
 
 	depID := deployment.GetID()
@@ -174,7 +173,7 @@ func createGithubDeployment(
 	)
 
 	if err != nil {
-		return nil, fmt.Errorf("%v: %w", errGithubAPI, err)
+		return nil, fmt.Errorf("create deployment status failed - %v: %w", errGithubAPI, err)
 	}
 
 	return deployment, nil

+ 24 - 21
cli/cmd/apply.go

@@ -151,6 +151,7 @@ func apply(_ *types.GetAuthenticatedUserResponse, client *api.Client, _ []string
 	if err != nil {
 		return fmt.Errorf("error creating deployment hook: %w", err)
 	}
+	fmt.Printf("stefan %#v\n\n%#v\n%v\n", deploymentHook, deploymentHookConfig, deploymentHook.isBranchDeploy())
 
 	worker.RegisterHook("deployment", &deploymentHook)
 
@@ -812,8 +813,6 @@ func NewDeploymentHook(conf DeploymentHookConfig) (DeploymentHook, error) {
 			}
 		}
 	}
-	fmt.Printf("stefan %#v %v\n", res, res.isBranchDeploy())
-	fmt.Println(res.clusterID, res.projectID)
 
 	return res, nil
 }
@@ -939,29 +938,33 @@ func (t *DeploymentHook) PreApply() error {
 			t.projectID, t.gitInstallationID, t.clusterID,
 			t.repoOwner, t.repoName, createReq,
 		)
-	} else if err == nil {
-		updateReq := &types.UpdateDeploymentRequest{
-			Namespace: t.namespace,
-			PRNumber:  t.prID,
-			CreateGHDeploymentRequest: &types.CreateGHDeploymentRequest{
-				ActionID: t.actionID,
-			},
-			PRBranchFrom: t.branchFrom,
-			CommitSHA:    t.commitSHA,
-		}
+		return fmt.Errorf("error creating deployment: %w", err)
+	}
 
-		if t.isBranchDeploy() {
-			updateReq.PRNumber = 0
-		}
+	updateReq := &types.UpdateDeploymentRequest{
+		Namespace: t.namespace,
+		PRNumber:  t.prID,
+		CreateGHDeploymentRequest: &types.CreateGHDeploymentRequest{
+			ActionID: t.actionID,
+		},
+		PRBranchFrom: t.branchFrom,
+		CommitSHA:    t.commitSHA,
+	}
 
-		_, err = t.client.UpdateDeployment(
-			context.Background(),
-			t.projectID, t.gitInstallationID, t.clusterID,
-			t.repoOwner, t.repoName, updateReq,
-		)
+	if t.isBranchDeploy() {
+		updateReq.PRNumber = 0
 	}
 
-	return err
+	_, err = t.client.UpdateDeployment(
+		context.Background(),
+		t.projectID, t.gitInstallationID, t.clusterID,
+		t.repoOwner, t.repoName, updateReq,
+	)
+	if err != nil {
+		return fmt.Errorf("error updating deployment: %w", err)
+	}
+
+	return nil
 }
 
 func (t *DeploymentHook) DataQueries() map[string]interface{} {