Skip to content

Commit 16cbd5b

Browse files
lunnyzeripath
andauthored
Fix generating compare link (#21519)
Fix #6318 Co-authored-by: zeripath <[email protected]>
1 parent da3b657 commit 16cbd5b

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

modules/templates/helper.go

+13
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,19 @@ func NewFuncMap() []template.FuncMap {
459459
return items
460460
},
461461
"HasPrefix": strings.HasPrefix,
462+
"CompareLink": func(baseRepo, repo *repo_model.Repository, branchName string) string {
463+
var curBranch string
464+
if repo.ID != baseRepo.ID {
465+
curBranch += fmt.Sprintf("%s/%s:", url.PathEscape(repo.OwnerName), url.PathEscape(repo.Name))
466+
}
467+
curBranch += util.PathEscapeSegments(branchName)
468+
469+
return fmt.Sprintf("%s/compare/%s...%s",
470+
baseRepo.Link(),
471+
util.PathEscapeSegments(baseRepo.DefaultBranch),
472+
curBranch,
473+
)
474+
},
462475
}}
463476
}
464477

templates/repo/home.tmpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
<!-- If home page, show new PR. If not, show breadcrumb -->
7171
{{if eq $n 0}}
7272
{{if and .CanCompareOrPull .IsViewBranch (not .Repository.IsArchived)}}
73-
<a href="{{.BaseRepo.Link}}/compare/{{PathEscapeSegments .BaseRepo.DefaultBranch}}...{{if ne .Repository.Owner.Name .BaseRepo.Owner.Name}}{{PathEscape .Repository.Owner.Name}}{{if .BaseRepo.IsFork}}/{{PathEscape .Repository.Name}}{{end}}:{{end}}{{PathEscapeSegments .BranchName}}">
73+
<a href="{{CompareLink .BaseRepo .Repository .BranchName}}">
7474
<button id="new-pull-request" class="ui compact basic button tooltip" data-content="{{if .PullRequestCtx.Allowed}}{{.locale.Tr "repo.pulls.compare_changes"}}{{else}}{{.locale.Tr "action.compare_branch"}}{{end}}"><span class="text">{{svg "octicon-git-pull-request"}}</span></button>
7575
</a>
7676
{{end}}

0 commit comments

Comments
 (0)