]> source.dussan.org Git - gitea.git/commitdiff
Ensure that new pull request button works on forked forks owned by owner of the root...
authorzeripath <art27@cantab.net>
Tue, 16 Mar 2021 01:36:34 +0000 (01:36 +0000)
committerGitHub <noreply@github.com>
Tue, 16 Mar 2021 01:36:34 +0000 (02:36 +0100)
Prevent 404 on new pull request button on forked fork owned by the owner
of the root repository. Also ensure that the names make sense.

Signed-off-by: Andrew Thornton <art27@cantab.net>
templates/repo/diff/compare.tmpl
templates/repo/home.tmpl

index 071a79045792fb3a18cfe92abb56f2173ca68b09..fdf65aaad381f39dfa927b510fdd402171fed8fa 100644 (file)
                                {{.i18n.Tr "action.compare_commits_general"}}
                        {{ end }}
                </h2>
+               {{ $BaseCompareName := $.BaseName -}}
+               {{- $HeadCompareName := $.HeadRepo.OwnerName -}}
+               {{- if and (eq $.BaseName $.HeadRepo.OwnerName) (ne $.Repository.Name $.HeadRepo.Name) -}}
+                       {{- $HeadCompareName = printf "%s/%s" $.HeadRepo.OwnerName $.HeadRepo.Name -}}
+               {{- end -}}
+               {{- $OwnForkCompareName := "" -}}
+               {{- if .OwnForkRepo -}}
+                       {{- $OwnForkCompareName = .OwnForkRepo.OwnerName -}}
+               {{- end -}}
+               {{- $RootRepoCompareName := "" -}}
+               {{- if .RootRepo -}}
+                       {{- $RootRepoCompareName = .RootRepo.OwnerName -}}
+                       {{- if eq $.HeadRepo.OwnerName .RootRepo.OwnerName -}}
+                               {{- $HeadCompareName = printf "%s/%s" $.HeadRepo.OwnerName $.HeadRepo.Name -}}
+                       {{- end -}}
+                       {{- if .OwnForkRepo -}}
+                               {{- if eq $.OwnForkRepo.OwnerName .RootRepo.OwnerName -}}
+                                       {{- $OwnForkRepoCompareName = printf "%s/%s" $.OwnForkRepo.OwnerName $.OwnForkRepo.Name -}}
+                               {{- end -}}
+                       {{- end -}}
+               {{- end -}}
                <div class="ui segment choose branch">
                        {{svg "octicon-git-compare"}}
                        <div class="ui floating filter dropdown" data-no-results="{{.i18n.Tr "repo.pulls.no_results"}}">
                                <div class="ui basic small button">
-                                       <span class="text">{{.i18n.Tr "repo.pulls.compare_base"}}: {{$.BaseName}}:{{$.BaseBranch}}</span>
+                                       <span class="text">{{.i18n.Tr "repo.pulls.compare_base"}}: {{$BaseCompareName}}:{{$.BaseBranch}}</span>
                                        {{svg "octicon-triangle-down" 14 "dropdown icon"}}
                                </div>
                                <div class="menu">
                                        </div>
                                        <div class="scrolling menu">
                                                {{range .Branches}}
-                                                       <div class="item {{if eq $.BaseBranch .}}selected{{end}}" data-url="{{$.RepoLink}}/compare/{{EscapePound .}}...{{if not $.PullRequestCtx.SameRepo}}{{$.HeadUser.Name}}/{{$.HeadRepo.Name}}:{{end}}{{EscapePound $.HeadBranch}}">{{$.BaseName}}:{{.}}</div>
+                                                       <div class="item {{if eq $.BaseBranch .}}selected{{end}}" data-url="{{$.RepoLink}}/compare/{{EscapePound .}}...{{if not $.PullRequestCtx.SameRepo}}{{$.HeadUser.Name}}/{{$.HeadRepo.Name}}:{{end}}{{EscapePound $.HeadBranch}}">{{$BaseCompareName}}:{{.}}</div>
                                                {{end}}
                                                {{if not .PullRequestCtx.SameRepo}}
                                                        {{range .HeadBranches}}
-                                                               <div class="item" data-url="{{$.HeadRepo.Link}}/compare/{{EscapePound .}}...{{$.HeadUser.Name}}/{{$.HeadRepo.Name}}:{{EscapePound $.HeadBranch}}">{{$.HeadUser.Name}}:{{.}}</div>
+                                                               <div class="item" data-url="{{$.HeadRepo.Link}}/compare/{{EscapePound .}}...{{$.HeadUser.Name}}/{{$.HeadRepo.Name}}:{{EscapePound $.HeadBranch}}">{{$HeadCompareName}}:{{.}}</div>
                                                        {{end}}
                                                {{end}}
                                                {{if .OwnForkRepo}}
                                                        {{range .OwnForkRepoBranches}}
-                                                               <div class="item" data-url="{{$.OwnForkRepo.Link}}/compare/{{EscapePound .}}...{{$.HeadUser.Name}}/{{$.HeadRepo.Name}}:{{EscapePound $.HeadBranch}}">{{$.OwnForkRepo.OwnerName}}:{{.}}</div>
+                                                               <div class="item" data-url="{{$.OwnForkRepo.Link}}/compare/{{EscapePound .}}...{{$.HeadUser.Name}}/{{$.HeadRepo.Name}}:{{EscapePound $.HeadBranch}}">{{$OwnForkCompareName}}:{{.}}</div>
                                                        {{end}}
                                                {{end}}
                                                {{if .RootRepo}}
                                                        {{range .RootRepoBranches}}
