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

@ -14,6 +14,7 @@ import (
"time"
"code.gitea.io/gitea/models"
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/log"
@ -23,7 +24,7 @@ import (
"github.com/unknwon/com"
)
func prepareRepoCommit(ctx context.Context, repo *models.Repository, tmpDir, repoPath string, opts models.CreateRepoOptions) error {
func prepareRepoCommit(ctx context.Context, repo *repo_model.Repository, tmpDir, repoPath string, opts models.CreateRepoOptions) error {
commitTimeStr := time.Now().Format(time.RFC3339)
authorSig := repo.Owner.NewGitSig()
@ -101,7 +102,7 @@ func prepareRepoCommit(ctx context.Context, repo *models.Repository, tmpDir, rep
}
// initRepoCommit temporarily changes with work directory.
func initRepoCommit(tmpPath string, repo *models.Repository, u *user_model.User, defaultBranch string) (err error) {
func initRepoCommit(tmpPath string, repo *repo_model.Repository, u *user_model.User, defaultBranch string) (err error) {
commitTimeStr := time.Now().Format(time.RFC3339)
sig := u.NewGitSig()
@ -137,7 +138,7 @@ func initRepoCommit(tmpPath string, repo *models.Repository, u *user_model.User,
if sign {
args = append(args, "-S"+keyID)
if repo.GetTrustModel() == models.CommitterTrustModel || repo.GetTrustModel() == models.CollaboratorCommitterTrustModel {
if repo.GetTrustModel() == repo_model.CommitterTrustModel || repo.GetTrustModel() == repo_model.CollaboratorCommitterTrustModel {
// need to set the committer to the KeyID owner
committerName = signer.Name
committerEmail = signer.Email
@ -175,7 +176,7 @@ func initRepoCommit(tmpPath string, repo *models.Repository, u *user_model.User,
func checkInitRepository(owner, name string) (err error) {
// Somehow the directory could exist.
repoPath := models.RepoPath(owner, name)
repoPath := repo_model.RepoPath(owner, name)
isExist, err := util.IsExist(repoPath)
if err != nil {
log.Error("Unable to check if %s exists. Error: %v", repoPath, err)
@ -198,7 +199,7 @@ func checkInitRepository(owner, name string) (err error) {
}
// InitRepository initializes README and .gitignore if needed.
func initRepository(ctx context.Context, repoPath string, u *user_model.User, repo *models.Repository, opts models.CreateRepoOptions) (err error) {
func initRepository(ctx context.Context, repoPath string, u *user_model.User, repo *repo_model.Repository, opts models.CreateRepoOptions) (err error) {
if err = checkInitRepository(repo.OwnerName, repo.Name); err != nil {
return err
}
@ -227,7 +228,7 @@ func initRepository(ctx context.Context, repoPath string, u *user_model.User, re
// Re-fetch the repository from database before updating it (else it would
// override changes that were done earlier with sql)
if repo, err = models.GetRepositoryByIDCtx(ctx, repo.ID); err != nil {
if repo, err = repo_model.GetRepositoryByIDCtx(ctx, repo.ID); err != nil {
return fmt.Errorf("getRepositoryByID: %v", err)
}