ソースを参照

enrich pr deployemnt with github metadata (backend)

sunguroku 4 年 前
コミット
89b7bd095f

+ 9 - 1
api/server/handlers/environment/create_deployment.go

@@ -66,13 +66,21 @@ func (c *CreateDeploymentHandler) ServeHTTP(w http.ResponseWriter, r *http.Reque
 		return
 	}
 
+	ghMetadata := types.GitHubMetadata{
+		DeploymentID: ghDeployment.GetID(),
+		RepoOwner: request.GitHubMetadata.RepoOwner,
+		RepoName: request.GitHubMetadata.RepoName,
+		PRName: request.GitHubMetadata.PRName,
+		CommitSHA: request.GitHubMetadata.CommitSHA,
+	}
+
 	// 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(),
+		GitHubMetadata:		ghMetadata,
 	})
 
 	if err != nil {

+ 1 - 1
api/server/handlers/environment/delete_deployment.go

@@ -95,7 +95,7 @@ func (c *DeleteDeploymentHandler) ServeHTTP(w http.ResponseWriter, r *http.Reque
 		context.Background(),
 		env.GitRepoOwner,
 		env.GitRepoName,
-		depl.GitHubDeploymentID,
+		depl.GitHubMetadata.DeploymentID,
 		&deploymentStatusRequest,
 	)
 

+ 1 - 1
api/server/handlers/environment/finalize_deployment.go

@@ -88,7 +88,7 @@ func (c *FinalizeDeploymentHandler) ServeHTTP(w http.ResponseWriter, r *http.Req
 		context.Background(),
 		env.GitRepoOwner,
 		env.GitRepoName,
-		depl.GitHubDeploymentID,
+		depl.GitHubMetadata.DeploymentID,
 		&deploymentStatusRequest,
 	)
 

+ 2 - 1
api/server/handlers/environment/update_deployment.go

@@ -71,7 +71,8 @@ func (c *UpdateDeploymentHandler) ServeHTTP(w http.ResponseWriter, r *http.Reque
 		return
 	}
 
-	depl.GitHubDeploymentID = ghDeployment.GetID()
+	depl.GitHubMetadata.DeploymentID = ghDeployment.GetID()
+	depl.GitHubMetadata.CommitSHA = request.CommitSHA
 
 	if err != nil {
 		c.HandleAPIError(w, r, apierrors.NewErrInternal(err))

+ 11 - 1
api/types/environment.go

@@ -17,6 +17,14 @@ type CreateEnvironmentRequest struct {
 	GitRepoName  string `json:"git_repo_name" form:"required"`
 }
 
+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"`
+}
+
 type Deployment struct {
 	ID                 uint   `json:"id"`
 	EnvironmentID      uint   `json:"environment_id"`
@@ -24,7 +32,7 @@ type Deployment struct {
 	Status             string `json:"status"`
 	Subdomain          string `json:"subdomain"`
 	PullRequestID      uint   `json:"pull_request_id"`
-	GitHubDeploymentID int64  `json:"github_deployment_id"`
+	GitHubMetadata *GitHubMetadata  `json:"github_metadata"`
 }
 
 type CreateGHDeploymentRequest struct {
@@ -34,6 +42,7 @@ type CreateGHDeploymentRequest struct {
 
 type CreateDeploymentRequest struct {
 	*CreateGHDeploymentRequest
+	*GitHubMetadata
 
 	Namespace     string `json:"namespace" form:"required"`
 	PullRequestID uint   `json:"pull_request_id" form:"required"`
@@ -47,6 +56,7 @@ type FinalizeDeploymentRequest struct {
 type UpdateDeploymentRequest struct {
 	*CreateGHDeploymentRequest
 
+	CommitSHA string `json:"commit_sha" form:"required"`	
 	Namespace string `json:"namespace" form:"required"`
 }
 

+ 11 - 2
internal/models/environment.go

@@ -37,10 +37,19 @@ type Deployment struct {
 	Status             string
 	Subdomain          string
 	PullRequestID      uint
-	GitHubDeploymentID int64
+	GitHubMetadata	   types.GitHubMetadata
 }
 
 func (d *Deployment) ToDeploymentType() *types.Deployment {
+
+	ghMetadata := &types.GitHubMetadata{
+		DeploymentID: d.GitHubMetadata.DeploymentID,
+		PRName:		  d.GitHubMetadata.PRName,
+		RepoName:	 d.GitHubMetadata.RepoName,
+		RepoOwner:	 d.GitHubMetadata.RepoOwner,
+		CommitSHA:	 d.GitHubMetadata.CommitSHA,
+	}
+
 	return &types.Deployment{
 		ID:                 d.Model.ID,
 		EnvironmentID:      d.EnvironmentID,
@@ -48,6 +57,6 @@ func (d *Deployment) ToDeploymentType() *types.Deployment {
 		Status:             d.Status,
 		Subdomain:          d.Subdomain,
 		PullRequestID:      d.PullRequestID,
-		GitHubDeploymentID: d.GitHubDeploymentID,
+		GitHubMetadata: 	ghMetadata,
 	}
 }