-                                                               <div class="item" data-url="{{$.RootRepo.Link}}/compare/{{EscapePound .}}...{{$.HeadUser.Name}}/{{$.HeadRepo.Name}}:{{EscapePound $.HeadBranch}}">{{$.RootRepo.OwnerName}}:{{.}}</div>
+                                                               <div class="item" data-url="{{$.RootRepo.Link}}/compare/{{EscapePound .}}...{{$.HeadUser.Name}}/{{$.HeadRepo.Name}}:{{EscapePound $.HeadBranch}}">{{$RootRepoCompareName}}:{{.}}</div>
                                                        {{end}}
                                                {{end}}
                                        </div>
@@ -49,7 +70,7 @@
                        ...
                        <div class="ui floating filter dropdown">
                                <div class="ui basic small button">
-                                       <span class="text">{{.i18n.Tr "repo.pulls.compare_compare"}}: {{$.HeadUser.Name}}:{{$.HeadBranch}}</span>
+                                       <span class="text">{{.i18n.Tr "repo.pulls.compare_compare"}}: {{$HeadCompareName}}:{{$.HeadBranch}}</span>
                                        {{svg "octicon-triangle-down" 14 "dropdown icon"}}
                                </div>
                                <div class="menu">
                                        </div>
                                        <div class="scrolling menu">
                                                {{range .HeadBranches}}
-                                                       <div class="{{if eq $.HeadBranch .}}selected{{end}} item" data-url="{{$.RepoLink}}/compare/{{EscapePound $.BaseBranch}}...{{if not $.PullRequestCtx.SameRepo}}{{$.HeadUser.Name}}/{{$.HeadRepo.Name}}:{{end}}{{EscapePound .}}">{{$.HeadUser.Name}}:{{.}}</div>
+                                                       <div class="{{if eq $.HeadBranch .}}selected{{end}} item" data-url="{{$.RepoLink}}/compare/{{EscapePound $.BaseBranch}}...{{if not $.PullRequestCtx.SameRepo}}{{$.HeadUser.Name}}/{{$.HeadRepo.Name}}:{{end}}{{EscapePound .}}">{{$HeadCompareName}}:{{.}}</div>
                                                {{end}}
                                                {{if not .PullRequestCtx.SameRepo}}
                                                        {{range .Branches}}
-                                                               <div class="item" data-url="{{$.RepoLink}}/compare/{{EscapePound $.BaseBranch}}...{{$.BaseName}}/{{$.Repository.Name}}:{{EscapePound .}}">{{$.BaseName}}:{{.}}</div>
+                                                               <div class="item" data-url="{{$.RepoLink}}/compare/{{EscapePound $.BaseBranch}}...{{$.BaseName}}/{{$.Repository.Name}}:{{EscapePound .}}">{{$BaseCompareName}}:{{.}}</div>
                                                        {{end}}
                                                {{end}}
                                                {{if .OwnForkRepo}}
                                                        {{range .OwnForkRepoBranches}}
-                                                               <div class="item" data-url="{{$.RepoLink}}/compare/{{EscapePound $.BaseBranch}}...{{$.OwnForkRepo.OwnerName}}/{{$.OwnForkRepo.Name}}:{{EscapePound .}}">{{$.OwnForkRepo.OwnerName}}:{{.}}</div>
+                                                               <div class="item" data-url="{{$.RepoLink}}/compare/{{EscapePound $.BaseBranch}}...{{$.OwnForkRepo.OwnerName}}/{{$.OwnForkRepo.Name}}:{{EscapePound .}}">{{$OwnForkCompareName}}:{{.}}</div>
                                                        {{end}}
                                                {{end}}
                                                {{if .RootRepo}}
                                                        {{range .RootRepoBranches}}
-                                                               <div class="item" data-url="{{$.RepoLink}}/compare/{{EscapePound $.BaseBranch}}...{{$.RootRepo.OwnerName}}/{{$.RootRepo.Name}}:{{EscapePound .}}">{{$.RootRepo.OwnerName}}:{{.}}</div>
+                                                               <div class="item" data-url="{{$.RepoLink}}/compare/{{EscapePound $.BaseBranch}}...{{$.RootRepo.OwnerName}}/{{$.RootRepo.Name}}:{{EscapePound .}}">{{$RootRepoCompareName}}:{{.}}</div>
                                                        {{end}}
                                                {{end}}
                                        </div>
index 4d8d28921172937c1844c02b396d152536da9a79..b77f28f9207c6f818c9077eeeb1e79547c3cea31 100644 (file)
@@ -64,7 +64,7 @@
                        {{if eq $n 0}}
                                {{if and .CanCompareOrPull .IsViewBranch (not .Repository.IsArchived)}}
                                        <div class="fitted item mx-0">
-                                               <a href="{{.BaseRepo.Link}}/compare/{{.BaseRepo.DefaultBranch | EscapePound}}...{{if ne .Repository.Owner.Name .BaseRepo.Owner.Name}}{{.Repository.Owner.Name}}:{{end}}{{.BranchName | EscapePound}}">
+                                               <a href="{{.BaseRepo.Link}}/compare/{{.BaseRepo.DefaultBranch | EscapePound}}...{{if ne .Repository.Owner.Name .BaseRepo.Owner.Name}}{{.Repository.Owner.Name}}{{if .BaseRepo.IsFork}}/{{.Repository.Name}}{{end}}:{{end}}{{.BranchName | EscapePound}}">
                                                        <button id="new-pull-request" class="ui compact basic button">{{if .PullRequestCtx.Allowed}}{{.i18n.Tr "repo.pulls.compare_changes"}}{{else}}{{.i18n.Tr "action.compare_branch"}}{{end}}</button>
                                                </a>
                                        </div>