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 /services | |
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 'services')
62 files changed, 287 insertions, 247 deletions
diff --git a/services/auth/source/ldap/source.go b/services/auth/source/ldap/source.go index 3e751f512b..be4a4b2d62 100644 --- a/services/auth/source/ldap/source.go +++ b/services/auth/source/ldap/source.go @@ -7,7 +7,6 @@ package ldap import ( "strings" - "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/login" "code.gitea.io/gitea/modules/json" "code.gitea.io/gitea/modules/secret" @@ -62,7 +61,7 @@ type Source struct { // FromDB fills up a LDAPConfig from serialized format. func (source *Source) FromDB(bs []byte) error { - err := models.JSONUnmarshalHandleDoubleEncode(bs, &source) + err := json.UnmarshalHandleDoubleEncode(bs, &source) if err != nil { return err } diff --git a/services/auth/source/oauth2/source.go b/services/auth/source/oauth2/source.go index 60845e3b0f..bedaed7ef3 100644 --- a/services/auth/source/oauth2/source.go +++ b/services/auth/source/oauth2/source.go @@ -5,7 +5,6 @@ package oauth2 import ( - "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/login" "code.gitea.io/gitea/modules/json" ) @@ -33,7 +32,7 @@ type Source struct { // FromDB fills up an OAuth2Config from serialized format. func (source *Source) FromDB(bs []byte) error { - return models.JSONUnmarshalHandleDoubleEncode(bs, &source) + return json.UnmarshalHandleDoubleEncode(bs, &source) } // ToDB exports an SMTPConfig to a serialized format. diff --git a/services/auth/source/pam/source.go b/services/auth/source/pam/source.go index 73850cd9a2..65ae76138c 100644 --- a/services/auth/source/pam/source.go +++ b/services/auth/source/pam/source.go @@ -5,7 +5,6 @@ package pam import ( - "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/login" "code.gitea.io/gitea/modules/json" ) @@ -29,7 +28,7 @@ type Source struct { // FromDB fills up a PAMConfig from serialized format. func (source *Source) FromDB(bs []byte) error { - return models.JSONUnmarshalHandleDoubleEncode(bs, &source) + return json.UnmarshalHandleDoubleEncode(bs, &source) } // ToDB exports a PAMConfig to a serialized format. diff --git a/services/auth/source/smtp/source.go b/services/auth/source/smtp/source.go index 52e2505670..006202e0d5 100644 --- a/services/auth/source/smtp/source.go +++ b/services/auth/source/smtp/source.go @@ -5,7 +5,6 @@ package smtp import ( - "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/login" "code.gitea.io/gitea/modules/json" ) @@ -35,7 +34,7 @@ type Source struct { // FromDB fills up an SMTPConfig from serialized format. func (source *Source) FromDB(bs []byte) error { - return models.JSONUnmarshalHandleDoubleEncode(bs, &source) + return json.UnmarshalHandleDoubleEncode(bs, &source) } // ToDB exports an SMTPConfig to a serialized format. diff --git a/services/auth/source/sspi/source.go b/services/auth/source/sspi/source.go index 68fd6a6079..8d469d481f 100644 --- a/services/auth/source/sspi/source.go +++ b/services/auth/source/sspi/source.go @@ -5,7 +5,6 @@ package sspi import ( - "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/login" "code.gitea.io/gitea/modules/json" ) @@ -28,7 +27,7 @@ type Source struct { // FromDB fills up an SSPIConfig from serialized format. func (cfg *Source) FromDB(bs []byte) error { - return models.JSONUnmarshalHandleDoubleEncode(bs, &cfg) + return json.UnmarshalHandleDoubleEncode(bs, &cfg) } // ToDB exports an SSPIConfig to a serialized format. diff --git a/services/comments/comments.go b/services/comments/comments.go index 6e96301275..296f06d75c 100644 --- a/services/comments/comments.go +++ b/services/comments/comments.go @@ -8,13 +8,14 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/db" "code.gitea.io/gitea/models/issues" + repo_model "code.gitea.io/gitea/models/repo" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/notification" "code.gitea.io/gitea/modules/timeutil" ) // CreateIssueComment creates a plain issue comment. -func CreateIssueComment(doer *user_model.User, repo *models.Repository, issue *models.Issue, content string, attachments []string) (*models.Comment, error) { +func CreateIssueComment(doer *user_model.User, repo *repo_model.Repository, issue *models.Issue, content string, attachments []string) (*models.Comment, error) { comment, err := models.CreateComment(&models.CreateCommentOptions{ Type: models.CommentTypeComment, Doer: doer, diff --git a/services/issue/commit.go b/services/issue/commit.go index 3e2f6c471b..0dda5f202f 100644 --- a/services/issue/commit.go +++ b/services/issue/commit.go @@ -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/references" "code.gitea.io/gitea/modules/repository" @@ -85,7 +86,7 @@ func issueAddTime(issue *models.Issue, doer *user_model.User, time time.Time, ti // getIssueFromRef returns the issue referenced by a ref. Returns a nil *Issue // if the provided ref references a non-existent issue. -func getIssueFromRef(repo *models.Repository, index int64) (*models.Issue, error) { +func getIssueFromRef(repo *repo_model.Repository, index int64) (*models.Issue, error) { issue, err := models.GetIssueByIndex(repo.ID, index) if err != nil { if models.IsErrIssueNotExist(err) { @@ -97,7 +98,7 @@ func getIssueFromRef(repo *models.Repository, index int64) (*models.Issue, error } // UpdateIssuesCommit checks if issues are manipulated by commit message. -func UpdateIssuesCommit(doer *user_model.User, repo *models.Repository, commits []*repository.PushCommit, branchName string) error { +func UpdateIssuesCommit(doer *user_model.User, repo *repo_model.Repository, commits []*repository.PushCommit, branchName string) error { // Commits are appended in the reverse order. for i := len(commits) - 1; i >= 0; i-- { c := commits[i] @@ -108,7 +109,7 @@ func UpdateIssuesCommit(doer *user_model.User, repo *models.Repository, commits } refMarked := make(map[markKey]bool) - var refRepo *models.Repository + var refRepo *repo_model.Repository var refIssue *models.Issue var err error for _, ref := range references.FindAllIssueReferences(c.Message) { diff --git a/services/issue/commit_test.go b/services/issue/commit_test.go index 1addbd080f..37283a7890 100644 --- a/services/issue/commit_test.go +++ b/services/issue/commit_test.go @@ -8,6 +8,7 @@ import ( "testing" "code.gitea.io/gitea/models" + repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/models/unittest" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/repository" @@ -46,7 +47,7 @@ func TestUpdateIssuesCommit(t *testing.T) { } user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User) - repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository) + repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}).(*repo_model.Repository) repo.Owner = user commentBean := &models.Comment{ @@ -75,7 +76,7 @@ func TestUpdateIssuesCommit(t *testing.T) { Message: "close #1", }, } - repo = unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 3}).(*models.Repository) + repo = unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 3}).(*repo_model.Repository) commentBean = &models.Comment{ Type: models.CommentTypeCommitRef, CommitSHA: "abcdef1", @@ -101,7 +102,7 @@ func TestUpdateIssuesCommit(t *testing.T) { Message: "close " + setting.AppURL + repo.FullName() + "/pulls/1", }, } - repo = unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 3}).(*models.Repository) + repo = unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 3}).(*repo_model.Repository) commentBean = &models.Comment{ Type: models.CommentTypeCommitRef, CommitSHA: "abcdef3", @@ -132,7 +133,7 @@ func TestUpdateIssuesCommit_Colon(t *testing.T) { } user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User) - repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository) + repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}).(*repo_model.Repository) repo.Owner = user issueBean := &models.Issue{RepoID: repo.ID, Index: 4} @@ -159,7 +160,7 @@ func TestUpdateIssuesCommit_Issue5957(t *testing.T) { }, } - repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 2}).(*models.Repository) + repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 2}).(*repo_model.Repository) commentBean := &models.Comment{ Type: models.CommentTypeCommitRef, CommitSHA: "abcdef1", @@ -194,7 +195,7 @@ func TestUpdateIssuesCommit_AnotherRepo(t *testing.T) { }, } - repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 2}).(*models.Repository) + repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 2}).(*repo_model.Repository) commentBean := &models.Comment{ Type: models.CommentTypeCommitRef, CommitSHA: "abcdef1", @@ -229,7 +230,7 @@ func TestUpdateIssuesCommit_AnotherRepo_FullAddress(t *testing.T) { }, } - repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 2}).(*models.Repository) + repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 2}).(*repo_model.Repository) commentBean := &models.Comment{ Type: models.CommentTypeCommitRef, CommitSHA: "abcdef1", @@ -272,7 +273,7 @@ func TestUpdateIssuesCommit_AnotherRepoNoPermission(t *testing.T) { }, } - repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 6}).(*models.Repository) + repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 6}).(*repo_model.Repository) commentBean := &models.Comment{ Type: models.CommentTypeCommitRef, CommitSHA: "abcdef3", diff --git a/services/issue/issue.go b/services/issue/issue.go index cb34a9eacd..ef2894b929 100644 --- a/services/issue/issue.go +++ b/services/issue/issue.go @@ -7,6 +7,7 @@ package issue 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/notification" @@ -14,7 +15,7 @@ import ( ) // NewIssue creates new issue with labels for repository. -func NewIssue(repo *models.Repository, issue *models.Issue, labelIDs []int64, uuids []string, assigneeIDs []int64) error { +func NewIssue(repo *repo_model.Repository, issue *models.Issue, labelIDs []int64, uuids []string, assigneeIDs []int64) error { if err := models.NewIssue(repo, issue, labelIDs, uuids); err != nil { return err } diff --git a/services/lfs/locks.go b/services/lfs/locks.go index 11cf5c16b9..c2ede20b7c 100644 --- a/services/lfs/locks.go +++ b/services/lfs/locks.go @@ -10,6 +10,7 @@ import ( "strings" "code.gitea.io/gitea/models" + repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/convert" "code.gitea.io/gitea/modules/json" @@ -19,7 +20,7 @@ import ( api "code.gitea.io/gitea/modules/structs" ) -func handleLockListOut(ctx *context.Context, repo *models.Repository, lock *models.LFSLock, err error) { +func handleLockListOut(ctx *context.Context, repo *repo_model.Repository, lock *models.LFSLock, err error) { if err != nil { if models.IsErrLFSLockNotExist(err) { ctx.JSON(http.StatusOK, api.LFSLockList{ @@ -47,7 +48,7 @@ func handleLockListOut(ctx *context.Context, repo *models.Repository, lock *mode func GetListLockHandler(ctx *context.Context) { rv := getRequestContext(ctx) - repository, err := models.GetRepositoryByOwnerAndName(rv.User, rv.Repo) + repository, err := repo_model.GetRepositoryByOwnerAndName(rv.User, rv.Repo) if err != nil { log.Debug("Could not find repository: %s/%s - %s", rv.User, rv.Repo, err) ctx.Resp.Header().Set("WWW-Authenticate", "Basic realm=gitea-lfs") @@ -134,7 +135,7 @@ func PostLockHandler(ctx *context.Context) { repoName := strings.TrimSuffix(ctx.Params("reponame"), ".git") authorization := ctx.Req.Header.Get("Authorization") - repository, err := models.GetRepositoryByOwnerAndName(userName, repoName) + repository, err := repo_model.GetRepositoryByOwnerAndName(userName, repoName) if err != nil { log.Error("Unable to get repository: %s/%s Error: %v", userName, repoName, err) ctx.Resp.Header().Set("WWW-Authenticate", "Basic realm=gitea-lfs") @@ -167,8 +168,7 @@ func PostLockHandler(ctx *context.Context) { return } - lock, err := models.CreateLFSLock(&models.LFSLock{ - Repo: repository, + lock, err := models.CreateLFSLock(repository, &models.LFSLock{ Path: req.Path, OwnerID: ctx.User.ID, }) @@ -202,7 +202,7 @@ func VerifyLockHandler(ctx *context.Context) { repoName := strings.TrimSuffix(ctx.Params("reponame"), ".git") authorization := ctx.Req.Header.Get("Authorization") - repository, err := models.GetRepositoryByOwnerAndName(userName, repoName) + repository, err := repo_model.GetRepositoryByOwnerAndName(userName, repoName) if err != nil { log.Error("Unable to get repository: %s/%s Error: %v", userName, repoName, err) ctx.Resp.Header().Set("WWW-Authenticate", "Basic realm=gitea-lfs") @@ -268,7 +268,7 @@ func UnLockHandler(ctx *context.Context) { repoName := strings.TrimSuffix(ctx.Params("reponame"), ".git") authorization := ctx.Req.Header.Get("Authorization") - repository, err := models.GetRepositoryByOwnerAndName(userName, repoName) + repository, err := repo_model.GetRepositoryByOwnerAndName(userName, repoName) if err != nil { log.Error("Unable to get repository: %s/%s Error: %v", userName, repoName, err) ctx.Resp.Header().Set("WWW-Authenticate", "Basic realm=gitea-lfs") @@ -301,7 +301,7 @@ func UnLockHandler(ctx *context.Context) { return } - lock, err := models.DeleteLFSLockByID(ctx.ParamsInt64("lid"), ctx.User, req.Force) + lock, err := models.DeleteLFSLockByID(ctx.ParamsInt64("lid"), repository, ctx.User, req.Force) if err != nil { if models.IsErrLFSUnauthorizedAction(err) { ctx.Resp.Header().Set("WWW-Authenticate", "Basic realm=gitea-lfs") diff --git a/services/lfs/server.go b/services/lfs/server.go index 2b0c8265c0..df0a8bd39a 100644 --- a/services/lfs/server.go +++ b/services/lfs/server.go @@ -20,6 +20,7 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/perm" + 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/context" @@ -195,7 +196,7 @@ func BatchHandler(ctx *context.Context) { return } - meta, err := repository.GetLFSMetaObjectByOid(p.Oid) + meta, err := models.GetLFSMetaObjectByOid(repository.ID, p.Oid) if err != nil && err != models.ErrLFSObjectNotExist { log.Error("Unable to get LFS MetaObject [%s] for %s/%s. Error: %v", p.Oid, rc.User, rc.Repo, err) writeStatus(ctx, http.StatusInternalServerError) @@ -333,7 +334,7 @@ func UploadHandler(ctx *context.Context) { } else { writeStatus(ctx, http.StatusInternalServerError) } - if _, err = repository.RemoveLFSMetaObjectByOid(p.Oid); err != nil { + if _, err = models.RemoveLFSMetaObjectByOid(repository.ID, p.Oid); err != nil { log.Error("Error whilst removing metaobject for LFS OID[%s]: %v", p.Oid, err) } return @@ -396,7 +397,7 @@ func getAuthenticatedMeta(ctx *context.Context, rc *requestContext, p lfs_module return nil } - meta, err := repository.GetLFSMetaObjectByOid(p.Oid) + meta, err := models.GetLFSMetaObjectByOid(repository.ID, p.Oid) if err != nil { log.Error("Unable to get LFS OID[%s] Error: %v", p.Oid, err) writeStatus(ctx, http.StatusNotFound) @@ -406,8 +407,8 @@ func getAuthenticatedMeta(ctx *context.Context, rc *requestContext, p lfs_module return meta } -func getAuthenticatedRepository(ctx *context.Context, rc *requestContext, requireWrite bool) *models.Repository { - repository, err := models.GetRepositoryByOwnerAndName(rc.User, rc.Repo) +func getAuthenticatedRepository(ctx *context.Context, rc *requestContext, requireWrite bool) *repo_model.Repository { + repository, err := repo_model.GetRepositoryByOwnerAndName(rc.User, rc.Repo) if err != nil { log.Error("Unable to get repository: %s/%s Error: %v", rc.User, rc.Repo, err) writeStatus(ctx, http.StatusNotFound) @@ -480,7 +481,7 @@ func writeStatusMessage(ctx *context.Context, status int, message string) { // authenticate uses the authorization string to determine whether // or not to proceed. This server assumes an HTTP Basic auth format. -func authenticate(ctx *context.Context, repository *models.Repository, authorization string, requireSigned, requireWrite bool) bool { +func authenticate(ctx *context.Context, repository *repo_model.Repository, authorization string, requireSigned, requireWrite bool) bool { accessMode := perm.AccessModeRead if requireWrite { accessMode = perm.AccessModeWrite @@ -508,7 +509,7 @@ func authenticate(ctx *context.Context, repository *models.Repository, authoriza return true } -func handleLFSToken(tokenSHA string, target *models.Repository, mode perm.AccessMode) (*user_model.User, error) { +func handleLFSToken(tokenSHA string, target *repo_model.Repository, mode perm.AccessMode) (*user_model.User, error) { if !strings.Contains(tokenSHA, ".") { return nil, nil } @@ -543,7 +544,7 @@ func handleLFSToken(tokenSHA string, target *models.Repository, mode perm.Access return u, nil } -func parseToken(authorization string, target *models.Repository, mode perm.AccessMode) (*user_model.User, error) { +func parseToken(authorization string, target *repo_model.Repository, mode perm.AccessMode) (*user_model.User, error) { if authorization == "" { return nil, fmt.Errorf("no token") } diff --git a/services/mailer/mail.go b/services/mailer/mail.go index a9978be8b1..91d39abead 100644 --- a/services/mailer/mail.go +++ b/services/mailer/mail.go @@ -16,6 +16,7 @@ import ( texttmpl "text/template" "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/base" "code.gitea.io/gitea/modules/emoji" @@ -176,7 +177,7 @@ func SendRegisterNotifyMail(u *user_model.User) { } // SendCollaboratorMail sends mail notification to new collaborator. -func SendCollaboratorMail(u, doer *user_model.User, repo *models.Repository) { +func SendCollaboratorMail(u, doer *user_model.User, repo *repo_model.Repository) { if setting.MailService == nil { // No mail service configured return diff --git a/services/mailer/mail_issue.go b/services/mailer/mail_issue.go index 1fbe68e022..22ebbb1a9c 100644 --- a/services/mailer/mail_issue.go +++ b/services/mailer/mail_issue.go @@ -139,7 +139,7 @@ func mailIssueCommentBatch(ctx *mailCommentContext, users []*user_model.User, vi visited[user.ID] = true // test if this user is allowed to see the issue/pull - if !ctx.Issue.Repo.CheckUnitUser(user, checkUnit) { + if !models.CheckRepoUnitUser(ctx.Issue.Repo, user, checkUnit) { continue } diff --git a/services/mailer/mail_repo.go b/services/mailer/mail_repo.go index 8a2eeac087..51b16aa7e2 100644 --- a/services/mailer/mail_repo.go +++ b/services/mailer/mail_repo.go @@ -9,6 +9,7 @@ import ( "fmt" "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/setting" "code.gitea.io/gitea/modules/templates" @@ -16,7 +17,7 @@ import ( ) // SendRepoTransferNotifyMail triggers a notification e-mail when a pending repository transfer was created -func SendRepoTransferNotifyMail(doer, newOwner *user_model.User, repo *models.Repository) error { +func SendRepoTransferNotifyMail(doer, newOwner *user_model.User, repo *repo_model.Repository) error { if setting.MailService == nil { // No mail service configured return nil @@ -46,7 +47,7 @@ func SendRepoTransferNotifyMail(doer, newOwner *user_model.User, repo *models.Re } // sendRepoTransferNotifyMail triggers a notification e-mail when a pending repository transfer was created for each language -func sendRepoTransferNotifyMailPerLang(lang string, newOwner, doer *user_model.User, emails []string, repo *models.Repository) error { +func sendRepoTransferNotifyMailPerLang(lang string, newOwner, doer *user_model.User, emails []string, repo *repo_model.Repository) error { var ( locale = translation.NewLocale(lang) content bytes.Buffer diff --git a/services/mailer/mail_test.go b/services/mailer/mail_test.go index 8e8cd98231..1ce1020d07 100644 --- a/services/mailer/mail_test.go +++ b/services/mailer/mail_test.go @@ -11,6 +11,7 @@ import ( texttmpl "text/template" "code.gitea.io/gitea/models" + repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/models/unittest" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/setting" @@ -41,7 +42,7 @@ const bodyTpl = ` </html> ` -func prepareMailerTest(t *testing.T) (doer *user_model.User, repo *models.Repository, issue *models.Issue, comment *models.Comment) { +func prepareMailerTest(t *testing.T) (doer *user_model.User, repo *repo_model.Repository, issue *models.Issue, comment *models.Comment) { assert.NoError(t, unittest.PrepareTestDatabase()) var mailService = setting.Mailer{ From: "test@gitea.com", @@ -51,7 +52,7 @@ func prepareMailerTest(t *testing.T) (doer *user_model.User, repo *models.Reposi setting.Domain = "localhost" doer = unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User) - repo = unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1, Owner: doer}).(*models.Repository) + repo = unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1, Owner: doer}).(*repo_model.Repository) issue = unittest.AssertExistsAndLoadBean(t, &models.Issue{ID: 1, Repo: repo, Poster: doer}).(*models.Issue) assert.NoError(t, issue.LoadRepo()) comment = unittest.AssertExistsAndLoadBean(t, &models.Comment{ID: 2, Issue: issue}).(*models.Comment) diff --git a/services/migrations/gitea_uploader.go b/services/migrations/gitea_uploader.go index 4808916c1d..0887aa1132 100644 --- a/services/migrations/gitea_uploader.go +++ b/services/migrations/gitea_uploader.go @@ -43,7 +43,7 @@ type GiteaLocalUploader struct { doer *user_model.User repoOwner string repoName string - repo *models.Repository + repo *repo_model.Repository labels sync.Map milestones sync.Map issues sync.Map @@ -93,7 +93,7 @@ func (g *GiteaLocalUploader) CreateRepo(repo *base.Repository, opts base.Migrate return err } - var r *models.Repository + var r *repo_model.Repository if opts.MigrateToRepoID <= 0 { r, err = repo_module.CreateRepository(g.doer, owner, models.CreateRepoOptions{ Name: g.repoName, @@ -102,10 +102,10 @@ func (g *GiteaLocalUploader) CreateRepo(repo *base.Repository, opts base.Migrate GitServiceType: opts.GitServiceType, IsPrivate: opts.Private, IsMirror: opts.Mirror, - Status: models.RepositoryBeingMigrated, + Status: repo_model.RepositoryBeingMigrated, }) } else { - r, err = models.GetRepositoryByID(opts.MigrateToRepoID) + r, err = repo_model.GetRepositoryByID(opts.MigrateToRepoID) } if err != nil { return err @@ -979,6 +979,6 @@ func (g *GiteaLocalUploader) Finish() error { return err } - g.repo.Status = models.RepositoryReady + g.repo.Status = repo_model.RepositoryReady return models.UpdateRepositoryCols(g.repo, "status") } diff --git a/services/migrations/gitea_uploader_test.go b/services/migrations/gitea_uploader_test.go index 45876dd960..7d4f77eac8 100644 --- a/services/migrations/gitea_uploader_test.go +++ b/services/migrations/gitea_uploader_test.go @@ -12,6 +12,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/unittest" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/graceful" @@ -53,9 +54,9 @@ func TestGiteaUploadRepo(t *testing.T) { }, nil) assert.NoError(t, err) - repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{OwnerID: user.ID, Name: repoName}).(*models.Repository) + repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{OwnerID: user.ID, Name: repoName}).(*repo_model.Repository) assert.True(t, repo.HasWiki()) - assert.EqualValues(t, models.RepositoryReady, repo.Status) + assert.EqualValues(t, repo_model.RepositoryReady, repo.Status) milestones, _, err := models.GetMilestones(models.GetMilestonesOption{ RepoID: repo.ID, diff --git a/services/migrations/migrate.go b/services/migrations/migrate.go index 02b167b27c..65ecceddbe 100644 --- a/services/migrations/migrate.go +++ b/services/migrations/migrate.go @@ -15,6 +15,7 @@ import ( "code.gitea.io/gitea/models" admin_model "code.gitea.io/gitea/models/admin" + repo_model "code.gitea.io/gitea/models/repo" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/hostmatcher" "code.gitea.io/gitea/modules/log" @@ -106,7 +107,7 @@ func IsMigrateURLAllowed(remoteURL string, doer *user_model.User) error { } // MigrateRepository migrate repository according MigrateOptions -func MigrateRepository(ctx context.Context, doer *user_model.User, ownerName string, opts base.MigrateOptions, messenger base.Messenger) (*models.Repository, error) { +func MigrateRepository(ctx context.Context, doer *user_model.User, ownerName string, opts base.MigrateOptions, messenger base.Messenger) (*repo_model.Repository, error) { err := IsMigrateURLAllowed(opts.CloneAddr, doer) if err != nil { return nil, err diff --git a/services/mirror/mirror.go b/services/mirror/mirror.go index dae6f2807b..2643200174 100644 --- a/services/mirror/mirror.go +++ b/services/mirror/mirror.go @@ -8,7 +8,7 @@ import ( "context" "fmt" - "code.gitea.io/gitea/models" + repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/modules/graceful" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/queue" @@ -59,7 +59,7 @@ func Update(ctx context.Context, pullLimit, pushLimit int) error { handler := func(idx int, bean interface{}, limit int) error { var item SyncRequest - if m, ok := bean.(*models.Mirror); ok { + if m, ok := bean.(*repo_model.Mirror); ok { if m.Repo == nil { log.Error("Disconnected mirror found: %d", m.ID) return nil @@ -68,7 +68,7 @@ func Update(ctx context.Context, pullLimit, pushLimit int) error { Type: PullMirrorType, RepoID: m.RepoID, } - } else if m, ok := bean.(*models.PushMirror); ok { + } else if m, ok := bean.(*repo_model.PushMirror); ok { if m.Repo == nil { log.Error("Disconnected push-mirror found: %d", m.ID) return nil @@ -111,7 +111,7 @@ func Update(ctx context.Context, pullLimit, pushLimit int) error { } if pullLimit != 0 { - if err := models.MirrorsIterate(func(idx int, bean interface{}) error { + if err := repo_model.MirrorsIterate(func(idx int, bean interface{}) error { return handler(idx, bean, pullLimit) }); err != nil && err != errLimit { log.Error("MirrorsIterate: %v", err) @@ -119,7 +119,7 @@ func Update(ctx context.Context, pullLimit, pushLimit int) error { } } if pushLimit != 0 { - if err := models.PushMirrorsIterate(func(idx int, bean interface{}) error { + if err := repo_model.PushMirrorsIterate(func(idx int, bean interface{}) error { return handler(idx, bean, pushLimit) }); err != nil && err != errLimit { log.Error("PushMirrorsIterate: %v", err) diff --git a/services/mirror/mirror_pull.go b/services/mirror/mirror_pull.go index 7a2bc125c5..1a15849226 100644 --- a/services/mirror/mirror_pull.go +++ b/services/mirror/mirror_pull.go @@ -13,6 +13,7 @@ import ( "code.gitea.io/gitea/models" admin_model "code.gitea.io/gitea/models/admin" "code.gitea.io/gitea/models/db" + repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/modules/cache" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/lfs" @@ -29,7 +30,7 @@ import ( const gitShortEmptySha = "0000000" // UpdateAddress writes new address to Git repository and database -func UpdateAddress(m *models.Mirror, addr string) error { +func UpdateAddress(m *repo_model.Mirror, addr string) error { remoteName := m.GetRemoteName() repoPath := m.Repo.RepoPath() // Remove old remote @@ -144,7 +145,7 @@ func parseRemoteUpdateOutput(output string) []*mirrorSyncResult { } func pruneBrokenReferences(ctx context.Context, - m *models.Mirror, + m *repo_model.Mirror, repoPath string, timeout time.Duration, stdoutBuilder, stderrBuilder *strings.Builder, @@ -181,7 +182,7 @@ func pruneBrokenReferences(ctx context.Context, } // runSync returns true if sync finished without error. -func runSync(ctx context.Context, m *models.Mirror) ([]*mirrorSyncResult, bool) { +func runSync(ctx context.Context, m *repo_model.Mirror) ([]*mirrorSyncResult, bool) { repoPath := m.Repo.RepoPath() wikiPath := m.Repo.WikiPath() timeout := time.Duration(setting.Git.Timeout.Mirror) * time.Second @@ -271,7 +272,7 @@ func runSync(ctx context.Context, m *models.Mirror) ([]*mirrorSyncResult, bool) gitRepo.Close() log.Trace("SyncMirrors [repo: %-v]: updating size of repository", m.Repo) - if err := m.Repo.UpdateSize(db.DefaultContext); err != nil { + if err := models.UpdateRepoSize(db.DefaultContext, m.Repo); err != nil { log.Error("Failed to update size for mirror repository: %v", err) } @@ -362,7 +363,7 @@ func SyncPullMirror(ctx context.Context, repoID int64) bool { log.Error("PANIC whilst syncMirrors[%d] Panic: %v\nStacktrace: %s", repoID, err, log.Stack(2)) }() - m, err := models.GetMirrorByRepoID(repoID) + m, err := repo_model.GetMirrorByRepoID(repoID) if err != nil { log.Error("GetMirrorByRepoID [%d]: %v", repoID, err) return false @@ -379,7 +380,7 @@ func SyncPullMirror(ctx context.Context, repoID int64) bool { log.Trace("SyncMirrors [repo: %-v]: Scheduling next update", m.Repo) m.ScheduleNextUpdate() - if err = models.UpdateMirror(m); err != nil { + if err = repo_model.UpdateMirror(m); err != nil { log.Error("UpdateMirror [%d]: %v", m.RepoID, err) return false } @@ -485,7 +486,7 @@ func SyncPullMirror(ctx context.Context, repoID int64) bool { return true } -func checkAndUpdateEmptyRepository(m *models.Mirror, gitRepo *git.Repository, results []*mirrorSyncResult) bool { +func checkAndUpdateEmptyRepository(m *repo_model.Mirror, gitRepo *git.Repository, results []*mirrorSyncResult) bool { if !m.Repo.IsEmpty { return true } diff --git a/services/mirror/mirror_push.go b/services/mirror/mirror_push.go index cf205e7b51..e1c395ea74 100644 --- a/services/mirror/mirror_push.go +++ b/services/mirror/mirror_push.go @@ -12,7 +12,7 @@ import ( "regexp" "time" - "code.gitea.io/gitea/models" + repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/lfs" "code.gitea.io/gitea/modules/log" @@ -26,7 +26,7 @@ import ( var stripExitStatus = regexp.MustCompile(`exit status \d+ - `) // AddPushMirrorRemote registers the push mirror remote. -func AddPushMirrorRemote(m *models.PushMirror, addr string) error { +func AddPushMirrorRemote(m *repo_model.PushMirror, addr string) error { addRemoteAndConfig := func(addr, path string) error { if _, err := git.NewCommand("remote", "add", "--mirror=push", m.RemoteName, addr).RunInDir(path); err != nil { return err @@ -57,7 +57,7 @@ func AddPushMirrorRemote(m *models.PushMirror, addr string) error { } // RemovePushMirrorRemote removes the push mirror remote. -func RemovePushMirrorRemote(m *models.PushMirror) error { +func RemovePushMirrorRemote(m *repo_model.PushMirror) error { cmd := git.NewCommand("remote", "rm", m.RemoteName) if _, err := cmd.RunInDir(m.Repo.RepoPath()); err != nil { @@ -86,7 +86,7 @@ func SyncPushMirror(ctx context.Context, mirrorID int64) bool { log.Error("PANIC whilst syncPushMirror[%d] Panic: %v\nStacktrace: %s", mirrorID, err, log.Stack(2)) }() - m, err := models.GetPushMirrorByID(mirrorID) + m, err := repo_model.GetPushMirrorByID(mirrorID) if err != nil { log.Error("GetPushMirrorByID [%d]: %v", mirrorID, err) return false @@ -106,7 +106,7 @@ func SyncPushMirror(ctx context.Context, mirrorID int64) bool { m.LastUpdateUnix = timeutil.TimeStampNow() - if err := models.UpdatePushMirror(m); err != nil { + if err := repo_model.UpdatePushMirror(m); err != nil { log.Error("UpdatePushMirror [%d]: %v", m.ID, err) return false @@ -117,7 +117,7 @@ func SyncPushMirror(ctx context.Context, mirrorID int64) bool { return err == nil } -func runPushSync(ctx context.Context, m *models.PushMirror) error { +func runPushSync(ctx context.Context, m *repo_model.PushMirror) error { timeout := time.Duration(setting.Git.Timeout.Mirror) * time.Second performPush := func(path string) error { diff --git a/services/org/org.go b/services/org/org.go index 834c6e5aba..4c0cfe87fc 100644 --- a/services/org/org.go +++ b/services/org/org.go @@ -9,6 +9,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/storage" "code.gitea.io/gitea/modules/util" @@ -23,7 +24,7 @@ func DeleteOrganization(org *models.Organization) error { defer commiter.Close() // Check ownership of repository. - count, err := models.GetRepositoryCount(ctx, org.ID) + count, err := repo_model.GetRepositoryCount(ctx, org.ID) if err != nil { return fmt.Errorf("GetRepositoryCount: %v", err) } else if count > 0 { diff --git a/services/pull/check.go b/services/pull/check.go index 03d4a39919..363a716b28 100644 --- a/services/pull/check.go +++ b/services/pull/check.go @@ -13,6 +13,8 @@ import ( "strings" "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/git" @@ -70,7 +72,7 @@ func checkAndUpdateStatus(pr *models.PullRequest) { func getMergeCommit(pr *models.PullRequest) (*git.Commit, error) { if pr.BaseRepo == nil { var err error - pr.BaseRepo, err = models.GetRepositoryByID(pr.BaseRepoID) + pr.BaseRepo, err = repo_model.GetRepositoryByID(pr.BaseRepoID) if err != nil { return nil, fmt.Errorf("GetRepositoryByID: %v", err) } @@ -165,7 +167,7 @@ func manuallyMerged(pr *models.PullRequest) bool { // When the commit author is unknown set the BaseRepo owner as merger if merger == nil { if pr.BaseRepo.Owner == nil { - if err = pr.BaseRepo.GetOwner(); err != nil { + if err = pr.BaseRepo.GetOwner(db.DefaultContext); err != nil { log.Error("BaseRepo.GetOwner[%d]: %v", pr.ID, err) return false } @@ -240,7 +242,7 @@ func handle(data ...queue.Data) { } // CheckPrsForBaseBranch check all pulls with bseBrannch -func CheckPrsForBaseBranch(baseRepo *models.Repository, baseBranchName string) error { +func CheckPrsForBaseBranch(baseRepo *repo_model.Repository, baseBranchName string) error { prs, err := models.GetUnmergedPullRequestsByBaseInfo(baseRepo.ID, baseBranchName) if err != nil { return err diff --git a/services/pull/lfs.go b/services/pull/lfs.go index b902c63619..c9ec415cb1 100644 --- a/services/pull/lfs.go +++ b/services/pull/lfs.go @@ -114,7 +114,7 @@ func createLFSMetaObjectsFromCatFileBatch(catFileBatchReader *io.PipeReader, wg } // Then we need to check that this pointer is in the db - if _, err := pr.HeadRepo.GetLFSMetaObjectByOid(pointer.Oid); err != nil { + if _, err := models.GetLFSMetaObjectByOid(pr.HeadRepo.ID, pointer.Oid); err != nil { if err == models.ErrLFSObjectNotExist { log.Warn("During merge of: %d in %-v, there is a pointer to LFS Oid: %s which although present in the LFS store is not associated with the head repo %-v", pr.Index, pr.BaseRepo, pointer.Oid, pr.HeadRepo) continue diff --git a/services/pull/merge.go b/services/pull/merge.go index 75c089eee8..49050d6bee 100644 --- a/services/pull/merge.go +++ b/services/pull/merge.go @@ -16,6 +16,8 @@ import ( "time" "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/cache" @@ -31,7 +33,7 @@ import ( // Merge merges pull request to base repository. // Caller should check PR is ready to be merged (review and status checks) // FIXME: add repoWorkingPull make sure two merges does not happen at same time. -func Merge(pr *models.PullRequest, doer *user_model.User, baseGitRepo *git.Repository, mergeStyle models.MergeStyle, message string) (err error) { +func Merge(pr *models.PullRequest, doer *user_model.User, baseGitRepo *git.Repository, mergeStyle repo_model.MergeStyle, message string) (err error) { if err = pr.LoadHeadRepo(); err != nil { log.Error("LoadHeadRepo: %v", err) return fmt.Errorf("LoadHeadRepo: %v", err) @@ -76,7 +78,7 @@ func Merge(pr *models.PullRequest, doer *user_model.User, baseGitRepo *git.Repos if err := pr.Issue.LoadRepo(); err != nil { log.Error("loadRepo for issue [%d]: %v", pr.ID, err) } - if err := pr.Issue.Repo.GetOwner(); err != nil { + if err := pr.Issue.Repo.GetOwner(db.DefaultContext); err != nil { log.Error("GetOwner for issue repo [%d]: %v", pr.ID, err) } @@ -111,7 +113,7 @@ func Merge(pr *models.PullRequest, doer *user_model.User, baseGitRepo *git.Repos } // rawMerge perform the merge operation without changing any pull information in database -func rawMerge(pr *models.PullRequest, doer *user_model.User, mergeStyle models.MergeStyle, message string) (string, error) { +func rawMerge(pr *models.PullRequest, doer *user_model.User, mergeStyle repo_model.MergeStyle, message string) (string, error) { err := git.LoadGitVersion() if err != nil { log.Error("git.LoadGitVersion: %v", err) @@ -219,7 +221,7 @@ func rawMerge(pr *models.PullRequest, doer *user_model.User, mergeStyle models.M sign, keyID, signer, _ := pr.SignMerge(doer, tmpBasePath, "HEAD", trackingBranch) if sign { signArg = "-S" + keyID - if pr.BaseRepo.GetTrustModel() == models.CommitterTrustModel || pr.BaseRepo.GetTrustModel() == models.CollaboratorCommitterTrustModel { + if pr.BaseRepo.GetTrustModel() == repo_model.CommitterTrustModel || pr.BaseRepo.GetTrustModel() == repo_model.CollaboratorCommitterTrustModel { committer = signer } } else if git.CheckGitVersionAtLeast("2.0.0") == nil { @@ -241,7 +243,7 @@ func rawMerge(pr *models.PullRequest, doer *user_model.User, mergeStyle models.M // Merge commits. switch mergeStyle { - case models.MergeStyleMerge: + case repo_model.MergeStyleMerge: cmd := git.NewCommand("merge", "--no-ff", "--no-commit", trackingBranch) if err := runMergeCommand(pr, mergeStyle, cmd, tmpBasePath); err != nil { log.Error("Unable to merge tracking into base: %v", err) @@ -252,11 +254,11 @@ func rawMerge(pr *models.PullRequest, doer *user_model.User, mergeStyle models.M log.Error("Unable to make final commit: %v", err) return "", err } - case models.MergeStyleRebase: + case repo_model.MergeStyleRebase: fallthrough - case models.MergeStyleRebaseUpdate: + case repo_model.MergeStyleRebaseUpdate: fallthrough - case models.MergeStyleRebaseMerge: + case repo_model.MergeStyleRebaseMerge: // Checkout head branch if err := git.NewCommand("checkout", "-b", stagingBranch, trackingBranch).RunInDirPipeline(tmpBasePath, &outbuf, &errbuf); err != nil { log.Error("git checkout base prior to merge post staging rebase [%s:%s -> %s:%s]: %v\n%s\n%s", pr.HeadRepo.FullName(), pr.HeadBranch, pr.BaseRepo.FullName(), pr.BaseBranch, err, outbuf.String(), errbuf.String()) @@ -309,7 +311,7 @@ func rawMerge(pr *models.PullRequest, doer *user_model.User, mergeStyle models.M errbuf.Reset() // not need merge, just update by rebase. so skip - if mergeStyle == models.MergeStyleRebaseUpdate { + if mergeStyle == repo_model.MergeStyleRebaseUpdate { break } @@ -322,7 +324,7 @@ func rawMerge(pr *models.PullRequest, doer *user_model.User, mergeStyle models.M errbuf.Reset() cmd := git.NewCommand("merge") - if mergeStyle == models.MergeStyleRebase { + if mergeStyle == repo_model.MergeStyleRebase { cmd.AddArguments("--ff-only") } else { cmd.AddArguments("--no-ff", "--no-commit") @@ -334,13 +336,13 @@ func rawMerge(pr *models.PullRequest, doer *user_model.User, mergeStyle models.M log.Error("Unable to merge staging into base: %v", err) return "", err } - if mergeStyle == models.MergeStyleRebaseMerge { + if mergeStyle == repo_model.MergeStyleRebaseMerge { if err := commitAndSignNoAuthor(pr, message, signArg, tmpBasePath, env); err != nil { log.Error("Unable to make final commit: %v", err) return "", err } } - case models.MergeStyleSquash: + case repo_model.MergeStyleSquash: // Merge with squash cmd := git.NewCommand("merge", "--squash", trackingBranch) if err := runMergeCommand(pr, mergeStyle, cmd, tmpBasePath); err != nil { @@ -398,7 +400,7 @@ func rawMerge(pr *models.PullRequest, doer *user_model.User, mergeStyle models.M } var headUser *user_model.User - err = pr.HeadRepo.GetOwner() + err = pr.HeadRepo.GetOwner(db.DefaultContext) if err != nil { if !user_model.IsErrUserNotExist(err) { log.Error("Can't find user: %d for head repository - %v", pr.HeadRepo.OwnerID, err) @@ -419,7 +421,7 @@ func rawMerge(pr *models.PullRequest, doer *user_model.User, mergeStyle models.M ) var pushCmd *git.Command - if mergeStyle == models.MergeStyleRebaseUpdate { + if mergeStyle == repo_model.MergeStyleRebaseUpdate { // force push the rebase result to head brach pushCmd = git.NewCommand("push", "-f", "head_repo", stagingBranch+":"+git.BranchPrefix+pr.HeadBranch) } else { @@ -467,7 +469,7 @@ func commitAndSignNoAuthor(pr *models.PullRequest, message, signArg, tmpBasePath return nil } -func runMergeCommand(pr *models.PullRequest, mergeStyle models.MergeStyle, cmd *git.Command, tmpBasePath string) error { +func runMergeCommand(pr *models.PullRequest, mergeStyle repo_model.MergeStyle, cmd *git.Command, tmpBasePath string) error { var outbuf, errbuf strings.Builder if err := cmd.RunInDirPipeline(tmpBasePath, &outbuf, &errbuf); err != nil { // Merge will leave a MERGE_HEAD file in the .git folder if there is a conflict @@ -567,7 +569,7 @@ func IsUserAllowedToMerge(pr *models.PullRequest, p models.Permission, user *use return false, err } - if (p.CanWrite(unit.TypeCode) && pr.ProtectedBranch == nil) || (pr.ProtectedBranch != nil && pr.ProtectedBranch.IsUserMergeWhitelisted(user.ID, p)) { + if (p.CanWrite(unit.TypeCode) && pr.ProtectedBranch == nil) || (pr.ProtectedBranch != nil && models.IsUserMergeWhitelisted(pr.ProtectedBranch, user.ID, p)) { return true, nil } @@ -641,8 +643,8 @@ func MergedManually(pr *models.PullRequest, doer *user_model.User, baseGitRepo * prConfig := prUnit.PullRequestsConfig() // Check if merge style is correct and allowed - if !prConfig.IsMergeStyleAllowed(models.MergeStyleManuallyMerged) { - return models.ErrInvalidMergeStyle{ID: pr.BaseRepo.ID, Style: models.MergeStyleManuallyMerged} + if !prConfig.IsMergeStyleAllowed(repo_model.MergeStyleManuallyMerged) { + return models.ErrInvalidMergeStyle{ID: pr.BaseRepo.ID, Style: repo_model.MergeStyleManuallyMerged} } if len(commitID) < 40 { diff --git a/services/pull/pull.go b/services/pull/pull.go index 8bfe20c80e..474c211622 100644 --- a/services/pull/pull.go +++ b/services/pull/pull.go @@ -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 "" diff --git a/services/pull/review.go b/services/pull/review.go index 31c2e99782..3f2e4bdf5f 100644 --- a/services/pull/review.go +++ b/services/pull/review.go @@ -13,6 +13,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/log" @@ -115,7 +116,7 @@ func CreateCodeComment(doer *user_model.User, gitRepo *git.Repository, issue *mo var notEnoughLines = regexp.MustCompile(`exit status 128 - fatal: file .* has only \d+ lines?`) // createCodeComment creates a plain code comment at the specified line / path -func createCodeComment(doer *user_model.User, repo *models.Repository, issue *models.Issue, content, treePath string, line, reviewID int64) (*models.Comment, error) { +func createCodeComment(doer *user_model.User, repo *repo_model.Repository, issue *models.Issue, content, treePath string, line, reviewID int64) (*models.Comment, error) { var commitID, patch string if err := issue.LoadPullRequest(); err != nil { return nil, fmt.Errorf("GetPullRequestByIssueID: %v", err) diff --git a/services/pull/temp_repo.go b/services/pull/temp_repo.go index e30dba7add..d5dc8a5c4b 100644 --- a/services/pull/temp_repo.go +++ b/services/pull/temp_repo.go @@ -12,6 +12,8 @@ import ( "strings" "code.gitea.io/gitea/models" + "code.gitea.io/gitea/models/db" + repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" ) @@ -24,7 +26,7 @@ func createTemporaryRepo(pr *models.PullRequest) (string, error) { return "", fmt.Errorf("LoadHeadRepo: %v", err) } else if pr.HeadRepo == nil { log.Error("Pr %d HeadRepo %d does not exist", pr.ID, pr.HeadRepoID) - return "", &models.ErrRepoNotExist{ + return "", &repo_model.ErrRepoNotExist{ ID: pr.HeadRepoID, } } else if err := pr.LoadBaseRepo(); err != nil { @@ -32,13 +34,13 @@ func createTemporaryRepo(pr *models.PullRequest) (string, error) { return "", fmt.Errorf("LoadBaseRepo: %v", err) } else if pr.BaseRepo == nil { log.Error("Pr %d BaseRepo %d does not exist", pr.ID, pr.BaseRepoID) - return "", &models.ErrRepoNotExist{ + return "", &repo_model.ErrRepoNotExist{ ID: pr.BaseRepoID, } - } else if err := pr.HeadRepo.GetOwner(); err != nil { + } else if err := pr.HeadRepo.GetOwner(db.DefaultContext); err != nil { log.Error("HeadRepo.GetOwner: %v", err) return "", fmt.Errorf("HeadRepo.GetOwner: %v", err) - } else if err := pr.BaseRepo.GetOwner(); err != nil { + } else if err := pr.BaseRepo.GetOwner(db.DefaultContext); err != nil { log.Error("BaseRepo.GetOwner: %v", err) return "", fmt.Errorf("BaseRepo.GetOwner: %v", err) } diff --git a/services/pull/update.go b/services/pull/update.go index ef6e84598e..25c6d36308 100644 --- a/services/pull/update.go +++ b/services/pull/update.go @@ -8,6 +8,7 @@ import ( "fmt" "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" @@ -17,12 +18,12 @@ import ( func Update(pull *models.PullRequest, doer *user_model.User, message string, rebase bool) error { var ( pr *models.PullRequest - style models.MergeStyle + style repo_model.MergeStyle ) if rebase { pr = pull - style = models.MergeStyleRebaseUpdate + style = repo_model.MergeStyleRebaseUpdate } else { //use merge functions but switch repo's and branch's pr = &models.PullRequest{ @@ -31,7 +32,7 @@ func Update(pull *models.PullRequest, doer *user_model.User, message string, reb HeadBranch: pull.BaseBranch, BaseBranch: pull.HeadBranch, } - style = models.MergeStyleMerge + style = repo_model.MergeStyleMerge } if pull.Flow == models.PullRequestFlowAGit { diff --git a/services/release/release.go b/services/release/release.go index ec1494d426..e20b91ece0 100644 --- a/services/release/release.go +++ b/services/release/release.go @@ -31,7 +31,7 @@ func createTag(gitRepo *git.Repository, rel *models.Release, msg string) (bool, return false, err } - protectedTags, err := rel.Repo.GetProtectedTags() + protectedTags, err := models.GetProtectedTags(rel.Repo.ID) if err != nil { return false, fmt.Errorf("GetProtectedTags: %v", err) } @@ -137,7 +137,7 @@ func CreateRelease(gitRepo *git.Repository, rel *models.Release, attachmentUUIDs } // CreateNewTag creates a new repository tag -func CreateNewTag(doer *user_model.User, repo *models.Repository, commit, tagName, msg string) error { +func CreateNewTag(doer *user_model.User, repo *repo_model.Repository, commit, tagName, msg string) error { isExist, err := models.IsReleaseExist(repo.ID, tagName) if err != nil { return err @@ -285,7 +285,7 @@ func DeleteReleaseByID(id int64, doer *user_model.User, delTag bool) error { return fmt.Errorf("GetReleaseByID: %v", err) } - repo, err := models.GetRepositoryByID(rel.RepoID) + repo, err := repo_model.GetRepositoryByID(rel.RepoID) if err != nil { return fmt.Errorf("GetRepositoryByID: %v", err) } diff --git a/services/release/release_test.go b/services/release/release_test.go index 29ff78ca3a..b41eea7e9e 100644 --- a/services/release/release_test.go +++ b/services/release/release_test.go @@ -28,8 +28,8 @@ func TestRelease_Create(t *testing.T) { assert.NoError(t, unittest.PrepareTestDatabase()) user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User) - repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository) - repoPath := models.RepoPath(user.Name, repo.Name) + repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}).(*repo_model.Repository) + repoPath := repo_model.RepoPath(user.Name, repo.Name) gitRepo, err := git.OpenRepository(repoPath) assert.NoError(t, err) @@ -132,8 +132,8 @@ func TestRelease_Update(t *testing.T) { assert.NoError(t, unittest.PrepareTestDatabase()) user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User) - repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository) - repoPath := models.RepoPath(user.Name, repo.Name) + repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}).(*repo_model.Repository) + repoPath := repo_model.RepoPath(user.Name, repo.Name) gitRepo, err := git.OpenRepository(repoPath) assert.NoError(t, err) @@ -274,8 +274,8 @@ func TestRelease_createTag(t *testing.T) { assert.NoError(t, unittest.PrepareTestDatabase()) user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User) - repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository) - repoPath := models.RepoPath(user.Name, repo.Name) + repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}).(*repo_model.Repository) + repoPath := repo_model.RepoPath(user.Name, repo.Name) gitRepo, err := git.OpenRepository(repoPath) assert.NoError(t, err) @@ -356,7 +356,7 @@ func TestRelease_createTag(t *testing.T) { func TestCreateNewTag(t *testing.T) { assert.NoError(t, unittest.PrepareTestDatabase()) user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User) - repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository) + repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}).(*repo_model.Repository) assert.NoError(t, CreateNewTag(user, repo, "master", "v2.0", "v2.0 is released \n\n BUGFIX: .... \n\n 123")) diff --git a/services/repository/adopt.go b/services/repository/adopt.go index 5503155ab0..d5b851d108 100644 --- a/services/repository/adopt.go +++ b/services/repository/adopt.go @@ -13,6 +13,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/log" @@ -25,7 +26,7 @@ import ( ) // AdoptRepository adopts pre-existing repository files for the user/organization. -func AdoptRepository(doer, u *user_model.User, opts models.CreateRepoOptions) (*models.Repository, error) { +func AdoptRepository(doer, u *user_model.User, opts models.CreateRepoOptions) (*repo_model.Repository, error) { if !doer.IsAdmin && !u.CanCreateRepo() { return nil, models.ErrReachLimitOfRepo{ Limit: u.MaxRepoCreation, @@ -36,7 +37,7 @@ func AdoptRepository(doer, u *user_model.User, opts models.CreateRepoOptions) (* opts.DefaultBranch = setting.Repository.DefaultBranch } - repo := &models.Repository{ + repo := &repo_model.Repository{ OwnerID: u.ID, Owner: u, OwnerName: u.Name, @@ -53,14 +54,14 @@ func AdoptRepository(doer, u *user_model.User, opts models.CreateRepoOptions) (* } if err := db.WithTx(func(ctx context.Context) error { - repoPath := models.RepoPath(u.Name, repo.Name) + repoPath := repo_model.RepoPath(u.Name, repo.Name) isExist, err := util.IsExist(repoPath) if err != nil { log.Error("Unable to check if %s exists. Error: %v", repoPath, err) return err } if !isExist { - return models.ErrRepoNotExist{ + return repo_model.ErrRepoNotExist{ OwnerName: u.Name, Name: repo.Name, } @@ -72,7 +73,7 @@ func AdoptRepository(doer, u *user_model.User, opts models.CreateRepoOptions) (* if err := adoptRepository(ctx, repoPath, doer, repo, opts); err != nil { return fmt.Errorf("createDelegateHooks: %v", err) } - if err := repo.CheckDaemonExportOK(ctx); err != nil { + if err := models.CheckDaemonExportOK(ctx, repo); err != nil { return fmt.Errorf("checkDaemonExportOK: %v", err) } @@ -99,7 +100,7 @@ func AdoptRepository(doer, u *user_model.User, opts models.CreateRepoOptions) (* return repo, nil } -func adoptRepository(ctx context.Context, repoPath string, u *user_model.User, repo *models.Repository, opts models.CreateRepoOptions) (err error) { +func adoptRepository(ctx context.Context, repoPath string, u *user_model.User, repo *repo_model.Repository, opts models.CreateRepoOptions) (err error) { isExist, err := util.IsExist(repoPath) if err != nil { log.Error("Unable to check if %s exists. Error: %v", repoPath, err) @@ -115,7 +116,7 @@ func adoptRepository(ctx context.Context, repoPath string, u *user_model.User, r // 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) } @@ -191,20 +192,20 @@ func DeleteUnadoptedRepository(doer, u *user_model.User, repoName string) error return err } - repoPath := models.RepoPath(u.Name, repoName) + repoPath := repo_model.RepoPath(u.Name, repoName) isExist, err := util.IsExist(repoPath) if err != nil { log.Error("Unable to check if %s exists. Error: %v", repoPath, err) return err } if !isExist { - return models.ErrRepoNotExist{ + return repo_model.ErrRepoNotExist{ OwnerName: u.Name, Name: repoName, } } - if exist, err := models.IsRepositoryExist(u, repoName); err != nil { + if exist, err := repo_model.IsRepositoryExist(u, repoName); err != nil { return err } else if exist { return models.ErrRepoAlreadyExist{ diff --git a/services/repository/branch.go b/services/repository/branch.go index 08310134bd..e1775fc12b 100644 --- a/services/repository/branch.go +++ b/services/repository/branch.go @@ -11,6 +11,7 @@ import ( "strings" "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" @@ -20,7 +21,7 @@ import ( ) // CreateNewBranch creates a new repository branch -func CreateNewBranch(doer *user_model.User, repo *models.Repository, oldBranchName, branchName string) (err error) { +func CreateNewBranch(doer *user_model.User, repo *repo_model.Repository, oldBranchName, branchName string) (err error) { // Check if branch name can be used if err := checkBranchName(git.DefaultContext, repo, branchName); err != nil { return err @@ -47,7 +48,7 @@ func CreateNewBranch(doer *user_model.User, repo *models.Repository, oldBranchNa } // GetBranch returns a branch by its name -func GetBranch(repo *models.Repository, branch string) (*git.Branch, error) { +func GetBranch(repo *repo_model.Repository, branch string) (*git.Branch, error) { if len(branch) == 0 { return nil, fmt.Errorf("GetBranch: empty string for branch") } @@ -62,12 +63,12 @@ func GetBranch(repo *models.Repository, branch string) (*git.Branch, error) { // GetBranches returns branches from the repository, skipping skip initial branches and // returning at most limit branches, or all branches if limit is 0. -func GetBranches(repo *models.Repository, skip, limit int) ([]*git.Branch, int, error) { +func GetBranches(repo *repo_model.Repository, skip, limit int) ([]*git.Branch, int, error) { return git.GetBranchesByPath(repo.RepoPath(), skip, limit) } // checkBranchName validates branch name with existing repository branches -func checkBranchName(ctx context.Context, repo *models.Repository, name string) error { +func checkBranchName(ctx context.Context, repo *repo_model.Repository, name string) error { _, err := git.WalkReferences(ctx, repo.RepoPath(), func(refName string) error { branchRefName := strings.TrimPrefix(refName, git.BranchPrefix) switch { @@ -97,7 +98,7 @@ func checkBranchName(ctx context.Context, repo *models.Repository, name string) } // CreateNewBranchFromCommit creates a new repository branch -func CreateNewBranchFromCommit(doer *user_model.User, repo *models.Repository, commit, branchName string) (err error) { +func CreateNewBranchFromCommit(doer *user_model.User, repo *repo_model.Repository, commit, branchName string) (err error) { // Check if branch name can be used if err := checkBranchName(git.DefaultContext, repo, branchName); err != nil { return err @@ -118,7 +119,7 @@ func CreateNewBranchFromCommit(doer *user_model.User, repo *models.Repository, c } // RenameBranch rename a branch -func RenameBranch(repo *models.Repository, doer *user_model.User, gitRepo *git.Repository, from, to string) (string, error) { +func RenameBranch(repo *repo_model.Repository, doer *user_model.User, gitRepo *git.Repository, from, to string) (string, error) { if from == to { return "target_exist", nil } @@ -131,7 +132,7 @@ func RenameBranch(repo *models.Repository, doer *user_model.User, gitRepo *git.R return "from_not_exist", nil } - if err := repo.RenameBranch(from, to, func(isDefault bool) error { + if err := models.RenameBranch(repo, from, to, func(isDefault bool) error { err2 := gitRepo.RenameBranch(from, to) if err2 != nil { return err2 @@ -162,12 +163,12 @@ var ( ) // DeleteBranch delete branch -func DeleteBranch(doer *user_model.User, repo *models.Repository, gitRepo *git.Repository, branchName string) error { +func DeleteBranch(doer *user_model.User, repo *repo_model.Repository, gitRepo *git.Repository, branchName string) error { if branchName == repo.DefaultBranch { return ErrBranchIsDefault } - isProtected, err := repo.IsProtectedBranch(branchName) + isProtected, err := models.IsProtectedBranch(repo.ID, branchName) if err != nil { return err } @@ -205,7 +206,7 @@ func DeleteBranch(doer *user_model.User, repo *models.Repository, gitRepo *git.R log.Error("Update: %v", err) } - if err := repo.AddDeletedBranch(branchName, commit.ID.String(), doer.ID); err != nil { + if err := models.AddDeletedBranch(repo.ID, branchName, commit.ID.String(), doer.ID); err != nil { log.Warn("AddDeletedBranch: %v", err) } diff --git a/services/repository/cache.go b/services/repository/cache.go index e574f1adb7..5b0c929be1 100644 --- a/services/repository/cache.go +++ b/services/repository/cache.go @@ -8,7 +8,7 @@ import ( "context" "strings" - "code.gitea.io/gitea/models" + repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/modules/cache" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/setting" @@ -24,7 +24,7 @@ func getRefName(fullRefName string) string { } // CacheRef cachhe last commit information of the branch or the tag -func CacheRef(ctx context.Context, repo *models.Repository, gitRepo *git.Repository, fullRefName string) error { +func CacheRef(ctx context.Context, repo *repo_model.Repository, gitRepo *git.Repository, fullRefName string) error { if !setting.CacheService.LastCommit.Enabled { return nil } diff --git a/services/repository/check.go b/services/repository/check.go index ab7539e555..7118b006bd 100644 --- a/services/repository/check.go +++ b/services/repository/check.go @@ -13,6 +13,7 @@ import ( "code.gitea.io/gitea/models" admin_model "code.gitea.io/gitea/models/admin" "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/log" @@ -27,10 +28,10 @@ func GitFsck(ctx context.Context, timeout time.Duration, args []string) error { if err := db.Iterate( db.DefaultContext, - new(models.Repository), + new(repo_model.Repository), builder.Expr("id>0 AND is_fsck_enabled=?", true), func(idx int, bean interface{}) error { - repo := bean.(*models.Repository) + repo := bean.(*repo_model.Repository) select { case <-ctx.Done(): return db.ErrCancelledf("before fsck of %s", repo.FullName()) @@ -62,10 +63,10 @@ func GitGcRepos(ctx context.Context, timeout time.Duration, args ...string) erro if err := db.Iterate( db.DefaultContext, - new(models.Repository), + new(repo_model.Repository), builder.Gt{"id": 0}, func(idx int, bean interface{}) error { - repo := bean.(*models.Repository) + repo := bean.(*repo_model.Repository) select { case <-ctx.Done(): return db.ErrCancelledf("before GC of %s", repo.FullName()) @@ -96,7 +97,7 @@ func GitGcRepos(ctx context.Context, timeout time.Duration, args ...string) erro } // Now update the size of the repository - if err := repo.UpdateSize(db.DefaultContext); err != nil { + if err := models.UpdateRepoSize(db.DefaultContext, repo); err != nil { log.Error("Updating size as part of garbage collection failed for %v. Stdout: %s\nError: %v", repo, stdout, err) desc := fmt.Sprintf("Updating size as part of garbage collection failed for %s. Stdout: %s\nError: %v", repo.RepoPath(), stdout, err) if err = admin_model.CreateRepositoryNotice(desc); err != nil { @@ -115,14 +116,14 @@ func GitGcRepos(ctx context.Context, timeout time.Duration, args ...string) erro return nil } -func gatherMissingRepoRecords(ctx context.Context) ([]*models.Repository, error) { - repos := make([]*models.Repository, 0, 10) +func gatherMissingRepoRecords(ctx context.Context) ([]*repo_model.Repository, error) { + repos := make([]*repo_model.Repository, 0, 10) if err := db.Iterate( db.DefaultContext, - new(models.Repository), + new(repo_model.Repository), builder.Gt{"id": 0}, func(idx int, bean interface{}) error { - repo := bean.(*models.Repository) + repo := bean.(*repo_model.Repository) select { case <-ctx.Done(): return db.ErrCancelledf("during gathering missing repo records before checking %s", repo.FullName()) diff --git a/services/repository/files/commit.go b/services/repository/files/commit.go index 8f14ed8926..6bff1bb97f 100644 --- a/services/repository/files/commit.go +++ b/services/repository/files/commit.go @@ -8,6 +8,7 @@ import ( "fmt" "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/structs" @@ -16,7 +17,7 @@ import ( // CreateCommitStatus creates a new CommitStatus given a bunch of parameters // NOTE: All text-values will be trimmed from whitespaces. // Requires: Repo, Creator, SHA -func CreateCommitStatus(repo *models.Repository, creator *user_model.User, sha string, status *models.CommitStatus) error { +func CreateCommitStatus(repo *repo_model.Repository, creator *user_model.User, sha string, status *models.CommitStatus) error { repoPath := repo.RepoPath() // confirm that commit is exist @@ -43,7 +44,7 @@ func CreateCommitStatus(repo *models.Repository, creator *user_model.User, sha s } // CountDivergingCommits determines how many commits a branch is ahead or behind the repository's base branch -func CountDivergingCommits(repo *models.Repository, branch string) (*git.DivergeObject, error) { +func CountDivergingCommits(repo *repo_model.Repository, branch string) (*git.DivergeObject, error) { divergence, err := git.GetDivergingCommits(repo.RepoPath(), repo.DefaultBranch, branch) if err != nil { return nil, err diff --git a/services/repository/files/content.go b/services/repository/files/content.go index afb775fed3..10461c82a7 100644 --- a/services/repository/files/content.go +++ b/services/repository/files/content.go @@ -11,6 +11,7 @@ import ( "strings" "code.gitea.io/gitea/models" + repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/setting" api "code.gitea.io/gitea/modules/structs" @@ -38,7 +39,7 @@ func (ct *ContentType) String() string { // GetContentsOrList gets the meta data of a file's contents (*ContentsResponse) if treePath not a tree // directory, otherwise a listing of file contents ([]*ContentsResponse). Ref can be a branch, commit or tag -func GetContentsOrList(repo *models.Repository, treePath, ref string) (interface{}, error) { +func GetContentsOrList(repo *repo_model.Repository, treePath, ref string) (interface{}, error) { if repo.IsEmpty { return make([]interface{}, 0), nil } @@ -100,7 +101,7 @@ func GetContentsOrList(repo *models.Repository, treePath, ref string) (interface } // GetContents gets the meta data on a file's contents. Ref can be a branch, commit or tag -func GetContents(repo *models.Repository, treePath, ref string, forList bool) (*api.ContentsResponse, error) { +func GetContents(repo *repo_model.Repository, treePath, ref string, forList bool) (*api.ContentsResponse, error) { if ref == "" { ref = repo.DefaultBranch } @@ -218,7 +219,7 @@ func GetContents(repo *models.Repository, treePath, ref string, forList bool) (* } // GetBlobBySHA get the GitBlobResponse of a repository using a sha hash. -func GetBlobBySHA(repo *models.Repository, sha string) (*api.GitBlobResponse, error) { +func GetBlobBySHA(repo *repo_model.Repository, sha string) (*api.GitBlobResponse, error) { gitRepo, err := git.OpenRepository(repo.RepoPath()) if err != nil { return nil, err diff --git a/services/repository/files/delete.go b/services/repository/files/delete.go index f7b342db3f..15208addda 100644 --- a/services/repository/files/delete.go +++ b/services/repository/files/delete.go @@ -9,6 +9,7 @@ import ( "strings" "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" api "code.gitea.io/gitea/modules/structs" @@ -30,7 +31,7 @@ type DeleteRepoFileOptions struct { } // DeleteRepoFile deletes a file in the given repository -func DeleteRepoFile(repo *models.Repository, doer *user_model.User, opts *DeleteRepoFileOptions) (*api.FileResponse, error) { +func DeleteRepoFile(repo *repo_model.Repository, doer *user_model.User, opts *DeleteRepoFileOptions) (*api.FileResponse, error) { // If no branch name is set, assume the repo's default branch if opts.OldBranch == "" { opts.OldBranch = repo.DefaultBranch diff --git a/services/repository/files/diff.go b/services/repository/files/diff.go index fadaf20231..fb41237e13 100644 --- a/services/repository/files/diff.go +++ b/services/repository/files/diff.go @@ -7,12 +7,12 @@ package files import ( "strings" - "code.gitea.io/gitea/models" + repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/services/gitdiff" ) // GetDiffPreview produces and returns diff result of a file which is not yet committed. -func GetDiffPreview(repo *models.Repository, branch, treePath, content string) (*gitdiff.Diff, error) { +func GetDiffPreview(repo *repo_model.Repository, branch, treePath, content string) (*gitdiff.Diff, error) { if branch == "" { branch = repo.DefaultBranch } diff --git a/services/repository/files/diff_test.go b/services/repository/files/diff_test.go index be8e92033d..2f256e888c 100644 --- a/services/repository/files/diff_test.go +++ b/services/repository/files/diff_test.go @@ -7,7 +7,7 @@ package files import ( "testing" - "code.gitea.io/gitea/models" + repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/models/unittest" "code.gitea.io/gitea/modules/json" "code.gitea.io/gitea/modules/test" @@ -152,7 +152,7 @@ func TestGetDiffPreviewErrors(t *testing.T) { content := "# repo1\n\nDescription for repo1\nthis is a new line" t.Run("empty repo", func(t *testing.T) { - diff, err := GetDiffPreview(&models.Repository{}, branch, treePath, content) + diff, err := GetDiffPreview(&repo_model.Repository{}, branch, treePath, content) assert.Nil(t, diff) assert.EqualError(t, err, "repository does not exist [id: 0, uid: 0, owner_name: , name: ]") }) diff --git a/services/repository/files/file.go b/services/repository/files/file.go index 8de60c4cb8..7886119587 100644 --- a/services/repository/files/file.go +++ b/services/repository/files/file.go @@ -11,14 +11,14 @@ import ( "strings" "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" api "code.gitea.io/gitea/modules/structs" ) // GetFileResponseFromCommit Constructs a FileResponse from a Commit object -func GetFileResponseFromCommit(repo *models.Repository, commit *git.Commit, branch, treeName string) (*api.FileResponse, error) { +func GetFileResponseFromCommit(repo *repo_model.Repository, commit *git.Commit, branch, treeName string) (*api.FileResponse, error) { fileContents, _ := GetContents(repo, treeName, branch, false) // ok if fails, then will be nil fileCommitResponse, _ := GetFileCommitResponse(repo, commit) // ok if fails, then will be nil verification := GetPayloadCommitVerification(commit) @@ -31,7 +31,7 @@ func GetFileResponseFromCommit(repo *models.Repository, commit *git.Commit, bran } // GetFileCommitResponse Constructs a FileCommitResponse from a Commit object -func GetFileCommitResponse(repo *models.Repository, commit *git.Commit) (*api.FileCommitResponse, error) { +func GetFileCommitResponse(repo *repo_model.Repository, commit *git.Commit) (*api.FileCommitResponse, error) { if repo == nil { return nil, fmt.Errorf("repo cannot be nil") } diff --git a/services/repository/files/temp_repo.go b/services/repository/files/temp_repo.go index 55dcd7436c..815aa2c69f 100644 --- a/services/repository/files/temp_repo.go +++ b/services/repository/files/temp_repo.go @@ -15,6 +15,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" @@ -24,13 +25,13 @@ import ( // TemporaryUploadRepository is a type to wrap our upload repositories as a shallow clone type TemporaryUploadRepository struct { - repo *models.Repository + repo *repo_model.Repository gitRepo *git.Repository basePath string } // NewTemporaryUploadRepository creates a new temporary upload repository -func NewTemporaryUploadRepository(repo *models.Repository) (*TemporaryUploadRepository, error) { +func NewTemporaryUploadRepository(repo *repo_model.Repository) (*TemporaryUploadRepository, error) { basePath, err := models.CreateTemporaryPath("upload") if err != nil { return nil, err @@ -56,7 +57,7 @@ func (t *TemporaryUploadRepository) Clone(branch string) error { Name: branch, } } else if matched, _ := regexp.MatchString(".* repository .* does not exist.*", stderr); matched { - return models.ErrRepoNotExist{ + return repo_model.ErrRepoNotExist{ ID: t.repo.ID, UID: t.repo.OwnerID, OwnerName: t.repo.OwnerName, @@ -216,10 +217,10 @@ func (t *TemporaryUploadRepository) CommitTreeWithDate(author, committer *user_m // Determine if we should sign if git.CheckGitVersionAtLeast("1.7.9") == nil { - sign, keyID, signer, _ := t.repo.SignCRUDAction(author, t.basePath, "HEAD") + sign, keyID, signer, _ := models.SignCRUDAction(t.repo, author, t.basePath, "HEAD") if sign { args = append(args, "-S"+keyID) - if t.repo.GetTrustModel() == models.CommitterTrustModel || t.repo.GetTrustModel() == models.CollaboratorCommitterTrustModel { + if t.repo.GetTrustModel() == repo_model.CommitterTrustModel || t.repo.GetTrustModel() == repo_model.CollaboratorCommitterTrustModel { if committerSig.Name != authorSig.Name || committerSig.Email != authorSig.Email { // Add trailers _, _ = messageBytes.WriteString("\n") diff --git a/services/repository/files/tree.go b/services/repository/files/tree.go index ede206274e..c6b77355ed 100644 --- a/services/repository/files/tree.go +++ b/services/repository/files/tree.go @@ -9,13 +9,14 @@ import ( "net/url" "code.gitea.io/gitea/models" + repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/setting" api "code.gitea.io/gitea/modules/structs" ) // GetTreeBySHA get the GitTreeResponse of a repository using a sha hash. -func GetTreeBySHA(repo *models.Repository, sha string, page, perPage int, recursive bool) (*api.GitTreeResponse, error) { +func GetTreeBySHA(repo *repo_model.Repository, sha string, page, perPage int, recursive bool) (*api.GitTreeResponse, error) { gitRepo, err := git.OpenRepository(repo.RepoPath()) if err != nil { return nil, err diff --git a/services/repository/files/update.go b/services/repository/files/update.go index eeb98f3630..9a069acbfc 100644 --- a/services/repository/files/update.go +++ b/services/repository/files/update.go @@ -12,6 +12,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/charset" "code.gitea.io/gitea/modules/git" @@ -55,7 +56,7 @@ type UpdateRepoFileOptions struct { Signoff bool } -func detectEncodingAndBOM(entry *git.TreeEntry, repo *models.Repository) (string, bool) { +func detectEncodingAndBOM(entry *git.TreeEntry, repo *repo_model.Repository) (string, bool) { reader, err := entry.Blob().DataAsync() if err != nil { // return default @@ -73,7 +74,7 @@ func detectEncodingAndBOM(entry *git.TreeEntry, repo *models.Repository) (string if setting.LFS.StartServer { pointer, _ := lfs.ReadPointerFromBuffer(buf) if pointer.IsValid() { - meta, err := repo.GetLFSMetaObjectByOid(pointer.Oid) + meta, err := models.GetLFSMetaObjectByOid(repo.ID, pointer.Oid) if err != nil && err != models.ErrLFSObjectNotExist { // return default return "UTF-8", false @@ -123,7 +124,7 @@ func detectEncodingAndBOM(entry *git.TreeEntry, repo *models.Repository) (string } // CreateOrUpdateRepoFile adds or updates a file in the given repository -func CreateOrUpdateRepoFile(repo *models.Repository, doer *user_model.User, opts *UpdateRepoFileOptions) (*structs.FileResponse, error) { +func CreateOrUpdateRepoFile(repo *repo_model.Repository, doer *user_model.User, opts *UpdateRepoFileOptions) (*structs.FileResponse, error) { // If no branch name is set, assume default branch if opts.OldBranch == "" { opts.OldBranch = repo.DefaultBranch @@ -413,7 +414,7 @@ func CreateOrUpdateRepoFile(repo *models.Repository, doer *user_model.User, opts } if !exist { if err := contentStore.Put(lfsMetaObject.Pointer, strings.NewReader(opts.Content)); err != nil { - if _, err2 := repo.RemoveLFSMetaObjectByOid(lfsMetaObject.Oid); err2 != nil { + if _, err2 := models.RemoveLFSMetaObjectByOid(repo.ID, lfsMetaObject.Oid); err2 != nil { return nil, fmt.Errorf("Error whilst removing failed inserted LFS object %s: %v (Prev Error: %v)", lfsMetaObject.Oid, err2, err) } return nil, err @@ -440,8 +441,8 @@ func CreateOrUpdateRepoFile(repo *models.Repository, doer *user_model.User, opts } // VerifyBranchProtection verify the branch protection for modifying the given treePath on the given branch -func VerifyBranchProtection(repo *models.Repository, doer *user_model.User, branchName string, treePath string) error { - protectedBranch, err := repo.GetBranchProtection(branchName) +func VerifyBranchProtection(repo *repo_model.Repository, doer *user_model.User, branchName string, treePath string) error { + protectedBranch, err := models.GetProtectedBranchBy(repo.ID, branchName) if err != nil { return err } @@ -457,7 +458,7 @@ func VerifyBranchProtection(repo *models.Repository, doer *user_model.User, bran } } if protectedBranch.RequireSignedCommits { - _, _, _, err := repo.SignCRUDAction(doer, repo.RepoPath(), branchName) + _, _, _, err := models.SignCRUDAction(repo, doer, repo.RepoPath(), branchName) if err != nil { if !models.IsErrWontSign(err) { return err diff --git a/services/repository/files/upload.go b/services/repository/files/upload.go index 7a0ea31085..5e9c936113 100644 --- a/services/repository/files/upload.go +++ b/services/repository/files/upload.go @@ -11,6 +11,7 @@ import ( "strings" "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/lfs" @@ -39,7 +40,7 @@ func cleanUpAfterFailure(infos *[]uploadInfo, t *TemporaryUploadRepository, orig continue } if !info.lfsMetaObject.Existing { - if _, err := t.repo.RemoveLFSMetaObjectByOid(info.lfsMetaObject.Oid); err != nil { + if _, err := models.RemoveLFSMetaObjectByOid(t.repo.ID, info.lfsMetaObject.Oid); err != nil { original = fmt.Errorf("%v, %v", original, err) } } @@ -48,7 +49,7 @@ func cleanUpAfterFailure(infos *[]uploadInfo, t *TemporaryUploadRepository, orig } // UploadRepoFiles uploads files to the given repository -func UploadRepoFiles(repo *models.Repository, doer *user_model.User, opts *UploadRepoFileOptions) error { +func UploadRepoFiles(repo *repo_model.Repository, doer *user_model.User, opts *UploadRepoFileOptions) error { if len(opts.Files) == 0 { return nil } @@ -63,7 +64,7 @@ func UploadRepoFiles(repo *models.Repository, doer *user_model.User, opts *Uploa for i, upload := range uploads { // Check file is not lfs locked, will return nil if lock setting not enabled filepath := path.Join(opts.TreePath, upload.Name) - lfsLock, err := repo.GetTreePathLock(filepath) + lfsLock, err := models.GetTreePathLock(repo.ID, filepath) if err != nil { return err } diff --git a/services/repository/fork.go b/services/repository/fork.go index 3fc08b4986..027877cfd5 100644 --- a/services/repository/fork.go +++ b/services/repository/fork.go @@ -12,6 +12,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/log" @@ -22,8 +23,8 @@ import ( ) // ForkRepository forks a repository -func ForkRepository(doer, owner *user_model.User, opts models.ForkRepoOptions) (_ *models.Repository, err error) { - forkedRepo, err := opts.BaseRepo.GetUserFork(owner.ID) +func ForkRepository(doer, owner *user_model.User, opts models.ForkRepoOptions) (_ *repo_model.Repository, err error) { + forkedRepo, err := models.GetUserFork(opts.BaseRepo.ID, owner.ID) if err != nil { return nil, err } @@ -35,7 +36,7 @@ func ForkRepository(doer, owner *user_model.User, opts models.ForkRepoOptions) ( } } - repo := &models.Repository{ + repo := &repo_model.Repository{ OwnerID: owner.ID, Owner: owner, OwnerName: owner.Name, @@ -57,7 +58,7 @@ func ForkRepository(doer, owner *user_model.User, opts models.ForkRepoOptions) ( return } - repoPath := models.RepoPath(owner.Name, repo.Name) + repoPath := repo_model.RepoPath(owner.Name, repo.Name) if exists, _ := util.IsExist(repoPath); !exists { return @@ -99,7 +100,7 @@ func ForkRepository(doer, owner *user_model.User, opts models.ForkRepoOptions) ( needsRollback = true - repoPath := models.RepoPath(owner.Name, repo.Name) + repoPath := repo_model.RepoPath(owner.Name, repo.Name) if stdout, err := git.NewCommandContext(ctx, "clone", "--bare", oldRepoPath, repoPath). SetDescription(fmt.Sprintf("ForkRepository(git clone): %s to %s", opts.BaseRepo.FullName(), repo.FullName())). @@ -108,7 +109,7 @@ func ForkRepository(doer, owner *user_model.User, opts models.ForkRepoOptions) ( return fmt.Errorf("git clone: %v", err) } - if err := repo.CheckDaemonExportOK(ctx); err != nil { + if err := models.CheckDaemonExportOK(ctx, repo); err != nil { return fmt.Errorf("checkDaemonExportOK: %v", err) } @@ -131,11 +132,10 @@ func ForkRepository(doer, owner *user_model.User, opts models.ForkRepoOptions) ( } // even if below operations failed, it could be ignored. And they will be retried - ctx := db.DefaultContext - if err := repo.UpdateSize(ctx); err != nil { + if err := models.UpdateRepoSize(db.DefaultContext, repo); err != nil { log.Error("Failed to update size for repository: %v", err) } - if err := models.CopyLanguageStat(opts.BaseRepo, repo); err != nil { + if err := repo_model.CopyLanguageStat(opts.BaseRepo, repo); err != nil { log.Error("Copy language stat from oldRepo failed") } @@ -145,9 +145,9 @@ func ForkRepository(doer, owner *user_model.User, opts models.ForkRepoOptions) ( } // ConvertForkToNormalRepository convert the provided repo from a forked repo to normal repo -func ConvertForkToNormalRepository(repo *models.Repository) error { +func ConvertForkToNormalRepository(repo *repo_model.Repository) error { err := db.WithTx(func(ctx context.Context) error { - repo, err := models.GetRepositoryByIDCtx(ctx, repo.ID) + repo, err := repo_model.GetRepositoryByIDCtx(ctx, repo.ID) if err != nil { return err } diff --git a/services/repository/fork_test.go b/services/repository/fork_test.go index befb606135..859889fc59 100644 --- a/services/repository/fork_test.go +++ b/services/repository/fork_test.go @@ -8,6 +8,7 @@ import ( "testing" "code.gitea.io/gitea/models" + repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/models/unittest" user_model "code.gitea.io/gitea/models/user" @@ -19,7 +20,7 @@ func TestForkRepository(t *testing.T) { // user 13 has already forked repo10 user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 13}).(*user_model.User) - repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 10}).(*models.Repository) + repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 10}).(*repo_model.Repository) fork, err := ForkRepository(user, user, models.ForkRepoOptions{ BaseRepo: repo, diff --git a/services/repository/generate.go b/services/repository/generate.go index 031648666d..2b5a750ad1 100644 --- a/services/repository/generate.go +++ b/services/repository/generate.go @@ -9,6 +9,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/log" "code.gitea.io/gitea/modules/notification" @@ -16,14 +17,14 @@ import ( ) // GenerateRepository generates a repository from a template -func GenerateRepository(doer, owner *user_model.User, templateRepo *models.Repository, opts models.GenerateRepoOptions) (_ *models.Repository, err error) { +func GenerateRepository(doer, owner *user_model.User, templateRepo *repo_model.Repository, opts models.GenerateRepoOptions) (_ *repo_model.Repository, err error) { if !doer.IsAdmin && !owner.CanCreateRepo() { return nil, models.ErrReachLimitOfRepo{ Limit: owner.MaxRepoCreation, } } - var generateRepo *models.Repository + var generateRepo *repo_model.Repository if err = db.WithTx(func(ctx context.Context) error { generateRepo, err = repo_module.GenerateRepository(ctx, doer, owner, templateRepo, opts) if err != nil { diff --git a/services/repository/hooks.go b/services/repository/hooks.go index a50853f6af..714cd6b2eb 100644 --- a/services/repository/hooks.go +++ b/services/repository/hooks.go @@ -8,8 +8,8 @@ import ( "context" "fmt" - "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/db" + repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/modules/log" repo_module "code.gitea.io/gitea/modules/repository" @@ -23,10 +23,10 @@ func SyncRepositoryHooks(ctx context.Context) error { if err := db.Iterate( db.DefaultContext, - new(models.Repository), + new(repo_model.Repository), builder.Gt{"id": 0}, func(idx int, bean interface{}) error { - repo := bean.(*models.Repository) + repo := bean.(*repo_model.Repository) select { case <-ctx.Done(): return db.ErrCancelledf("before sync repository hooks for %s", repo.FullName()) diff --git a/services/repository/push.go b/services/repository/push.go index 7b439a41f4..60d2f0c58d 100644 --- a/services/repository/push.go +++ b/services/repository/push.go @@ -13,6 +13,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/cache" "code.gitea.io/gitea/modules/git" @@ -76,7 +77,7 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error { return nil } - repo, err := models.GetRepositoryByOwnerAndName(optsList[0].RepoUserName, optsList[0].RepoName) + repo, err := repo_model.GetRepositoryByOwnerAndName(optsList[0].RepoUserName, optsList[0].RepoName) if err != nil { return fmt.Errorf("GetRepositoryByOwnerAndName failed: %v", err) } @@ -88,7 +89,7 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error { } defer gitRepo.Close() - if err = repo.UpdateSize(db.DefaultContext); err != nil { + if err = models.UpdateRepoSize(db.DefaultContext, repo); err != nil { log.Error("Failed to update size for repository: %v", err) } @@ -209,7 +210,7 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error { commits.CompareURL = repo.ComposeCompareURL(opts.OldCommitID, opts.NewCommitID) notification.NotifyPushCommits(pusher, repo, opts, commits) - if err = models.RemoveDeletedBranch(repo.ID, branch); err != nil { + if err = models.RemoveDeletedBranchByName(repo.ID, branch); err != nil { log.Error("models.RemoveDeletedBranch %s/%s failed: %v", repo.ID, branch, err) } @@ -246,7 +247,7 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error { } // PushUpdateAddDeleteTags updates a number of added and delete tags -func PushUpdateAddDeleteTags(repo *models.Repository, gitRepo *git.Repository, addTags, delTags []string) error { +func PushUpdateAddDeleteTags(repo *repo_model.Repository, gitRepo *git.Repository, addTags, delTags []string) error { return db.WithTx(func(ctx context.Context) error { if err := models.PushUpdateDeleteTagsContext(ctx, repo, delTags); err != nil { return err @@ -256,7 +257,7 @@ func PushUpdateAddDeleteTags(repo *models.Repository, gitRepo *git.Repository, a } // pushUpdateAddTags updates a number of add tags -func pushUpdateAddTags(ctx context.Context, repo *models.Repository, gitRepo *git.Repository, tags []string) error { +func pushUpdateAddTags(ctx context.Context, repo *repo_model.Repository, gitRepo *git.Repository, tags []string) error { if len(tags) == 0 { return nil } diff --git a/services/repository/repository.go b/services/repository/repository.go index 4929f9f446..0b97148f66 100644 --- a/services/repository/repository.go +++ b/services/repository/repository.go @@ -8,6 +8,7 @@ import ( "fmt" "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/log" "code.gitea.io/gitea/modules/notification" @@ -17,7 +18,7 @@ import ( ) // CreateRepository creates a repository for the user/organization. -func CreateRepository(doer, owner *user_model.User, opts models.CreateRepoOptions) (*models.Repository, error) { +func CreateRepository(doer, owner *user_model.User, opts models.CreateRepoOptions) (*repo_model.Repository, error) { repo, err := repo_module.CreateRepository(doer, owner, opts) if err != nil { // No need to rollback here we should do this in CreateRepository... @@ -30,7 +31,7 @@ func CreateRepository(doer, owner *user_model.User, opts models.CreateRepoOption } // DeleteRepository deletes a repository for a user or organization. -func DeleteRepository(doer *user_model.User, repo *models.Repository) error { +func DeleteRepository(doer *user_model.User, repo *repo_model.Repository) error { if err := pull_service.CloseRepoBranchesPulls(doer, repo); err != nil { log.Error("CloseRepoBranchesPulls failed: %v", err) } @@ -43,7 +44,7 @@ func DeleteRepository(doer *user_model.User, repo *models.Repository) error { } // PushCreateRepo creates a repository when a new repository is pushed to an appropriate namespace -func PushCreateRepo(authUser, owner *user_model.User, repoName string) (*models.Repository, error) { +func PushCreateRepo(authUser, owner *user_model.User, repoName string) (*repo_model.Repository, error) { if !authUser.IsAdmin { if owner.IsOrganization() { if ok, err := models.CanCreateOrgRepo(owner.ID, authUser.ID); err != nil { diff --git a/services/repository/transfer.go b/services/repository/transfer.go index d6aea70ffd..b60338300b 100644 --- a/services/repository/transfer.go +++ b/services/repository/transfer.go @@ -8,7 +8,9 @@ import ( "fmt" "code.gitea.io/gitea/models" + "code.gitea.io/gitea/models/db" "code.gitea.io/gitea/models/perm" + repo_model "code.gitea.io/gitea/models/repo" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/notification" "code.gitea.io/gitea/modules/sync" @@ -18,8 +20,8 @@ import ( var repoWorkingPool = sync.NewExclusivePool() // TransferOwnership transfers all corresponding setting from old user to new one. -func TransferOwnership(doer, newOwner *user_model.User, repo *models.Repository, teams []*models.Team) error { - if err := repo.GetOwner(); err != nil { +func TransferOwnership(doer, newOwner *user_model.User, repo *repo_model.Repository, teams []*models.Team) error { + if err := repo.GetOwner(db.DefaultContext); err != nil { return err } for _, team := range teams { @@ -37,7 +39,7 @@ func TransferOwnership(doer, newOwner *user_model.User, repo *models.Repository, } repoWorkingPool.CheckOut(fmt.Sprint(repo.ID)) - newRepo, err := models.GetRepositoryByID(repo.ID) + newRepo, err := repo_model.GetRepositoryByID(repo.ID) if err != nil { return err } @@ -54,7 +56,7 @@ func TransferOwnership(doer, newOwner *user_model.User, repo *models.Repository, } // ChangeRepositoryName changes all corresponding setting from old repository name to new one. -func ChangeRepositoryName(doer *user_model.User, repo *models.Repository, newRepoName string) error { +func ChangeRepositoryName(doer *user_model.User, repo *repo_model.Repository, newRepoName string) error { oldRepoName := repo.Name // Change repository directory name. We must lock the local copy of the @@ -75,7 +77,7 @@ func ChangeRepositoryName(doer *user_model.User, repo *models.Repository, newRep // StartRepositoryTransfer transfer a repo from one owner to a new one. // it make repository into pending transfer state, if doer can not create repo for new owner. -func StartRepositoryTransfer(doer, newOwner *user_model.User, repo *models.Repository, teams []*models.Team) error { +func StartRepositoryTransfer(doer, newOwner *user_model.User, repo *repo_model.Repository, teams []*models.Team) error { if err := models.TestRepositoryReadyForTransfer(repo.Status); err != nil { return err } @@ -102,16 +104,16 @@ func StartRepositoryTransfer(doer, newOwner *user_model.User, repo *models.Repos return err } if !hasAccess { - if err := repo.AddCollaborator(newOwner); err != nil { + if err := models.AddCollaborator(repo, newOwner); err != nil { return err } - if err := repo.ChangeCollaborationAccessMode(newOwner.ID, perm.AccessModeRead); err != nil { + if err := models.ChangeCollaborationAccessMode(repo, newOwner.ID, perm.AccessModeRead); err != nil { return err } } // Make repo as pending for transfer - repo.Status = models.RepositoryPendingTransfer + repo.Status = repo_model.RepositoryPendingTransfer if err := models.CreatePendingRepositoryTransfer(doer, newOwner, repo.ID, teams); err != nil { return err } diff --git a/services/repository/transfer_test.go b/services/repository/transfer_test.go index 866e49c866..d4fbe95834 100644 --- a/services/repository/transfer_test.go +++ b/services/repository/transfer_test.go @@ -9,6 +9,7 @@ import ( "testing" "code.gitea.io/gitea/models" + repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/models/unittest" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/notification" @@ -32,17 +33,17 @@ func TestTransferOwnership(t *testing.T) { assert.NoError(t, unittest.PrepareTestDatabase()) doer := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User) - repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 3}).(*models.Repository) + repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 3}).(*repo_model.Repository) repo.Owner = unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}).(*user_model.User) assert.NoError(t, TransferOwnership(doer, doer, repo, nil)) - transferredRepo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 3}).(*models.Repository) + transferredRepo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 3}).(*repo_model.Repository) assert.EqualValues(t, 2, transferredRepo.OwnerID) - exist, err := util.IsExist(models.RepoPath("user3", "repo3")) + exist, err := util.IsExist(repo_model.RepoPath("user3", "repo3")) assert.NoError(t, err) assert.False(t, exist) - exist, err = util.IsExist(models.RepoPath("user2", "repo3")) + exist, err = util.IsExist(repo_model.RepoPath("user2", "repo3")) assert.NoError(t, err) assert.True(t, exist) unittest.AssertExistsAndLoadBean(t, &models.Action{ @@ -52,7 +53,7 @@ func TestTransferOwnership(t *testing.T) { Content: "user3/repo3", }) - unittest.CheckConsistencyFor(t, &models.Repository{}, &user_model.User{}, &models.Team{}) + unittest.CheckConsistencyFor(t, &repo_model.Repository{}, &user_model.User{}, &models.Team{}) } func TestStartRepositoryTransferSetPermission(t *testing.T) { @@ -60,7 +61,7 @@ func TestStartRepositoryTransferSetPermission(t *testing.T) { doer := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 3}).(*user_model.User) recipient := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 5}).(*user_model.User) - repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 3}).(*models.Repository) + repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 3}).(*repo_model.Repository) repo.Owner = unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}).(*user_model.User) hasAccess, err := models.HasAccess(recipient.ID, repo) @@ -73,5 +74,5 @@ func TestStartRepositoryTransferSetPermission(t *testing.T) { assert.NoError(t, err) assert.True(t, hasAccess) - unittest.CheckConsistencyFor(t, &models.Repository{}, &user_model.User{}, &models.Team{}) + unittest.CheckConsistencyFor(t, &repo_model.Repository{}, &user_model.User{}, &models.Team{}) } diff --git a/services/task/migrate.go b/services/task/migrate.go index 8e9f6115bc..dbe237b691 100644 --- a/services/task/migrate.go +++ b/services/task/migrate.go @@ -11,6 +11,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/graceful" "code.gitea.io/gitea/modules/json" @@ -79,7 +80,7 @@ func runMigrateTask(t *models.Task) (err error) { } // if repository is ready, then just finish the task - if t.Repo.Status == models.RepositoryReady { + if t.Repo.Status == repo_model.RepositoryReady { return nil } diff --git a/services/task/task.go b/services/task/task.go index 350b8206b2..4994be87dd 100644 --- a/services/task/task.go +++ b/services/task/task.go @@ -8,6 +8,7 @@ import ( "fmt" "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/graceful" "code.gitea.io/gitea/modules/json" @@ -110,7 +111,7 @@ func CreateMigrateTask(doer, u *user_model.User, opts base.MigrateOptions) (*mod GitServiceType: opts.GitServiceType, IsPrivate: opts.Private, IsMirror: opts.Mirror, - Status: models.RepositoryBeingMigrated, + Status: repo_model.RepositoryBeingMigrated, }) if err != nil { task.EndTime = timeutil.TimeStampNow() diff --git a/services/user/user.go b/services/user/user.go index 6df9eec131..72052f4ec9 100644 --- a/services/user/user.go +++ b/services/user/user.go @@ -15,6 +15,7 @@ import ( "code.gitea.io/gitea/models" admin_model "code.gitea.io/gitea/models/admin" "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/avatar" "code.gitea.io/gitea/modules/log" @@ -40,7 +41,7 @@ func DeleteUser(u *user_model.User) error { // cannot perform delete operation. // Check ownership of repository. - count, err := models.GetRepositoryCount(ctx, u.ID) + count, err := repo_model.GetRepositoryCount(ctx, u.ID) if err != nil { return fmt.Errorf("GetRepositoryCount: %v", err) } else if count > 0 { diff --git a/services/user/user_test.go b/services/user/user_test.go index e18b760308..5b35db790c 100644 --- a/services/user/user_test.go +++ b/services/user/user_test.go @@ -10,6 +10,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/unittest" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/setting" @@ -26,8 +27,8 @@ func TestDeleteUser(t *testing.T) { assert.NoError(t, unittest.PrepareTestDatabase()) user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: userID}).(*user_model.User) - ownedRepos := make([]*models.Repository, 0, 10) - assert.NoError(t, db.GetEngine(db.DefaultContext).Find(&ownedRepos, &models.Repository{OwnerID: userID})) + ownedRepos := make([]*repo_model.Repository, 0, 10) + assert.NoError(t, db.GetEngine(db.DefaultContext).Find(&ownedRepos, &repo_model.Repository{OwnerID: userID})) if len(ownedRepos) > 0 { err := DeleteUser(user) assert.Error(t, err) @@ -45,7 +46,7 @@ func TestDeleteUser(t *testing.T) { } assert.NoError(t, DeleteUser(user)) unittest.AssertNotExistsBean(t, &user_model.User{ID: userID}) - unittest.CheckConsistencyFor(t, &user_model.User{}, &models.Repository{}) + unittest.CheckConsistencyFor(t, &user_model.User{}, &repo_model.Repository{}) } test(2) test(4) diff --git a/services/webhook/main_test.go b/services/webhook/main_test.go index fc58f72565..e64acf3b61 100644 --- a/services/webhook/main_test.go +++ b/services/webhook/main_test.go @@ -8,6 +8,7 @@ import ( "path/filepath" "testing" + _ "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/unittest" ) diff --git a/services/webhook/webhook.go b/services/webhook/webhook.go index d4fe4e3bcc..9356f4ee11 100644 --- a/services/webhook/webhook.go +++ b/services/webhook/webhook.go @@ -8,7 +8,7 @@ import ( "fmt" "strings" - "code.gitea.io/gitea/models" + repo_model "code.gitea.io/gitea/models/repo" webhook_model "code.gitea.io/gitea/models/webhook" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" @@ -99,7 +99,7 @@ func getPayloadBranch(p api.Payloader) string { } // PrepareWebhook adds special webhook to task queue for given payload. -func PrepareWebhook(w *webhook_model.Webhook, repo *models.Repository, event webhook_model.HookEventType, p api.Payloader) error { +func PrepareWebhook(w *webhook_model.Webhook, repo *repo_model.Repository, event webhook_model.HookEventType, p api.Payloader) error { if err := prepareWebhook(w, repo, event, p); err != nil { return err } @@ -123,7 +123,7 @@ func checkBranch(w *webhook_model.Webhook, branch string) bool { return g.Match(branch) } -func prepareWebhook(w *webhook_model.Webhook, repo *models.Repository, event webhook_model.HookEventType, p api.Payloader) error { +func prepareWebhook(w *webhook_model.Webhook, repo *repo_model.Repository, event webhook_model.HookEventType, p api.Payloader) error { // Skip sending if webhooks are disabled. if setting.DisableWebhooks { return nil @@ -180,7 +180,7 @@ func prepareWebhook(w *webhook_model.Webhook, repo *models.Repository, event web } // PrepareWebhooks adds new webhooks to task queue for given payload. -func PrepareWebhooks(repo *models.Repository, event webhook_model.HookEventType, p api.Payloader) error { +func PrepareWebhooks(repo *repo_model.Repository, event webhook_model.HookEventType, p api.Payloader) error { if err := prepareWebhooks(repo, event, p); err != nil { return err } @@ -189,7 +189,7 @@ func PrepareWebhooks(repo *models.Repository, event webhook_model.HookEventType, return nil } -func prepareWebhooks(repo *models.Repository, event webhook_model.HookEventType, p api.Payloader) error { +func prepareWebhooks(repo *repo_model.Repository, event webhook_model.HookEventType, p api.Payloader) error { ws, err := webhook_model.ListWebhooksByOpts(&webhook_model.ListWebhookOptions{ RepoID: repo.ID, IsActive: util.OptionalBoolTrue, diff --git a/services/webhook/webhook_test.go b/services/webhook/webhook_test.go index c332332787..85fc39770e 100644 --- a/services/webhook/webhook_test.go +++ b/services/webhook/webhook_test.go @@ -7,7 +7,7 @@ package webhook import ( "testing" - "code.gitea.io/gitea/models" + repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/models/unittest" webhook_model "code.gitea.io/gitea/models/webhook" api "code.gitea.io/gitea/modules/structs" @@ -30,7 +30,7 @@ func TestWebhook_GetSlackHook(t *testing.T) { func TestPrepareWebhooks(t *testing.T) { assert.NoError(t, unittest.PrepareTestDatabase()) - repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository) + repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}).(*repo_model.Repository) hookTasks := []*webhook_model.HookTask{ {RepoID: repo.ID, HookID: 1, EventType: webhook_model.HookEventPush}, } @@ -46,7 +46,7 @@ func TestPrepareWebhooks(t *testing.T) { func TestPrepareWebhooksBranchFilterMatch(t *testing.T) { assert.NoError(t, unittest.PrepareTestDatabase()) - repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 2}).(*models.Repository) + repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 2}).(*repo_model.Repository) hookTasks := []*webhook_model.HookTask{ {RepoID: repo.ID, HookID: 4, EventType: webhook_model.HookEventPush}, } @@ -63,7 +63,7 @@ func TestPrepareWebhooksBranchFilterMatch(t *testing.T) { func TestPrepareWebhooksBranchFilterNoMatch(t *testing.T) { assert.NoError(t, unittest.PrepareTestDatabase()) - repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 2}).(*models.Repository) + repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 2}).(*repo_model.Repository) hookTasks := []*webhook_model.HookTask{ {RepoID: repo.ID, HookID: 4, EventType: webhook_model.HookEventPush}, } diff --git a/services/wiki/wiki.go b/services/wiki/wiki.go index cf25c33274..18e9b26d81 100644 --- a/services/wiki/wiki.go +++ b/services/wiki/wiki.go @@ -14,6 +14,7 @@ import ( "code.gitea.io/gitea/models" admin_model "code.gitea.io/gitea/models/admin" "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/git" @@ -70,7 +71,7 @@ func FilenameToName(filename string) (string, error) { // InitWiki initializes a wiki for repository, // it does nothing when repository already has wiki. -func InitWiki(repo *models.Repository) error { +func InitWiki(repo *repo_model.Repository) error { if repo.HasWiki() { return nil } @@ -117,7 +118,7 @@ func prepareWikiFileName(gitRepo *git.Repository, wikiName string) (bool, string } // updateWikiPage adds a new page to the repository wiki. -func updateWikiPage(doer *user_model.User, repo *models.Repository, oldWikiName, newWikiName, content, message string, isNew bool) (err error) { +func updateWikiPage(doer *user_model.User, repo *repo_model.Repository, oldWikiName, newWikiName, content, message string, isNew bool) (err error) { if err = nameAllowed(newWikiName); err != nil { return err } @@ -224,10 +225,10 @@ func updateWikiPage(doer *user_model.User, repo *models.Repository, oldWikiName, committer := doer.NewGitSig() - sign, signingKey, signer, _ := repo.SignWikiCommit(doer) + sign, signingKey, signer, _ := models.SignWikiCommit(repo, doer) if sign { commitTreeOpts.KeyID = signingKey - if repo.GetTrustModel() == models.CommitterTrustModel || repo.GetTrustModel() == models.CollaboratorCommitterTrustModel { + if repo.GetTrustModel() == repo_model.CommitterTrustModel || repo.GetTrustModel() == repo_model.CollaboratorCommitterTrustModel { committer = signer } } else { @@ -265,18 +266,18 @@ func updateWikiPage(doer *user_model.User, repo *models.Repository, oldWikiName, } // AddWikiPage adds a new wiki page with a given wikiPath. -func AddWikiPage(doer *user_model.User, repo *models.Repository, wikiName, content, message string) error { +func AddWikiPage(doer *user_model.User, repo *repo_model.Repository, wikiName, content, message string) error { return updateWikiPage(doer, repo, "", wikiName, content, message, true) } // EditWikiPage updates a wiki page identified by its wikiPath, // optionally also changing wikiPath. -func EditWikiPage(doer *user_model.User, repo *models.Repository, oldWikiName, newWikiName, content, message string) error { +func EditWikiPage(doer *user_model.User, repo *repo_model.Repository, oldWikiName, newWikiName, content, message string) error { return updateWikiPage(doer, repo, oldWikiName, newWikiName, content, message, false) } // DeleteWikiPage deletes a wiki page identified by its path. -func DeleteWikiPage(doer *user_model.User, repo *models.Repository, wikiName string) (err error) { +func DeleteWikiPage(doer *user_model.User, repo *repo_model.Repository, wikiName string) (err error) { wikiWorkingPool.CheckIn(fmt.Sprint(repo.ID)) defer wikiWorkingPool.CheckOut(fmt.Sprint(repo.ID)) @@ -342,10 +343,10 @@ func DeleteWikiPage(doer *user_model.User, repo *models.Repository, wikiName str committer := doer.NewGitSig() - sign, signingKey, signer, _ := repo.SignWikiCommit(doer) + sign, signingKey, signer, _ := models.SignWikiCommit(repo, doer) if sign { commitTreeOpts.KeyID = signingKey - if repo.GetTrustModel() == models.CommitterTrustModel || repo.GetTrustModel() == models.CollaboratorCommitterTrustModel { + if repo.GetTrustModel() == repo_model.CommitterTrustModel || repo.GetTrustModel() == repo_model.CollaboratorCommitterTrustModel { committer = signer } } else { @@ -372,7 +373,7 @@ func DeleteWikiPage(doer *user_model.User, repo *models.Repository, wikiName str } // DeleteWiki removes the actual and local copy of repository wiki. -func DeleteWiki(repo *models.Repository) error { +func DeleteWiki(repo *repo_model.Repository) error { if err := models.UpdateRepositoryUnits(repo, nil, []unit.Type{unit.TypeWiki}); err != nil { return err } diff --git a/services/wiki/wiki_test.go b/services/wiki/wiki_test.go index 5b42dd590f..659666f977 100644 --- a/services/wiki/wiki_test.go +++ b/services/wiki/wiki_test.go @@ -10,6 +10,7 @@ import ( "testing" "code.gitea.io/gitea/models" + repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/models/unittest" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/git" @@ -113,11 +114,11 @@ func TestWikiNameToFilenameToName(t *testing.T) { func TestRepository_InitWiki(t *testing.T) { unittest.PrepareTestEnv(t) // repo1 already has a wiki - repo1 := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository) + repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}).(*repo_model.Repository) assert.NoError(t, InitWiki(repo1)) // repo2 does not already have a wiki - repo2 := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 2}).(*models.Repository) + repo2 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 2}).(*repo_model.Repository) assert.NoError(t, InitWiki(repo2)) assert.True(t, repo2.HasWiki()) } @@ -126,7 +127,7 @@ func TestRepository_AddWikiPage(t *testing.T) { assert.NoError(t, unittest.PrepareTestDatabase()) const wikiContent = "This is the wiki content" const commitMsg = "Commit message" - repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository) + repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}).(*repo_model.Repository) doer := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User) for _, wikiName := range []string{ "Another page", @@ -171,7 +172,7 @@ func TestRepository_EditWikiPage(t *testing.T) { const newWikiContent = "This is the new content" const commitMsg = "Commit message" - repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository) + repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}).(*repo_model.Repository) doer := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User) for _, newWikiName := range []string{ "Home", // same name as before @@ -201,7 +202,7 @@ func TestRepository_EditWikiPage(t *testing.T) { func TestRepository_DeleteWikiPage(t *testing.T) { unittest.PrepareTestEnv(t) - repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository) + repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}).(*repo_model.Repository) doer := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User) assert.NoError(t, DeleteWikiPage(doer, repo, "Home")) @@ -218,7 +219,7 @@ func TestRepository_DeleteWikiPage(t *testing.T) { func TestPrepareWikiFileName(t *testing.T) { unittest.PrepareTestEnv(t) - repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository) + repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}).(*repo_model.Repository) gitRepo, err := git.OpenRepository(repo.WikiPath()) defer gitRepo.Close() assert.NoError(t, err) |