From efba6c4a2d6351a3c731601b9499a0164e1d4817 Mon Sep 17 00:00:00 2001 From: Rajesh Jonnalagadda Date: Tue, 12 Nov 2024 02:24:36 +0530 Subject: [PATCH] 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 @@
{{if or (eq $expandDirection 3) (eq $expandDirection 5)}} - {{end}} {{if or (eq $expandDirection 3) (eq $expandDirection 4)}} - {{end}} {{if eq $expandDirection 2}} - {{end}} @@ -88,17 +88,17 @@
{{if or (eq $expandDirection 3) (eq $expandDirection 5)}} - {{end}} {{if or (eq $expandDirection 3) (eq $expandDirection 4)}} - {{end}} {{if eq $expandDirection 2}} - {{end}} @@ -117,9 +117,7 @@ {{svg "octicon-plus"}} {{end}} - - {{$inlineDiff.Content}} - + {{$inlineDiff.Content}} {{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}} @@ -28,17 +29,17 @@
{{if or (eq $expandDirection 3) (eq $expandDirection 5)}} - {{end}} {{if or (eq $expandDirection 3) (eq $expandDirection 4)}} - {{end}} {{if eq $expandDirection 2}} - {{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}} @@ -24,17 +25,17 @@
{{if or (eq $expandDirection 3) (eq $expandDirection 5)}} - {{end}} {{if or (eq $expandDirection 3) (eq $expandDirection 4)}} - {{end}} {{if eq $expandDirection 2}} - {{end}}