Skip to content

Commit b300e3f

Browse files
lunny6543
andauthored
Support open compare page directly (#17975)
* Support open compare page directly * simple code * Some improvements Co-authored-by: 6543 <[email protected]>
1 parent 4cbc865 commit b300e3f

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

routers/web/repo/compare.go

+12-14
Original file line numberDiff line numberDiff line change
@@ -215,23 +215,21 @@ func ParseCompareInfo(ctx *context.Context) *CompareInfo {
215215
)
216216

217217
infoPath = ctx.Params("*")
218-
infos := strings.SplitN(infoPath, "...", 2)
219-
220-
if len(infos) != 2 {
221-
infos = []string{baseRepo.DefaultBranch, infoPath}
222-
if strings.Contains(infoPath, "..") {
223-
infos = strings.SplitN(infoPath, "..", 2)
224-
ci.DirectComparison = true
225-
ctx.Data["PageIsComparePull"] = false
218+
var infos []string
219+
if infoPath == "" {
220+
infos = []string{baseRepo.DefaultBranch, baseRepo.DefaultBranch}
221+
} else {
222+
infos = strings.SplitN(infoPath, "...", 2)
223+
if len(infos) != 2 {
224+
if infos = strings.SplitN(infoPath, "..", 2); len(infos) == 2 {
225+
ci.DirectComparison = true
226+
ctx.Data["PageIsComparePull"] = false
227+
} else {
228+
infos = []string{baseRepo.DefaultBranch, infoPath}
229+
}
226230
}
227231
}
228232

229-
if len(infos) != 2 {
230-
log.Trace("ParseCompareInfo[%d]: not enough compared branches information %s", baseRepo.ID, infos)
231-
ctx.NotFound("CompareAndPullRequest", nil)
232-
return nil
233-
}
234-
235233
ctx.Data["BaseName"] = baseRepo.OwnerName
236234
ci.BaseBranch = infos[0]
237235
ctx.Data["BaseBranch"] = ci.BaseBranch

routers/web/web.go

+1
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,7 @@ func RegisterRoutes(m *web.Route) {
702702
m.Group("/milestone", func() {
703703
m.Get("/{id}", repo.MilestoneIssuesAndPulls)
704704
}, reqRepoIssuesOrPullsReader, context.RepoRef())
705+
m.Get("/compare", repo.MustBeNotEmpty, reqRepoCodeReader, repo.SetEditorconfigIfExists, ignSignIn, repo.SetDiffViewStyle, repo.SetWhitespaceBehavior, repo.CompareDiff)
705706
m.Combo("/compare/*", repo.MustBeNotEmpty, reqRepoCodeReader, repo.SetEditorconfigIfExists).
706707
Get(ignSignIn, repo.SetDiffViewStyle, repo.SetWhitespaceBehavior, repo.CompareDiff).
707708
Post(reqSignIn, context.RepoMustNotBeArchived(), reqRepoPullsReader, repo.MustAllowPulls, bindIgnErr(forms.CreateIssueForm{}), repo.SetWhitespaceBehavior, repo.CompareAndPullRequestPost)

0 commit comments

Comments
 (0)