Open delvh opened 2 years ago
There is an old issue, it seems related.
duplicated
@delvh are you working on this? Should we keep this issue open, or use the old one?
We can use the other one, and so far I'm not working on it because a) I have close to no time right now (see my sparse interactions in the last few days) b) I haven't found the root location of this "bug" yet, whenever I attempt to follow the trail, it leads me throughout the whole application...
Hmm ... these 2 issues are related, but not exactly the same (#4388 is about sending notification before summit, this is about saving content history before submit). I think we can keep both open, just link them for further investigation.
Hi, I ended up being nerd snipped by @jolheiser on this issue last night. Heres the rundown:
There are 3 issues occuring during a pending PR Review:
I think its easier to start with showing what happens in the working case first:
Adding a new pending comment during a pending PR review does not send a webhook notification
pull_service.CreateCodeComment
with the pendingReview
parameter set to false
https://github.com/go-gitea/gitea/blob/main/routers/web/repo/pull_review.go#L76if !pendingReview && existsReview
. For new comments this evaluates to if !true && false
. As such, it does not go down that if path which contains a call to the notification service https://github.com/go-gitea/gitea/blob/main/services/pull/review.go#L116. As you see above, the new comment path never ends up calling the notification service, so no notifications are sent out. These notifications are eventually sent when the PR Review is published https://github.com/go-gitea/gitea/blob/main/services/pull/review.go#L310
Replying to a pending comment during a pending PR Review will send a webhook notification
When you press the "Reply" button on a Reply message during a pending PR Review it will call this endpoint https://github.com/go-gitea/gitea/blob/88479e0dfcbcb9ce229a72ead8c3c9c3b6bb04b0/routers/web/web.go#L1304 with the "single_review"
flag set to "true"
This will go through the repo layer and call pull_service.CreateCodeComment
with the pendingReview
parameter set to false
https://github.com/go-gitea/gitea/blob/main/routers/web/repo/pull_review.go#L76
This ends up in the pull review service https://github.com/go-gitea/gitea/blob/main/services/pull/review.go#L73 where there is a check if !pendingReview && existsReview
. For reply comments this evaluates to if !false && true
. As such, it goes down the if path which contains a call to the notification service https://github.com/go-gitea/gitea/blob/main/services/pull/review.go#L116.
A notification is sent out
The fix here would be to do some type of check around this notification call to ensure if the Review is pending or not when this path is called.
Deleting a pending comment during a pending PR Review will send a webhook notification
issue_service.DeleteComment
https://github.com/go-gitea/gitea/blob/main/routers/web/repo/issue.go#L3121issue_service.DeleteComment
is a implementation that simply deletes the comment and sends a notification https://github.com/go-gitea/gitea/blob/main/services/issue/comments.go#L104The fix here would be to add a DeleteComment
function to the pull_service
that does much the same as the pull_service.CreateCodeComment
. It needs to check if the review is pending, and if so dont sent a notification. Then add a layer in the pull review repo to handle the review case. Then create a new endpoint that goes to this repo.
Editing a pending comment during a pending PR review will send a webhook notification
issue_service.UpdateComment
https://github.com/go-gitea/gitea/blob/main/routers/web/repo/issue.go#L3065issue_service.UpdateComment
is an implementation that simply updates the comment and sends a notification https://github.com/go-gitea/gitea/blob/main/services/issue/comments.go#L72The fix here would be to add a UpdateComment
function to the pull_service
that does much the same as the pull_service.CreateCodeComment
. It needs to check if the review is pending, and if so dont sent a notification. Then add a layer in the pull review repo to handle the review case. Then create a new endpoint that goes to this repo.
And when you first time open a PR and assign someone. 2 notifications are sent that should be merged to one.
Gitea Version
1.16.1-dev
Git Version
NA
Operating System
Linux
How are you running Gitea?
NA
Database
No response
Can you reproduce the bug on the Gitea demo site?
Yes, unfortunately
Log Gist
No response
Description
Currently, any edit to a comment will be logged in its change history. For PR Reviews, however, edits should only be logged after the review was submitted. Edits prior to that should simply be discarded.
Scope
There are two aspects that makes this issue way worse:
Keep in mind
The creation change should be adapted to not show the original text, but the text of the last edit before submitting the review. However, this appears to already be done within
models/issues/content_history.go#keepLimitedContentHistory
see https://try.gitea.io/delvh/kanban-test/pulls/16#issuecomment-113571 for example.
Screenshots
No response