Skip to content

Commit 80d7159

Browse files
lunnyGiteaBot
andcommitted
Reload issue when sending webhook to make num comments is right. (go-gitea#35243)
Fix go-gitea#35229 --------- Co-authored-by: Giteabot <[email protected]>
1 parent 04114c6 commit 80d7159

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
@@ -260,11 +260,6 @@ func (n *actionsNotifier) CreateIssueComment(ctx context.Context, doer *user_mod
260260
func (n *actionsNotifier) UpdateComment(ctx context.Context, doer *user_model.User, c *issues_model.Comment, oldContent string) {
261261
ctx = withMethod(ctx, "UpdateComment")
262262

263-
if err := c.LoadIssue(ctx); err != nil {
264-
log.Error("LoadIssue: %v", err)
265-
return
266-
}
267-
268263
if c.Issue.IsPull {
269264
notifyIssueCommentChange(ctx, doer, c, oldContent, webhook_module.HookEventPullRequestComment, api.HookIssueCommentEdited)
270265
return
@@ -275,11 +270,6 @@ func (n *actionsNotifier) UpdateComment(ctx context.Context, doer *user_model.Us
275270
func (n *actionsNotifier) DeleteComment(ctx context.Context, doer *user_model.User, comment *issues_model.Comment) {
276271
ctx = withMethod(ctx, "DeleteComment")
277272

278-
if err := comment.LoadIssue(ctx); err != nil {
279-
log.Error("LoadIssue: %v", err)
280-
return
281-
}
282-
283273
if comment.Issue.IsPull {
284274
notifyIssueCommentChange(ctx, doer, comment, "", webhook_module.HookEventPullRequestComment, api.HookIssueCommentDeleted)
285275
return
@@ -288,6 +278,7 @@ func (n *actionsNotifier) DeleteComment(ctx context.Context, doer *user_model.Us
288278
}
289279

290280
func notifyIssueCommentChange(ctx context.Context, doer *user_model.User, comment *issues_model.Comment, oldContent string, event webhook_module.HookEventType, action api.HookIssueCommentAction) {
281+
comment.Issue = nil // force issue to be loaded
291282
if err := comment.LoadIssue(ctx); err != nil {
292283
log.Error("LoadIssue: %v", err)
293284
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
@@ -445,6 +445,7 @@ func (m *webhookNotifier) DeleteComment(ctx context.Context, doer *user_model.Us
445445
log.Error("LoadPoster: %v", err)
446446
return
447447
}
448+
comment.Issue = nil // reload issue to ensure it has the latest data, especially the number of comments
448449
if err = comment.LoadIssue(ctx); err != nil {
449450
log.Error("LoadIssue: %v", err)
450451
return

0 commit comments

Comments
 (0)