From 8633c3fe9fc3677aa475fb535da5dc4e3dfd290c Mon Sep 17 00:00:00 2001 From: Jonas Franz Date: Thu, 18 Oct 2018 15:24:55 +0200 Subject: [PATCH 1/2] Add comment replies --- modules/auth/repo_form.go | 1 + routers/repo/pull_review.go | 8 ++++++-- templates/repo/diff/box.tmpl | 4 ++-- templates/repo/diff/comment_form.tmpl | 10 +++++----- templates/repo/diff/section_unified.tmpl | 2 +- templates/repo/issue/view_content/comments.tmpl | 2 +- 6 files changed, 16 insertions(+), 11 deletions(-) diff --git a/modules/auth/repo_form.go b/modules/auth/repo_form.go index a819a60491b92..a4a00d53b4f4c 100644 --- a/modules/auth/repo_form.go +++ b/modules/auth/repo_form.go @@ -377,6 +377,7 @@ type CodeCommentForm struct { Line int64 TreePath string `form:"path" binding:"Required"` IsReview bool `form:"is_review"` + Reply int64 `form:"reply"` } // Validate validates the fields diff --git a/routers/repo/pull_review.go b/routers/repo/pull_review.go index 91257fea33958..9bb6ccda8cb8e 100644 --- a/routers/repo/pull_review.go +++ b/routers/repo/pull_review.go @@ -63,6 +63,10 @@ func CreateCodeComment(ctx *context.Context, form auth.CodeCommentForm) { } } } + reviewID := review.ID + if reviewID == 0 { + reviewID = form.Reply + } //FIXME check if line, commit and treepath exist comment, err := models.CreateCodeComment( ctx.User, @@ -71,14 +75,14 @@ func CreateCodeComment(ctx *context.Context, form auth.CodeCommentForm) { form.Content, form.TreePath, signedLine, - review.ID, + reviewID, ) if err != nil { ctx.ServerError("CreateCodeComment", err) return } // Send no notification if comment is pending - if !form.IsReview { + if !form.IsReview || form.Reply != 0 { notification.NotifyCreateIssueComment(ctx.User, issue.Repo, issue, comment) } diff --git a/templates/repo/diff/box.tmpl b/templates/repo/diff/box.tmpl index b5bc3ee07377c..729e37c8b940b 100644 --- a/templates/repo/diff/box.tmpl +++ b/templates/repo/diff/box.tmpl @@ -151,7 +151,7 @@ {{ template "repo/diff/comments" dict "root" $ "comments" $line.Comments}} - {{template "repo/diff/comment_form_datahandler" dict "hidden" true "root" $ "comment" (index $line.Comments 0)}} + {{template "repo/diff/comment_form_datahandler" dict "reply" (index $line.Comments 0).ReviewID "hidden" true "root" $ "comment" (index $line.Comments 0)}} {{end}} @@ -164,7 +164,7 @@ {{ template "repo/diff/comments" dict "root" $ "comments" $line.Comments}} - {{template "repo/diff/comment_form_datahandler" dict "hidden" true "root" $ "comment" (index $line.Comments 0)}} + {{template "repo/diff/comment_form_datahandler" dict "reply" (index $line.Comments 0).ReviewID "hidden" true "root" $ "comment" (index $line.Comments 0)}} {{end}} diff --git a/templates/repo/diff/comment_form.tmpl b/templates/repo/diff/comment_form.tmpl index 9683c3e4017b9..9eb557d86b4dd 100644 --- a/templates/repo/diff/comment_form.tmpl +++ b/templates/repo/diff/comment_form.tmpl @@ -25,19 +25,19 @@ diff --git a/templates/repo/issue/view_content/comments.tmpl b/templates/repo/issue/view_content/comments.tmpl index ee10ff56f04aa..4e79fd866c19e 100644 --- a/templates/repo/issue/view_content/comments.tmpl +++ b/templates/repo/issue/view_content/comments.tmpl @@ -342,7 +342,7 @@ {{end}} - {{template "repo/diff/comment_form_datahandler" dict "hidden" true "reply" true "root" $ "comment" (index $comms 0)}} + {{template "repo/diff/comment_form_datahandler" dict "hidden" true "reply" (index $comms 0).ReviewID "root" $ "comment" (index $comms 0)}} {{end}} From 15cb19af4d3a0e908cd55ae4916376b41c19b3d8 Mon Sep 17 00:00:00 2001 From: Jonas Franz Date: Sun, 21 Oct 2018 16:07:18 +0200 Subject: [PATCH 2/2] Replace reviewID with review.ID --- routers/repo/pull_review.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/routers/repo/pull_review.go b/routers/repo/pull_review.go index 9bb6ccda8cb8e..7576ebe90bbf6 100644 --- a/routers/repo/pull_review.go +++ b/routers/repo/pull_review.go @@ -63,9 +63,8 @@ func CreateCodeComment(ctx *context.Context, form auth.CodeCommentForm) { } } } - reviewID := review.ID - if reviewID == 0 { - reviewID = form.Reply + if review.ID == 0 { + review.ID = form.Reply } //FIXME check if line, commit and treepath exist comment, err := models.CreateCodeComment( @@ -75,7 +74,7 @@ func CreateCodeComment(ctx *context.Context, form auth.CodeCommentForm) { form.Content, form.TreePath, signedLine, - reviewID, + review.ID, ) if err != nil { ctx.ServerError("CreateCodeComment", err)