From 110fc57cbcf293c19ed7017d8ea528b4bbbd7396 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Sun, 12 Jun 2022 23:51:54 +0800 Subject: Move some code into models/git (#19879) * Move access and repo permission to models/perm/access * fix test * Move some git related files into sub package models/git * Fix build * fix git test * move lfs to sub package * move more git related functions to models/git * Move functions sequence * Some improvements per @KN4CK3R and @delvh --- modules/convert/convert.go | 9 +++++---- modules/convert/status.go | 8 ++++---- 2 files changed, 9 insertions(+), 8 deletions(-) (limited to 'modules/convert') diff --git a/modules/convert/convert.go b/modules/convert/convert.go index 67b3902cd7..4e8aa59067 100644 --- a/modules/convert/convert.go +++ b/modules/convert/convert.go @@ -15,6 +15,7 @@ import ( asymkey_model "code.gitea.io/gitea/models/asymkey" "code.gitea.io/gitea/models/auth" "code.gitea.io/gitea/models/db" + git_model "code.gitea.io/gitea/models/git" "code.gitea.io/gitea/models/organization" "code.gitea.io/gitea/models/perm" access_model "code.gitea.io/gitea/models/perm/access" @@ -39,7 +40,7 @@ func ToEmail(email *user_model.EmailAddress) *api.Email { } // ToBranch convert a git.Commit and git.Branch to an api.Branch -func ToBranch(repo *repo_model.Repository, b *git.Branch, c *git.Commit, bp *models.ProtectedBranch, user *user_model.User, isRepoAdmin bool) (*api.Branch, error) { +func ToBranch(repo *repo_model.Repository, b *git.Branch, c *git.Commit, bp *git_model.ProtectedBranch, user *user_model.User, isRepoAdmin bool) (*api.Branch, error) { if bp == nil { var hasPerm bool var canPush bool @@ -88,14 +89,14 @@ func ToBranch(repo *repo_model.Repository, b *git.Branch, c *git.Commit, bp *mod return nil, err } branch.UserCanPush = bp.CanUserPush(user.ID) - branch.UserCanMerge = models.IsUserMergeWhitelisted(db.DefaultContext, bp, user.ID, permission) + branch.UserCanMerge = git_model.IsUserMergeWhitelisted(db.DefaultContext, bp, user.ID, permission) } return branch, nil } // ToBranchProtection convert a ProtectedBranch to api.BranchProtection -func ToBranchProtection(bp *models.ProtectedBranch) *api.BranchProtection { +func ToBranchProtection(bp *git_model.ProtectedBranch) *api.BranchProtection { pushWhitelistUsernames, err := user_model.GetUserNamesByIDs(bp.WhitelistUserIDs) if err != nil { log.Error("GetUserNamesByIDs (WhitelistUserIDs): %v", err) @@ -399,7 +400,7 @@ func ToOAuth2Application(app *auth.OAuth2Application) *api.OAuth2Application { } // ToLFSLock convert a LFSLock to api.LFSLock -func ToLFSLock(l *models.LFSLock) *api.LFSLock { +func ToLFSLock(l *git_model.LFSLock) *api.LFSLock { u, err := user_model.GetUserByID(l.OwnerID) if err != nil { return nil diff --git a/modules/convert/status.go b/modules/convert/status.go index 1ac2a0f3e1..7ed28a9c10 100644 --- a/modules/convert/status.go +++ b/modules/convert/status.go @@ -5,13 +5,13 @@ package convert import ( - "code.gitea.io/gitea/models" + git_model "code.gitea.io/gitea/models/git" user_model "code.gitea.io/gitea/models/user" api "code.gitea.io/gitea/modules/structs" ) -// ToCommitStatus converts models.CommitStatus to api.CommitStatus -func ToCommitStatus(status *models.CommitStatus) *api.CommitStatus { +// ToCommitStatus converts git_model.CommitStatus to api.CommitStatus +func ToCommitStatus(status *git_model.CommitStatus) *api.CommitStatus { apiStatus := &api.CommitStatus{ Created: status.CreatedUnix.AsTime(), Updated: status.CreatedUnix.AsTime(), @@ -32,7 +32,7 @@ func ToCommitStatus(status *models.CommitStatus) *api.CommitStatus { } // ToCombinedStatus converts List of CommitStatus to a CombinedStatus -func ToCombinedStatus(statuses []*models.CommitStatus, repo *api.Repository) *api.CombinedStatus { +func ToCombinedStatus(statuses []*git_model.CommitStatus, repo *api.Repository) *api.CombinedStatus { if len(statuses) == 0 { return nil } -- cgit v1.2.3