Skip to content

Commit 50bab1b

Browse files
chore: remove the add comment on the line section. fix the hsaComments logic
1 parent 649201d commit 50bab1b

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

routers/web/repo/compare.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -956,8 +956,8 @@ func ExcerptBlob(ctx *context.Context) {
956956
return
957957
}
958958
lineCommits := allComments[filePath]
959-
for _, line := range section.Lines {
960-
if line.SectionInfo != nil && line.SectionInfo.RightHunkSize > 0 {
959+
for index, line := range section.Lines {
960+
if line.SectionInfo != nil && line.Type == 4 && !(line.SectionInfo.LastRightIdx == 0 && index+1 == len(section.Lines)) {
961961
start := int64(line.SectionInfo.LastRightIdx + 1)
962962
end := int64(line.SectionInfo.RightIdx - 1)
963963
for start <= end {

services/gitdiff/gitdiff.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ func (d *DiffLine) GetHTMLDiffLineType() string {
121121

122122
// CanComment returns whether a line can get commented
123123
func (d *DiffLine) CanComment() bool {
124-
return len(d.Comments) == 0
124+
return len(d.Comments) == 0 && d.Type != DiffLineSection
125125
}
126126

127127
// GetCommentSide returns the comment side of the first comment, if not set returns empty string
@@ -481,8 +481,8 @@ func (diff *Diff) LoadComments(ctx context.Context, issue *issues_model.Issue, c
481481
for _, file := range diff.Files {
482482
if lineCommits, ok := allComments[file.Name]; ok {
483483
for _, section := range file.Sections {
484-
for _, line := range section.Lines {
485-
if line.SectionInfo != nil && line.SectionInfo.RightHunkSize > 0 {
484+
for index, line := range section.Lines {
485+
if line.SectionInfo != nil && line.Type == 4 && !(line.SectionInfo.LastRightIdx == 0 && index+1 == len(section.Lines)) {
486486
start := int64(line.SectionInfo.LastRightIdx + 1)
487487
end := int64(line.SectionInfo.RightIdx - 1)
488488
for start <= end {

services/gitdiff/gitdiff_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,7 @@ func TestDiff_LoadCommentsWithOutdated(t *testing.T) {
615615
}
616616

617617
func TestDiffLine_CanComment(t *testing.T) {
618-
assert.True(t, (&DiffLine{Type: DiffLineSection}).CanComment())
618+
assert.False(t, (&DiffLine{Type: DiffLineSection}).CanComment())
619619
assert.False(t, (&DiffLine{Type: DiffLineAdd, Comments: []*issues_model.Comment{{Content: "bla"}}}).CanComment())
620620
assert.True(t, (&DiffLine{Type: DiffLineAdd}).CanComment())
621621
assert.True(t, (&DiffLine{Type: DiffLineDel}).CanComment())

0 commit comments

Comments
 (0)