From 274ed544842fe81fe9fa3a901022d3d5968d7330 Mon Sep 17 00:00:00 2001
From: Rajesh Jonnalagadda <rajeshjonnalagadda48@gmail.com>
Date: Mon, 11 Nov 2024 07:03:55 +0530
Subject: [PATCH 01/13] feat: phase 1 changes: add comments feat to unchanged
 lines in the pull request.

---
 routers/web/repo/compare.go              | 113 ++++++++++++++++++++---
 routers/web/web.go                       |   5 +
 services/gitdiff/gitdiff.go              |  73 +++++++++++----
 services/repository/files/diff_test.go   |  17 ++--
 templates/repo/diff/blob_excerpt.tmpl    |  98 +++++++++++++++-----
 templates/repo/diff/section_split.tmpl   |  41 ++++----
 templates/repo/diff/section_unified.tmpl |  20 +++-
 web_src/css/base.css                     |   7 ++
 8 files changed, 292 insertions(+), 82 deletions(-)

diff --git a/routers/web/repo/compare.go b/routers/web/repo/compare.go
index 3927972837..eaea91b584 100644
--- a/routers/web/repo/compare.go
+++ b/routers/web/repo/compare.go
@@ -14,6 +14,7 @@ import (
 	"net/http"
 	"net/url"
 	"path/filepath"
+	"sort"
 	"strings"
 
 	"code.gitea.io/gitea/models/db"
@@ -39,6 +40,7 @@ import (
 	"code.gitea.io/gitea/services/context"
 	"code.gitea.io/gitea/services/context/upload"
 	"code.gitea.io/gitea/services/gitdiff"
+	user_service "code.gitea.io/gitea/services/user"
 )
 
 const (
@@ -864,6 +866,14 @@ func ExcerptBlob(ctx *context.Context) {
 	direction := ctx.FormString("direction")
 	filePath := ctx.FormString("path")
 	gitRepo := ctx.Repo.GitRepo
+	lastRightCommentIdx := ctx.FormInt("last_left_comment_idx")
+	rightCommentIdx := ctx.FormInt("left_comment_idx")
+	fileName := ctx.FormString("file_name")
+
+	if ctx.FormBool("pull") {
+		ctx.Data["PageIsPullFiles"] = true
+	}
+
 	if ctx.FormBool("wiki") {
 		var err error
 		gitRepo, err = gitrepo.OpenWikiRepository(ctx, ctx.Repo.Repository)
@@ -873,6 +883,17 @@ func ExcerptBlob(ctx *context.Context) {
 		}
 		defer gitRepo.Close()
 	}
+
+	issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, int64(2))
+
+	if err != nil {
+		ctx.ServerError("GetIssueByIndex", err)
+		return
+	}
+
+	allComments, err := issues_model.FetchCodeComments(ctx, issue, ctx.Doer, false)
+	lineCommits := allComments[fileName]
+
 	chunkSize := gitdiff.BlobExcerptChunkSize
 	commit, err := gitRepo.GetCommit(commitID)
 	if err != nil {
@@ -882,15 +903,16 @@ func ExcerptBlob(ctx *context.Context) {
 	section := &gitdiff.DiffSection{
 		FileName: filePath,
 		Name:     filePath,
+		Lines:    []*gitdiff.DiffLine{},
 	}
 	if direction == "up" && (idxLeft-lastLeft) > chunkSize {
 		idxLeft -= chunkSize
 		idxRight -= chunkSize
 		leftHunkSize += chunkSize
 		rightHunkSize += chunkSize
-		section.Lines, err = getExcerptLines(commit, filePath, idxLeft-1, idxRight-1, chunkSize)
+		section.Lines, err = getExcerptLines(commit, filePath, idxLeft-1, idxRight-1, chunkSize, lastRightCommentIdx, rightCommentIdx)
 	} else if direction == "down" && (idxLeft-lastLeft) > chunkSize {
-		section.Lines, err = getExcerptLines(commit, filePath, lastLeft, lastRight, chunkSize)
+		section.Lines, err = getExcerptLines(commit, filePath, lastLeft, lastRight, chunkSize, lastRightCommentIdx, rightCommentIdx)
 		lastLeft += chunkSize
 		lastRight += chunkSize
 	} else {
@@ -898,7 +920,7 @@ func ExcerptBlob(ctx *context.Context) {
 		if direction == "down" {
 			offset = 0
 		}
-		section.Lines, err = getExcerptLines(commit, filePath, lastLeft, lastRight, idxRight-lastRight+offset)
+		section.Lines, err = getExcerptLines(commit, filePath, lastLeft, lastRight, idxRight-lastRight+offset, lastRightCommentIdx, rightCommentIdx)
 		leftHunkSize = 0
 		rightHunkSize = 0
 		idxLeft = lastLeft
@@ -918,14 +940,18 @@ func ExcerptBlob(ctx *context.Context) {
 			Type:    gitdiff.DiffLineSection,
 			Content: lineText,
 			SectionInfo: &gitdiff.DiffLineSectionInfo{
-				Path:          filePath,
-				LastLeftIdx:   lastLeft,
-				LastRightIdx:  lastRight,
-				LeftIdx:       idxLeft,
-				RightIdx:      idxRight,
-				LeftHunkSize:  leftHunkSize,
-				RightHunkSize: rightHunkSize,
+				Path:                filePath,
+				LastLeftIdx:         lastLeft,
+				LastRightIdx:        lastRight,
+				LeftIdx:             idxLeft,
+				RightIdx:            idxRight,
+				LeftHunkSize:        leftHunkSize,
+				RightHunkSize:       rightHunkSize,
+				HasComments:         false,
+				LastRightCommentIdx: 0,
+				RightCommentIdx:     0,
 			},
+			Comments: nil,
 		}
 		if direction == "up" {
 			section.Lines = append([]*gitdiff.DiffLine{lineSection}, section.Lines...)
@@ -933,14 +959,74 @@ func ExcerptBlob(ctx *context.Context) {
 			section.Lines = append(section.Lines, lineSection)
 		}
 	}
+
+	for _, line := range section.Lines {
+		if line.SectionInfo != nil {
+			//for now considerign only right side.
+			start := int64(line.SectionInfo.LastRightIdx + 1)
+			end := int64(line.SectionInfo.RightIdx - 1)
+
+			//to check section has comments or not.
+			//1.  we can use binary search
+			//2. we can LastRightCommentIdx, RightCommentIdx, LastLeftCommentIdx, LeftCommentIdx(little complex but fast)
+			//3. for demo using linear search
+			for start <= end {
+				if _, ok := lineCommits[start]; ok {
+					if !line.SectionInfo.HasComments {
+						// line.SectionInfo.LastRightCommentIdx = int(start)
+						// line.SectionInfo.RightCommentIdx = int(start)
+						line.SectionInfo.HasComments = true
+						break
+					}
+
+				}
+				start += 1
+			}
+
+		}
+		if comments, ok := lineCommits[int64(line.LeftIdx*-1)]; ok {
+			line.Comments = append(line.Comments, comments...)
+		}
+		if comments, ok := lineCommits[int64(line.RightIdx)]; ok {
+			line.Comments = append(line.Comments, comments...)
+		}
+
+		sort.SliceStable(line.Comments, func(i, j int) bool {
+			return line.Comments[i].CreatedUnix < line.Comments[j].CreatedUnix
+		})
+	}
+
+	for _, line := range section.Lines {
+		for _, comment := range line.Comments {
+			if err := comment.LoadAttachments(ctx); err != nil {
+				ctx.ServerError("LoadAttachments", err)
+				return
+			}
+		}
+	}
+
 	ctx.Data["section"] = section
 	ctx.Data["FileNameHash"] = git.HashFilePathForWebUI(filePath)
 	ctx.Data["AfterCommitID"] = commitID
 	ctx.Data["Anchor"] = anchor
+	ctx.Data["Issue"] = issue
+	ctx.Data["issue"] = issue.Index
+	ctx.Data["SignedUserID"] = ctx.Data["SignedUserID"]
+	ctx.Data["CanBlockUser"] = func(blocker, blockee *user_model.User) bool {
+		return user_service.CanBlockUser(ctx, ctx.Doer, blocker, blockee)
+	}
+
+	if ctx.Data["SignedUserID"] == nil {
+		ctx.Data["SignedUserID"] = ctx.Doer.ID
+	}
+	ctx.Data["SignedUser"] = ctx.Doer
+	ctx.Data["IsSigned"] = ctx.Doer != nil
+	ctx.Data["Repository"] = ctx.Repo.Repository
+	ctx.Data["Permission"] = &ctx.Repo.Permission
 	ctx.HTML(http.StatusOK, tplBlobExcerpt)
 }
 
-func getExcerptLines(commit *git.Commit, filePath string, idxLeft, idxRight, chunkSize int) ([]*gitdiff.DiffLine, error) {
+func getExcerptLines(commit *git.Commit, filePath string, idxLeft, idxRight, chunkSize, lastRightCommentIdx, rightCommentIdx int) ([]*gitdiff.DiffLine, error) {
 	blob, err := commit.Tree.GetBlobByPath(filePath)
 	if err != nil {
 		return nil, err
@@ -965,7 +1051,12 @@ func getExcerptLines(commit *git.Commit, filePath string, idxLeft, idxRight, chu
 			RightIdx: line + 1,
 			Type:     gitdiff.DiffLinePlain,
 			Content:  " " + lineText,
+			Comments: []*issues_model.Comment{},
 		}
+		// if diffLine.SectionInfo != nil {
+		// 	diffLine.SectionInfo.LastRightCommentIdx = lastRightCommentIdx
+		// 	diffLine.SectionInfo.RightCommentIdx = rightCommentIdx
+		// }
 		diffLines = append(diffLines, diffLine)
 	}
 	if err = scanner.Err(); err != nil {
diff --git a/routers/web/web.go b/routers/web/web.go
index 29dd8a8edc..7573724134 100644
--- a/routers/web/web.go
+++ b/routers/web/web.go
@@ -1511,6 +1511,11 @@ func registerRoutes(m *web.Router) {
 			m.Get("/{sha}", repo.SetEditorconfigIfExists, repo.SetDiffViewStyle, repo.ExcerptBlob)
 		}, func(ctx *context.Context) gocontext.CancelFunc {
 			// FIXME: refactor this function, use separate routes for wiki/code
+			if ctx.FormBool("pull") {
+				ctx.Data["PageIsPullFiles"] = true
+
+			}
+
 			if ctx.FormBool("wiki") {
 				ctx.Data["PageIsWiki"] = true
 				repo.MustEnableWiki(ctx)
diff --git a/services/gitdiff/gitdiff.go b/services/gitdiff/gitdiff.go
index bb1722039e..1954be760a 100644
--- a/services/gitdiff/gitdiff.go
+++ b/services/gitdiff/gitdiff.go
@@ -86,13 +86,16 @@ type DiffLine struct {
 
 // DiffLineSectionInfo represents diff line section meta data
 type DiffLineSectionInfo struct {
-	Path          string
-	LastLeftIdx   int
-	LastRightIdx  int
-	LeftIdx       int
-	RightIdx      int
-	LeftHunkSize  int
-	RightHunkSize int
+	Path                string
+	LastLeftIdx         int
+	LastRightIdx        int
+	LeftIdx             int
+	RightIdx            int
+	LeftHunkSize        int
+	RightHunkSize       int
+	HasComments         bool
+	LastRightCommentIdx int
+	RightCommentIdx     int
 }
 
 // BlobExcerptChunkSize represent max lines of excerpt
@@ -118,7 +121,7 @@ func (d *DiffLine) GetHTMLDiffLineType() string {
 
 // CanComment returns whether a line can get commented
 func (d *DiffLine) CanComment() bool {
-	return len(d.Comments) == 0 && d.Type != DiffLineSection
+	return len(d.Comments) == 0
 }
 
 // GetCommentSide returns the comment side of the first comment, if not set returns empty string
@@ -143,10 +146,12 @@ func (d *DiffLine) GetBlobExcerptQuery() string {
 		"last_left=%d&last_right=%d&"+
 			"left=%d&right=%d&"+
 			"left_hunk_size=%d&right_hunk_size=%d&"+
+			"last_rightt_comment_idx=%d&right_comment_idx=%d&"+
 			"path=%s",
 		d.SectionInfo.LastLeftIdx, d.SectionInfo.LastRightIdx,
 		d.SectionInfo.LeftIdx, d.SectionInfo.RightIdx,
 		d.SectionInfo.LeftHunkSize, d.SectionInfo.RightHunkSize,
+		d.SectionInfo.LastRightCommentIdx, d.SectionInfo.RightCommentIdx,
 		url.QueryEscape(d.SectionInfo.Path))
 	return query
 }
@@ -170,13 +175,16 @@ func getDiffLineSectionInfo(treePath, line string, lastLeftIdx, lastRightIdx int
 	leftLine, leftHunk, rightLine, righHunk := git.ParseDiffHunkString(line)
 
 	return &DiffLineSectionInfo{
-		Path:          treePath,
-		LastLeftIdx:   lastLeftIdx,
-		LastRightIdx:  lastRightIdx,
-		LeftIdx:       leftLine,
-		RightIdx:      rightLine,
-		LeftHunkSize:  leftHunk,
-		RightHunkSize: righHunk,
+		Path:                treePath,
+		LastLeftIdx:         lastLeftIdx,
+		LastRightIdx:        lastRightIdx,
+		LeftIdx:             leftLine,
+		RightIdx:            rightLine,
+		LeftHunkSize:        leftHunk,
+		RightHunkSize:       righHunk,
+		HasComments:         false,
+		LastRightCommentIdx: 0,
+		RightCommentIdx:     0,
 	}
 }
 
@@ -396,11 +404,14 @@ func (diffFile *DiffFile) GetTailSection(gitRepo *git.Repository, leftCommit, ri
 		Type:    DiffLineSection,
 		Content: " ",
 		SectionInfo: &DiffLineSectionInfo{
-			Path:         diffFile.Name,
-			LastLeftIdx:  lastLine.LeftIdx,
-			LastRightIdx: lastLine.RightIdx,
-			LeftIdx:      leftLineCount,
-			RightIdx:     rightLineCount,
+			Path:                diffFile.Name,
+			LastLeftIdx:         lastLine.LeftIdx,
+			LastRightIdx:        lastLine.RightIdx,
+			LeftIdx:             leftLineCount,
+			RightIdx:            rightLineCount,
+			HasComments:         false,
+			LastRightCommentIdx: 0,
+			RightCommentIdx:     0,
 		},
 	}
 	tailSection := &DiffSection{FileName: diffFile.Name, Lines: []*DiffLine{tailDiffLine}}
@@ -458,16 +469,38 @@ type Diff struct {
 	NumViewedFiles               int // user-specific
 }
 
+// function (section *DiffSection) GetType() int {
+
 // LoadComments loads comments into each line
 func (diff *Diff) LoadComments(ctx context.Context, issue *issues_model.Issue, currentUser *user_model.User, showOutdatedComments bool) error {
 	allComments, err := issues_model.FetchCodeComments(ctx, issue, currentUser, showOutdatedComments)
 	if err != nil {
 		return err
 	}
+
 	for _, file := range diff.Files {
 		if lineCommits, ok := allComments[file.Name]; ok {
 			for _, section := range file.Sections {
 				for _, line := range section.Lines {
+					if line.SectionInfo != nil {
+						start := int64(line.SectionInfo.LastRightIdx + 1)
+						end := int64(line.SectionInfo.RightIdx - 1)
+
+						for start <= end {
+							if _, ok := lineCommits[start]; ok {
+								if line.SectionInfo.LastRightCommentIdx == 0 {
+									// line.SectionInfo.LastRightCommentIdx = int(start)
+									// line.SectionInfo.RightCommentIdx = int(start)
+									line.SectionInfo.HasComments = true
+
+									break
+								}
+
+							}
+							start += 1
+
+						}
+					}
 					if comments, ok := lineCommits[int64(line.LeftIdx*-1)]; ok {
 						line.Comments = append(line.Comments, comments...)
 					}
diff --git a/services/repository/files/diff_test.go b/services/repository/files/diff_test.go
index ea6ffe60c3..7b98886358 100644
--- a/services/repository/files/diff_test.go
+++ b/services/repository/files/diff_test.go
@@ -59,13 +59,16 @@ func TestGetDiffPreview(t *testing.T) {
 								Content:  "@@ -1,3 +1,4 @@",
 								Comments: nil,
 								SectionInfo: &gitdiff.DiffLineSectionInfo{
-									Path:          "README.md",
-									LastLeftIdx:   0,
-									LastRightIdx:  0,
-									LeftIdx:       1,
-									RightIdx:      1,
-									LeftHunkSize:  3,
-									RightHunkSize: 4,
+									Path:                "README.md",
+									LastLeftIdx:         0,
+									LastRightIdx:        0,
+									LeftIdx:             1,
+									RightIdx:            1,
+									LeftHunkSize:        3,
+									RightHunkSize:       4,
+									HasComments:         false,
+									LastRightCommentIdx: 0,
+									RightCommentIdx:     0,
 								},
 							},
 							{
diff --git a/templates/repo/diff/blob_excerpt.tmpl b/templates/repo/diff/blob_excerpt.tmpl
index cc2237029b..63d6f970b6 100644
--- a/templates/repo/diff/blob_excerpt.tmpl
+++ b/templates/repo/diff/blob_excerpt.tmpl
@@ -1,35 +1,49 @@
 {{if $.IsSplitStyle}}
 	{{range $k, $line := $.section.Lines}}
+	{{$inlineDiff := $.section.GetComputedInlineDiffFor $line ctx.Locale}}
 	<tr class="{{.GetHTMLDiffLineType}}-code nl-{{$k}} ol-{{$k}} line-expanded">
 		{{if eq .GetType 4}}
 			{{$expandDirection := $line.GetExpandDirection}}
 			<td class="lines-num lines-num-old" data-line-num="{{if $line.LeftIdx}}{{$line.LeftIdx}}{{end}}">
-				<div class="code-expander-buttons" data-expand-direction="{{$expandDirection}}">
-				{{if or (eq $expandDirection 3) (eq $expandDirection 5)}}
-					<button class="code-expander-button" hx-target="closest tr" hx-get="{{$.RepoLink}}/blob_excerpt/{{PathEscape $.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=split&direction=down&wiki={{$.PageIsWiki}}&anchor={{$.Anchor}}">
-						{{svg "octicon-fold-down"}}
-					</button>
-				{{end}}
-				{{if or (eq $expandDirection 3) (eq $expandDirection 4)}}
-					<button class="code-expander-button" hx-target="closest tr" hx-get="{{$.RepoLink}}/blob_excerpt/{{PathEscape $.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=split&direction=up&wiki={{$.PageIsWiki}}&anchor={{$.Anchor}}">
-						{{svg "octicon-fold-up"}}
-					</button>
-				{{end}}
-				{{if eq $expandDirection 2}}
-					<button class="code-expander-button" hx-target="closest tr" hx-get="{{$.RepoLink}}/blob_excerpt/{{PathEscape $.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=split&direction=&wiki={{$.PageIsWiki}}&anchor={{$.Anchor}}">
-						{{svg "octicon-fold"}}
-					</button>
-				{{end}}
-				</div>
-			</td>
+        	  <div class="lines-comment">
+        	    <div>
+        	      {{if $line.SectionInfo.HasComments}}
+        	        <button>
+        	          {{svg "octicon-comment-discussion"}}
+        	        </button>
+        	      {{end}}
+        	    </div>
+        	    <div class="code-expander-buttons" data-expand-direction="{{$expandDirection}}">
+        	      {{if or (eq $expandDirection 3) (eq $expandDirection 5)}}
+        	        <button class="code-expander-button" hx-target="closest tr" hx-get="{{$.RepoLink}}/blob_excerpt/{{PathEscape $.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=split&direction=down&wiki={{$.PageIsWiki}}&pull={{$.PageIsPullFiles}}&anchor={{$.Anchor}}&file_name={{$.section.FileName}}">
+        	          {{svg "octicon-fold-down"}}
+        	        </button>
+        	      {{end}}
+        	      {{if or (eq $expandDirection 3) (eq $expandDirection 4)}}
+        	        <button class="code-expander-button" hx-target="closest tr" hx-get="{{$.RepoLink}}/blob_excerpt/{{PathEscape $.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=split&direction=up&wiki={{$.PageIsWiki}}&pull={{$.PageIsPullFiles}}&anchor={{$.Anchor}}&file_name={{$.section.FileName}}">
+        	          {{svg "octicon-fold-up"}}
+        	        </button>
+        	      {{end}}
+        	      {{if eq $expandDirection 2}}
+        	        <button class="code-expander-button" hx-target="closest tr" hx-get="{{$.RepoLink}}/blob_excerpt/{{PathEscape $.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=split&direction=&wiki={{$.PageIsWiki}}&pull={{$.PageIsPullFiles}}&anchor={{$.Anchor}}&file_name={{$.section.FileName}}">
+        	          {{svg "octicon-fold"}}
+        	        </button>
+        	      {{end}}
+        	    </div>
+        	  </div>
+        	</td>
 			<td colspan="7" class="lines-code lines-code-old ">{{$inlineDiff := $.section.GetComputedInlineDiffFor $line ctx.Locale}}{{/*
 				*/}}{{template "repo/diff/section_code" dict "diff" $inlineDiff}}</td>
 		{{else}}
-			{{$inlineDiff := $.section.GetComputedInlineDiffFor $line ctx.Locale}}
 			<td class="lines-num lines-num-old" data-line-num="{{if $line.LeftIdx}}{{$line.LeftIdx}}{{end}}"><span rel="{{if $line.LeftIdx}}diff-{{$.FileNameHash}}L{{$line.LeftIdx}}{{end}}"></span></td>
 			<td class="lines-escape lines-escape-old">{{if and $line.LeftIdx $inlineDiff.EscapeStatus.Escaped}}<button class="toggle-escape-button btn interact-bg" title="{{template "repo/diff/escape_title" dict "diff" $inlineDiff}}"></button>{{end}}</td>
 			<td class="lines-type-marker lines-type-marker-old">{{if $line.LeftIdx}}<span class="tw-font-mono" data-type-marker=""></span>{{end}}</td>
 			<td class="lines-code lines-code-old">{{/*
+			*/}}{{if and $.SignedUserID $.PageIsPullFiles}}{{/*
+					*/}}<button type="button" aria-label="{{ctx.Locale.Tr "repo.diff.comment.add_line_comment"}}" class="ui primary button add-code-comment add-code-comment-{{if $line.RightIdx}}right{{else}}left{{end}}{{if (not $line.CanComment)}} tw-invisible{{end}}" data-side="{{if $line.RightIdx}}right{{else}}left{{end}}" data-idx="{{if $line.RightIdx}}{{$line.RightIdx}}{{else}}{{$line.LeftIdx}}{{end}}">{{/*
+						*/}}{{svg "octicon-plus"}}{{/*
+						*/}}</button>{{/*
+				*/}}{{end}}{{/*
 				*/}}{{if $line.LeftIdx}}{{template "repo/diff/section_code" dict "diff" $inlineDiff}}{{else}}{{/*
 					*/}}<code class="code-inner"></code>{{/*
 				*/}}{{end}}{{/*
@@ -38,45 +52,81 @@
 			<td class="lines-escape lines-escape-new">{{if and $line.RightIdx $inlineDiff.EscapeStatus.Escaped}}<button class="toggle-escape-button btn interact-bg" title="{{template "repo/diff/escape_title" dict "diff" $inlineDiff}}"></button>{{end}}</td>
 			<td class="lines-type-marker lines-type-marker-new">{{if $line.RightIdx}}<span class="tw-font-mono" data-type-marker=""></span>{{end}}</td>
 			<td class="lines-code lines-code-new">{{/*
+			*/}}{{if and $.SignedUserID $.PageIsPullFiles}}{{/*
+					*/}}<button type="button" aria-label="{{ctx.Locale.Tr "repo.diff.comment.add_line_comment"}}" class="ui primary button add-code-comment add-code-comment-{{if $line.RightIdx}}right{{else}}left{{end}}{{if (not $line.CanComment)}} tw-invisible{{end}}" data-side="{{if $line.RightIdx}}right{{else}}left{{end}}" data-idx="{{if $line.RightIdx}}{{$line.RightIdx}}{{else}}{{$line.LeftIdx}}{{end}}">{{/*
+						*/}}{{svg "octicon-plus"}}{{/*
+						*/}}</button>{{/*
+				*/}}{{end}}{{/*
 				*/}}{{if $line.RightIdx}}{{template "repo/diff/section_code" dict "diff" $inlineDiff}}{{else}}{{/*
 					*/}}<code class="code-inner"></code>{{/*
 				*/}}{{end}}{{/*
 			*/}}</td>
 		{{end}}
 	</tr>
+	{{if $line.Comments}}
+			<tr class="add-comment" data-line-type="{{.GetHTMLDiffLineType}}">
+				<td class="add-comment-right" colspan="5">
+					{{template "repo/diff/conversation" dict "." $ "comments" $line.Comments}}}
+				</td>
+			</tr>
+		{{end}}
 	{{end}}
 {{else}}
 	{{range $k, $line := $.section.Lines}}
+	{{$inlineDiff := $.section.GetComputedInlineDiffFor $line ctx.Locale}}
 	<tr class="{{.GetHTMLDiffLineType}}-code nl-{{$k}} ol-{{$k}} line-expanded">
 		{{if eq .GetType 4}}
 			{{$expandDirection := $line.GetExpandDirection}}
 			<td colspan="2" class="lines-num">
+			 <div class="lines-comment">
+        	    <div>
+        	      {{if $line.SectionInfo.HasComments}}
+        	        <button>
+        	          {{svg "octicon-comment-discussion"}}
+        	        </button>
+        	      {{end}}
+        	    </div>
 				<div class="code-expander-buttons" data-expand-direction="{{$expandDirection}}">
 					{{if or (eq $expandDirection 3) (eq $expandDirection 5)}}
-						<button class="code-expander-button" hx-target="closest tr" hx-get="{{$.RepoLink}}/blob_excerpt/{{PathEscape $.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=unified&direction=down&wiki={{$.PageIsWiki}}&anchor={{$.Anchor}}">
+						<button class="code-expander-button" hx-target="closest tr" hx-get="{{$.RepoLink}}/blob_excerpt/{{PathEscape $.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=unified&direction=down&wiki={{$.PageIsWiki}}&pull={{$.PageIsPullFiles}}&anchor={{$.Anchor}}&file_name={{$.section.FileName}}">
 							{{svg "octicon-fold-down"}}
 						</button>
+						test else down blob {{$line.SectionInfo.HasComments}}
 					{{end}}
 					{{if or (eq $expandDirection 3) (eq $expandDirection 4)}}
-						<button class="code-expander-button" hx-target="closest tr" hx-get="{{$.RepoLink}}/blob_excerpt/{{PathEscape $.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=unified&direction=up&wiki={{$.PageIsWiki}}&anchor={{$.Anchor}}">
+						<button class="code-expander-button" hx-target="closest tr" hx-get="{{$.RepoLink}}/blob_excerpt/{{PathEscape $.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=unified&direction=up&wiki={{$.PageIsWiki}}&pull={{$.PageIsPullFiles}}&anchor={{$.Anchor}}&file_name={{$.section.FileName}}">
 							{{svg "octicon-fold-up"}}
 						</button>
+						test else up  blob
 					{{end}}
 					{{if eq $expandDirection 2}}
-						<button class="code-expander-button" hx-target="closest tr" hx-get="{{$.RepoLink}}/blob_excerpt/{{PathEscape $.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=unified&direction=&wiki={{$.PageIsWiki}}&anchor={{$.Anchor}}">
+						<button class="code-expander-button" hx-target="closest tr" hx-get="{{$.RepoLink}}/blob_excerpt/{{PathEscape $.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=unified&direction=&wiki={{$.PageIsWiki}}&pull={{$.PageIsPullFiles}}&anchor={{$.Anchor}}&file_name={{$.section.FileName}}">
 							{{svg "octicon-fold"}}
 						</button>
+						test else both  blob
 					{{end}}
 				</div>
+			 </div>	
 			</td>
 		{{else}}
 			<td class="lines-num lines-num-old" data-line-num="{{if $line.LeftIdx}}{{$line.LeftIdx}}{{end}}"><span rel="{{if $line.LeftIdx}}diff-{{$.FileNameHash}}L{{$line.LeftIdx}}{{end}}"></span></td>
 			<td class="lines-num lines-num-new" data-line-num="{{if $line.RightIdx}}{{$line.RightIdx}}{{end}}"><span rel="{{if $line.RightIdx}}diff-{{$.FileNameHash}}R{{$line.RightIdx}}{{end}}"></span></td>
 		{{end}}
-		{{$inlineDiff := $.section.GetComputedInlineDiffFor $line ctx.Locale}}
 		<td class="lines-escape">{{if $inlineDiff.EscapeStatus.Escaped}}<button class="toggle-escape-button btn interact-bg" title="{{template "repo/diff/escape_title" dict "diff" $inlineDiff}}"></button>{{end}}</td>
 		<td class="lines-type-marker"><span class="tw-font-mono" data-type-marker="{{$line.GetLineTypeMarker}}"></span></td>
-		<td class="lines-code{{if (not $line.RightIdx)}} lines-code-old{{end}}"><code {{if $inlineDiff.EscapeStatus.Escaped}}class="code-inner has-escaped" title="{{template "repo/diff/escape_title" dict "diff" $inlineDiff}}"{{else}}class="code-inner"{{end}}>{{$inlineDiff.Content}}</code></td>
+		<td class="lines-code{{if (not $line.RightIdx)}} lines-code-old{{end}}">
+		{{if and $.SignedUserID $.PageIsPullFiles}}
+		<button type="button" aria-label="{{ctx.Locale.Tr "repo.diff.comment.add_line_comment"}}" class="ui primary button add-code-comment add-code-comment-{{if $line.RightIdx}}right{{else}}left{{end}}{{if (not $line.CanComment)}} tw-invisible{{end}}" data-side="{{if $line.RightIdx}}right{{else}}left{{end}}" data-idx="{{if $line.RightIdx}}{{$line.RightIdx}}{{else}}{{$line.LeftIdx}}{{end}}">{{svg "octicon-plus"}}
+		</button>
+		{{end}}
+			<code {{if $inlineDiff.EscapeStatus.Escaped}}class="code-inner has-escaped" title="{{template "repo/diff/escape_title" dict "diff" $inlineDiff}}"{{else}}class="code-inner"{{end}}>{{$inlineDiff.Content}}</code></td>	
 	</tr>
+	{{if $line.Comments}}
+			<tr class="add-comment" data-line-type="{{.GetHTMLDiffLineType}}">
+				<td class="add-comment-right" colspan="5">
+					{{template "repo/diff/conversation" dict "." $ "comments" $line.Comments}}
+				</td>
+			</tr>
+		{{end}}
 	{{end}}
 {{end}}
diff --git a/templates/repo/diff/section_split.tmpl b/templates/repo/diff/section_split.tmpl
index 37b42bcb37..fb432bf4ff 100644
--- a/templates/repo/diff/section_split.tmpl
+++ b/templates/repo/diff/section_split.tmpl
@@ -18,22 +18,31 @@
 				{{if eq .GetType 4}}
 					{{$expandDirection := $line.GetExpandDirection}}
 					<td class="lines-num lines-num-old">
-						<div class="code-expander-buttons" data-expand-direction="{{$expandDirection}}">
-						{{if or (eq $expandDirection 3) (eq $expandDirection 5)}}
-							<button class="code-expander-button" hx-target="closest tr" hx-get="{{$blobExcerptRepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=split&direction=down&wiki={{$.root.PageIsWiki}}&anchor=diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}">
-								{{svg "octicon-fold-down"}}
-							</button>
-						{{end}}
-						{{if or (eq $expandDirection 3) (eq $expandDirection 4)}}
-							<button class="code-expander-button" hx-target="closest tr" hx-get="{{$blobExcerptRepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=split&direction=up&wiki={{$.root.PageIsWiki}}&anchor=diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}">
-								{{svg "octicon-fold-up"}}
-							</button>
-						{{end}}
-						{{if eq $expandDirection 2}}
-							<button class="code-expander-button" hx-target="closest tr" hx-get="{{$blobExcerptRepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=split&direction=&wiki={{$.root.PageIsWiki}}&anchor=diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}">
-								{{svg "octicon-fold"}}
-							</button>
-						{{end}}
+						<div class="lines-comment">
+							<div>
+							    {{if $line.SectionInfo.HasComments}}
+							        <button>
+							            {{svg "octicon-comment-discussion"}}
+							        </button>
+							    {{end}}
+							</div>
+							<div class="code-expander-buttons" data-expand-direction="{{$expandDirection}}">
+							{{if or (eq $expandDirection 3) (eq $expandDirection 5)}}
+								<button class="code-expander-button" hx-target="closest tr" hx-get="{{$blobExcerptRepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=split&direction=down&wiki={{$.root.PageIsWiki}}&pull={{$.root.PageIsPullFiles}}&anchor=diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}&file_name={{$section.FileName}}">
+									{{svg "octicon-fold-down"}}
+								</button>
+							{{end}}
+							{{if or (eq $expandDirection 3) (eq $expandDirection 4)}}
+								<button class="code-expander-button" hx-target="closest tr" hx-get="{{$blobExcerptRepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=split&direction=up&wiki={{$.root.PageIsWiki}}&pull={{$.root.PageIsPullFiles}}&anchor=diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}&file_name={{$section.FileName}}">
+									{{svg "octicon-fold-up"}}
+								</button>
+							{{end}}
+							{{if eq $expandDirection 2}}
+								<button class="code-expander-button" hx-target="closest tr" hx-get="{{$blobExcerptRepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=split&direction=&wiki={{$.root.PageIsWiki}}&pull={{$.root.PageIsPullFiles}}&anchor=diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}&file_name={{$section.FileName}}">
+									{{svg "octicon-fold"}}
+								</button>
+							{{end}}
+							</div>
 						</div>
 					</td>{{$inlineDiff := $section.GetComputedInlineDiffFor $line ctx.Locale}}
 					<td class="lines-escape lines-escape-old">{{if $inlineDiff.EscapeStatus.Escaped}}<button class="toggle-escape-button btn interact-bg" title="{{template "repo/diff/escape_title" dict "diff" $inlineDiff}}"></button>{{end}}</td>
diff --git a/templates/repo/diff/section_unified.tmpl b/templates/repo/diff/section_unified.tmpl
index 708b333291..5c90d79459 100644
--- a/templates/repo/diff/section_unified.tmpl
+++ b/templates/repo/diff/section_unified.tmpl
@@ -13,24 +13,36 @@
 			{{if eq .GetType 4}}
 				{{if $.root.AfterCommitID}}
 					{{$expandDirection := $line.GetExpandDirection}}
-					<td colspan="2" class="lines-num">
+					<td colspan="2" class="lines-num">						
+						<div class="lines-comment">
+							<div>
+							    {{if $line.SectionInfo.HasComments}}
+							        <button>
+							            {{svg "octicon-comment-discussion"}}
+							        </button>
+							    {{end}}
+							</div>
 						<div class="code-expander-buttons" data-expand-direction="{{$expandDirection}}">
 							{{if or (eq $expandDirection 3) (eq $expandDirection 5)}}
-								<button class="code-expander-button" hx-target="closest tr" hx-get="{{$blobExcerptRepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=unified&direction=down&wiki={{$.root.PageIsWiki}}&anchor=diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}">
+								<button class="code-expander-button" hx-target="closest tr" hx-get="{{$blobExcerptRepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=unified&direction=down&wiki={{$.root.PageIsWiki}}&pull={{$.root.PageIsPullFiles}}&anchor=diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}&file_name={{$section.FileName}}">
 									{{svg "octicon-fold-down"}}
 								</button>
+								test down
 							{{end}}
 							{{if or (eq $expandDirection 3) (eq $expandDirection 4)}}
-								<button class="code-expander-button" hx-target="closest tr" hx-get="{{$blobExcerptRepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=unified&direction=up&wiki={{$.root.PageIsWiki}}&anchor=diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}">
+								<button class="code-expander-button" hx-target="closest tr" hx-get="{{$blobExcerptRepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=unified&direction=up&wiki={{$.root.PageIsWiki}}&pull={{$.root.PageIsPullFiles}}&anchor=diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}&file_name={{$section.FileName}}">
 									{{svg "octicon-fold-up"}}
 								</button>
+								test up
 							{{end}}
 							{{if eq $expandDirection 2}}
-								<button class="code-expander-button" hx-target="closest tr" hx-get="{{$blobExcerptRepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=unified&direction=&wiki={{$.root.PageIsWiki}}&anchor=diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}">
+								<button class="code-expander-button" hx-target="closest tr" hx-get="{{$blobExcerptRepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=unified&direction=&wiki={{$.root.PageIsWiki}}&pull={{$.root.PageIsPullFiles}}&anchor=diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}&file_name={{$section.FileName}}">
 									{{svg "octicon-fold"}}
 								</button>
+								test fold
 							{{end}}
 						</div>
+						</div>
 					</td>
 				{{else}}
 					{{/* for code file preview page or comment diffs on pull comment pages, do not show the expansion arrows */}}
diff --git a/web_src/css/base.css b/web_src/css/base.css
index 8d9f810ef8..9589e501cc 100644
--- a/web_src/css/base.css
+++ b/web_src/css/base.css
@@ -1141,6 +1141,13 @@ overflow-menu .ui.label {
   font-family: var(--fonts-regular);
 }
 
+.lines-comment {
+  display: flex;
+  align-items: center;
+  justify-content: space-between;
+  gap: 1px;
+}
+
 .lines-commit .blame-info .blame-data .blame-message {
   flex-grow: 2;
   overflow: hidden;

From abd1d2f7706155064f21a0e8db586612be300679 Mon Sep 17 00:00:00 2001
From: Rajesh Jonnalagadda <rajeshjonnalagadda48@gmail.com>
Date: Mon, 11 Nov 2024 07:32:44 +0530
Subject: [PATCH 02/13] chore: fix  lint issues

---
 routers/web/repo/compare.go              | 40 ++++++------------------
 routers/web/web.go                       |  1 -
 services/gitdiff/gitdiff.go              | 10 ++----
 services/gitdiff/gitdiff_test.go         |  2 +-
 templates/repo/diff/blob_excerpt.tmpl    |  3 --
 templates/repo/diff/section_unified.tmpl |  3 --
 6 files changed, 12 insertions(+), 47 deletions(-)

diff --git a/routers/web/repo/compare.go b/routers/web/repo/compare.go
index 12a78f7ccb..a41058f412 100644
--- a/routers/web/repo/compare.go
+++ b/routers/web/repo/compare.go
@@ -865,10 +865,7 @@ func ExcerptBlob(ctx *context.Context) {
 	direction := ctx.FormString("direction")
 	filePath := ctx.FormString("path")
 	gitRepo := ctx.Repo.GitRepo
-	lastRightCommentIdx := ctx.FormInt("last_left_comment_idx")
-	rightCommentIdx := ctx.FormInt("left_comment_idx")
 	fileName := ctx.FormString("file_name")
-
 	if ctx.FormBool("pull") {
 		ctx.Data["PageIsPullFiles"] = true
 	}
@@ -882,17 +879,17 @@ func ExcerptBlob(ctx *context.Context) {
 		}
 		defer gitRepo.Close()
 	}
-
 	issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, int64(2))
-
 	if err != nil {
 		ctx.ServerError("GetIssueByIndex", err)
 		return
 	}
-
 	allComments, err := issues_model.FetchCodeComments(ctx, issue, ctx.Doer, false)
+	if err != nil {
+		ctx.ServerError("FetchCodeComments", err)
+		return
+	}
 	lineCommits := allComments[fileName]
-
 	chunkSize := gitdiff.BlobExcerptChunkSize
 	commit, err := gitRepo.GetCommit(commitID)
 	if err != nil {
@@ -909,9 +906,9 @@ func ExcerptBlob(ctx *context.Context) {
 		idxRight -= chunkSize
 		leftHunkSize += chunkSize
 		rightHunkSize += chunkSize
-		section.Lines, err = getExcerptLines(commit, filePath, idxLeft-1, idxRight-1, chunkSize, lastRightCommentIdx, rightCommentIdx)
+		section.Lines, err = getExcerptLines(commit, filePath, idxLeft-1, idxRight-1, chunkSize)
 	} else if direction == "down" && (idxLeft-lastLeft) > chunkSize {
-		section.Lines, err = getExcerptLines(commit, filePath, lastLeft, lastRight, chunkSize, lastRightCommentIdx, rightCommentIdx)
+		section.Lines, err = getExcerptLines(commit, filePath, lastLeft, lastRight, chunkSize)
 		lastLeft += chunkSize
 		lastRight += chunkSize
 	} else {
@@ -919,7 +916,7 @@ func ExcerptBlob(ctx *context.Context) {
 		if direction == "down" {
 			offset = 0
 		}
-		section.Lines, err = getExcerptLines(commit, filePath, lastLeft, lastRight, idxRight-lastRight+offset, lastRightCommentIdx, rightCommentIdx)
+		section.Lines, err = getExcerptLines(commit, filePath, lastLeft, lastRight, idxRight-lastRight+offset)
 		leftHunkSize = 0
 		rightHunkSize = 0
 		idxLeft = lastLeft
@@ -958,30 +955,19 @@ func ExcerptBlob(ctx *context.Context) {
 			section.Lines = append(section.Lines, lineSection)
 		}
 	}
-
 	for _, line := range section.Lines {
 		if line.SectionInfo != nil {
-			//for now considerign only right side.
 			start := int64(line.SectionInfo.LastRightIdx + 1)
 			end := int64(line.SectionInfo.RightIdx - 1)
-
-			//to check section has comments or not.
-			//1.  we can use binary search
-			//2. we can LastRightCommentIdx, RightCommentIdx, LastLeftCommentIdx, LeftCommentIdx(little complex but fast)
-			//3. for demo using linear search
 			for start <= end {
 				if _, ok := lineCommits[start]; ok {
 					if !line.SectionInfo.HasComments {
-						// line.SectionInfo.LastRightCommentIdx = int(start)
-						// line.SectionInfo.RightCommentIdx = int(start)
 						line.SectionInfo.HasComments = true
 						break
 					}
-
 				}
-				start += 1
+				start++
 			}
-
 		}
 		if comments, ok := lineCommits[int64(line.LeftIdx*-1)]; ok {
 			line.Comments = append(line.Comments, comments...)
@@ -994,7 +980,6 @@ func ExcerptBlob(ctx *context.Context) {
 			return line.Comments[i].CreatedUnix < line.Comments[j].CreatedUnix
 		})
 	}
-
 	for _, line := range section.Lines {
 		for _, comment := range line.Comments {
 			if err := comment.LoadAttachments(ctx); err != nil {
@@ -1003,18 +988,15 @@ func ExcerptBlob(ctx *context.Context) {
 			}
 		}
 	}
-
 	ctx.Data["section"] = section
 	ctx.Data["FileNameHash"] = git.HashFilePathForWebUI(filePath)
 	ctx.Data["AfterCommitID"] = commitID
 	ctx.Data["Anchor"] = anchor
 	ctx.Data["Issue"] = issue
 	ctx.Data["issue"] = issue.Index
-	ctx.Data["SignedUserID"] = ctx.Data["SignedUserID"]
 	ctx.Data["CanBlockUser"] = func(blocker, blockee *user_model.User) bool {
 		return user_service.CanBlockUser(ctx, ctx.Doer, blocker, blockee)
 	}
-
 	if ctx.Data["SignedUserID"] == nil {
 		ctx.Data["SignedUserID"] = ctx.Doer.ID
 	}
@@ -1025,7 +1007,7 @@ func ExcerptBlob(ctx *context.Context) {
 	ctx.HTML(http.StatusOK, tplBlobExcerpt)
 }
 
-func getExcerptLines(commit *git.Commit, filePath string, idxLeft, idxRight, chunkSize, lastRightCommentIdx, rightCommentIdx int) ([]*gitdiff.DiffLine, error) {
+func getExcerptLines(commit *git.Commit, filePath string, idxLeft, idxRight, chunkSize int) ([]*gitdiff.DiffLine, error) {
 	blob, err := commit.Tree.GetBlobByPath(filePath)
 	if err != nil {
 		return nil, err
@@ -1052,10 +1034,6 @@ func getExcerptLines(commit *git.Commit, filePath string, idxLeft, idxRight, chu
 			Content:  " " + lineText,
 			Comments: []*issues_model.Comment{},
 		}
-		// if diffLine.SectionInfo != nil {
-		// 	diffLine.SectionInfo.LastRightCommentIdx = lastRightCommentIdx
-		// 	diffLine.SectionInfo.RightCommentIdx = rightCommentIdx
-		// }
 		diffLines = append(diffLines, diffLine)
 	}
 	if err = scanner.Err(); err != nil {
diff --git a/routers/web/web.go b/routers/web/web.go
index 3aa9ba9f09..388e473b66 100644
--- a/routers/web/web.go
+++ b/routers/web/web.go
@@ -1513,7 +1513,6 @@ func registerRoutes(m *web.Router) {
 			// FIXME: refactor this function, use separate routes for wiki/code
 			if ctx.FormBool("pull") {
 				ctx.Data["PageIsPullFiles"] = true
-
 			}
 
 			if ctx.FormBool("wiki") {
diff --git a/services/gitdiff/gitdiff.go b/services/gitdiff/gitdiff.go
index 1954be760a..9dedf618b1 100644
--- a/services/gitdiff/gitdiff.go
+++ b/services/gitdiff/gitdiff.go
@@ -485,20 +485,14 @@ func (diff *Diff) LoadComments(ctx context.Context, issue *issues_model.Issue, c
 					if line.SectionInfo != nil {
 						start := int64(line.SectionInfo.LastRightIdx + 1)
 						end := int64(line.SectionInfo.RightIdx - 1)
-
 						for start <= end {
 							if _, ok := lineCommits[start]; ok {
-								if line.SectionInfo.LastRightCommentIdx == 0 {
-									// line.SectionInfo.LastRightCommentIdx = int(start)
-									// line.SectionInfo.RightCommentIdx = int(start)
+								if !line.SectionInfo.HasComments {
 									line.SectionInfo.HasComments = true
-
 									break
 								}
-
 							}
-							start += 1
-
+							start++
 						}
 					}
 					if comments, ok := lineCommits[int64(line.LeftIdx*-1)]; ok {
diff --git a/services/gitdiff/gitdiff_test.go b/services/gitdiff/gitdiff_test.go
index adcac355a7..644c2475f4 100644
--- a/services/gitdiff/gitdiff_test.go
+++ b/services/gitdiff/gitdiff_test.go
@@ -615,7 +615,7 @@ func TestDiff_LoadCommentsWithOutdated(t *testing.T) {
 }
 
 func TestDiffLine_CanComment(t *testing.T) {
-	assert.False(t, (&DiffLine{Type: DiffLineSection}).CanComment())
+	assert.True(t, (&DiffLine{Type: DiffLineSection}).CanComment())
 	assert.False(t, (&DiffLine{Type: DiffLineAdd, Comments: []*issues_model.Comment{{Content: "bla"}}}).CanComment())
 	assert.True(t, (&DiffLine{Type: DiffLineAdd}).CanComment())
 	assert.True(t, (&DiffLine{Type: DiffLineDel}).CanComment())
diff --git a/templates/repo/diff/blob_excerpt.tmpl b/templates/repo/diff/blob_excerpt.tmpl
index 63d6f970b6..50ecd26621 100644
--- a/templates/repo/diff/blob_excerpt.tmpl
+++ b/templates/repo/diff/blob_excerpt.tmpl
@@ -91,19 +91,16 @@
 						<button class="code-expander-button" hx-target="closest tr" hx-get="{{$.RepoLink}}/blob_excerpt/{{PathEscape $.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=unified&direction=down&wiki={{$.PageIsWiki}}&pull={{$.PageIsPullFiles}}&anchor={{$.Anchor}}&file_name={{$.section.FileName}}">
 							{{svg "octicon-fold-down"}}
 						</button>
-						test else down blob {{$line.SectionInfo.HasComments}}
 					{{end}}
 					{{if or (eq $expandDirection 3) (eq $expandDirection 4)}}
 						<button class="code-expander-button" hx-target="closest tr" hx-get="{{$.RepoLink}}/blob_excerpt/{{PathEscape $.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=unified&direction=up&wiki={{$.PageIsWiki}}&pull={{$.PageIsPullFiles}}&anchor={{$.Anchor}}&file_name={{$.section.FileName}}">
 							{{svg "octicon-fold-up"}}
 						</button>
-						test else up  blob
 					{{end}}
 					{{if eq $expandDirection 2}}
 						<button class="code-expander-button" hx-target="closest tr" hx-get="{{$.RepoLink}}/blob_excerpt/{{PathEscape $.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=unified&direction=&wiki={{$.PageIsWiki}}&pull={{$.PageIsPullFiles}}&anchor={{$.Anchor}}&file_name={{$.section.FileName}}">
 							{{svg "octicon-fold"}}
 						</button>
-						test else both  blob
 					{{end}}
 				</div>
 			 </div>	
diff --git a/templates/repo/diff/section_unified.tmpl b/templates/repo/diff/section_unified.tmpl
index 5c90d79459..f2b51cfa16 100644
--- a/templates/repo/diff/section_unified.tmpl
+++ b/templates/repo/diff/section_unified.tmpl
@@ -27,19 +27,16 @@
 								<button class="code-expander-button" hx-target="closest tr" hx-get="{{$blobExcerptRepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=unified&direction=down&wiki={{$.root.PageIsWiki}}&pull={{$.root.PageIsPullFiles}}&anchor=diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}&file_name={{$section.FileName}}">
 									{{svg "octicon-fold-down"}}
 								</button>
-								test down
 							{{end}}
 							{{if or (eq $expandDirection 3) (eq $expandDirection 4)}}
 								<button class="code-expander-button" hx-target="closest tr" hx-get="{{$blobExcerptRepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=unified&direction=up&wiki={{$.root.PageIsWiki}}&pull={{$.root.PageIsPullFiles}}&anchor=diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}&file_name={{$section.FileName}}">
 									{{svg "octicon-fold-up"}}
 								</button>
-								test up
 							{{end}}
 							{{if eq $expandDirection 2}}
 								<button class="code-expander-button" hx-target="closest tr" hx-get="{{$blobExcerptRepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=unified&direction=&wiki={{$.root.PageIsWiki}}&pull={{$.root.PageIsPullFiles}}&anchor=diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}&file_name={{$section.FileName}}">
 									{{svg "octicon-fold"}}
 								</button>
-								test fold
 							{{end}}
 						</div>
 						</div>

From ccd797abee10489ee8932cfaa77606a5979e4844 Mon Sep 17 00:00:00 2001
From: Rajesh Jonnalagadda <rajeshjonnalagadda48@gmail.com>
Date: Mon, 11 Nov 2024 21:59:27 +0530
Subject: [PATCH 03/13] chore: fixed the tmpl lint issues

---
 templates/repo/diff/blob_excerpt.tmpl    | 150 ++++++++++++-----------
 templates/repo/diff/section_split.tmpl   |  40 +++---
 templates/repo/diff/section_unified.tmpl |  46 +++----
 3 files changed, 120 insertions(+), 116 deletions(-)

diff --git a/templates/repo/diff/blob_excerpt.tmpl b/templates/repo/diff/blob_excerpt.tmpl
index 50ecd26621..9793b17b8f 100644
--- a/templates/repo/diff/blob_excerpt.tmpl
+++ b/templates/repo/diff/blob_excerpt.tmpl
@@ -5,33 +5,33 @@
 		{{if eq .GetType 4}}
 			{{$expandDirection := $line.GetExpandDirection}}
 			<td class="lines-num lines-num-old" data-line-num="{{if $line.LeftIdx}}{{$line.LeftIdx}}{{end}}">
-        	  <div class="lines-comment">
-        	    <div>
-        	      {{if $line.SectionInfo.HasComments}}
-        	        <button>
-        	          {{svg "octicon-comment-discussion"}}
-        	        </button>
-        	      {{end}}
-        	    </div>
-        	    <div class="code-expander-buttons" data-expand-direction="{{$expandDirection}}">
-        	      {{if or (eq $expandDirection 3) (eq $expandDirection 5)}}
-        	        <button class="code-expander-button" hx-target="closest tr" hx-get="{{$.RepoLink}}/blob_excerpt/{{PathEscape $.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=split&direction=down&wiki={{$.PageIsWiki}}&pull={{$.PageIsPullFiles}}&anchor={{$.Anchor}}&file_name={{$.section.FileName}}">
-        	          {{svg "octicon-fold-down"}}
-        	        </button>
-        	      {{end}}
-        	      {{if or (eq $expandDirection 3) (eq $expandDirection 4)}}
-        	        <button class="code-expander-button" hx-target="closest tr" hx-get="{{$.RepoLink}}/blob_excerpt/{{PathEscape $.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=split&direction=up&wiki={{$.PageIsWiki}}&pull={{$.PageIsPullFiles}}&anchor={{$.Anchor}}&file_name={{$.section.FileName}}">
-        	          {{svg "octicon-fold-up"}}
-        	        </button>
-        	      {{end}}
-        	      {{if eq $expandDirection 2}}
-        	        <button class="code-expander-button" hx-target="closest tr" hx-get="{{$.RepoLink}}/blob_excerpt/{{PathEscape $.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=split&direction=&wiki={{$.PageIsWiki}}&pull={{$.PageIsPullFiles}}&anchor={{$.Anchor}}&file_name={{$.section.FileName}}">
-        	          {{svg "octicon-fold"}}
-        	        </button>
-        	      {{end}}
-        	    </div>
-        	  </div>
-        	</td>
+				<div class="lines-comment">
+					<div>
+						{{if $line.SectionInfo.HasComments}}
+							<button>
+								{{svg "octicon-comment-discussion"}}
+							</button>
+						{{end}}
+					</div>
+					<div class="code-expander-buttons" data-expand-direction="{{$expandDirection}}">
+						{{if or (eq $expandDirection 3) (eq $expandDirection 5)}}
+							<button class="code-expander-button" hx-target="closest tr" hx-get="{{$.RepoLink}}/blob_excerpt/{{PathEscape $.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=split&direction=down&wiki={{$.PageIsWiki}}&pull={{$.PageIsPullFiles}}&anchor={{$.Anchor}}&file_name={{$.section.FileName}}">
+								{{svg "octicon-fold-down"}}
+							</button>
+						{{end}}
+						{{if or (eq $expandDirection 3) (eq $expandDirection 4)}}
+							<button class="code-expander-button" hx-target="closest tr" hx-get="{{$.RepoLink}}/blob_excerpt/{{PathEscape $.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=split&direction=up&wiki={{$.PageIsWiki}}&pull={{$.PageIsPullFiles}}&anchor={{$.Anchor}}&file_name={{$.section.FileName}}">
+								{{svg "octicon-fold-up"}}
+							</button>
+						{{end}}
+						{{if eq $expandDirection 2}}
+							<button class="code-expander-button" hx-target="closest tr" hx-get="{{$.RepoLink}}/blob_excerpt/{{PathEscape $.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=split&direction=&wiki={{$.PageIsWiki}}&pull={{$.PageIsPullFiles}}&anchor={{$.Anchor}}&file_name={{$.section.FileName}}">
+								{{svg "octicon-fold"}}
+							</button>
+						{{end}}
+					</div>
+				</div>
+			</td>
 			<td colspan="7" class="lines-code lines-code-old ">{{$inlineDiff := $.section.GetComputedInlineDiffFor $line ctx.Locale}}{{/*
 				*/}}{{template "repo/diff/section_code" dict "diff" $inlineDiff}}</td>
 		{{else}}
@@ -39,10 +39,10 @@
 			<td class="lines-escape lines-escape-old">{{if and $line.LeftIdx $inlineDiff.EscapeStatus.Escaped}}<button class="toggle-escape-button btn interact-bg" title="{{template "repo/diff/escape_title" dict "diff" $inlineDiff}}"></button>{{end}}</td>
 			<td class="lines-type-marker lines-type-marker-old">{{if $line.LeftIdx}}<span class="tw-font-mono" data-type-marker=""></span>{{end}}</td>
 			<td class="lines-code lines-code-old">{{/*
-			*/}}{{if and $.SignedUserID $.PageIsPullFiles}}{{/*
+				*/}}{{if and $.SignedUserID $.PageIsPullFiles}}{{/*
 					*/}}<button type="button" aria-label="{{ctx.Locale.Tr "repo.diff.comment.add_line_comment"}}" class="ui primary button add-code-comment add-code-comment-{{if $line.RightIdx}}right{{else}}left{{end}}{{if (not $line.CanComment)}} tw-invisible{{end}}" data-side="{{if $line.RightIdx}}right{{else}}left{{end}}" data-idx="{{if $line.RightIdx}}{{$line.RightIdx}}{{else}}{{$line.LeftIdx}}{{end}}">{{/*
 						*/}}{{svg "octicon-plus"}}{{/*
-						*/}}</button>{{/*
+					*/}}</button>{{/*
 				*/}}{{end}}{{/*
 				*/}}{{if $line.LeftIdx}}{{template "repo/diff/section_code" dict "diff" $inlineDiff}}{{else}}{{/*
 					*/}}<code class="code-inner"></code>{{/*
@@ -52,10 +52,10 @@
 			<td class="lines-escape lines-escape-new">{{if and $line.RightIdx $inlineDiff.EscapeStatus.Escaped}}<button class="toggle-escape-button btn interact-bg" title="{{template "repo/diff/escape_title" dict "diff" $inlineDiff}}"></button>{{end}}</td>
 			<td class="lines-type-marker lines-type-marker-new">{{if $line.RightIdx}}<span class="tw-font-mono" data-type-marker=""></span>{{end}}</td>
 			<td class="lines-code lines-code-new">{{/*
-			*/}}{{if and $.SignedUserID $.PageIsPullFiles}}{{/*
+				*/}}{{if and $.SignedUserID $.PageIsPullFiles}}{{/*
 					*/}}<button type="button" aria-label="{{ctx.Locale.Tr "repo.diff.comment.add_line_comment"}}" class="ui primary button add-code-comment add-code-comment-{{if $line.RightIdx}}right{{else}}left{{end}}{{if (not $line.CanComment)}} tw-invisible{{end}}" data-side="{{if $line.RightIdx}}right{{else}}left{{end}}" data-idx="{{if $line.RightIdx}}{{$line.RightIdx}}{{else}}{{$line.LeftIdx}}{{end}}">{{/*
 						*/}}{{svg "octicon-plus"}}{{/*
-						*/}}</button>{{/*
+					*/}}</button>{{/*
 				*/}}{{end}}{{/*
 				*/}}{{if $line.RightIdx}}{{template "repo/diff/section_code" dict "diff" $inlineDiff}}{{else}}{{/*
 					*/}}<code class="code-inner"></code>{{/*
@@ -64,12 +64,12 @@
 		{{end}}
 	</tr>
 	{{if $line.Comments}}
-			<tr class="add-comment" data-line-type="{{.GetHTMLDiffLineType}}">
-				<td class="add-comment-right" colspan="5">
-					{{template "repo/diff/conversation" dict "." $ "comments" $line.Comments}}}
-				</td>
-			</tr>
-		{{end}}
+		<tr class="add-comment" data-line-type="{{.GetHTMLDiffLineType}}">
+			<td class="add-comment-right" colspan="5">
+				{{template "repo/diff/conversation" dict "." $ "comments" $line.Comments}}}
+			</td>
+		</tr>
+	{{end}}
 	{{end}}
 {{else}}
 	{{range $k, $line := $.section.Lines}}
@@ -78,32 +78,32 @@
 		{{if eq .GetType 4}}
 			{{$expandDirection := $line.GetExpandDirection}}
 			<td colspan="2" class="lines-num">
-			 <div class="lines-comment">
-        	    <div>
-        	      {{if $line.SectionInfo.HasComments}}
-        	        <button>
-        	          {{svg "octicon-comment-discussion"}}
-        	        </button>
-        	      {{end}}
-        	    </div>
-				<div class="code-expander-buttons" data-expand-direction="{{$expandDirection}}">
-					{{if or (eq $expandDirection 3) (eq $expandDirection 5)}}
-						<button class="code-expander-button" hx-target="closest tr" hx-get="{{$.RepoLink}}/blob_excerpt/{{PathEscape $.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=unified&direction=down&wiki={{$.PageIsWiki}}&pull={{$.PageIsPullFiles}}&anchor={{$.Anchor}}&file_name={{$.section.FileName}}">
-							{{svg "octicon-fold-down"}}
-						</button>
-					{{end}}
-					{{if or (eq $expandDirection 3) (eq $expandDirection 4)}}
-						<button class="code-expander-button" hx-target="closest tr" hx-get="{{$.RepoLink}}/blob_excerpt/{{PathEscape $.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=unified&direction=up&wiki={{$.PageIsWiki}}&pull={{$.PageIsPullFiles}}&anchor={{$.Anchor}}&file_name={{$.section.FileName}}">
-							{{svg "octicon-fold-up"}}
-						</button>
-					{{end}}
-					{{if eq $expandDirection 2}}
-						<button class="code-expander-button" hx-target="closest tr" hx-get="{{$.RepoLink}}/blob_excerpt/{{PathEscape $.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=unified&direction=&wiki={{$.PageIsWiki}}&pull={{$.PageIsPullFiles}}&anchor={{$.Anchor}}&file_name={{$.section.FileName}}">
-							{{svg "octicon-fold"}}
-						</button>
-					{{end}}
+				<div class="lines-comment">
+					<div>
+						{{if $line.SectionInfo.HasComments}}
+							<button>
+								{{svg "octicon-comment-discussion"}}
+							</button>
+						{{end}}
+					</div>
+					<div class="code-expander-buttons" data-expand-direction="{{$expandDirection}}">
+						{{if or (eq $expandDirection 3) (eq $expandDirection 5)}}
+							<button class="code-expander-button" hx-target="closest tr" hx-get="{{$.RepoLink}}/blob_excerpt/{{PathEscape $.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=unified&direction=down&wiki={{$.PageIsWiki}}&pull={{$.PageIsPullFiles}}&anchor={{$.Anchor}}&file_name={{$.section.FileName}}">
+								{{svg "octicon-fold-down"}}
+							</button>
+						{{end}}
+						{{if or (eq $expandDirection 3) (eq $expandDirection 4)}}
+							<button class="code-expander-button" hx-target="closest tr" hx-get="{{$.RepoLink}}/blob_excerpt/{{PathEscape $.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=unified&direction=up&wiki={{$.PageIsWiki}}&pull={{$.PageIsPullFiles}}&anchor={{$.Anchor}}&file_name={{$.section.FileName}}">
+								{{svg "octicon-fold-up"}}
+							</button>
+						{{end}}
+						{{if eq $expandDirection 2}}
+							<button class="code-expander-button" hx-target="closest tr" hx-get="{{$.RepoLink}}/blob_excerpt/{{PathEscape $.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=unified&direction=&wiki={{$.PageIsWiki}}&pull={{$.PageIsPullFiles}}&anchor={{$.Anchor}}&file_name={{$.section.FileName}}">
+								{{svg "octicon-fold"}}
+							</button>
+						{{end}}
+					</div>
 				</div>
-			 </div>	
 			</td>
 		{{else}}
 			<td class="lines-num lines-num-old" data-line-num="{{if $line.LeftIdx}}{{$line.LeftIdx}}{{end}}"><span rel="{{if $line.LeftIdx}}diff-{{$.FileNameHash}}L{{$line.LeftIdx}}{{end}}"></span></td>
@@ -112,18 +112,22 @@
 		<td class="lines-escape">{{if $inlineDiff.EscapeStatus.Escaped}}<button class="toggle-escape-button btn interact-bg" title="{{template "repo/diff/escape_title" dict "diff" $inlineDiff}}"></button>{{end}}</td>
 		<td class="lines-type-marker"><span class="tw-font-mono" data-type-marker="{{$line.GetLineTypeMarker}}"></span></td>
 		<td class="lines-code{{if (not $line.RightIdx)}} lines-code-old{{end}}">
-		{{if and $.SignedUserID $.PageIsPullFiles}}
-		<button type="button" aria-label="{{ctx.Locale.Tr "repo.diff.comment.add_line_comment"}}" class="ui primary button add-code-comment add-code-comment-{{if $line.RightIdx}}right{{else}}left{{end}}{{if (not $line.CanComment)}} tw-invisible{{end}}" data-side="{{if $line.RightIdx}}right{{else}}left{{end}}" data-idx="{{if $line.RightIdx}}{{$line.RightIdx}}{{else}}{{$line.LeftIdx}}{{end}}">{{svg "octicon-plus"}}
-		</button>
-		{{end}}
-			<code {{if $inlineDiff.EscapeStatus.Escaped}}class="code-inner has-escaped" title="{{template "repo/diff/escape_title" dict "diff" $inlineDiff}}"{{else}}class="code-inner"{{end}}>{{$inlineDiff.Content}}</code></td>	
+			{{if and $.SignedUserID $.PageIsPullFiles}}
+				<button type="button" aria-label="{{ctx.Locale.Tr "repo.diff.comment.add_line_comment"}}" class="ui primary button add-code-comment add-code-comment-{{if $line.RightIdx}}right{{else}}left{{end}}{{if (not $line.CanComment)}} tw-invisible{{end}}" data-side="{{if $line.RightIdx}}right{{else}}left{{end}}" data-idx="{{if $line.RightIdx}}{{$line.RightIdx}}{{else}}{{$line.LeftIdx}}{{end}}">
+					{{svg "octicon-plus"}}
+				</button>
+			{{end}}
+			<code {{if $inlineDiff.EscapeStatus.Escaped}}class="code-inner has-escaped" title="{{template "repo/diff/escape_title" dict "diff" $inlineDiff}}"{{else}}class="code-inner"{{end}}>
+				{{$inlineDiff.Content}}
+			</code>
+		</td>
 	</tr>
 	{{if $line.Comments}}
-			<tr class="add-comment" data-line-type="{{.GetHTMLDiffLineType}}">
-				<td class="add-comment-right" colspan="5">
-					{{template "repo/diff/conversation" dict "." $ "comments" $line.Comments}}
-				</td>
-			</tr>
-		{{end}}
+		<tr class="add-comment" data-line-type="{{.GetHTMLDiffLineType}}">
+			<td class="add-comment-right" colspan="5">
+				{{template "repo/diff/conversation" dict "." $ "comments" $line.Comments}}
+			</td>
+		</tr>
+	{{end}}
 	{{end}}
 {{end}}
diff --git a/templates/repo/diff/section_split.tmpl b/templates/repo/diff/section_split.tmpl
index fb432bf4ff..3d36b41697 100644
--- a/templates/repo/diff/section_split.tmpl
+++ b/templates/repo/diff/section_split.tmpl
@@ -20,28 +20,28 @@
 					<td class="lines-num lines-num-old">
 						<div class="lines-comment">
 							<div>
-							    {{if $line.SectionInfo.HasComments}}
-							        <button>
-							            {{svg "octicon-comment-discussion"}}
-							        </button>
-							    {{end}}
+								{{if $line.SectionInfo.HasComments}}
+									<button>
+										{{svg "octicon-comment-discussion"}}
+									</button>
+								{{end}}
 							</div>
 							<div class="code-expander-buttons" data-expand-direction="{{$expandDirection}}">
-							{{if or (eq $expandDirection 3) (eq $expandDirection 5)}}
-								<button class="code-expander-button" hx-target="closest tr" hx-get="{{$blobExcerptRepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=split&direction=down&wiki={{$.root.PageIsWiki}}&pull={{$.root.PageIsPullFiles}}&anchor=diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}&file_name={{$section.FileName}}">
-									{{svg "octicon-fold-down"}}
-								</button>
-							{{end}}
-							{{if or (eq $expandDirection 3) (eq $expandDirection 4)}}
-								<button class="code-expander-button" hx-target="closest tr" hx-get="{{$blobExcerptRepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=split&direction=up&wiki={{$.root.PageIsWiki}}&pull={{$.root.PageIsPullFiles}}&anchor=diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}&file_name={{$section.FileName}}">
-									{{svg "octicon-fold-up"}}
-								</button>
-							{{end}}
-							{{if eq $expandDirection 2}}
-								<button class="code-expander-button" hx-target="closest tr" hx-get="{{$blobExcerptRepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=split&direction=&wiki={{$.root.PageIsWiki}}&pull={{$.root.PageIsPullFiles}}&anchor=diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}&file_name={{$section.FileName}}">
-									{{svg "octicon-fold"}}
-								</button>
-							{{end}}
+								{{if or (eq $expandDirection 3) (eq $expandDirection 5)}}
+									<button class="code-expander-button" hx-target="closest tr" hx-get="{{$blobExcerptRepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=split&direction=down&wiki={{$.root.PageIsWiki}}&pull={{$.root.PageIsPullFiles}}&anchor=diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}&file_name={{$section.FileName}}">
+										{{svg "octicon-fold-down"}}
+									</button>
+								{{end}}
+								{{if or (eq $expandDirection 3) (eq $expandDirection 4)}}
+									<button class="code-expander-button" hx-target="closest tr" hx-get="{{$blobExcerptRepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=split&direction=up&wiki={{$.root.PageIsWiki}}&pull={{$.root.PageIsPullFiles}}&anchor=diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}&file_name={{$section.FileName}}">
+										{{svg "octicon-fold-up"}}
+									</button>
+								{{end}}
+								{{if eq $expandDirection 2}}
+									<button class="code-expander-button" hx-target="closest tr" hx-get="{{$blobExcerptRepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=split&direction=&wiki={{$.root.PageIsWiki}}&pull={{$.root.PageIsPullFiles}}&anchor=diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}&file_name={{$section.FileName}}">
+										{{svg "octicon-fold"}}
+									</button>
+								{{end}}
 							</div>
 						</div>
 					</td>{{$inlineDiff := $section.GetComputedInlineDiffFor $line ctx.Locale}}
diff --git a/templates/repo/diff/section_unified.tmpl b/templates/repo/diff/section_unified.tmpl
index f2b51cfa16..79f8139ae3 100644
--- a/templates/repo/diff/section_unified.tmpl
+++ b/templates/repo/diff/section_unified.tmpl
@@ -13,32 +13,32 @@
 			{{if eq .GetType 4}}
 				{{if $.root.AfterCommitID}}
 					{{$expandDirection := $line.GetExpandDirection}}
-					<td colspan="2" class="lines-num">						
+					<td colspan="2" class="lines-num">
 						<div class="lines-comment">
 							<div>
-							    {{if $line.SectionInfo.HasComments}}
-							        <button>
-							            {{svg "octicon-comment-discussion"}}
-							        </button>
-							    {{end}}
+								{{if $line.SectionInfo.HasComments}}
+									<button>
+										{{svg "octicon-comment-discussion"}}
+									</button>
+								{{end}}
+							</div>
+							<div class="code-expander-buttons" data-expand-direction="{{$expandDirection}}">
+								{{if or (eq $expandDirection 3) (eq $expandDirection 5)}}
+									<button class="code-expander-button" hx-target="closest tr" hx-get="{{$blobExcerptRepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=unified&direction=down&wiki={{$.root.PageIsWiki}}&pull={{$.root.PageIsPullFiles}}&anchor=diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}&file_name={{$section.FileName}}">
+										{{svg "octicon-fold-down"}}
+									</button>
+								{{end}}
+								{{if or (eq $expandDirection 3) (eq $expandDirection 4)}}
+									<button class="code-expander-button" hx-target="closest tr" hx-get="{{$blobExcerptRepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=unified&direction=up&wiki={{$.root.PageIsWiki}}&pull={{$.root.PageIsPullFiles}}&anchor=diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}&file_name={{$section.FileName}}">
+										{{svg "octicon-fold-up"}}
+									</button>
+								{{end}}
+								{{if eq $expandDirection 2}}
+									<button class="code-expander-button" hx-target="closest tr" hx-get="{{$blobExcerptRepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=unified&direction=&wiki={{$.root.PageIsWiki}}&pull={{$.root.PageIsPullFiles}}&anchor=diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}&file_name={{$section.FileName}}">
+										{{svg "octicon-fold"}}
+									</button>
+								{{end}}
 							</div>
-						<div class="code-expander-buttons" data-expand-direction="{{$expandDirection}}">
-							{{if or (eq $expandDirection 3) (eq $expandDirection 5)}}
-								<button class="code-expander-button" hx-target="closest tr" hx-get="{{$blobExcerptRepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=unified&direction=down&wiki={{$.root.PageIsWiki}}&pull={{$.root.PageIsPullFiles}}&anchor=diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}&file_name={{$section.FileName}}">
-									{{svg "octicon-fold-down"}}
-								</button>
-							{{end}}
-							{{if or (eq $expandDirection 3) (eq $expandDirection 4)}}
-								<button class="code-expander-button" hx-target="closest tr" hx-get="{{$blobExcerptRepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=unified&direction=up&wiki={{$.root.PageIsWiki}}&pull={{$.root.PageIsPullFiles}}&anchor=diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}&file_name={{$section.FileName}}">
-									{{svg "octicon-fold-up"}}
-								</button>
-							{{end}}
-							{{if eq $expandDirection 2}}
-								<button class="code-expander-button" hx-target="closest tr" hx-get="{{$blobExcerptRepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=unified&direction=&wiki={{$.root.PageIsWiki}}&pull={{$.root.PageIsPullFiles}}&anchor=diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}&file_name={{$section.FileName}}">
-									{{svg "octicon-fold"}}
-								</button>
-							{{end}}
-						</div>
 						</div>
 					</td>
 				{{else}}

From efba6c4a2d6351a3c731601b9499a0164e1d4817 Mon Sep 17 00:00:00 2001
From: Rajesh Jonnalagadda <rajeshjonnalagadda48@gmail.com>
Date: Tue, 12 Nov 2024 02:24:36 +0530
Subject: [PATCH 04/13] chore:  remove issue index and minro template changes

---
 routers/web/repo/compare.go              | 82 ++++++++++++------------
 routers/web/repo/pull.go                 |  1 +
 templates/repo/diff/blob_excerpt.tmpl    | 16 ++---
 templates/repo/diff/section_split.tmpl   |  7 +-
 templates/repo/diff/section_unified.tmpl |  7 +-
 5 files changed, 58 insertions(+), 55 deletions(-)

diff --git a/routers/web/repo/compare.go b/routers/web/repo/compare.go
index a41058f412..559a22e825 100644
--- a/routers/web/repo/compare.go
+++ b/routers/web/repo/compare.go
@@ -865,7 +865,6 @@ func ExcerptBlob(ctx *context.Context) {
 	direction := ctx.FormString("direction")
 	filePath := ctx.FormString("path")
 	gitRepo := ctx.Repo.GitRepo
-	fileName := ctx.FormString("file_name")
 	if ctx.FormBool("pull") {
 		ctx.Data["PageIsPullFiles"] = true
 	}
@@ -879,17 +878,6 @@ func ExcerptBlob(ctx *context.Context) {
 		}
 		defer gitRepo.Close()
 	}
-	issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, int64(2))
-	if err != nil {
-		ctx.ServerError("GetIssueByIndex", err)
-		return
-	}
-	allComments, err := issues_model.FetchCodeComments(ctx, issue, ctx.Doer, false)
-	if err != nil {
-		ctx.ServerError("FetchCodeComments", err)
-		return
-	}
-	lineCommits := allComments[fileName]
 	chunkSize := gitdiff.BlobExcerptChunkSize
 	commit, err := gitRepo.GetCommit(commitID)
 	if err != nil {
@@ -955,45 +943,59 @@ func ExcerptBlob(ctx *context.Context) {
 			section.Lines = append(section.Lines, lineSection)
 		}
 	}
-	for _, line := range section.Lines {
-		if line.SectionInfo != nil {
-			start := int64(line.SectionInfo.LastRightIdx + 1)
-			end := int64(line.SectionInfo.RightIdx - 1)
-			for start <= end {
-				if _, ok := lineCommits[start]; ok {
-					if !line.SectionInfo.HasComments {
-						line.SectionInfo.HasComments = true
-						break
+	issueIndex := ctx.FormInt64("issue_index")
+	if ctx.FormBool("pull") && issueIndex > 0 {
+		issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, issueIndex)
+		if issue == nil {
+			ctx.ServerError("GetIssueByIndex", err)
+			return
+		}
+		allComments, err := issues_model.FetchCodeComments(ctx, issue, ctx.Doer, false)
+		if err != nil {
+			ctx.ServerError("FetchCodeComments", err)
+			return
+		}
+		lineCommits := allComments[filePath]
+		for _, line := range section.Lines {
+			if line.SectionInfo != nil {
+				start := int64(line.SectionInfo.LastRightIdx + 1)
+				end := int64(line.SectionInfo.RightIdx - 1)
+				for start <= end {
+					if _, ok := lineCommits[start]; ok {
+						if !line.SectionInfo.HasComments {
+							line.SectionInfo.HasComments = true
+							break
+						}
 					}
+					start++
 				}
-				start++
 			}
-		}
-		if comments, ok := lineCommits[int64(line.LeftIdx*-1)]; ok {
-			line.Comments = append(line.Comments, comments...)
-		}
-		if comments, ok := lineCommits[int64(line.RightIdx)]; ok {
-			line.Comments = append(line.Comments, comments...)
-		}
+			if comments, ok := lineCommits[int64(line.LeftIdx*-1)]; ok {
+				line.Comments = append(line.Comments, comments...)
+			}
+			if comments, ok := lineCommits[int64(line.RightIdx)]; ok {
+				line.Comments = append(line.Comments, comments...)
+			}
 
-		sort.SliceStable(line.Comments, func(i, j int) bool {
-			return line.Comments[i].CreatedUnix < line.Comments[j].CreatedUnix
-		})
-	}
-	for _, line := range section.Lines {
-		for _, comment := range line.Comments {
-			if err := comment.LoadAttachments(ctx); err != nil {
-				ctx.ServerError("LoadAttachments", err)
-				return
+			sort.SliceStable(line.Comments, func(i, j int) bool {
+				return line.Comments[i].CreatedUnix < line.Comments[j].CreatedUnix
+			})
+		}
+		for _, line := range section.Lines {
+			for _, comment := range line.Comments {
+				if err := comment.LoadAttachments(ctx); err != nil {
+					ctx.ServerError("LoadAttachments", err)
+					return
+				}
 			}
 		}
+		ctx.Data["Issue"] = issue
+		ctx.Data["IssueIndex"] = issue.Index
 	}
 	ctx.Data["section"] = section
 	ctx.Data["FileNameHash"] = git.HashFilePathForWebUI(filePath)
 	ctx.Data["AfterCommitID"] = commitID
 	ctx.Data["Anchor"] = anchor
-	ctx.Data["Issue"] = issue
-	ctx.Data["issue"] = issue.Index
 	ctx.Data["CanBlockUser"] = func(blocker, blockee *user_model.User) bool {
 		return user_service.CanBlockUser(ctx, ctx.Doer, blocker, blockee)
 	}
diff --git a/routers/web/repo/pull.go b/routers/web/repo/pull.go
index bb814eab6e..e9ea3eaccb 100644
--- a/routers/web/repo/pull.go
+++ b/routers/web/repo/pull.go
@@ -128,6 +128,7 @@ func getPullInfo(ctx *context.Context) (issue *issues_model.Issue, ok bool) {
 	}
 	ctx.Data["Title"] = fmt.Sprintf("#%d - %s", issue.Index, emoji.ReplaceAliases(issue.Title))
 	ctx.Data["Issue"] = issue
+	ctx.Data["IssueIndex"] = issue.Index
 
 	if !issue.IsPull {
 		ctx.NotFound("ViewPullCommits", nil)
diff --git a/templates/repo/diff/blob_excerpt.tmpl b/templates/repo/diff/blob_excerpt.tmpl
index 9793b17b8f..10601fa576 100644
--- a/templates/repo/diff/blob_excerpt.tmpl
+++ b/templates/repo/diff/blob_excerpt.tmpl
@@ -15,17 +15,17 @@
 					</div>
 					<div class="code-expander-buttons" data-expand-direction="{{$expandDirection}}">
 						{{if or (eq $expandDirection 3) (eq $expandDirection 5)}}
-							<button class="code-expander-button" hx-target="closest tr" hx-get="{{$.RepoLink}}/blob_excerpt/{{PathEscape $.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=split&direction=down&wiki={{$.PageIsWiki}}&pull={{$.PageIsPullFiles}}&anchor={{$.Anchor}}&file_name={{$.section.FileName}}">
+							<button class="code-expander-button" hx-target="closest tr" hx-get="{{$.RepoLink}}/blob_excerpt/{{PathEscape $.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=split&direction=down&wiki={{$.PageIsWiki}}&pull={{$.PageIsPullFiles}}&anchor={{$.Anchor}}&issue_index={{$.IssueIndex}}">
 								{{svg "octicon-fold-down"}}
 							</button>
 						{{end}}
 						{{if or (eq $expandDirection 3) (eq $expandDirection 4)}}
-							<button class="code-expander-button" hx-target="closest tr" hx-get="{{$.RepoLink}}/blob_excerpt/{{PathEscape $.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=split&direction=up&wiki={{$.PageIsWiki}}&pull={{$.PageIsPullFiles}}&anchor={{$.Anchor}}&file_name={{$.section.FileName}}">
+							<button class="code-expander-button" hx-target="closest tr" hx-get="{{$.RepoLink}}/blob_excerpt/{{PathEscape $.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=split&direction=up&wiki={{$.PageIsWiki}}&pull={{$.PageIsPullFiles}}&anchor={{$.Anchor}}&issue_index={{$.IssueIndex}}">
 								{{svg "octicon-fold-up"}}
 							</button>
 						{{end}}
 						{{if eq $expandDirection 2}}
-							<button class="code-expander-button" hx-target="closest tr" hx-get="{{$.RepoLink}}/blob_excerpt/{{PathEscape $.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=split&direction=&wiki={{$.PageIsWiki}}&pull={{$.PageIsPullFiles}}&anchor={{$.Anchor}}&file_name={{$.section.FileName}}">
+							<button class="code-expander-button" hx-target="closest tr" hx-get="{{$.RepoLink}}/blob_excerpt/{{PathEscape $.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=split&direction=&wiki={{$.PageIsWiki}}&pull={{$.PageIsPullFiles}}&anchor={{$.Anchor}}}&issue_index={{$.IssueIndex}}">
 								{{svg "octicon-fold"}}
 							</button>
 						{{end}}
@@ -88,17 +88,17 @@
 					</div>
 					<div class="code-expander-buttons" data-expand-direction="{{$expandDirection}}">
 						{{if or (eq $expandDirection 3) (eq $expandDirection 5)}}
-							<button class="code-expander-button" hx-target="closest tr" hx-get="{{$.RepoLink}}/blob_excerpt/{{PathEscape $.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=unified&direction=down&wiki={{$.PageIsWiki}}&pull={{$.PageIsPullFiles}}&anchor={{$.Anchor}}&file_name={{$.section.FileName}}">
+							<button class="code-expander-button" hx-target="closest tr" hx-get="{{$.RepoLink}}/blob_excerpt/{{PathEscape $.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=unified&direction=down&wiki={{$.PageIsWiki}}&pull={{$.PageIsPullFiles}}&anchor={{$.Anchor}}}&issue_index={{$.IssueIndex}}">
 								{{svg "octicon-fold-down"}}
 							</button>
 						{{end}}
 						{{if or (eq $expandDirection 3) (eq $expandDirection 4)}}
-							<button class="code-expander-button" hx-target="closest tr" hx-get="{{$.RepoLink}}/blob_excerpt/{{PathEscape $.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=unified&direction=up&wiki={{$.PageIsWiki}}&pull={{$.PageIsPullFiles}}&anchor={{$.Anchor}}&file_name={{$.section.FileName}}">
+							<button class="code-expander-button" hx-target="closest tr" hx-get="{{$.RepoLink}}/blob_excerpt/{{PathEscape $.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=unified&direction=up&wiki={{$.PageIsWiki}}&pull={{$.PageIsPullFiles}}&anchor={{$.Anchor}}}&issue_index={{$.IssueIndex}}">
 								{{svg "octicon-fold-up"}}
 							</button>
 						{{end}}
 						{{if eq $expandDirection 2}}
-							<button class="code-expander-button" hx-target="closest tr" hx-get="{{$.RepoLink}}/blob_excerpt/{{PathEscape $.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=unified&direction=&wiki={{$.PageIsWiki}}&pull={{$.PageIsPullFiles}}&anchor={{$.Anchor}}&file_name={{$.section.FileName}}">
+							<button class="code-expander-button" hx-target="closest tr" hx-get="{{$.RepoLink}}/blob_excerpt/{{PathEscape $.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=unified&direction=&wiki={{$.PageIsWiki}}&pull={{$.PageIsPullFiles}}&anchor={{$.Anchor}}}&issue_index={{$.IssueIndex}}">
 								{{svg "octicon-fold"}}
 							</button>
 						{{end}}
@@ -117,9 +117,7 @@
 					{{svg "octicon-plus"}}
 				</button>
 			{{end}}
-			<code {{if $inlineDiff.EscapeStatus.Escaped}}class="code-inner has-escaped" title="{{template "repo/diff/escape_title" dict "diff" $inlineDiff}}"{{else}}class="code-inner"{{end}}>
-				{{$inlineDiff.Content}}
-			</code>
+			<code {{if $inlineDiff.EscapeStatus.Escaped}}class="code-inner has-escaped" title="{{template "repo/diff/escape_title" dict "diff" $inlineDiff}}"{{else}}class="code-inner"{{end}}>{{$inlineDiff.Content}}</code>
 		</td>
 	</tr>
 	{{if $line.Comments}}
diff --git a/templates/repo/diff/section_split.tmpl b/templates/repo/diff/section_split.tmpl
index 3d36b41697..b245884536 100644
--- a/templates/repo/diff/section_split.tmpl
+++ b/templates/repo/diff/section_split.tmpl
@@ -1,5 +1,6 @@
 {{$file := .file}}
 {{$blobExcerptRepoLink := or ctx.RootData.CommitRepoLink ctx.RootData.RepoLink}}
+{{$issueIndex := or ctx.RootData.IssueIndex $.root.IssueIndex}}
 <colgroup>
 	<col width="50">
 	<col width="10">
@@ -28,17 +29,17 @@
 							</div>
 							<div class="code-expander-buttons" data-expand-direction="{{$expandDirection}}">
 								{{if or (eq $expandDirection 3) (eq $expandDirection 5)}}
-									<button class="code-expander-button" hx-target="closest tr" hx-get="{{$blobExcerptRepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=split&direction=down&wiki={{$.root.PageIsWiki}}&pull={{$.root.PageIsPullFiles}}&anchor=diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}&file_name={{$section.FileName}}">
+									<button class="code-expander-button" hx-target="closest tr" hx-get="{{$blobExcerptRepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=split&direction=down&wiki={{$.root.PageIsWiki}}&pull={{$.root.PageIsPullFiles}}&anchor=diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}&issue_index={{$issueIndex}}">
 										{{svg "octicon-fold-down"}}
 									</button>
 								{{end}}
 								{{if or (eq $expandDirection 3) (eq $expandDirection 4)}}
-									<button class="code-expander-button" hx-target="closest tr" hx-get="{{$blobExcerptRepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=split&direction=up&wiki={{$.root.PageIsWiki}}&pull={{$.root.PageIsPullFiles}}&anchor=diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}&file_name={{$section.FileName}}">
+									<button class="code-expander-button" hx-target="closest tr" hx-get="{{$blobExcerptRepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=split&direction=up&wiki={{$.root.PageIsWiki}}&pull={{$.root.PageIsPullFiles}}&anchor=diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}&issue_index={{$issueIndex}}">
 										{{svg "octicon-fold-up"}}
 									</button>
 								{{end}}
 								{{if eq $expandDirection 2}}
-									<button class="code-expander-button" hx-target="closest tr" hx-get="{{$blobExcerptRepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=split&direction=&wiki={{$.root.PageIsWiki}}&pull={{$.root.PageIsPullFiles}}&anchor=diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}&file_name={{$section.FileName}}">
+									<button class="code-expander-button" hx-target="closest tr" hx-get="{{$blobExcerptRepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=split&direction=&wiki={{$.root.PageIsWiki}}&pull={{$.root.PageIsPullFiles}}&anchor=diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}&issue_index={{$issueIndex}}">
 										{{svg "octicon-fold"}}
 									</button>
 								{{end}}
diff --git a/templates/repo/diff/section_unified.tmpl b/templates/repo/diff/section_unified.tmpl
index 79f8139ae3..fe1a6d0faf 100644
--- a/templates/repo/diff/section_unified.tmpl
+++ b/templates/repo/diff/section_unified.tmpl
@@ -1,5 +1,6 @@
 {{$file := .file}}
 {{$blobExcerptRepoLink := or ctx.RootData.CommitRepoLink ctx.RootData.RepoLink}}
+{{$issueIndex := or ctx.RootData.IssueIndex $.root.IssueIndex}}
 <colgroup>
 	<col width="50">
 	<col width="50">
@@ -24,17 +25,17 @@
 							</div>
 							<div class="code-expander-buttons" data-expand-direction="{{$expandDirection}}">
 								{{if or (eq $expandDirection 3) (eq $expandDirection 5)}}
-									<button class="code-expander-button" hx-target="closest tr" hx-get="{{$blobExcerptRepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=unified&direction=down&wiki={{$.root.PageIsWiki}}&pull={{$.root.PageIsPullFiles}}&anchor=diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}&file_name={{$section.FileName}}">
+									<button class="code-expander-button" hx-target="closest tr" hx-get="{{$blobExcerptRepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=unified&direction=down&wiki={{$.root.PageIsWiki}}&pull={{$.root.PageIsPullFiles}}&anchor=diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}&issue_index={{$issueIndex}}">
 										{{svg "octicon-fold-down"}}
 									</button>
 								{{end}}
 								{{if or (eq $expandDirection 3) (eq $expandDirection 4)}}
-									<button class="code-expander-button" hx-target="closest tr" hx-get="{{$blobExcerptRepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=unified&direction=up&wiki={{$.root.PageIsWiki}}&pull={{$.root.PageIsPullFiles}}&anchor=diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}&file_name={{$section.FileName}}">
+									<button class="code-expander-button" hx-target="closest tr" hx-get="{{$blobExcerptRepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=unified&direction=up&wiki={{$.root.PageIsWiki}}&pull={{$.root.PageIsPullFiles}}&anchor=diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}&issue_index={{$issueIndex}}">
 										{{svg "octicon-fold-up"}}
 									</button>
 								{{end}}
 								{{if eq $expandDirection 2}}
-									<button class="code-expander-button" hx-target="closest tr" hx-get="{{$blobExcerptRepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=unified&direction=&wiki={{$.root.PageIsWiki}}&pull={{$.root.PageIsPullFiles}}&anchor=diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}&file_name={{$section.FileName}}">
+									<button class="code-expander-button" hx-target="closest tr" hx-get="{{$blobExcerptRepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=unified&direction=&wiki={{$.root.PageIsWiki}}&pull={{$.root.PageIsPullFiles}}&anchor=diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}&issue_index={{$issueIndex}}">
 										{{svg "octicon-fold"}}
 									</button>
 								{{end}}

From ea285c213178e5d2ac2162b38d9221cc5be7c6de Mon Sep 17 00:00:00 2001
From: Rajesh Jonnalagadda <rajeshjonnalagadda48@gmail.com>
Date: Thu, 28 Nov 2024 04:27:47 +0530
Subject: [PATCH 05/13] chore: fix the extra comment icon at the end and change
 the icon pointer

---
 routers/web/repo/compare.go              | 2 +-
 services/gitdiff/gitdiff.go              | 2 +-
 templates/repo/diff/blob_excerpt.tmpl    | 4 ++--
 templates/repo/diff/section_split.tmpl   | 2 +-
 templates/repo/diff/section_unified.tmpl | 2 +-
 web_src/css/base.css                     | 4 ++++
 6 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/routers/web/repo/compare.go b/routers/web/repo/compare.go
index 07e8a39dfe..a3e9ad3bf9 100644
--- a/routers/web/repo/compare.go
+++ b/routers/web/repo/compare.go
@@ -957,7 +957,7 @@ func ExcerptBlob(ctx *context.Context) {
 		}
 		lineCommits := allComments[filePath]
 		for _, line := range section.Lines {
-			if line.SectionInfo != nil {
+			if line.SectionInfo != nil && line.SectionInfo.RightHunkSize > 0 {
 				start := int64(line.SectionInfo.LastRightIdx + 1)
 				end := int64(line.SectionInfo.RightIdx - 1)
 				for start <= end {
diff --git a/services/gitdiff/gitdiff.go b/services/gitdiff/gitdiff.go
index 9dedf618b1..4b253e0eb6 100644
--- a/services/gitdiff/gitdiff.go
+++ b/services/gitdiff/gitdiff.go
@@ -482,7 +482,7 @@ func (diff *Diff) LoadComments(ctx context.Context, issue *issues_model.Issue, c
 		if lineCommits, ok := allComments[file.Name]; ok {
 			for _, section := range file.Sections {
 				for _, line := range section.Lines {
-					if line.SectionInfo != nil {
+					if line.SectionInfo != nil && line.SectionInfo.RightHunkSize > 0 {
 						start := int64(line.SectionInfo.LastRightIdx + 1)
 						end := int64(line.SectionInfo.RightIdx - 1)
 						for start <= end {
diff --git a/templates/repo/diff/blob_excerpt.tmpl b/templates/repo/diff/blob_excerpt.tmpl
index 10601fa576..72a1e786a3 100644
--- a/templates/repo/diff/blob_excerpt.tmpl
+++ b/templates/repo/diff/blob_excerpt.tmpl
@@ -8,7 +8,7 @@
 				<div class="lines-comment">
 					<div>
 						{{if $line.SectionInfo.HasComments}}
-							<button>
+							<button class="section-comment-icon">
 								{{svg "octicon-comment-discussion"}}
 							</button>
 						{{end}}
@@ -81,7 +81,7 @@
 				<div class="lines-comment">
 					<div>
 						{{if $line.SectionInfo.HasComments}}
-							<button>
+							<button class="section-comment-icon">
 								{{svg "octicon-comment-discussion"}}
 							</button>
 						{{end}}
diff --git a/templates/repo/diff/section_split.tmpl b/templates/repo/diff/section_split.tmpl
index b245884536..ce1f626d90 100644
--- a/templates/repo/diff/section_split.tmpl
+++ b/templates/repo/diff/section_split.tmpl
@@ -22,7 +22,7 @@
 						<div class="lines-comment">
 							<div>
 								{{if $line.SectionInfo.HasComments}}
-									<button>
+									<button class="section-comment-icon">
 										{{svg "octicon-comment-discussion"}}
 									</button>
 								{{end}}
diff --git a/templates/repo/diff/section_unified.tmpl b/templates/repo/diff/section_unified.tmpl
index fe1a6d0faf..8ca2c8cc4f 100644
--- a/templates/repo/diff/section_unified.tmpl
+++ b/templates/repo/diff/section_unified.tmpl
@@ -18,7 +18,7 @@
 						<div class="lines-comment">
 							<div>
 								{{if $line.SectionInfo.HasComments}}
-									<button>
+									<button class="section-comment-icon">
 										{{svg "octicon-comment-discussion"}}
 									</button>
 								{{end}}
diff --git a/web_src/css/base.css b/web_src/css/base.css
index ebb41bde85..c31dfd05bd 100644
--- a/web_src/css/base.css
+++ b/web_src/css/base.css
@@ -1148,6 +1148,10 @@ overflow-menu .ui.label {
   gap: 1px;
 }
 
+.section-comment-icon {
+  cursor: default;
+}
+
 .lines-commit .blame-info .blame-data .blame-message {
   flex-grow: 2;
   overflow: hidden;

From 5d9651b8ed0673b86a131098f42acf09bbe03893 Mon Sep 17 00:00:00 2001
From: Rajesh Jonnalagadda <rajeshjonnalagadda48@gmail.com>
Date: Thu, 28 Nov 2024 18:12:06 +0530
Subject: [PATCH 06/13] chore: fix the comment context menu drop down

---
 templates/repo/diff/blob_excerpt.tmpl | 7 +++++++
 web_src/js/features/repo-diff.ts      | 8 ++++++++
 2 files changed, 15 insertions(+)

diff --git a/templates/repo/diff/blob_excerpt.tmpl b/templates/repo/diff/blob_excerpt.tmpl
index 72a1e786a3..01f1e4b866 100644
--- a/templates/repo/diff/blob_excerpt.tmpl
+++ b/templates/repo/diff/blob_excerpt.tmpl
@@ -126,6 +126,13 @@
 				{{template "repo/diff/conversation" dict "." $ "comments" $line.Comments}}
 			</td>
 		</tr>
+		<button class="pull-request-diff-comments hidden"></button>
+		<script class="pull-request-diff-comments">
+    		var $buttons = document.querySelector('button.pull-request-diff-comments');
+    		if ($buttons) {
+    		    $buttons.click();
+    		}
+		</script>
 	{{end}}
 	{{end}}
 {{end}}
diff --git a/web_src/js/features/repo-diff.ts b/web_src/js/features/repo-diff.ts
index f39de96f5b..403b5f8689 100644
--- a/web_src/js/features/repo-diff.ts
+++ b/web_src/js/features/repo-diff.ts
@@ -19,6 +19,7 @@ import {
 import {POST, GET} from '../modules/fetch.ts';
 import {fomanticQuery} from '../modules/fomantic/base.ts';
 import {createTippy} from '../modules/tippy.ts';
+import {initGlobalDropdown} from './common-page.ts';
 
 const {pageData, i18n} = window.config;
 
@@ -94,6 +95,13 @@ function initRepoDiffConversationForm() {
     }
   });
 
+  $(document).on('click', '.pull-request-diff-comments', async (e) => {
+    e.preventDefault();
+    initGlobalDropdown();
+    // post initiation cleaning up the buttons and scripts
+    $('.pull-request-diff-comments').remove();
+  });
+
   $(document).on('click', '.resolve-conversation', async function (e) {
     e.preventDefault();
     const comment_id = $(this).data('comment-id');

From 728fc122b29cf2b7a748b08515c5c279f8446711 Mon Sep 17 00:00:00 2001
From: Rajesh Jonnalagadda <rajeshjonnalagadda48@gmail.com>
Date: Thu, 28 Nov 2024 18:26:07 +0530
Subject: [PATCH 07/13] chore: fix backedn-lint issues

---
 templates/repo/diff/blob_excerpt.tmpl | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/templates/repo/diff/blob_excerpt.tmpl b/templates/repo/diff/blob_excerpt.tmpl
index 01f1e4b866..b36ba38747 100644
--- a/templates/repo/diff/blob_excerpt.tmpl
+++ b/templates/repo/diff/blob_excerpt.tmpl
@@ -127,12 +127,12 @@
 			</td>
 		</tr>
 		<button class="pull-request-diff-comments hidden"></button>
-		<script class="pull-request-diff-comments">
-    		var $buttons = document.querySelector('button.pull-request-diff-comments');
-    		if ($buttons) {
-    		    $buttons.click();
-    		}
-		</script>
+    	<script class="pull-request-diff-comments">
+    	    var $buttons = document.querySelector('button.pull-request-diff-comments');
+    	    if ($buttons) {
+    	        $buttons.click();
+    	    }
+    	</script>
 	{{end}}
 	{{end}}
 {{end}}

From bf3535a7a30ea7ef005458e4949dbe06b75f28f7 Mon Sep 17 00:00:00 2001
From: Rajesh Jonnalagadda <rajeshjonnalagadda48@gmail.com>
Date: Thu, 28 Nov 2024 18:41:45 +0530
Subject: [PATCH 08/13] chore: fix lint issue

---
 templates/repo/diff/blob_excerpt.tmpl | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/templates/repo/diff/blob_excerpt.tmpl b/templates/repo/diff/blob_excerpt.tmpl
index b36ba38747..ba4e29ad43 100644
--- a/templates/repo/diff/blob_excerpt.tmpl
+++ b/templates/repo/diff/blob_excerpt.tmpl
@@ -127,12 +127,12 @@
 			</td>
 		</tr>
 		<button class="pull-request-diff-comments hidden"></button>
-    	<script class="pull-request-diff-comments">
-    	    var $buttons = document.querySelector('button.pull-request-diff-comments');
-    	    if ($buttons) {
-    	        $buttons.click();
-    	    }
-    	</script>
+		<script class="pull-request-diff-comments">
+			var $buttons = document.querySelector('button.pull-request-diff-comments');
+			if ($buttons) {
+				$buttons.click();
+			}
+		</script>
 	{{end}}
 	{{end}}
 {{end}}

From 50bab1b24bc851a201bc782303367a095e825e5e Mon Sep 17 00:00:00 2001
From: Rajesh Jonnalagadda <rajeshjonnalagadda48@gmail.com>
Date: Fri, 6 Dec 2024 20:49:34 +0530
Subject: [PATCH 09/13] chore: remove the add comment on the line section. fix
 the hsaComments logic

---
 routers/web/repo/compare.go      | 4 ++--
 services/gitdiff/gitdiff.go      | 6 +++---
 services/gitdiff/gitdiff_test.go | 2 +-
 3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/routers/web/repo/compare.go b/routers/web/repo/compare.go
index a3e9ad3bf9..8112886683 100644
--- a/routers/web/repo/compare.go
+++ b/routers/web/repo/compare.go
@@ -956,8 +956,8 @@ func ExcerptBlob(ctx *context.Context) {
 			return
 		}
 		lineCommits := allComments[filePath]
-		for _, line := range section.Lines {
-			if line.SectionInfo != nil && line.SectionInfo.RightHunkSize > 0 {
+		for index, line := range section.Lines {
+			if line.SectionInfo != nil && line.Type == 4 && !(line.SectionInfo.LastRightIdx == 0 && index+1 == len(section.Lines)) {
 				start := int64(line.SectionInfo.LastRightIdx + 1)
 				end := int64(line.SectionInfo.RightIdx - 1)
 				for start <= end {
diff --git a/services/gitdiff/gitdiff.go b/services/gitdiff/gitdiff.go
index 4b253e0eb6..c9e338c080 100644
--- a/services/gitdiff/gitdiff.go
+++ b/services/gitdiff/gitdiff.go
@@ -121,7 +121,7 @@ func (d *DiffLine) GetHTMLDiffLineType() string {
 
 // CanComment returns whether a line can get commented
 func (d *DiffLine) CanComment() bool {
-	return len(d.Comments) == 0
+	return len(d.Comments) == 0 && d.Type != DiffLineSection
 }
 
 // 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
 	for _, file := range diff.Files {
 		if lineCommits, ok := allComments[file.Name]; ok {
 			for _, section := range file.Sections {
-				for _, line := range section.Lines {
-					if line.SectionInfo != nil && line.SectionInfo.RightHunkSize > 0 {
+				for index, line := range section.Lines {
+					if line.SectionInfo != nil && line.Type == 4 && !(line.SectionInfo.LastRightIdx == 0 && index+1 == len(section.Lines)) {
 						start := int64(line.SectionInfo.LastRightIdx + 1)
 						end := int64(line.SectionInfo.RightIdx - 1)
 						for start <= end {
diff --git a/services/gitdiff/gitdiff_test.go b/services/gitdiff/gitdiff_test.go
index 644c2475f4..adcac355a7 100644
--- a/services/gitdiff/gitdiff_test.go
+++ b/services/gitdiff/gitdiff_test.go
@@ -615,7 +615,7 @@ func TestDiff_LoadCommentsWithOutdated(t *testing.T) {
 }
 
 func TestDiffLine_CanComment(t *testing.T) {
-	assert.True(t, (&DiffLine{Type: DiffLineSection}).CanComment())
+	assert.False(t, (&DiffLine{Type: DiffLineSection}).CanComment())
 	assert.False(t, (&DiffLine{Type: DiffLineAdd, Comments: []*issues_model.Comment{{Content: "bla"}}}).CanComment())
 	assert.True(t, (&DiffLine{Type: DiffLineAdd}).CanComment())
 	assert.True(t, (&DiffLine{Type: DiffLineDel}).CanComment())

From 96849dda831b62da6fb583e1096145c2a75e5d13 Mon Sep 17 00:00:00 2001
From: Rajesh Jonnalagadda <rajeshjonnalagadda48@gmail.com>
Date: Tue, 10 Dec 2024 12:54:50 +0530
Subject: [PATCH 10/13] chore: handle feedback

---
 models/issues/comment_code.go          | 15 +++++--
 models/issues/comment_test.go          |  4 +-
 models/issues/review.go                |  2 +-
 routers/web/repo/compare.go            | 22 +++++-----
 routers/web/web.go                     |  4 --
 services/gitdiff/gitdiff.go            | 56 +++++++++++---------------
 services/repository/files/diff_test.go | 18 ++++-----
 7 files changed, 56 insertions(+), 65 deletions(-)

diff --git a/models/issues/comment_code.go b/models/issues/comment_code.go
index 67a77ceb13..fdba7dca25 100644
--- a/models/issues/comment_code.go
+++ b/models/issues/comment_code.go
@@ -18,11 +18,11 @@ import (
 type CodeComments map[string]map[int64][]*Comment
 
 // FetchCodeComments will return a 2d-map: ["Path"]["Line"] = Comments at line
-func FetchCodeComments(ctx context.Context, issue *Issue, currentUser *user_model.User, showOutdatedComments bool) (CodeComments, error) {
-	return fetchCodeCommentsByReview(ctx, issue, currentUser, nil, showOutdatedComments)
+func FetchCodeComments(ctx context.Context, issue *Issue, currentUser *user_model.User, showOutdatedComments bool, filePath *string) (CodeComments, error) {
+	return fetchCodeCommentsByReview(ctx, issue, currentUser, nil, showOutdatedComments, filePath)
 }
 
-func fetchCodeCommentsByReview(ctx context.Context, issue *Issue, currentUser *user_model.User, review *Review, showOutdatedComments bool) (CodeComments, error) {
+func fetchCodeCommentsByReview(ctx context.Context, issue *Issue, currentUser *user_model.User, review *Review, showOutdatedComments bool, filePath *string) (CodeComments, error) {
 	pathToLineToComment := make(CodeComments)
 	if review == nil {
 		review = &Review{ID: 0}
@@ -33,6 +33,15 @@ func fetchCodeCommentsByReview(ctx context.Context, issue *Issue, currentUser *u
 		ReviewID: review.ID,
 	}
 
+	if filePath != nil {
+		opts = FindCommentsOptions{
+			Type:     CommentTypeCode,
+			IssueID:  issue.ID,
+			ReviewID: review.ID,
+			TreePath: *filePath,
+		}
+	}
+
 	comments, err := findCodeComments(ctx, opts, issue, currentUser, review, showOutdatedComments)
 	if err != nil {
 		return nil, err
diff --git a/models/issues/comment_test.go b/models/issues/comment_test.go
index c5bbfdedc2..10a4558639 100644
--- a/models/issues/comment_test.go
+++ b/models/issues/comment_test.go
@@ -50,7 +50,7 @@ func TestFetchCodeComments(t *testing.T) {
 
 	issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 2})
 	user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1})
-	res, err := issues_model.FetchCodeComments(db.DefaultContext, issue, user, false)
+	res, err := issues_model.FetchCodeComments(db.DefaultContext, issue, user, false, nil)
 	assert.NoError(t, err)
 	assert.Contains(t, res, "README.md")
 	assert.Contains(t, res["README.md"], int64(4))
@@ -58,7 +58,7 @@ func TestFetchCodeComments(t *testing.T) {
 	assert.Equal(t, int64(4), res["README.md"][4][0].ID)
 
 	user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
-	res, err = issues_model.FetchCodeComments(db.DefaultContext, issue, user2, false)
+	res, err = issues_model.FetchCodeComments(db.DefaultContext, issue, user2, false, nil)
 	assert.NoError(t, err)
 	assert.Len(t, res, 1)
 }
diff --git a/models/issues/review.go b/models/issues/review.go
index 8b345e5fd8..1242517261 100644
--- a/models/issues/review.go
+++ b/models/issues/review.go
@@ -158,7 +158,7 @@ func (r *Review) LoadCodeComments(ctx context.Context) (err error) {
 	if err = r.LoadIssue(ctx); err != nil {
 		return err
 	}
-	r.CodeComments, err = fetchCodeCommentsByReview(ctx, r.Issue, nil, r, false)
+	r.CodeComments, err = fetchCodeCommentsByReview(ctx, r.Issue, nil, r, false, nil)
 	return err
 }
 
diff --git a/routers/web/repo/compare.go b/routers/web/repo/compare.go
index 8112886683..4cd2f1006a 100644
--- a/routers/web/repo/compare.go
+++ b/routers/web/repo/compare.go
@@ -924,16 +924,14 @@ func ExcerptBlob(ctx *context.Context) {
 			Type:    gitdiff.DiffLineSection,
 			Content: lineText,
 			SectionInfo: &gitdiff.DiffLineSectionInfo{
-				Path:                filePath,
-				LastLeftIdx:         lastLeft,
-				LastRightIdx:        lastRight,
-				LeftIdx:             idxLeft,
-				RightIdx:            idxRight,
-				LeftHunkSize:        leftHunkSize,
-				RightHunkSize:       rightHunkSize,
-				HasComments:         false,
-				LastRightCommentIdx: 0,
-				RightCommentIdx:     0,
+				Path:          filePath,
+				LastLeftIdx:   lastLeft,
+				LastRightIdx:  lastRight,
+				LeftIdx:       idxLeft,
+				RightIdx:      idxRight,
+				LeftHunkSize:  leftHunkSize,
+				RightHunkSize: rightHunkSize,
+				HasComments:   false,
 			},
 			Comments: nil,
 		}
@@ -946,11 +944,11 @@ func ExcerptBlob(ctx *context.Context) {
 	issueIndex := ctx.FormInt64("issue_index")
 	if ctx.FormBool("pull") && issueIndex > 0 {
 		issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, issueIndex)
-		if issue == nil {
+		if err != nil {
 			ctx.ServerError("GetIssueByIndex", err)
 			return
 		}
-		allComments, err := issues_model.FetchCodeComments(ctx, issue, ctx.Doer, false)
+		allComments, err := issues_model.FetchCodeComments(ctx, issue, ctx.Doer, false, &filePath)
 		if err != nil {
 			ctx.ServerError("FetchCodeComments", err)
 			return
diff --git a/routers/web/web.go b/routers/web/web.go
index 6a1fb58264..85e0fdc41e 100644
--- a/routers/web/web.go
+++ b/routers/web/web.go
@@ -1520,10 +1520,6 @@ func registerRoutes(m *web.Router) {
 			m.Get("/{sha}", repo.SetEditorconfigIfExists, repo.SetDiffViewStyle, repo.ExcerptBlob)
 		}, func(ctx *context.Context) gocontext.CancelFunc {
 			// FIXME: refactor this function, use separate routes for wiki/code
-			if ctx.FormBool("pull") {
-				ctx.Data["PageIsPullFiles"] = true
-			}
-
 			if ctx.FormBool("wiki") {
 				ctx.Data["PageIsWiki"] = true
 				repo.MustEnableWiki(ctx)
diff --git a/services/gitdiff/gitdiff.go b/services/gitdiff/gitdiff.go
index c9e338c080..9cc1cc15a3 100644
--- a/services/gitdiff/gitdiff.go
+++ b/services/gitdiff/gitdiff.go
@@ -86,16 +86,14 @@ type DiffLine struct {
 
 // DiffLineSectionInfo represents diff line section meta data
 type DiffLineSectionInfo struct {
-	Path                string
-	LastLeftIdx         int
-	LastRightIdx        int
-	LeftIdx             int
-	RightIdx            int
-	LeftHunkSize        int
-	RightHunkSize       int
-	HasComments         bool
-	LastRightCommentIdx int
-	RightCommentIdx     int
+	Path          string
+	LastLeftIdx   int
+	LastRightIdx  int
+	LeftIdx       int
+	RightIdx      int
+	LeftHunkSize  int
+	RightHunkSize int
+	HasComments   bool
 }
 
 // BlobExcerptChunkSize represent max lines of excerpt
@@ -146,12 +144,10 @@ func (d *DiffLine) GetBlobExcerptQuery() string {
 		"last_left=%d&last_right=%d&"+
 			"left=%d&right=%d&"+
 			"left_hunk_size=%d&right_hunk_size=%d&"+
-			"last_rightt_comment_idx=%d&right_comment_idx=%d&"+
 			"path=%s",
 		d.SectionInfo.LastLeftIdx, d.SectionInfo.LastRightIdx,
 		d.SectionInfo.LeftIdx, d.SectionInfo.RightIdx,
 		d.SectionInfo.LeftHunkSize, d.SectionInfo.RightHunkSize,
-		d.SectionInfo.LastRightCommentIdx, d.SectionInfo.RightCommentIdx,
 		url.QueryEscape(d.SectionInfo.Path))
 	return query
 }
@@ -175,16 +171,14 @@ func getDiffLineSectionInfo(treePath, line string, lastLeftIdx, lastRightIdx int
 	leftLine, leftHunk, rightLine, righHunk := git.ParseDiffHunkString(line)
 
 	return &DiffLineSectionInfo{
-		Path:                treePath,
-		LastLeftIdx:         lastLeftIdx,
-		LastRightIdx:        lastRightIdx,
-		LeftIdx:             leftLine,
-		RightIdx:            rightLine,
-		LeftHunkSize:        leftHunk,
-		RightHunkSize:       righHunk,
-		HasComments:         false,
-		LastRightCommentIdx: 0,
-		RightCommentIdx:     0,
+		Path:          treePath,
+		LastLeftIdx:   lastLeftIdx,
+		LastRightIdx:  lastRightIdx,
+		LeftIdx:       leftLine,
+		RightIdx:      rightLine,
+		LeftHunkSize:  leftHunk,
+		RightHunkSize: righHunk,
+		HasComments:   false,
 	}
 }
 
@@ -404,14 +398,12 @@ func (diffFile *DiffFile) GetTailSection(gitRepo *git.Repository, leftCommit, ri
 		Type:    DiffLineSection,
 		Content: " ",
 		SectionInfo: &DiffLineSectionInfo{
-			Path:                diffFile.Name,
-			LastLeftIdx:         lastLine.LeftIdx,
-			LastRightIdx:        lastLine.RightIdx,
-			LeftIdx:             leftLineCount,
-			RightIdx:            rightLineCount,
-			HasComments:         false,
-			LastRightCommentIdx: 0,
-			RightCommentIdx:     0,
+			Path:         diffFile.Name,
+			LastLeftIdx:  lastLine.LeftIdx,
+			LastRightIdx: lastLine.RightIdx,
+			LeftIdx:      leftLineCount,
+			RightIdx:     rightLineCount,
+			HasComments:  false,
 		},
 	}
 	tailSection := &DiffSection{FileName: diffFile.Name, Lines: []*DiffLine{tailDiffLine}}
@@ -469,11 +461,9 @@ type Diff struct {
 	NumViewedFiles               int // user-specific
 }
 
-// function (section *DiffSection) GetType() int {
-
 // LoadComments loads comments into each line
 func (diff *Diff) LoadComments(ctx context.Context, issue *issues_model.Issue, currentUser *user_model.User, showOutdatedComments bool) error {
-	allComments, err := issues_model.FetchCodeComments(ctx, issue, currentUser, showOutdatedComments)
+	allComments, err := issues_model.FetchCodeComments(ctx, issue, currentUser, showOutdatedComments, nil)
 	if err != nil {
 		return err
 	}
diff --git a/services/repository/files/diff_test.go b/services/repository/files/diff_test.go
index 7b98886358..c698c83892 100644
--- a/services/repository/files/diff_test.go
+++ b/services/repository/files/diff_test.go
@@ -59,16 +59,14 @@ func TestGetDiffPreview(t *testing.T) {
 								Content:  "@@ -1,3 +1,4 @@",
 								Comments: nil,
 								SectionInfo: &gitdiff.DiffLineSectionInfo{
-									Path:                "README.md",
-									LastLeftIdx:         0,
-									LastRightIdx:        0,
-									LeftIdx:             1,
-									RightIdx:            1,
-									LeftHunkSize:        3,
-									RightHunkSize:       4,
-									HasComments:         false,
-									LastRightCommentIdx: 0,
-									RightCommentIdx:     0,
+									Path:          "README.md",
+									LastLeftIdx:   0,
+									LastRightIdx:  0,
+									LeftIdx:       1,
+									RightIdx:      1,
+									LeftHunkSize:  3,
+									RightHunkSize: 4,
+									HasComments:   false,
 								},
 							},
 							{

From a68fbd5f2dff67bd46c78e16ff3b6cebb36cf031 Mon Sep 17 00:00:00 2001
From: Rajesh Jonnalagadda <rajeshjonnalagadda48@gmail.com>
Date: Sun, 2 Mar 2025 15:41:32 +0530
Subject: [PATCH 11/13] chore: remove unwanted class in script

---
 templates/repo/diff/blob_excerpt.tmpl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/templates/repo/diff/blob_excerpt.tmpl b/templates/repo/diff/blob_excerpt.tmpl
index 5385ad224d..941ac44ae2 100644
--- a/templates/repo/diff/blob_excerpt.tmpl
+++ b/templates/repo/diff/blob_excerpt.tmpl
@@ -147,7 +147,7 @@
 			</td>
 		</tr>
 		<button class="pull-request-diff-comments hidden"></button>
-		<script class="pull-request-diff-comments">
+		<script>
 			var $buttons = document.querySelector('button.pull-request-diff-comments');
 			if ($buttons) {
 				$buttons.click();

From ebad7a3ec118a5edc2227477a9e443041d997caa Mon Sep 17 00:00:00 2001
From: Rajesh Jonnalagadda <rajeshjonnalagadda48@gmail.com>
Date: Sun, 2 Mar 2025 16:03:46 +0530
Subject: [PATCH 12/13] chore: fix lint issues

---
 web_src/js/features/repo-diff.ts | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/web_src/js/features/repo-diff.ts b/web_src/js/features/repo-diff.ts
index dfae981f6e..fa43debc8f 100644
--- a/web_src/js/features/repo-diff.ts
+++ b/web_src/js/features/repo-diff.ts
@@ -12,8 +12,6 @@ import {invertFileFolding} from './file-fold.ts';
 import {parseDom} from '../utils.ts';
 import {observeAddedElement} from '../modules/observer.ts';
 import {initGlobalDropdown} from './common-page.ts';
-
-
 const {i18n} = window.config;
 
 function initRepoDiffFileBox(el: HTMLElement) {
@@ -90,7 +88,7 @@ function initRepoDiffConversationForm() {
       console.error('Error:', error);
       showErrorToast(i18n.network_error);
     } finally {
-      form?.classList.remove('is-loading'); 
+      form?.classList.remove('is-loading');
     }
   });
 

From df2ee8b634d8ce8c6bb112ca9bf20f8f42ca1b48 Mon Sep 17 00:00:00 2001
From: Rajesh Jonnalagadda <rajeshjonnalagadda48@gmail.com>
Date: Wed, 5 Mar 2025 10:50:53 +0530
Subject: [PATCH 13/13] chore: resolve conflict

---
 web_src/js/features/repo-diff.ts | 1 -
 1 file changed, 1 deletion(-)

diff --git a/web_src/js/features/repo-diff.ts b/web_src/js/features/repo-diff.ts
index c1ee2d676d..12cd7ce7ac 100644
--- a/web_src/js/features/repo-diff.ts
+++ b/web_src/js/features/repo-diff.ts
@@ -10,7 +10,6 @@ import {POST, GET} from '../modules/fetch.ts';
 import {createTippy} from '../modules/tippy.ts';
 import {invertFileFolding} from './file-fold.ts';
 import {parseDom} from '../utils.ts';
-import {observeAddedElement} from '../modules/observer.ts';
 import {initGlobalDropdown} from './common-page.ts';
 import {registerGlobalSelectorFunc} from '../modules/observer.ts';