Skip to content

Commit cf3145a

Browse files
committed
Some improvements
1 parent def6e8c commit cf3145a

File tree

5 files changed

+30
-4
lines changed

5 files changed

+30
-4
lines changed

routers/api/v1/repo/compare.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
repo_model "code.gitea.io/gitea/models/repo"
1212
"code.gitea.io/gitea/models/unit"
1313
user_model "code.gitea.io/gitea/models/user"
14+
"code.gitea.io/gitea/modules/git"
1415
"code.gitea.io/gitea/modules/gitrepo"
1516
"code.gitea.io/gitea/modules/log"
1617
api "code.gitea.io/gitea/modules/structs"
@@ -69,6 +70,8 @@ func CompareDiff(ctx *context.APIContext) {
6970
ctx.NotFound("GetRepositoryByOwnerAndName")
7071
case errors.Is(err, util.ErrInvalidArgument):
7172
ctx.NotFound("ParseComparePathParams")
73+
case git.IsErrNotExist(err):
74+
ctx.NotFound("ParseComparePathParams")
7275
default:
7376
ctx.ServerError("GetRepositoryByOwnerAndName", err)
7477
}

routers/api/v1/repo/pull.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,8 @@ func CreatePullRequest(ctx *context.APIContext) {
417417
ctx.NotFound("GetRepositoryByOwnerAndName")
418418
case errors.Is(err, util.ErrInvalidArgument):
419419
ctx.NotFound("ParseComparePathParams")
420+
case git.IsErrNotExist(err):
421+
ctx.NotFound("ParseComparePathParams")
420422
default:
421423
ctx.ServerError("GetRepositoryByOwnerAndName", err)
422424
}

routers/common/compare.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ func (cr *CompareRouter) DirectComparison() bool {
3030
return cr.DotTimes == 2
3131
}
3232

33+
func (cr *CompareRouter) CompareDots() string {
34+
return strings.Repeat(".", cr.DotTimes)
35+
}
36+
3337
func parseBase(base string) (string, int) {
3438
parts := strings.SplitN(base, "^", 2)
3539
if len(parts) == 1 {

routers/common/compare_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,26 @@ func Test_ParseComparePathParams(t *testing.T) {
414414
IsHeadCommit: true,
415415
},
416416
},
417+
{
418+
repoName: "repo1",
419+
hasClose: true,
420+
router: "user12/repo10:master",
421+
compareInfo: &CompareInfo{
422+
CompareRouter: &CompareRouter{
423+
BaseOriRef: repo11.DefaultBranch,
424+
BaseFullRef: git.RefNameFromBranch(repo11.DefaultBranch),
425+
HeadOwnerName: "user12",
426+
HeadRepoName: "repo10",
427+
HeadOriRef: "master",
428+
HeadFullRef: git.RefNameFromBranch("master"),
429+
DotTimes: 3,
430+
},
431+
BaseRepo: repo1,
432+
HeadUser: repo10.Owner,
433+
HeadRepo: repo10,
434+
HeadGitRepo: gitRepo10,
435+
},
436+
},
417437
}
418438

419439
for _, kase := range kases {

routers/web/repo/compare.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -554,11 +554,8 @@ func CompareDiff(ctx *context.Context) {
554554
}
555555
beforeCommitID := ctx.Data["BeforeCommitID"].(string)
556556
afterCommitID := ctx.Data["AfterCommitID"].(string)
557+
separator := ci.CompareDots()
557558

558-
separator := "..."
559-
if ci.DirectComparison() {
560-
separator = ".."
561-
}
562559
ctx.Data["Title"] = "Comparing " + base.ShortSha(beforeCommitID) + separator + base.ShortSha(afterCommitID)
563560

564561
ctx.Data["IsDiffCompare"] = true

0 commit comments

Comments
 (0)