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
This commit is contained in:
Lunny Xiao 2021-12-10 09:27:50 +08:00 committed by GitHub
parent fb8166c6c6
commit 719bddcd76
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
301 changed files with 3193 additions and 2919 deletions

View file

@ -15,6 +15,7 @@ import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/models/db"
repo_model "code.gitea.io/gitea/models/repo"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/graceful"
@ -26,7 +27,7 @@ import (
)
// NewPullRequest creates new pull request with labels for repository.
func NewPullRequest(repo *models.Repository, pull *models.Issue, labelIDs []int64, uuids []string, pr *models.PullRequest, assigneeIDs []int64) error {
func NewPullRequest(repo *repo_model.Repository, pull *models.Issue, labelIDs []int64, uuids []string, pr *models.PullRequest, assigneeIDs []int64) error {
if err := TestPatch(pr); err != nil {
return err
}
@ -211,7 +212,7 @@ func ChangeTargetBranch(pr *models.PullRequest, doer *user_model.User, targetBra
}
func checkForInvalidation(requests models.PullRequestList, repoID int64, doer *user_model.User, branch string) error {
repo, err := models.GetRepositoryByID(repoID)
repo, err := repo_model.GetRepositoryByID(repoID)
if err != nil {
return fmt.Errorf("GetRepositoryByID: %v", err)
}
@ -524,7 +525,7 @@ func CloseBranchPulls(doer *user_model.User, repoID int64, branch string) error
}
// CloseRepoBranchesPulls close all pull requests which head branches are in the given repository, but only whose base repo is not in the given repository
func CloseRepoBranchesPulls(doer *user_model.User, repo *models.Repository) error {
func CloseRepoBranchesPulls(doer *user_model.User, repo *repo_model.Repository) error {
branches, _, err := git.GetBranchesByPath(repo.RepoPath(), 0, 0)
if err != nil {
return err
@ -575,7 +576,7 @@ func GetSquashMergeCommitMessages(pr *models.PullRequest) string {
if pr.HeadRepo == nil {
var err error
pr.HeadRepo, err = models.GetRepositoryByID(pr.HeadRepoID)
pr.HeadRepo, err = repo_model.GetRepositoryByID(pr.HeadRepoID)
if err != nil {
log.Error("GetRepositoryById[%d]: %v", pr.HeadRepoID, err)
return ""