aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwxiaoguang <wxiaoguang@gmail.com>2024-02-04 21:05:01 +0800
committerGitHub <noreply@github.com>2024-02-04 13:05:01 +0000
commitb4513f48ce3e748ac621a6f3ddf082feca67e938 (patch)
tree8bf55d60af8b2df93c81e6bc16ebfd00ecdefee1
parent9bea276055edc9527e3d6d66df3bbf0d20326f8b (diff)
downloadgitea-b4513f48ce3e748ac621a6f3ddf082feca67e938.tar.gz
gitea-b4513f48ce3e748ac621a6f3ddf082feca67e938.zip
Do not render empty comments (#29039)
Follow #28654 The `comments` might be empty, so the templates shouldn't (and couldn't) use it to render. When there is no comment, the UI should also be updated to empty, so returning an empty body is good enough.
-rw-r--r--routers/web/repo/pull_review.go11
1 files changed, 10 insertions, 1 deletions
diff --git a/routers/web/repo/pull_review.go b/routers/web/repo/pull_review.go
index 156b70a999..a6b3bd1c8d 100644
--- a/routers/web/repo/pull_review.go
+++ b/routers/web/repo/pull_review.go
@@ -153,12 +153,19 @@ func UpdateResolveConversation(ctx *context.Context) {
}
func renderConversation(ctx *context.Context, comment *issues_model.Comment, origin string) {
+ ctx.Data["PageIsPullFiles"] = origin == "diff"
+
comments, err := issues_model.FetchCodeCommentsByLine(ctx, comment.Issue, ctx.Doer, comment.TreePath, comment.Line, ctx.Data["ShowOutdatedComments"].(bool))
if err != nil {
ctx.ServerError("FetchCodeCommentsByLine", err)
return
}
- ctx.Data["PageIsPullFiles"] = (origin == "diff")
+ if len(comments) == 0 {
+ // if the comments are empty (deleted, outdated, etc), it doesn't need to render anything, just return an empty body to replace "conversation-holder" on the page
+ ctx.Resp.WriteHeader(http.StatusOK)
+ return
+ }
+
ctx.Data["comments"] = comments
if ctx.Data["CanMarkConversation"], err = issues_model.CanMarkConversation(ctx, comment.Issue, ctx.Doer); err != nil {
ctx.ServerError("CanMarkConversation", err)
@@ -179,6 +186,8 @@ func renderConversation(ctx *context.Context, comment *issues_model.Comment, ori
ctx.HTML(http.StatusOK, tplDiffConversation)
} else if origin == "timeline" {
ctx.HTML(http.StatusOK, tplTimelineConversation)
+ } else {
+ ctx.Error(http.StatusBadRequest, "Unknown origin: "+origin)
}
}