Browse Source

cases to handle for comments

Mohammed Nafees 3 years ago
parent
commit
b583efbd00

+ 10 - 0
api/server/handlers/environment/finalize_deployment.go

@@ -104,6 +104,16 @@ func (c *FinalizeDeploymentHandler) ServeHTTP(w http.ResponseWriter, r *http.Req
 		return
 	}
 
+	// when updating a PR comment, we have to handle several cases:
+	//   1. when a Porter environment has deployment status repeat-comments enabled
+	//      - nothing special here, simply create a new comment in the PR
+	//   2. when a Porter environment has deployment status repeat-comments disabled
+	//      - when a Porter deployment has Github comment ID saved in the DB
+	//        - try to update the comment using the Github comment ID
+	//        - if the above fails, try creating a new comment and save the new comment ID in the DB
+	//      - when a Porter deployment does not have a Github comment ID saved in the DB
+	//        - create a new comment and save the Github comment ID in the DB
+
 	// write comment in PR
 	commentBody := fmt.Sprintf("Porter has deployed this pull request to the following URL:\n%s", depl.Subdomain)
 	prComment := github.IssueComment{

+ 1 - 0
api/types/environment.go

@@ -24,6 +24,7 @@ type CreateEnvironmentRequest struct {
 
 type GitHubMetadata struct {
 	DeploymentID int64  `json:"gh_deployment_id"`
+	PRCommentID  int64  `json:"gh_pr_comment_id"`
 	PRName       string `json:"gh_pr_name"`
 	RepoName     string `json:"gh_repo_name"`
 	RepoOwner    string `json:"gh_repo_owner"`

+ 13 - 0
dashboard/src/shared/api.tsx

@@ -199,6 +199,18 @@ const listEnvironments = baseApi<
   return `/api/projects/${project_id}/clusters/${cluster_id}/environments`;
 });
 
+const toggleNewCommentForEnvironment = baseApi<
+  {},
+  {
+    project_id: number;
+    cluster_id: number;
+    environment_id: number;
+  }
+>("GET", (pathParams) => {
+  let { project_id, cluster_id, environment_id } = pathParams;
+  return `/api/projects/${project_id}/clusters/${cluster_id}/environments/${environment_id}`;
+});
+
 const createGCPIntegration = baseApi<
   {
     gcp_key_data: string;
@@ -2029,6 +2041,7 @@ export default {
   createPreviewEnvironmentDeployment,
   reenablePreviewEnvironmentDeployment,
   listEnvironments,
+  toggleNewCommentForEnvironment,
   createGCPIntegration,
   createInvite,
   createNamespace,

+ 2 - 0
internal/models/environment.go

@@ -51,6 +51,7 @@ type Deployment struct {
 	Subdomain      string
 	PullRequestID  uint
 	GHDeploymentID int64
+	GHPRCommentID  int64
 	PRName         string
 	RepoName       string
 	RepoOwner      string
@@ -69,6 +70,7 @@ func (d *Deployment) ToDeploymentType() *types.Deployment {
 		CommitSHA:    d.CommitSHA,
 		PRBranchFrom: d.PRBranchFrom,
 		PRBranchInto: d.PRBranchInto,
+		PRCommentID:  d.GHPRCommentID,
 	}
 
 	return &types.Deployment{