Skip to content

Commit 12db9d1

Browse files
theakshaypantchmouel
authored andcommitted
perf(github): skip comment edit when body is already up to date
Avoid unnecessary GitHub API calls by checking if comment body already matches before editing. Use github.Ptr() for consistency. Signed-off-by: Akshay Pant <akshay.akshaypant@gmail.com>
1 parent a076d20 commit 12db9d1

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

pkg/provider/github/github.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -776,9 +776,13 @@ func (v *Provider) CreateComment(ctx context.Context, event *info.Event, commit,
776776
re := regexp.MustCompile(regexp.QuoteMeta(updateMarker))
777777
for _, comment := range comments {
778778
if re.MatchString(comment.GetBody()) {
779+
// No edit required if the comment is exactly the same.
780+
if comment.GetBody() == commit {
781+
return nil
782+
}
779783
if _, _, err := wrapAPI(v, "edit_comment", func() (*github.IssueComment, *github.Response, error) {
780784
return v.Client().Issues.EditComment(ctx, event.Organization, event.Repository, comment.GetID(), &github.IssueComment{
781-
Body: &commit,
785+
Body: github.Ptr(commit),
782786
})
783787
}); err != nil {
784788
return err
@@ -790,7 +794,7 @@ func (v *Provider) CreateComment(ctx context.Context, event *info.Event, commit,
790794

791795
_, _, err := wrapAPI(v, "create_comment", func() (*github.IssueComment, *github.Response, error) {
792796
return v.Client().Issues.CreateComment(ctx, event.Organization, event.Repository, event.PullRequestNumber, &github.IssueComment{
793-
Body: &commit,
797+
Body: github.Ptr(commit),
794798
})
795799
})
796800
return err

0 commit comments

Comments
 (0)