Skip to content

Commit 87b28b3

Browse files
lunnyGiteaBot
andauthored
Reload issue when sending webhook to make num comments is right. (#35243)
Fix #35229 --------- Co-authored-by: Giteabot <[email protected]>
1 parent 9b5a3e9 commit 87b28b3

File tree

3 files changed

+8
-10
lines changed

3 files changed

+8
-10
lines changed

services/actions/notifier.go

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -263,11 +263,6 @@ func (n *actionsNotifier) CreateIssueComment(ctx context.Context, doer *user_mod
263263
func (n *actionsNotifier) UpdateComment(ctx context.Context, doer *user_model.User, c *issues_model.Comment, oldContent string) {
264264
ctx = withMethod(ctx, "UpdateComment")
265265

266-
if err := c.LoadIssue(ctx); err != nil {
267-
log.Error("LoadIssue: %v", err)
268-
return
269-
}
270-
271266
if c.Issue.IsPull {
272267
notifyIssueCommentChange(ctx, doer, c, oldContent, webhook_module.HookEventPullRequestComment, api.HookIssueCommentEdited)
273268
return
@@ -278,11 +273,6 @@ func (n *actionsNotifier) UpdateComment(ctx context.Context, doer *user_model.Us
278273
func (n *actionsNotifier) DeleteComment(ctx context.Context, doer *user_model.User, comment *issues_model.Comment) {
279274
ctx = withMethod(ctx, "DeleteComment")
280275

281-
if err := comment.LoadIssue(ctx); err != nil {
282-
log.Error("LoadIssue: %v", err)
283-
return
284-
}
285-
286276
if comment.Issue.IsPull {
287277
notifyIssueCommentChange(ctx, doer, comment, "", webhook_module.HookEventPullRequestComment, api.HookIssueCommentDeleted)
288278
return
@@ -291,6 +281,7 @@ func (n *actionsNotifier) DeleteComment(ctx context.Context, doer *user_model.Us
291281
}
292282

293283
func notifyIssueCommentChange(ctx context.Context, doer *user_model.User, comment *issues_model.Comment, oldContent string, event webhook_module.HookEventType, action api.HookIssueCommentAction) {
284+
comment.Issue = nil // force issue to be loaded
294285
if err := comment.LoadIssue(ctx); err != nil {
295286
log.Error("LoadIssue: %v", err)
296287
return

services/issue/comments.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ func CreateIssueComment(ctx context.Context, doer *user_model.User, repo *repo_m
8080
return nil, err
8181
}
8282

83+
// reload issue to ensure it has the latest data, especially the number of comments
84+
issue, err = issues_model.GetIssueByID(ctx, issue.ID)
85+
if err != nil {
86+
return nil, err
87+
}
88+
8389
notify_service.CreateIssueComment(ctx, doer, repo, issue, comment, mentions)
8490

8591
return comment, nil

services/webhook/notifier.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,7 @@ func (m *webhookNotifier) DeleteComment(ctx context.Context, doer *user_model.Us
481481
log.Error("LoadPoster: %v", err)
482482
return
483483
}
484+
comment.Issue = nil // reload issue to ensure it has the latest data, especially the number of comments
484485
if err = comment.LoadIssue(ctx); err != nil {
485486
log.Error("LoadIssue: %v", err)
486487
return

0 commit comments

Comments
 (0)