|
|
@@ -51,41 +51,61 @@ func (c *ReenableDeploymentHandler) ServeHTTP(w http.ResponseWriter, r *http.Req
|
|
|
}
|
|
|
|
|
|
if depl.Status != types.DeploymentStatusInactive {
|
|
|
+ c.HandleAPIError(w, r, apierrors.NewErrPassThroughToClient(
|
|
|
+ fmt.Errorf("trying to re-enable deployment which is not marked \"inactive\""), http.StatusPreconditionFailed,
|
|
|
+ ))
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- depl.Status = types.DeploymentStatusCreating
|
|
|
-
|
|
|
- depl, err = c.Repo().Environment().UpdateDeployment(depl)
|
|
|
+ env, err := c.Repo().Environment().ReadEnvironmentByID(project.ID, cluster.ID, depl.EnvironmentID)
|
|
|
|
|
|
if err != nil {
|
|
|
c.HandleAPIError(w, r, apierrors.NewErrInternal(err))
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- // create the backing namespace
|
|
|
- agent, err := c.GetAgent(r, cluster, "")
|
|
|
+ client, err := getGithubClientFromEnvironment(c.Config(), env)
|
|
|
|
|
|
if err != nil {
|
|
|
c.HandleAPIError(w, r, apierrors.NewErrInternal(err))
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- _, err = agent.CreateNamespace(depl.Namespace)
|
|
|
+ // add a check for the PR to be open before creating a comment
|
|
|
+ prClosed, err := isGithubPRClosed(client, depl.RepoOwner, depl.RepoName, int(depl.PullRequestID))
|
|
|
+
|
|
|
+ if err != nil {
|
|
|
+ c.HandleAPIError(w, r, apierrors.NewErrPassThroughToClient(
|
|
|
+ fmt.Errorf("error fetching details of github PR for deployment ID: %d. Error: %w",
|
|
|
+ depl.ID, err), http.StatusConflict,
|
|
|
+ ))
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if prClosed {
|
|
|
+ c.HandleAPIError(w, r, apierrors.NewErrPassThroughToClient(fmt.Errorf("Github PR has been closed"),
|
|
|
+ http.StatusConflict))
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ depl.Status = types.DeploymentStatusCreating
|
|
|
+
|
|
|
+ depl, err = c.Repo().Environment().UpdateDeployment(depl)
|
|
|
|
|
|
if err != nil {
|
|
|
c.HandleAPIError(w, r, apierrors.NewErrInternal(err))
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- env, err := c.Repo().Environment().ReadEnvironmentByID(project.ID, cluster.ID, depl.EnvironmentID)
|
|
|
+ // create the backing namespace
|
|
|
+ agent, err := c.GetAgent(r, cluster, "")
|
|
|
|
|
|
if err != nil {
|
|
|
c.HandleAPIError(w, r, apierrors.NewErrInternal(err))
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- client, err := getGithubClientFromEnvironment(c.Config(), env)
|
|
|
+ _, err = agent.CreateNamespace(depl.Namespace)
|
|
|
|
|
|
if err != nil {
|
|
|
c.HandleAPIError(w, r, apierrors.NewErrInternal(err))
|