@@ -9,11 +9,40 @@ import (
9
9
10
10
"code.gitea.io/gitea/models"
11
11
"code.gitea.io/gitea/modules/auth"
12
+ "code.gitea.io/gitea/modules/base"
12
13
"code.gitea.io/gitea/modules/context"
13
14
"code.gitea.io/gitea/modules/log"
14
15
pull_service "code.gitea.io/gitea/services/pull"
15
16
)
16
17
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
+
17
46
// CreateCodeComment will create a code comment including an pending review if required
18
47
func CreateCodeComment (ctx * context.Context , form auth.CodeCommentForm ) {
19
48
issue := GetActionIssue (ctx )
@@ -58,11 +87,17 @@ func CreateCodeComment(ctx *context.Context, form auth.CodeCommentForm) {
58
87
}
59
88
60
89
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
+ }
61
95
ctx .Redirect (comment .HTMLURL ())
62
96
}
63
97
64
98
// UpdateResolveConversation add or remove an Conversation resolved mark
65
99
func UpdateResolveConversation (ctx * context.Context ) {
100
+ origin := ctx .Query ("origin" )
66
101
action := ctx .Query ("action" )
67
102
commentID := ctx .QueryInt64 ("comment_id" )
68
103
@@ -103,11 +138,38 @@ func UpdateResolveConversation(ctx *context.Context) {
103
138
return
104
139
}
105
140
141
+ if origin == "diff" {
142
+ renderConversation (ctx , comment )
143
+ return
144
+ }
106
145
ctx .JSON (200 , map [string ]interface {}{
107
146
"ok" : true ,
108
147
})
109
148
}
110
149
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
+
111
173
// SubmitReview creates a review out of the existing pending review or creates a new one if no pending review exist
112
174
func SubmitReview (ctx * context.Context , form auth.SubmitReviewForm ) {
113
175
issue := GetActionIssue (ctx )
0 commit comments