Some improvements

pull/32786/head
Lunny Xiao 1 month ago
parent def6e8cc6b
commit cf3145a4fe
No known key found for this signature in database
GPG Key ID: C3B7C91B632F738A
  1. 3
      routers/api/v1/repo/compare.go
  2. 2
      routers/api/v1/repo/pull.go
  3. 4
      routers/common/compare.go
  4. 20
      routers/common/compare_test.go
  5. 5
      routers/web/repo/compare.go

@ -11,6 +11,7 @@ import (
repo_model "code.gitea.io/gitea/models/repo" repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/models/unit" "code.gitea.io/gitea/models/unit"
user_model "code.gitea.io/gitea/models/user" user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/gitrepo" "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/log"
api "code.gitea.io/gitea/modules/structs" api "code.gitea.io/gitea/modules/structs"
@ -69,6 +70,8 @@ func CompareDiff(ctx *context.APIContext) {
ctx.NotFound("GetRepositoryByOwnerAndName") ctx.NotFound("GetRepositoryByOwnerAndName")
case errors.Is(err, util.ErrInvalidArgument): case errors.Is(err, util.ErrInvalidArgument):
ctx.NotFound("ParseComparePathParams") ctx.NotFound("ParseComparePathParams")
case git.IsErrNotExist(err):
ctx.NotFound("ParseComparePathParams")
default: default:
ctx.ServerError("GetRepositoryByOwnerAndName", err) ctx.ServerError("GetRepositoryByOwnerAndName", err)
} }

@ -417,6 +417,8 @@ func CreatePullRequest(ctx *context.APIContext) {
ctx.NotFound("GetRepositoryByOwnerAndName") ctx.NotFound("GetRepositoryByOwnerAndName")
case errors.Is(err, util.ErrInvalidArgument): case errors.Is(err, util.ErrInvalidArgument):
ctx.NotFound("ParseComparePathParams") ctx.NotFound("ParseComparePathParams")
case git.IsErrNotExist(err):
ctx.NotFound("ParseComparePathParams")
default: default:
ctx.ServerError("GetRepositoryByOwnerAndName", err) ctx.ServerError("GetRepositoryByOwnerAndName", err)
} }

@ -30,6 +30,10 @@ func (cr *CompareRouter) DirectComparison() bool {
return cr.DotTimes == 2 return cr.DotTimes == 2
} }
func (cr *CompareRouter) CompareDots() string {
return strings.Repeat(".", cr.DotTimes)
}
func parseBase(base string) (string, int) { func parseBase(base string) (string, int) {
parts := strings.SplitN(base, "^", 2) parts := strings.SplitN(base, "^", 2)
if len(parts) == 1 { if len(parts) == 1 {

@ -414,6 +414,26 @@ func Test_ParseComparePathParams(t *testing.T) {
IsHeadCommit: true, IsHeadCommit: true,
}, },
}, },
{
repoName: "repo1",
hasClose: true,
router: "user12/repo10:master",
compareInfo: &CompareInfo{
CompareRouter: &CompareRouter{
BaseOriRef: repo11.DefaultBranch,
BaseFullRef: git.RefNameFromBranch(repo11.DefaultBranch),
HeadOwnerName: "user12",
HeadRepoName: "repo10",
HeadOriRef: "master",
HeadFullRef: git.RefNameFromBranch("master"),
DotTimes: 3,
},
BaseRepo: repo1,
HeadUser: repo10.Owner,
HeadRepo: repo10,
HeadGitRepo: gitRepo10,
},
},
} }
for _, kase := range kases { for _, kase := range kases {

@ -554,11 +554,8 @@ func CompareDiff(ctx *context.Context) {
} }
beforeCommitID := ctx.Data["BeforeCommitID"].(string) beforeCommitID := ctx.Data["BeforeCommitID"].(string)
afterCommitID := ctx.Data["AfterCommitID"].(string) afterCommitID := ctx.Data["AfterCommitID"].(string)
separator := ci.CompareDots()
separator := "..."
if ci.DirectComparison() {
separator = ".."
}
ctx.Data["Title"] = "Comparing " + base.ShortSha(beforeCommitID) + separator + base.ShortSha(afterCommitID) ctx.Data["Title"] = "Comparing " + base.ShortSha(beforeCommitID) + separator + base.ShortSha(afterCommitID)
ctx.Data["IsDiffCompare"] = true ctx.Data["IsDiffCompare"] = true

Loading…
Cancel
Save