diff --git a/commenter/commenter.go b/commenter/commenter.go index d45afe9..91603ac 100644 --- a/commenter/commenter.go +++ b/commenter/commenter.go @@ -141,6 +141,9 @@ func (c *Commenter) writeCommentIfRequired(prComment *github.PullRequestComment) } return nil }(existing) + if commentId != nil { + break + } } if err := c.ghConnector.writeReviewComment(prComment, commentId); err != nil { diff --git a/commenter/connector.go b/commenter/connector.go index 05d8d57..21ac55e 100644 --- a/commenter/connector.go +++ b/commenter/connector.go @@ -81,7 +81,7 @@ func newEnterpriseGithubClient(token, baseUrl, uploadUrl string) (*github.Client client, err := github.NewEnterpriseClient(baseUrl, uploadUrl, tc) if err != nil { - return nil, err + return nil, err } return client, nil @@ -91,16 +91,16 @@ func (c *connector) writeReviewComment(block *github.PullRequestComment, comment ctx := context.Background() if commentId != nil { - if _, err := c.prs.DeleteComment(ctx, c.owner, c.repo, *commentId); err != nil { - return fmt.Errorf("delete existing comment %d: %w", *commentId, err) - } + return writeCommentWithRetries(c.owner, c.repo, c.prNumber, func() (*github.Response, error) { + _, resp, err := c.prs.EditComment(ctx, c.owner, c.repo, *commentId, block) + return resp, err + }) } - writeReviewCommentFn := func() (*github.Response, error) { + return writeCommentWithRetries(c.owner, c.repo, c.prNumber, func() (*github.Response, error) { _, resp, err := c.prs.CreateComment(ctx, c.owner, c.repo, c.prNumber, block) return resp, err - } - return writeCommentWithRetries(c.owner, c.repo, c.prNumber, writeReviewCommentFn) + }) } func (c *connector) writeGeneralComment(comment *github.IssueComment) error {