|
|
@@ -59,6 +59,46 @@ func (c *CreateDeploymentHandler) ServeHTTP(w http.ResponseWriter, r *http.Reque
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+ ghDeployment, err := createDeployment(client, env, request.CreateGHDeploymentRequest)
|
|
|
+
|
|
|
+ if err != nil {
|
|
|
+ c.HandleAPIError(w, r, apierrors.NewErrInternal(err))
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // create the deployment
|
|
|
+ depl, err := c.Repo().Environment().CreateDeployment(&models.Deployment{
|
|
|
+ EnvironmentID: env.ID,
|
|
|
+ Namespace: request.Namespace,
|
|
|
+ Status: "creating",
|
|
|
+ PullRequestID: request.PullRequestID,
|
|
|
+ GitHubDeploymentID: ghDeployment.GetID(),
|
|
|
+ })
|
|
|
+
|
|
|
+ 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())
|
|
|
+}
|
|
|
+
|
|
|
+func createDeployment(client *github.Client, env *models.Environment, request *types.CreateGHDeploymentRequest) (*github.Deployment, error) {
|
|
|
branch := request.Branch
|
|
|
envName := "Preview"
|
|
|
automerge := false
|
|
|
@@ -79,8 +119,7 @@ func (c *CreateDeploymentHandler) ServeHTTP(w http.ResponseWriter, r *http.Reque
|
|
|
)
|
|
|
|
|
|
if err != nil {
|
|
|
- c.HandleAPIError(w, r, apierrors.NewErrInternal(err))
|
|
|
- return
|
|
|
+ return nil, err
|
|
|
}
|
|
|
|
|
|
depID := deployment.GetID()
|
|
|
@@ -88,7 +127,7 @@ func (c *CreateDeploymentHandler) ServeHTTP(w http.ResponseWriter, r *http.Reque
|
|
|
// Create Deployment Status to indicate it's in progress
|
|
|
|
|
|
state := "in_progress"
|
|
|
- log_url := fmt.Sprintf("https://github.com/%s/%s/actions/%d", env.GitRepoOwner, env.GitRepoName, request.ActionID)
|
|
|
+ log_url := fmt.Sprintf("https://github.com/%s/%s/runs/%d", env.GitRepoOwner, env.GitRepoName, request.ActionID)
|
|
|
|
|
|
deploymentStatusRequest := github.DeploymentStatusRequest{
|
|
|
State: &state,
|
|
|
@@ -104,38 +143,8 @@ func (c *CreateDeploymentHandler) ServeHTTP(w http.ResponseWriter, r *http.Reque
|
|
|
)
|
|
|
|
|
|
if err != nil {
|
|
|
- c.HandleAPIError(w, r, apierrors.NewErrInternal(err))
|
|
|
- return
|
|
|
+ return nil, err
|
|
|
}
|
|
|
|
|
|
- // 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())
|
|
|
+ return deployment, nil
|
|
|
}
|