From 4eca76e7e669d74761dfdfeab9a9f083087a00f8 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Fri, 8 Aug 2025 17:10:14 -0700 Subject: [PATCH 1/3] realod issue when sending webhook to make num comments is right. --- services/issue/comments.go | 6 ++++++ services/webhook/notifier.go | 1 + 2 files changed, 7 insertions(+) diff --git a/services/issue/comments.go b/services/issue/comments.go index 10c81198d57e2..5a73d502e1db0 100644 --- a/services/issue/comments.go +++ b/services/issue/comments.go @@ -80,6 +80,12 @@ func CreateIssueComment(ctx context.Context, doer *user_model.User, repo *repo_m return nil, err } + // reaload issue to ensure it has the latest data, especially the number of comments + issue, err = issues_model.GetIssueByID(ctx, issue.ID) + if err != nil { + return nil, err + } + notify_service.CreateIssueComment(ctx, doer, repo, issue, comment, mentions) return comment, nil diff --git a/services/webhook/notifier.go b/services/webhook/notifier.go index 672abd5c95d0e..80de6b00fdbd1 100644 --- a/services/webhook/notifier.go +++ b/services/webhook/notifier.go @@ -481,6 +481,7 @@ func (m *webhookNotifier) DeleteComment(ctx context.Context, doer *user_model.Us log.Error("LoadPoster: %v", err) return } + comment.Issue = nil // reload issue to ensure it has the latest data, especially the number of comments if err = comment.LoadIssue(ctx); err != nil { log.Error("LoadIssue: %v", err) return From 9efc119a65f2564f4bb517df78b11854c55dea8d Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Sat, 9 Aug 2025 10:58:20 -0700 Subject: [PATCH 2/3] Fix typo --- services/issue/comments.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/issue/comments.go b/services/issue/comments.go index 5a73d502e1db0..9442701029b57 100644 --- a/services/issue/comments.go +++ b/services/issue/comments.go @@ -80,7 +80,7 @@ func CreateIssueComment(ctx context.Context, doer *user_model.User, repo *repo_m return nil, err } - // reaload issue to ensure it has the latest data, especially the number of comments + // reload issue to ensure it has the latest data, especially the number of comments issue, err = issues_model.GetIssueByID(ctx, issue.ID) if err != nil { return nil, err From aef2e2f491f36d2d72e62ea396f7b12e2f870bf7 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Sat, 9 Aug 2025 11:23:09 -0700 Subject: [PATCH 3/3] Fix action notifier issue's num comment --- services/actions/notifier.go | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/services/actions/notifier.go b/services/actions/notifier.go index d10cc0ab34419..110e330f68d59 100644 --- a/services/actions/notifier.go +++ b/services/actions/notifier.go @@ -263,11 +263,6 @@ func (n *actionsNotifier) CreateIssueComment(ctx context.Context, doer *user_mod func (n *actionsNotifier) UpdateComment(ctx context.Context, doer *user_model.User, c *issues_model.Comment, oldContent string) { ctx = withMethod(ctx, "UpdateComment") - if err := c.LoadIssue(ctx); err != nil { - log.Error("LoadIssue: %v", err) - return - } - if c.Issue.IsPull { notifyIssueCommentChange(ctx, doer, c, oldContent, webhook_module.HookEventPullRequestComment, api.HookIssueCommentEdited) return @@ -278,11 +273,6 @@ func (n *actionsNotifier) UpdateComment(ctx context.Context, doer *user_model.Us func (n *actionsNotifier) DeleteComment(ctx context.Context, doer *user_model.User, comment *issues_model.Comment) { ctx = withMethod(ctx, "DeleteComment") - if err := comment.LoadIssue(ctx); err != nil { - log.Error("LoadIssue: %v", err) - return - } - if comment.Issue.IsPull { notifyIssueCommentChange(ctx, doer, comment, "", webhook_module.HookEventPullRequestComment, api.HookIssueCommentDeleted) return @@ -291,6 +281,7 @@ func (n *actionsNotifier) DeleteComment(ctx context.Context, doer *user_model.Us } func notifyIssueCommentChange(ctx context.Context, doer *user_model.User, comment *issues_model.Comment, oldContent string, event webhook_module.HookEventType, action api.HookIssueCommentAction) { + comment.Issue = nil // force issue to be loaded if err := comment.LoadIssue(ctx); err != nil { log.Error("LoadIssue: %v", err) return