Skip to content
This repository has been archived by the owner on May 19, 2024. It is now read-only.

Commit

Permalink
Stop checking comment ids when comment found
Browse files Browse the repository at this point in the history
- edit the comment rather than delete and create
- stop searching for comment when its found
- add abuse backoff for the edit comment
  • Loading branch information
owenrumney committed Jan 19, 2022
1 parent 6bc76fa commit c64d8a9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
3 changes: 3 additions & 0 deletions commenter/commenter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
14 changes: 7 additions & 7 deletions commenter/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down

0 comments on commit c64d8a9

Please sign in to comment.