Fix empty compare

pull/32786/head
Lunny Xiao 3 weeks ago
parent 3dd931086e
commit 62e21e823f
No known key found for this signature in database
GPG Key ID: C3B7C91B632F738A
  1. 5
      routers/common/compare.go
  2. 27
      routers/common/compare_test.go

@ -241,7 +241,10 @@ func ParseComparePathParams(ctx context.Context, pathParam string, baseRepo *rep
var err error var err error
if pathParam == "" { if pathParam == "" {
ci.HeadOriRef = baseRepo.DefaultBranch ci.CompareRouter = &CompareRouter{
HeadOriRef: baseRepo.DefaultBranch,
DotTimes: 3,
}
} else { } else {
ci.CompareRouter, err = parseCompareRouter(pathParam) ci.CompareRouter, err = parseCompareRouter(pathParam)
if err != nil { if err != nil {

@ -21,6 +21,14 @@ func TestCompareRouters(t *testing.T) {
router string router string
compareRouter *CompareRouter compareRouter *CompareRouter
}{ }{
{
router: "",
compareRouter: &CompareRouter{
BaseOriRef: "",
HeadOriRef: "",
DotTimes: 3,
},
},
{ {
router: "main...develop", router: "main...develop",
compareRouter: &CompareRouter{ compareRouter: &CompareRouter{
@ -175,6 +183,25 @@ func Test_ParseComparePathParams(t *testing.T) {
router string router string
compareInfo *CompareInfo compareInfo *CompareInfo
}{ }{
{
repoName: "repo1",
router: "",
compareInfo: &CompareInfo{
CompareRouter: &CompareRouter{
BaseOriRef: "master",
BaseFullRef: git.RefNameFromBranch("master"),
HeadOriRef: "master",
HeadFullRef: git.RefNameFromBranch("master"),
HeadOwnerName: repo1.OwnerName,
HeadRepoName: repo1.Name,
DotTimes: 3,
},
BaseRepo: repo1,
HeadUser: repo1.Owner,
HeadRepo: repo1,
HeadGitRepo: gitRepo1,
},
},
{ {
repoName: "repo1", repoName: "repo1",
router: "master...branch2", router: "master...branch2",

Loading…
Cancel
Save