Skip to content

Commit

Permalink
Do not render empty comments (#29039)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
wxiaoguang authored Feb 4, 2024
1 parent 9bea276 commit b4513f4
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion routers/web/repo/pull_review.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
}
}

Expand Down

0 comments on commit b4513f4

Please sign in to comment.