Skip to content

Commit 4befec2

Browse files
authored
Code review UI improvements and bugfixes (#4682)
* Code review UI improvements * More fixes to dark theme * Style fix * Fix to allow add code review comments only on review files tab * More readability dark style fixes * Fix commenting on deleted files. Fixes #4752 * Fix line blame getting for multiple corner cases
1 parent 756eafa commit 4befec2

File tree

11 files changed

+101
-33
lines changed

11 files changed

+101
-33
lines changed

models/git_diff.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ func (diff *Diff) NumFiles() int {
273273
}
274274

275275
// Example: @@ -1,8 +1,9 @@ => [..., 1, 8, 1, 9]
276-
var hunkRegex = regexp.MustCompile(`^@@ -([0-9]+),([0-9]+) \+([0-9]+),([0-9]+) @@`)
276+
var hunkRegex = regexp.MustCompile(`^@@ -([0-9]+),([0-9]+) \+([0-9]+)(,([0-9]+))? @@`)
277277

278278
func isHeader(lof string) bool {
279279
return strings.HasPrefix(lof, cmdDiffHead) || strings.HasPrefix(lof, "---") || strings.HasPrefix(lof, "+++")
@@ -319,7 +319,11 @@ func CutDiffAroundLine(originalDiff io.Reader, line int64, old bool, numbersOfLi
319319
otherLine = com.StrTo(groups[3]).MustInt64()
320320
} else {
321321
begin = com.StrTo(groups[3]).MustInt64()
322-
end = com.StrTo(groups[4]).MustInt64()
322+
if groups[5] != "" {
323+
end = com.StrTo(groups[5]).MustInt64()
324+
} else {
325+
end = 0
326+
}
323327
// init otherLine with begin of opposite side
324328
otherLine = com.StrTo(groups[1]).MustInt64()
325329
}

models/issue_comment.go

+10-10
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ func (c *Comment) checkInvalidation(e Engine, doer *User, repo *git.Repository,
392392
if err != nil {
393393
return err
394394
}
395-
if c.CommitSHA != commit.ID.String() {
395+
if c.CommitSHA != "" && c.CommitSHA != commit.ID.String() {
396396
c.Invalidated = true
397397
return UpdateComment(doer, c, "")
398398
}
@@ -824,17 +824,18 @@ func CreateCodeComment(doer *User, repo *Repository, issue *Issue, content, tree
824824
if err != nil {
825825
return nil, fmt.Errorf("OpenRepository: %v", err)
826826
}
827-
// FIXME differentiate between previous and proposed line
828-
var gitLine = line
829-
if gitLine < 0 {
830-
gitLine *= -1
831-
}
827+
832828
// FIXME validate treePath
833829
// Get latest commit referencing the commented line
834-
commit, err := gitRepo.LineBlame(pr.GetGitRefName(), gitRepo.Path, treePath, uint(gitLine))
835-
if err != nil {
836-
return nil, fmt.Errorf("LineBlame[%s, %s, %s, %d]: %v", pr.GetGitRefName(), gitRepo.Path, treePath, gitLine, err)
830+
// No need for get commit for base branch changes
831+
if line > 0 {
832+
commit, err := gitRepo.LineBlame(pr.GetGitRefName(), gitRepo.Path, treePath, uint(line))
833+
if err != nil {
834+
return nil, fmt.Errorf("LineBlame[%s, %s, %s, %d]: %v", pr.GetGitRefName(), gitRepo.Path, treePath, line, err)
835+
}
836+
commitID = commit.ID.String()
837837
}
838+
838839
// Only fetch diff if comment is review comment
839840
if reviewID != 0 {
840841
headCommitID, err := gitRepo.GetRefCommitID(pr.GetGitRefName())
@@ -846,7 +847,6 @@ func CreateCodeComment(doer *User, repo *Repository, issue *Issue, content, tree
846847
return nil, fmt.Errorf("GetRawDiffForLine[%s, %s, %s, %s]: %v", err, gitRepo.Path, pr.MergeBase, headCommitID, treePath)
847848
}
848849
patch = CutDiffAroundLine(strings.NewReader(patchBuf.String()), int64((&Comment{Line: line}).UnsignedLine()), line < 0, setting.UI.CodeCommentLines)
849-
commitID = commit.ID.String()
850850
}
851851
return CreateComment(&CreateCommentOptions{
852852
Type: CommentTypeCode,

public/css/index.css

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/css/theme-arc-green.css

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/js/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,7 @@ function initPullRequestReview() {
780780
$("#show-outdated-" + id).removeClass('hide');
781781
});
782782

783-
$('.comment-form-reply').on('click', function (e) {
783+
$('button.comment-form-reply').on('click', function (e) {
784784
e.preventDefault();
785785
$(this).hide();
786786
var form = $(this).parent().find('.comment-form')
@@ -2649,7 +2649,7 @@ function cancelCodeComment(btn) {
26492649
var form = $(btn).closest("form");
26502650
if(form.length > 0 && form.hasClass('comment-form')) {
26512651
form.addClass('hide');
2652-
form.parent().find('.comment-form-reply').show();
2652+
form.parent().find('button.comment-form-reply').show();
26532653
}else {
26542654
console.log("Hey");
26552655
form.closest('.comment-code-cloud').remove()

public/less/_review.less

+21-10
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,21 @@
4242
top: -13px;
4343
}
4444

45-
.attached.tab {
46-
border: none;
47-
padding: 0;
48-
margin: 0;
49-
50-
&.markdown {
51-
padding: 1em;
52-
min-height: 168px;
45+
.attached
46+
{
47+
&.tab {
48+
border: none;
49+
padding: 0;
50+
margin: 0;
51+
52+
&.markdown {
53+
padding: 1em;
54+
min-height: 168px;
55+
}
56+
}
57+
58+
&.header {
59+
padding: .1rem 1rem;
5360
}
5461
}
5562

@@ -92,8 +99,12 @@
9299
}
93100
}
94101

95-
.comment-form-reply {
96-
margin: 0.5em !important;
102+
button.comment-form-reply {
103+
margin: 0.5em 0.5em 0.5em 4.5em;
104+
}
105+
106+
form.comment-form-reply {
107+
margin: 0 0 0 4em;
97108
}
98109
}
99110

public/less/themes/arc-green.less

+43-2
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,9 @@
181181
background: #404552;
182182
border: 2px solid #353945;
183183
color: #dbdbdb;
184+
}
185+
.ui.accordion .title:not(.ui) {
186+
color: #dbdbdb;
184187
}
185188
.ui.label {
186189
color: #dbdbdb;
@@ -195,9 +198,14 @@
195198
.issue.list > .item {
196199
border-bottom: 1px dashed #475767;
197200
}
198-
.ui.green.label, .ui.green.labels .label {
201+
.ui.green.label, .ui.green.labels .label, .ui.basic.green.label {
199202
background-color: #2d693b!important;
200203
border-color: #2d693b!important;
204+
}
205+
.ui.basic.green.labels a.label:hover, a.ui.basic.green.label:hover {
206+
background-color: #16ab39 !important;
207+
border-color: #16ab39 !important;
208+
color: #fff !important;
201209
}
202210
.issue.list > .item .comment {
203211
color: #129c92;
@@ -554,10 +562,17 @@
554562
}
555563
.ui.attached.info.message, .ui.info.message {
556564
box-shadow: 0 0 0 1px #4b5e71 inset, 0 0 0 0 transparent;
565+
}
566+
.ui.positive.message {
567+
background-color: #2c662d;
568+
color: #fcfff5;
557569
}
558570
.ui.info.message {
559571
background-color: #2c3b4a;
560572
color: #9ebcc5;
573+
}
574+
.CodeMirror div.CodeMirror-cursor {
575+
border-left: 1px solid #9e9e9e;
561576
}
562577
.ui .warning.header {
563578
background-color: #5d3a22 !important;
@@ -767,8 +782,34 @@
767782
}
768783

769784
.repository .diff-detail-box {
770-
background-color: inherit;
785+
background-color: #383c4a;
771786
.detail-files {
772787
background-color: inherit;
773788
}
774789
}
790+
791+
.comment-code-cloud {
792+
.ui.attached.tabular.menu {
793+
background: none transparent;
794+
border: none;
795+
}
796+
.footer .markdown-info {
797+
color: inherit;
798+
}
799+
}
800+
801+
.file-comment {
802+
color: #888;
803+
}
804+
805+
.ui.comments .comment {
806+
.author {
807+
color: #dbdbdb;
808+
}
809+
.metadata {
810+
color: #808084;
811+
}
812+
.text {
813+
color: #9e9e9e;
814+
}
815+
}

routers/repo/pull_review.go

+12-2
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,23 @@ func SubmitReview(ctx *context.Context, form auth.SubmitReviewForm) {
128128
}
129129
}
130130

131-
if form.HasEmptyContent() {
131+
review, err = models.GetCurrentReview(ctx.User, issue)
132+
if err == nil {
133+
review.Issue = issue
134+
if errl := review.LoadCodeComments(); errl != nil {
135+
ctx.ServerError("LoadCodeComments", err)
136+
return
137+
}
138+
}
139+
140+
if ((err == nil && len(review.CodeComments) == 0) ||
141+
(err != nil && models.IsErrReviewNotExist(err))) &&
142+
form.HasEmptyContent() {
132143
ctx.Flash.Error(ctx.Tr("repo.issues.review.content.empty"))
133144
ctx.Redirect(fmt.Sprintf("%s/pulls/%d/files", ctx.Repo.RepoLink, issue.Index))
134145
return
135146
}
136147

137-
review, err = models.GetCurrentReview(ctx.User, issue)
138148
if err != nil {
139149
if !models.IsErrReviewNotExist(err) {
140150
ctx.ServerError("GetCurrentReview", err)

templates/repo/diff/box.tmpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@
125125

126126
</td>
127127
<td class="lines-code lines-code-old halfwidth">
128-
{{if and $.root.SignedUserID $line.CanComment}}
128+
{{if and $.root.SignedUserID $line.CanComment $.root.PageIsPullFiles}}
129129
<a class="ui green button add-code-comment add-code-comment-left" data-path="{{$file.Name}}" data-side="left" data-idx="{{$line.LeftIdx}}">+</a>
130130
{{end}}
131131
<pre><code class="wrap {{if $highlightClass}}language-{{$highlightClass}}{{else}}nohighlight{{end}}">{{if $line.LeftIdx}}{{$section.GetComputedInlineDiffFor $line}}{{end}}</code></pre>

templates/repo/diff/comment_form.tmpl

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
{{if $.hidden}}
33
<button class="comment-form-reply ui green labeled icon tiny button"><i class="reply icon"></i> {{$.root.i18n.Tr "repo.diff.comment.reply"}}</button>
44
{{end}}
5-
<form class="ui form {{if $.hidden}}hide comment-form{{end}}" action="{{$.root.Issue.HTMLURL}}/files/reviews/comments" method="post">
5+
<form class="ui form {{if $.hidden}}hide comment-form comment-form-reply{{end}}" action="{{$.root.Issue.HTMLURL}}/files/reviews/comments" method="post">
66
{{$.root.CsrfTokenHtml}}
77
<input type="hidden" name="side" value="{{if $.Side}}{{$.Side}}{{end}}">
88
<input type="hidden" name="line" value="{{if $.Line}}{{$.Line}}{{end}}">
@@ -34,8 +34,10 @@
3434
class="ui submit green tiny button btn-start-review">{{$.root.i18n.Tr "repo.diff.comment.start_review"}}</button>
3535
{{end}}
3636
{{end}}
37+
{{if not $.root.CurrentReview}}
3738
<button type="submit"
3839
class="ui submit tiny basic button btn-add-single">{{$.root.i18n.Tr "repo.diff.comment.add_single_comment"}}</button>
40+
{{end}}
3941
{{if or (not $.HasComments) $.hidden}}
4042
<button type="button" class="ui submit tiny basic button btn-cancel" onclick="cancelCodeComment(this);">{{$.root.i18n.Tr "cancel"}}</button>
4143
{{end}}

templates/repo/diff/section_unified.tmpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
</td>
1717
{{end}}
1818
<td class="lines-code {{if (not $line.RightIdx)}}lines-code-old{{end}}">
19-
{{if and $.root.SignedUserID $line.CanComment}}
19+
{{if and $.root.SignedUserID $line.CanComment $.root.PageIsPullFiles}}
2020
<a class="ui green button add-code-comment add-code-comment-{{if $line.RightIdx}}right{{else}}left{{end}}" data-path="{{$file.Name}}" data-side="{{if $line.RightIdx}}right{{else}}left{{end}}" data-idx="{{if $line.RightIdx}}{{$line.RightIdx}}{{else}}{{$line.LeftIdx}}{{end}}">+</a>
2121
{{end}}
2222
<pre><code class="wrap {{if $highlightClass}}language-{{$highlightClass}}{{else}}nohighlight{{end}}">{{$section.GetComputedInlineDiffFor $line}}</code></pre>

0 commit comments

Comments
 (0)