Support open compare page directly (#17975)

* Support open compare page directly

* simple code

* Some improvements

Co-authored-by: 6543 <6543@obermui.de>
tokarchuk/v1.17
Lunny Xiao 3 years ago committed by GitHub
parent 4cbc865d83
commit b300e3f485
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 26
      routers/web/repo/compare.go
  2. 1
      routers/web/web.go

@ -215,23 +215,21 @@ func ParseCompareInfo(ctx *context.Context) *CompareInfo {
) )
infoPath = ctx.Params("*") infoPath = ctx.Params("*")
infos := strings.SplitN(infoPath, "...", 2) var infos []string
if infoPath == "" {
if len(infos) != 2 { infos = []string{baseRepo.DefaultBranch, baseRepo.DefaultBranch}
infos = []string{baseRepo.DefaultBranch, infoPath} } else {
if strings.Contains(infoPath, "..") { infos = strings.SplitN(infoPath, "...", 2)
infos = strings.SplitN(infoPath, "..", 2) if len(infos) != 2 {
ci.DirectComparison = true if infos = strings.SplitN(infoPath, "..", 2); len(infos) == 2 {
ctx.Data["PageIsComparePull"] = false ci.DirectComparison = true
ctx.Data["PageIsComparePull"] = false
} else {
infos = []string{baseRepo.DefaultBranch, infoPath}
}
} }
} }
if len(infos) != 2 {
log.Trace("ParseCompareInfo[%d]: not enough compared branches information %s", baseRepo.ID, infos)
ctx.NotFound("CompareAndPullRequest", nil)
return nil
}
ctx.Data["BaseName"] = baseRepo.OwnerName ctx.Data["BaseName"] = baseRepo.OwnerName
ci.BaseBranch = infos[0] ci.BaseBranch = infos[0]
ctx.Data["BaseBranch"] = ci.BaseBranch ctx.Data["BaseBranch"] = ci.BaseBranch

@ -702,6 +702,7 @@ func RegisterRoutes(m *web.Route) {
m.Group("/milestone", func() { m.Group("/milestone", func() {
m.Get("/{id}", repo.MilestoneIssuesAndPulls) m.Get("/{id}", repo.MilestoneIssuesAndPulls)
}, reqRepoIssuesOrPullsReader, context.RepoRef()) }, reqRepoIssuesOrPullsReader, context.RepoRef())
m.Get("/compare", repo.MustBeNotEmpty, reqRepoCodeReader, repo.SetEditorconfigIfExists, ignSignIn, repo.SetDiffViewStyle, repo.SetWhitespaceBehavior, repo.CompareDiff)
m.Combo("/compare/*", repo.MustBeNotEmpty, reqRepoCodeReader, repo.SetEditorconfigIfExists). m.Combo("/compare/*", repo.MustBeNotEmpty, reqRepoCodeReader, repo.SetEditorconfigIfExists).
Get(ignSignIn, repo.SetDiffViewStyle, repo.SetWhitespaceBehavior, repo.CompareDiff). Get(ignSignIn, repo.SetDiffViewStyle, repo.SetWhitespaceBehavior, repo.CompareDiff).
Post(reqSignIn, context.RepoMustNotBeArchived(), reqRepoPullsReader, repo.MustAllowPulls, bindIgnErr(forms.CreateIssueForm{}), repo.SetWhitespaceBehavior, repo.CompareAndPullRequestPost) Post(reqSignIn, context.RepoMustNotBeArchived(), reqRepoPullsReader, repo.MustAllowPulls, bindIgnErr(forms.CreateIssueForm{}), repo.SetWhitespaceBehavior, repo.CompareAndPullRequestPost)

Loading…
Cancel
Save