Skip to content

Commit 188c8c1

Browse files
wxiaoguangdelvhtechknowlogick
authored
Make Ctrl+Enter submit a pending comment (starting review) instead of submitting a single comment (#23245)
Close #23241 Before: press Ctrl+Enter in the Code Review Form, a single comment will be added. After: press Ctrl+Enter in the Code Review Form, start the review with pending comments. The old name `is_review` is not clear, so the new code use `pending_review` as the new name. Co-authored-by: delvh <[email protected]> Co-authored-by: techknowlogick <[email protected]>
1 parent 47b912c commit 188c8c1

File tree

9 files changed

+25
-28
lines changed

9 files changed

+25
-28
lines changed

routers/api/v1/repo/pull_review.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ func DeletePullReview(ctx *context.APIContext) {
268268
ctx.Status(http.StatusNoContent)
269269
}
270270

271-
// CreatePullReview create a review to an pull request
271+
// CreatePullReview create a review to a pull request
272272
func CreatePullReview(ctx *context.APIContext) {
273273
// swagger:operation POST /repos/{owner}/{repo}/pulls/{index}/reviews repository repoCreatePullReview
274274
// ---
@@ -360,7 +360,7 @@ func CreatePullReview(ctx *context.APIContext) {
360360
line,
361361
c.Body,
362362
c.Path,
363-
true, // is review
363+
true, // pending review
364364
0, // no reply
365365
opts.CommitID,
366366
); err != nil {

routers/web/repo/pull_review.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func CreateCodeComment(ctx *context.Context) {
7777
signedLine,
7878
form.Content,
7979
form.TreePath,
80-
form.IsReview,
80+
!form.SingleReview,
8181
form.Reply,
8282
form.LatestCommitID,
8383
)

services/forms/repo_form.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ type CodeCommentForm struct {
622622
Side string `binding:"Required;In(previous,proposed)"`
623623
Line int64
624624
TreePath string `form:"path" binding:"Required"`
625-
IsReview bool `form:"is_review"`
625+
SingleReview bool `form:"single_review"`
626626
Reply int64 `form:"reply"`
627627
LatestCommitID string
628628
}

services/mailer/incoming/incoming_handler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ func (h *ReplyHandler) Handle(ctx context.Context, content *MailContent, doer *u
127127
comment.Line,
128128
content.Content,
129129
comment.TreePath,
130-
false,
130+
false, // not pending review but a single review
131131
comment.ReviewID,
132132
"",
133133
)

services/pull/review.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func InvalidateCodeComments(ctx context.Context, prs issues_model.PullRequestLis
7171
}
7272

7373
// CreateCodeComment creates a comment on the code line
74-
func CreateCodeComment(ctx context.Context, doer *user_model.User, gitRepo *git.Repository, issue *issues_model.Issue, line int64, content, treePath string, isReview bool, replyReviewID int64, latestCommitID string) (*issues_model.Comment, error) {
74+
func CreateCodeComment(ctx context.Context, doer *user_model.User, gitRepo *git.Repository, issue *issues_model.Issue, line int64, content, treePath string, pendingReview bool, replyReviewID int64, latestCommitID string) (*issues_model.Comment, error) {
7575
var (
7676
existsReview bool
7777
err error
@@ -82,7 +82,7 @@ func CreateCodeComment(ctx context.Context, doer *user_model.User, gitRepo *git.
8282
// - Comments that are part of a review
8383
// - Comments that reply to an existing review
8484

85-
if !isReview && replyReviewID != 0 {
85+
if !pendingReview && replyReviewID != 0 {
8686
// It's not part of a review; maybe a reply to a review comment or a single comment.
8787
// Check if there are reviews for that line already; if there are, this is a reply
8888
if existsReview, err = issues_model.ReviewExists(issue, treePath, line); err != nil {
@@ -91,7 +91,7 @@ func CreateCodeComment(ctx context.Context, doer *user_model.User, gitRepo *git.
9191
}
9292

9393
// Comments that are replies don't require a review header to show up in the issue view
94-
if !isReview && existsReview {
94+
if !pendingReview && existsReview {
9595
if err = issue.LoadRepo(ctx); err != nil {
9696
return nil, err
9797
}
@@ -149,7 +149,7 @@ func CreateCodeComment(ctx context.Context, doer *user_model.User, gitRepo *git.
149149
return nil, err
150150
}
151151

152-
if !isReview && !existsReview {
152+
if !pendingReview && !existsReview {
153153
// Submit the review we've just created so the comment shows up in the issue view
154154
if _, _, err = SubmitReview(ctx, doer, gitRepo, issue, issues_model.ReviewTypeComment, "", latestCommitID, nil); err != nil {
155155
return nil, err

templates/repo/diff/comment_form.tmpl

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{{if and $.root.SignedUserID (not $.Repository.IsArchived)}}
2-
<form class="ui form {{if $.hidden}}gt-hidden comment-form comment-form-reply{{end}}" action="{{$.root.Issue.Link}}/files/reviews/comments" method="post">
2+
<form class="ui form {{if $.hidden}}gt-hidden comment-form{{end}}" action="{{$.root.Issue.Link}}/files/reviews/comments" method="post">
33
{{$.root.CsrfTokenHtml}}
44
<input type="hidden" name="origin" value="{{if $.root.PageIsPullFiles}}diff{{else}}timeline{{end}}">
55
<input type="hidden" name="latest_commit_id" value="{{$.root.AfterCommitID}}"/>
@@ -29,15 +29,10 @@
2929
<input type="hidden" name="reply" value="{{$.reply}}">
3030
{{else}}
3131
{{if $.root.CurrentReview}}
32-
{{/* if there is only one "Add comment" button, the quick-submit should submit the form with is_review=true even if the "Add comment" button is not really clicked */}}
33-
<input type="hidden" name="is_review" value="true">
34-
<button name="is_review" value="true" type="submit"
35-
class="ui submit green tiny button btn-add-comment">{{$.root.locale.Tr "repo.diff.comment.add_review_comment"}}</button>
32+
<button name="pending_review" type="submit" class="ui submit green tiny button btn-add-comment">{{$.root.locale.Tr "repo.diff.comment.add_review_comment"}}</button>
3633
{{else}}
37-
<button name="is_review" value="true" type="submit"
38-
class="ui submit green tiny button btn-start-review">{{$.root.locale.Tr "repo.diff.comment.start_review"}}</button>
39-
<button type="submit"
40-
class="ui submit tiny basic button btn-add-single">{{$.root.locale.Tr "repo.diff.comment.add_single_comment"}}</button>
34+
<button name="pending_review" type="submit" class="ui submit green tiny button btn-start-review">{{$.root.locale.Tr "repo.diff.comment.start_review"}}</button>
35+
<button name="single_review" value="true" type="submit" class="ui submit tiny basic button btn-add-single">{{$.root.locale.Tr "repo.diff.comment.add_single_comment"}}</button>
4136
{{end}}
4237
{{end}}
4338
{{if or (not $.HasComments) $.hidden}}

web_src/js/features/repo-diff.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,8 @@ export function initRepoDiffReviewButton() {
1111
const $reviewBox = $('#review-box');
1212
const $counter = $reviewBox.find('.review-comments-counter');
1313

14-
$(document).on('click', 'button[name="is_review"]', (e) => {
14+
$(document).on('click', 'button[name="pending_review"]', (e) => {
1515
const $form = $(e.target).closest('form');
16-
$form.append('<input type="hidden" name="is_review" value="true">');
17-
1816
// Watch for the form's submit event.
1917
$form.on('submit', () => {
2018
const num = parseInt($counter.attr('data-pending-comment-number')) + 1 || 1;
@@ -50,7 +48,15 @@ export function initRepoDiffConversationForm() {
5048
return;
5149
}
5250

53-
const formDataString = String(new URLSearchParams(new FormData($form[0])));
51+
const formData = new FormData($form[0]);
52+
53+
// if the form is submitted by a button, append the button's name and value to the form data
54+
const submitter = e.originalEvent?.submitter;
55+
const isSubmittedByButton = (submitter?.nodeName === 'BUTTON') || (submitter?.nodeName === 'INPUT' && submitter.type === 'submit');
56+
if (isSubmittedByButton && submitter.name) {
57+
formData.append(submitter.name, submitter.value);
58+
}
59+
const formDataString = String(new URLSearchParams(formData));
5460
const $newConversationHolder = $(await $.post($form.attr('action'), formDataString));
5561
const {path, side, idx} = $newConversationHolder.data();
5662

web_src/js/features/repo-issue.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ export function initRepoPullRequestReview() {
535535

536536
const td = ntr.find(`.add-comment-${side}`);
537537
let commentCloud = td.find('.comment-code-cloud');
538-
if (commentCloud.length === 0 && !ntr.find('button[name="is_review"]').length) {
538+
if (commentCloud.length === 0 && !ntr.find('button[name="pending_review"]').length) {
539539
const data = await $.get($(this).closest('[data-new-comment-url]').data('new-comment-url'));
540540
td.html(data);
541541
commentCloud = td.find('.comment-code-cloud');

web_src/less/_repository.less

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -963,10 +963,6 @@
963963
}
964964
}
965965

966-
.comment-form-reply .footer {
967-
padding-bottom: 1em;
968-
}
969-
970966
@media @mediaSm {
971967
.ui.segments {
972968
margin-left: -2rem;
@@ -3282,7 +3278,7 @@ td.blob-excerpt {
32823278
position: sticky;
32833279
top: 77px;
32843280
z-index: 7;
3285-
3281+
32863282
@media (max-width: 480px) {
32873283
position: static;
32883284
}

0 commit comments

Comments
 (0)