Fix force push time-line commit comments of pull request#36653
Fix force push time-line commit comments of pull request#36653lunny wants to merge 11 commits intogo-gitea:mainfrom
Conversation
|
"comments"? I think you mean "timeline entries", right? |
Yes. But it stored as comment in the database. |
|
Comment written by Claude Code (claude-opus-4-6) Some observations from reviewing this PR: 1. Raw DELETE bypasses The bulk delete at db.GetEngine(ctx).Where("issue_id = ?", pr.IssueID).
And("type = ?", issues_model.CommentTypePullRequestPush).
NoAutoCondition().
Delete(new(issues_model.Comment))The existing 2. The old code only called 3. Inconsistent use of Inside the transaction, the deletion guard uses the function parameter |
Oh ok, definitely a odd decision, but one that is probably hard to correct. We need to ensure comment-related logic stays intact. |
|
On more observation: When force-pushing over a single commit, it works as expected and the commit is replaced in the timeline, so I think that issue only showed when force-pushing over multiple commits. #36666 is a semi-related issue with incorrect status icon on force-pushed commits. |
I will send another PR to fix that issue after this merged. |
There was a problem hiding this comment.
Pull request overview
This PR addresses long-standing issues where force-pushing a PR branch leaves stale “pushed commits” entries in the PR timeline, by clearing prior push timeline comments on force-push and recreating the appropriate entries.
Changes:
- Update
CreatePushPullCommentto delete existing PR push-timeline comments on force-push, then recreate comments to reflect the new state. - Wrap force-push comment recreation in a DB transaction to keep deletion/recreation atomic.
- Add a unit test validating that force-push removes prior PR push-timeline comments.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
services/pull/comment.go |
Deletes old PR push comments on force-push and recreates timeline comments within a transaction. |
services/pull/comment_test.go |
Adds a test ensuring old PR push comments are removed when simulating a force-push. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: silverwind <me@silverwind.io>
|
@lunny let me know when this is ready, then I will test a few force-push scenarios. |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Lunny Xiao <xiaolunwen@gmail.com>
It's ready to review again now. |
silverwind
left a comment
There was a problem hiding this comment.
Comment written by AI, prompted by @silverwind
The core approach (delete stale push comments on force push, re-create current ones) looks correct and matches GitHub's behavior.
One concern with the current implementation:
The raw delete at https://github.com/go-gitea/gitea/pull/36653/files#diff-c7e89599de0966ea68aa2e1ff2e4187bfab6477e4e4a49e1f1bbc87077e1eb24R82-R87 bypasses issues_model.DeleteComment() which handles cascading cleanup of attachments, reactions, content history, actions table entries, and cross-references. For CommentTypePullRequestPush comments most of these are unlikely to exist in practice, but for correctness the comments should be queried first and then deleted individually via the proper DeleteComment() function.


Fix #36647
Fix #25827
Fix #25870