Skip to content

Commit

Permalink
Support open compare page directly
Browse files Browse the repository at this point in the history
  • Loading branch information
lunny committed Dec 16, 2021
1 parent 3a3cbcf commit 2d29e4a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
30 changes: 17 additions & 13 deletions routers/web/repo/compare.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,21 +215,25 @@ func ParseCompareInfo(ctx *context.Context) *CompareInfo {
)

infoPath = ctx.Params("*")
infos := strings.SplitN(infoPath, "...", 2)

if len(infos) != 2 {
infos = []string{baseRepo.DefaultBranch, infoPath}
if strings.Contains(infoPath, "..") {
infos = strings.SplitN(infoPath, "..", 2)
ci.DirectComparison = true
ctx.Data["PageIsComparePull"] = false
var infos []string
if infoPath == "" {
infos = []string{ctx.Repo.Repository.DefaultBranch, ctx.Repo.Repository.DefaultBranch}
} else {
infos = strings.SplitN(infoPath, "...", 2)
if len(infos) != 2 {
infos = []string{baseRepo.DefaultBranch, infoPath}
if strings.Contains(infoPath, "..") {
infos = strings.SplitN(infoPath, "..", 2)
ci.DirectComparison = true
ctx.Data["PageIsComparePull"] = false
}
}
}

if len(infos) != 2 {
log.Trace("ParseCompareInfo[%d]: not enough compared branches information %s", baseRepo.ID, infos)
ctx.NotFound("CompareAndPullRequest", nil)
return nil
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
Expand Down
1 change: 1 addition & 0 deletions routers/web/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,7 @@ func RegisterRoutes(m *web.Route) {
m.Group("/milestone", func() {
m.Get("/{id}", repo.MilestoneIssuesAndPulls)
}, 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).
Get(ignSignIn, repo.SetDiffViewStyle, repo.SetWhitespaceBehavior, repo.CompareDiff).
Post(reqSignIn, context.RepoMustNotBeArchived(), reqRepoPullsReader, repo.MustAllowPulls, bindIgnErr(forms.CreateIssueForm{}), repo.SetWhitespaceBehavior, repo.CompareAndPullRequestPost)
Expand Down

0 comments on commit 2d29e4a

Please sign in to comment.