Use a temporary variable so issue is only overwritten on success,
preventing a nil dereference in notify_service.CreateIssueComment.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
When NewComment's CreateIssueComment call failed, ctx.ServerError wrote
an HTML 500 page but the deferred function still ran and appended a JSON
redirect to the response body, producing an invalid mixed HTML+JSON
response shown as a toast error.
Fix by adding a ctx.Written() guard in the defer to skip writing when a
response was already sent. Also make post-creation errors in
CreateIssueComment (FindAndUpdateIssueMentions, GetIssueByID) non-fatal
since the comment is already persisted at that point, preventing
duplicate comments on retry.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This PR moved the creation of pushing comments before pull request
mergeable checking. So that when the pull request status changed, the
comments should have been created.
---------
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
Part of #27065
This PR touches functions used in templates. As templates are not static
typed, errors are harder to find, but I hope I catch it all. I think
some tests from other persons do not hurt.
I noticed that `issue_service.CreateComment` adds transaction operations
on `issues_model.CreateComment`, we can merge the two functions and we
can avoid calling each other's methods in the `services` layer.
Co-authored-by: Giteabot <teabot@gitea.io>
To avoid deadlock problem, almost database related functions should be
have ctx as the first parameter.
This PR do a refactor for some of these functions.
Close#24195
Some of the changes are taken from my another fix
f07b0de997
in #20147 (although that PR was discarded ....)
The bug is:
1. The old code doesn't handle `removedfile` event correctly
2. The old code doesn't provide attachments for type=CommentTypeReview
This PR doesn't intend to refactor the "upload" code to a perfect state
(to avoid making the review difficult), so some legacy styles are kept.
---------
Co-authored-by: silverwind <me@silverwind.io>
Co-authored-by: Giteabot <teabot@gitea.io>