diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2021-12-10 09:27:50 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-10 09:27:50 +0800 |
commit | 719bddcd76610a63dadc8555760072957a11cf30 (patch) | |
tree | 0df26092fba7e3e21444fe493e6b349473b6b0cb /routers/web/repo/pull.go | |
parent | fb8166c6c6b652a0e6fa98681780a6a71090faf3 (diff) | |
download | gitea-719bddcd76610a63dadc8555760072957a11cf30.tar.gz gitea-719bddcd76610a63dadc8555760072957a11cf30.zip |
Move repository model into models/repo (#17933)
* Some refactors related repository model
* Move more methods out of repository
* Move repository into models/repo
* Fix test
* Fix test
* some improvements
* Remove unnecessary function
Diffstat (limited to 'routers/web/repo/pull.go')
-rw-r--r-- | routers/web/repo/pull.go | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/routers/web/repo/pull.go b/routers/web/repo/pull.go index 7593e7fbc8..b08f749cde 100644 --- a/routers/web/repo/pull.go +++ b/routers/web/repo/pull.go @@ -19,6 +19,7 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/db" + repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/models/unit" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/base" @@ -59,10 +60,10 @@ var ( } ) -func getRepository(ctx *context.Context, repoID int64) *models.Repository { - repo, err := models.GetRepositoryByID(repoID) +func getRepository(ctx *context.Context, repoID int64) *repo_model.Repository { + repo, err := repo_model.GetRepositoryByID(repoID) if err != nil { - if models.IsErrRepoNotExist(err) { + if repo_model.IsErrRepoNotExist(err) { ctx.NotFound("GetRepositoryByID", nil) } else { ctx.ServerError("GetRepositoryByID", err) @@ -89,7 +90,7 @@ func getRepository(ctx *context.Context, repoID int64) *models.Repository { return repo } -func getForkRepository(ctx *context.Context) *models.Repository { +func getForkRepository(ctx *context.Context) *repo_model.Repository { forkRepo := getRepository(ctx, ctx.ParamsInt64(":repoid")) if ctx.Written() { return nil @@ -101,7 +102,7 @@ func getForkRepository(ctx *context.Context) *models.Repository { return nil } - if err := forkRepo.GetOwner(); err != nil { + if err := forkRepo.GetOwner(db.DefaultContext); err != nil { ctx.ServerError("GetOwner", err) return nil } @@ -141,7 +142,7 @@ func getForkRepository(ctx *context.Context) *models.Repository { if !traverseParentRepo.IsFork { break } - traverseParentRepo, err = models.GetRepositoryByID(traverseParentRepo.ForkID) + traverseParentRepo, err = repo_model.GetRepositoryByID(traverseParentRepo.ForkID) if err != nil { ctx.ServerError("GetRepositoryByID", err) return nil @@ -209,7 +210,7 @@ func ForkPost(ctx *context.Context) { if !traverseParentRepo.IsFork { break } - traverseParentRepo, err = models.GetRepositoryByID(traverseParentRepo.ForkID) + traverseParentRepo, err = repo_model.GetRepositoryByID(traverseParentRepo.ForkID) if err != nil { ctx.ServerError("GetRepositoryByID", err) return @@ -702,7 +703,7 @@ func ViewPullFiles(ctx *context.Context) { ctx.Data["RequireHighlightJS"] = true ctx.Data["RequireSimpleMDE"] = true ctx.Data["RequireTribute"] = true - if ctx.Data["Assignees"], err = ctx.Repo.Repository.GetAssignees(); err != nil { + if ctx.Data["Assignees"], err = models.GetRepoAssignees(ctx.Repo.Repository); err != nil { ctx.ServerError("GetAssignees", err) return } @@ -847,7 +848,7 @@ func MergePullRequest(ctx *context.Context) { } // handle manually-merged mark - if models.MergeStyle(form.Do) == models.MergeStyleManuallyMerged { + if repo_model.MergeStyle(form.Do) == repo_model.MergeStyleManuallyMerged { if err = pull_service.MergedManually(pr, ctx.User, ctx.Repo.GitRepo, form.MergeCommitID); err != nil { if models.IsErrInvalidMergeStyle(err) { ctx.Flash.Error(ctx.Tr("repo.pulls.invalid_merge_option")) @@ -902,13 +903,13 @@ func MergePullRequest(ctx *context.Context) { message := strings.TrimSpace(form.MergeTitleField) if len(message) == 0 { - if models.MergeStyle(form.Do) == models.MergeStyleMerge { + if repo_model.MergeStyle(form.Do) == repo_model.MergeStyleMerge { message = pr.GetDefaultMergeMessage() } - if models.MergeStyle(form.Do) == models.MergeStyleRebaseMerge { + if repo_model.MergeStyle(form.Do) == repo_model.MergeStyleRebaseMerge { message = pr.GetDefaultMergeMessage() } - if models.MergeStyle(form.Do) == models.MergeStyleSquash { + if repo_model.MergeStyle(form.Do) == repo_model.MergeStyleSquash { message = pr.GetDefaultSquashMessage() } } @@ -932,7 +933,7 @@ func MergePullRequest(ctx *context.Context) { return } - if err = pull_service.Merge(pr, ctx.User, ctx.Repo.GitRepo, models.MergeStyle(form.Do), message); err != nil { + if err = pull_service.Merge(pr, ctx.User, ctx.Repo.GitRepo, repo_model.MergeStyle(form.Do), message); err != nil { if models.IsErrInvalidMergeStyle(err) { ctx.Flash.Error(ctx.Tr("repo.pulls.invalid_merge_option")) ctx.Redirect(issue.Link()) @@ -1227,7 +1228,7 @@ func CleanUpPullRequest(ctx *context.Context) { } else if err = pr.LoadBaseRepo(); err != nil { ctx.ServerError("LoadBaseRepo", err) return - } else if err = pr.HeadRepo.GetOwner(); err != nil { + } else if err = pr.HeadRepo.GetOwner(db.DefaultContext); err != nil { ctx.ServerError("HeadRepo.GetOwner", err) return } |