From 9e1f7604068c4876697282eba2988e9543717864 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Thu, 2 Mar 2023 20:52:47 +0800 Subject: [PATCH] fix --- routers/api/v1/repo/pull_review.go | 4 ++-- routers/web/repo/pull_review.go | 2 +- services/forms/repo_form.go | 2 +- services/mailer/incoming/incoming_handler.go | 2 +- services/pull/review.go | 8 ++++---- templates/repo/diff/comment_form.tmpl | 13 ++++--------- web_src/js/features/repo-diff.js | 14 ++++++++++---- web_src/js/features/repo-issue.js | 2 +- web_src/less/_repository.less | 6 +----- 9 files changed, 25 insertions(+), 28 deletions(-) diff --git a/routers/api/v1/repo/pull_review.go b/routers/api/v1/repo/pull_review.go index f6acaa780a02..8f4b9dafec67 100644 --- a/routers/api/v1/repo/pull_review.go +++ b/routers/api/v1/repo/pull_review.go @@ -268,7 +268,7 @@ func DeletePullReview(ctx *context.APIContext) { ctx.Status(http.StatusNoContent) } -// CreatePullReview create a review to an pull request +// CreatePullReview create a review to a pull request func CreatePullReview(ctx *context.APIContext) { // swagger:operation POST /repos/{owner}/{repo}/pulls/{index}/reviews repository repoCreatePullReview // --- @@ -360,7 +360,7 @@ func CreatePullReview(ctx *context.APIContext) { line, c.Body, c.Path, - true, // is review + true, // pending review 0, // no reply opts.CommitID, ); err != nil { diff --git a/routers/web/repo/pull_review.go b/routers/web/repo/pull_review.go index d43a786c5668..90cfd5bfcdb3 100644 --- a/routers/web/repo/pull_review.go +++ b/routers/web/repo/pull_review.go @@ -77,7 +77,7 @@ func CreateCodeComment(ctx *context.Context) { signedLine, form.Content, form.TreePath, - form.IsReview, + !form.SingleReview, form.Reply, form.LatestCommitID, ) diff --git a/services/forms/repo_form.go b/services/forms/repo_form.go index e9645b5ab737..3bd073c070d3 100644 --- a/services/forms/repo_form.go +++ b/services/forms/repo_form.go @@ -622,7 +622,7 @@ type CodeCommentForm struct { Side string `binding:"Required;In(previous,proposed)"` Line int64 TreePath string `form:"path" binding:"Required"` - IsReview bool `form:"is_review"` + SingleReview bool `form:"single_review"` Reply int64 `form:"reply"` LatestCommitID string } diff --git a/services/mailer/incoming/incoming_handler.go b/services/mailer/incoming/incoming_handler.go index d89a5eab3d1b..454039c60fb5 100644 --- a/services/mailer/incoming/incoming_handler.go +++ b/services/mailer/incoming/incoming_handler.go @@ -127,7 +127,7 @@ func (h *ReplyHandler) Handle(ctx context.Context, content *MailContent, doer *u comment.Line, content.Content, comment.TreePath, - false, + false, // not pending review but a single review comment.ReviewID, "", ) diff --git a/services/pull/review.go b/services/pull/review.go index ca386ca6b027..ba93b5e2f540 100644 --- a/services/pull/review.go +++ b/services/pull/review.go @@ -71,7 +71,7 @@ func InvalidateCodeComments(ctx context.Context, prs issues_model.PullRequestLis } // CreateCodeComment creates a comment on the code line -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) { +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) { var ( existsReview bool err error @@ -82,7 +82,7 @@ func CreateCodeComment(ctx context.Context, doer *user_model.User, gitRepo *git. // - Comments that are part of a review // - Comments that reply to an existing review - if !isReview && replyReviewID != 0 { + if !pendingReview && replyReviewID != 0 { // It's not part of a review; maybe a reply to a review comment or a single comment. // Check if there are reviews for that line already; if there are, this is a reply 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. } // Comments that are replies don't require a review header to show up in the issue view - if !isReview && existsReview { + if !pendingReview && existsReview { if err = issue.LoadRepo(ctx); err != nil { return nil, err } @@ -149,7 +149,7 @@ func CreateCodeComment(ctx context.Context, doer *user_model.User, gitRepo *git. return nil, err } - if !isReview && !existsReview { + if !pendingReview && !existsReview { // Submit the review we've just created so the comment shows up in the issue view if _, _, err = SubmitReview(ctx, doer, gitRepo, issue, issues_model.ReviewTypeComment, "", latestCommitID, nil); err != nil { return nil, err diff --git a/templates/repo/diff/comment_form.tmpl b/templates/repo/diff/comment_form.tmpl index 407f84e5c900..225e40f7f01d 100644 --- a/templates/repo/diff/comment_form.tmpl +++ b/templates/repo/diff/comment_form.tmpl @@ -1,5 +1,5 @@ {{if and $.root.SignedUserID (not $.Repository.IsArchived)}} -
+ {{$.root.CsrfTokenHtml}} @@ -29,15 +29,10 @@ {{else}} {{if $.root.CurrentReview}} - {{/* 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 */}} - - + {{else}} - - + + {{end}} {{end}} {{if or (not $.HasComments) $.hidden}} diff --git a/web_src/js/features/repo-diff.js b/web_src/js/features/repo-diff.js index d2559b123707..56ebe4fc991e 100644 --- a/web_src/js/features/repo-diff.js +++ b/web_src/js/features/repo-diff.js @@ -11,10 +11,8 @@ export function initRepoDiffReviewButton() { const $reviewBox = $('#review-box'); const $counter = $reviewBox.find('.review-comments-counter'); - $(document).on('click', 'button[name="is_review"]', (e) => { + $(document).on('click', 'button[name="pending_review"]', (e) => { const $form = $(e.target).closest('form'); - $form.append(''); - // Watch for the form's submit event. $form.on('submit', () => { const num = parseInt($counter.attr('data-pending-comment-number')) + 1 || 1; @@ -50,7 +48,15 @@ export function initRepoDiffConversationForm() { return; } - const formDataString = String(new URLSearchParams(new FormData($form[0]))); + const formData = new FormData($form[0]); + + // if the form is submitted by a button, append the button's name and value to the form data + const submitter = e.originalEvent?.submitter; + const isSubmittedByButton = (submitter?.nodeName === 'BUTTON') || (submitter?.nodeName === 'INPUT' && submitter.type === 'submit'); + if (isSubmittedByButton && submitter.name) { + formData.append(submitter.name, submitter.value); + } + const formDataString = String(new URLSearchParams(formData)); const $newConversationHolder = $(await $.post($form.attr('action'), formDataString)); const {path, side, idx} = $newConversationHolder.data(); diff --git a/web_src/js/features/repo-issue.js b/web_src/js/features/repo-issue.js index 4fc8bb5e62d9..e824f7177041 100644 --- a/web_src/js/features/repo-issue.js +++ b/web_src/js/features/repo-issue.js @@ -531,7 +531,7 @@ export function initRepoPullRequestReview() { const td = ntr.find(`.add-comment-${side}`); let commentCloud = td.find('.comment-code-cloud'); - if (commentCloud.length === 0 && !ntr.find('button[name="is_review"]').length) { + if (commentCloud.length === 0 && !ntr.find('button[name="pending_review"]').length) { const data = await $.get($(this).closest('[data-new-comment-url]').data('new-comment-url')); td.html(data); commentCloud = td.find('.comment-code-cloud'); diff --git a/web_src/less/_repository.less b/web_src/less/_repository.less index abbacfb53246..9eaa8644f141 100644 --- a/web_src/less/_repository.less +++ b/web_src/less/_repository.less @@ -963,10 +963,6 @@ } } - .comment-form-reply .footer { - padding-bottom: 1em; - } - @media @mediaSm { .ui.segments { margin-left: -2rem; @@ -3282,7 +3278,7 @@ td.blob-excerpt { position: sticky; top: 77px; z-index: 7; - + @media (max-width: 480px) { position: static; }