|
|
@@ -1,6 +1,7 @@
|
|
|
package environment
|
|
|
|
|
|
import (
|
|
|
+ "fmt"
|
|
|
"context"
|
|
|
"net/http"
|
|
|
|
|
|
@@ -50,34 +51,6 @@ func (c *CreateDeploymentHandler) ServeHTTP(w http.ResponseWriter, r *http.Reque
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- // create the deployment
|
|
|
- depl, err := c.Repo().Environment().CreateDeployment(&models.Deployment{
|
|
|
- EnvironmentID: env.ID,
|
|
|
- Namespace: request.Namespace,
|
|
|
- Status: "creating",
|
|
|
- PullRequestID: request.PullRequestID,
|
|
|
- })
|
|
|
-
|
|
|
- if err != nil {
|
|
|
- c.HandleAPIError(w, r, apierrors.NewErrInternal(err))
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- // create the backing namespace
|
|
|
- agent, err := c.GetAgent(r, cluster, "")
|
|
|
-
|
|
|
- if err != nil {
|
|
|
- c.HandleAPIError(w, r, apierrors.NewErrInternal(err))
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- _, err = agent.CreateNamespace(depl.Namespace)
|
|
|
-
|
|
|
- if err != nil {
|
|
|
- c.HandleAPIError(w, r, apierrors.NewErrInternal(err))
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
// create deployment on GitHub API
|
|
|
client, err := getGithubClientFromEnvironment(c.Config(), env)
|
|
|
|
|
|
@@ -86,14 +59,16 @@ func (c *CreateDeploymentHandler) ServeHTTP(w http.ResponseWriter, r *http.Reque
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- envName := "preview"
|
|
|
+ branch := request.Branch
|
|
|
+ envName := "Preview"
|
|
|
+ automerge := false
|
|
|
|
|
|
deploymentRequest := github.DeploymentRequest{
|
|
|
- Ref: &envName,
|
|
|
+ Ref: &branch,
|
|
|
Environment: &envName,
|
|
|
+ AutoMerge: &automerge,
|
|
|
}
|
|
|
|
|
|
- // create deployment in GitHub (This really should belong in create_deployment)
|
|
|
deployment, _, err := client.Repositories.CreateDeployment(
|
|
|
context.Background(),
|
|
|
env.GitRepoOwner,
|
|
|
@@ -105,13 +80,13 @@ func (c *CreateDeploymentHandler) ServeHTTP(w http.ResponseWriter, r *http.Reque
|
|
|
c.HandleAPIError(w, r, apierrors.NewErrInternal(err))
|
|
|
return
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
depID := deployment.GetID()
|
|
|
|
|
|
// Create Deployment Status to indicate it's in progress
|
|
|
|
|
|
- state := "queued"
|
|
|
- log_url := "https://github.com/actions"
|
|
|
+ state := "in_progress"
|
|
|
+ log_url := fmt.Sprintf("https://github.com/%s/%s/actions/%d", env.GitRepoOwner, env.GitRepoName, request.ActionID)
|
|
|
|
|
|
deploymentStatusRequest := github.DeploymentStatusRequest{
|
|
|
State: &state,
|
|
|
@@ -131,5 +106,34 @@ func (c *CreateDeploymentHandler) ServeHTTP(w http.ResponseWriter, r *http.Reque
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+ // create the deployment
|
|
|
+ depl, err := c.Repo().Environment().CreateDeployment(&models.Deployment{
|
|
|
+ EnvironmentID: env.ID,
|
|
|
+ Namespace: request.Namespace,
|
|
|
+ Status: "creating",
|
|
|
+ PullRequestID: request.PullRequestID,
|
|
|
+ GitHubDeploymentID: depID,
|
|
|
+ })
|
|
|
+
|
|
|
+ if err != nil {
|
|
|
+ c.HandleAPIError(w, r, apierrors.NewErrInternal(err))
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // create the backing namespace
|
|
|
+ agent, err := c.GetAgent(r, cluster, "")
|
|
|
+
|
|
|
+ if err != nil {
|
|
|
+ c.HandleAPIError(w, r, apierrors.NewErrInternal(err))
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ _, err = agent.CreateNamespace(depl.Namespace)
|
|
|
+
|
|
|
+ if err != nil {
|
|
|
+ c.HandleAPIError(w, r, apierrors.NewErrInternal(err))
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
c.WriteResult(w, r, depl.ToDeploymentType())
|
|
|
}
|