@@ -9,11 +9,40 @@ import (
99
1010 "code.gitea.io/gitea/models"
1111 "code.gitea.io/gitea/modules/auth"
12+ "code.gitea.io/gitea/modules/base"
1213 "code.gitea.io/gitea/modules/context"
1314 "code.gitea.io/gitea/modules/log"
1415 pull_service "code.gitea.io/gitea/services/pull"
1516)
1617
18+ const (
19+ tplConversation base.TplName = "repo/diff/conversation"
20+ tplNewComment base.TplName = "repo/diff/new_comment"
21+ )
22+
23+ // RenderNewCodeCommentForm will render the form for creating a new review comment
24+ func RenderNewCodeCommentForm (ctx * context.Context ) {
25+ issue := GetActionIssue (ctx )
26+ if ! issue .IsPull {
27+ return
28+ }
29+ currentReview , err := models .GetCurrentReview (ctx .User , issue )
30+ if err != nil && ! models .IsErrReviewNotExist (err ) {
31+ ctx .ServerError ("GetCurrentReview" , err )
32+ return
33+ }
34+ ctx .Data ["PageIsPullFiles" ] = true
35+ ctx .Data ["Issue" ] = issue
36+ ctx .Data ["CurrentReview" ] = currentReview
37+ pullHeadCommitID , err := ctx .Repo .GitRepo .GetRefCommitID (issue .PullRequest .GetGitRefName ())
38+ if err != nil {
39+ ctx .ServerError ("GetRefCommitID" , err )
40+ return
41+ }
42+ ctx .Data ["AfterCommitID" ] = pullHeadCommitID
43+ ctx .HTML (200 , tplNewComment )
44+ }
45+
1746// CreateCodeComment will create a code comment including an pending review if required
1847func CreateCodeComment (ctx * context.Context , form auth.CodeCommentForm ) {
1948 issue := GetActionIssue (ctx )
@@ -58,11 +87,17 @@ func CreateCodeComment(ctx *context.Context, form auth.CodeCommentForm) {
5887 }
5988
6089 log .Trace ("Comment created: %-v #%d[%d] Comment[%d]" , ctx .Repo .Repository , issue .Index , issue .ID , comment .ID )
90+
91+ if form .Origin == "diff" {
92+ renderConversation (ctx , comment )
93+ return
94+ }
6195 ctx .Redirect (comment .HTMLURL ())
6296}
6397
6498// UpdateResolveConversation add or remove an Conversation resolved mark
6599func UpdateResolveConversation (ctx * context.Context ) {
100+ origin := ctx .Query ("origin" )
66101 action := ctx .Query ("action" )
67102 commentID := ctx .QueryInt64 ("comment_id" )
68103
@@ -103,11 +138,38 @@ func UpdateResolveConversation(ctx *context.Context) {
103138 return
104139 }
105140
141+ if origin == "diff" {
142+ renderConversation (ctx , comment )
143+ return
144+ }
106145 ctx .JSON (200 , map [string ]interface {}{
107146 "ok" : true ,
108147 })
109148}
110149
150+ func renderConversation (ctx * context.Context , comment * models.Comment ) {
151+ comments , err := models .FetchCodeCommentsByLine (comment .Issue , ctx .User , comment .TreePath , comment .Line )
152+ if err != nil {
153+ ctx .ServerError ("FetchCodeCommentsByLine" , err )
154+ return
155+ }
156+ ctx .Data ["PageIsPullFiles" ] = true
157+ ctx .Data ["comments" ] = comments
158+ ctx .Data ["CanMarkConversation" ] = true
159+ ctx .Data ["Issue" ] = comment .Issue
160+ if err = comment .Issue .LoadPullRequest (); err != nil {
161+ ctx .ServerError ("comment.Issue.LoadPullRequest" , err )
162+ return
163+ }
164+ pullHeadCommitID , err := ctx .Repo .GitRepo .GetRefCommitID (comment .Issue .PullRequest .GetGitRefName ())
165+ if err != nil {
166+ ctx .ServerError ("GetRefCommitID" , err )
167+ return
168+ }
169+ ctx .Data ["AfterCommitID" ] = pullHeadCommitID
170+ ctx .HTML (200 , tplConversation )
171+ }
172+
111173// SubmitReview creates a review out of the existing pending review or creates a new one if no pending review exist
112174func SubmitReview (ctx * context.Context , form auth.SubmitReviewForm ) {
113175 issue := GetActionIssue (ctx )
0 commit comments