diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2022-06-12 23:51:54 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-12 23:51:54 +0800 |
commit | 110fc57cbcf293c19ed7017d8ea528b4bbbd7396 (patch) | |
tree | b36eb2ee0e3f8417a35ad095e25880b778ded0ba /integrations | |
parent | a9dc9b06e4a4106ec8315fe7b2922efa440ca199 (diff) | |
download | gitea-110fc57cbcf293c19ed7017d8ea528b4bbbd7396.tar.gz gitea-110fc57cbcf293c19ed7017d8ea528b4bbbd7396.zip |
Move some code into models/git (#19879)
* Move access and repo permission to models/perm/access
* fix test
* Move some git related files into sub package models/git
* Fix build
* fix git test
* move lfs to sub package
* move more git related functions to models/git
* Move functions sequence
* Some improvements per @KN4CK3R and @delvh
Diffstat (limited to 'integrations')
-rw-r--r-- | integrations/api_repo_lfs_test.go | 22 | ||||
-rw-r--r-- | integrations/lfs_getobject_test.go | 6 | ||||
-rw-r--r-- | integrations/repo_tag_test.go | 9 |
3 files changed, 19 insertions, 18 deletions
diff --git a/integrations/api_repo_lfs_test.go b/integrations/api_repo_lfs_test.go index 947d157d5b..6a2fccebb5 100644 --- a/integrations/api_repo_lfs_test.go +++ b/integrations/api_repo_lfs_test.go @@ -12,7 +12,7 @@ import ( "strings" "testing" - "code.gitea.io/gitea/models" + git_model "code.gitea.io/gitea/models/git" repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/models/unittest" user_model "code.gitea.io/gitea/models/user" @@ -76,7 +76,7 @@ func TestAPILFSBatch(t *testing.T) { content := []byte("dummy1") oid := storeObjectInRepo(t, repo.ID, &content) - defer models.RemoveLFSMetaObjectByOid(repo.ID, oid) + defer git_model.RemoveLFSMetaObjectByOid(repo.ID, oid) session := loginUser(t, "user2") @@ -260,9 +260,9 @@ func TestAPILFSBatch(t *testing.T) { content := []byte("dummy0") storeObjectInRepo(t, repo2.ID, &content) - meta, err := models.GetLFSMetaObjectByOid(repo.ID, p.Oid) + meta, err := git_model.GetLFSMetaObjectByOid(repo.ID, p.Oid) assert.Nil(t, meta) - assert.Equal(t, models.ErrLFSObjectNotExist, err) + assert.Equal(t, git_model.ErrLFSObjectNotExist, err) req := newRequest(t, &lfs.BatchRequest{ Operation: "upload", @@ -275,7 +275,7 @@ func TestAPILFSBatch(t *testing.T) { assert.Nil(t, br.Objects[0].Error) assert.Empty(t, br.Objects[0].Actions) - meta, err = models.GetLFSMetaObjectByOid(repo.ID, p.Oid) + meta, err = git_model.GetLFSMetaObjectByOid(repo.ID, p.Oid) assert.NoError(t, err) assert.NotNil(t, meta) @@ -336,7 +336,7 @@ func TestAPILFSUpload(t *testing.T) { content := []byte("dummy3") oid := storeObjectInRepo(t, repo.ID, &content) - defer models.RemoveLFSMetaObjectByOid(repo.ID, oid) + defer git_model.RemoveLFSMetaObjectByOid(repo.ID, oid) session := loginUser(t, "user2") @@ -365,9 +365,9 @@ func TestAPILFSUpload(t *testing.T) { err = contentStore.Put(p, bytes.NewReader([]byte("dummy5"))) assert.NoError(t, err) - meta, err := models.GetLFSMetaObjectByOid(repo.ID, p.Oid) + meta, err := git_model.GetLFSMetaObjectByOid(repo.ID, p.Oid) assert.Nil(t, meta) - assert.Equal(t, models.ErrLFSObjectNotExist, err) + assert.Equal(t, git_model.ErrLFSObjectNotExist, err) t.Run("InvalidAccess", func(t *testing.T) { req := newRequest(t, p, "invalid") @@ -378,7 +378,7 @@ func TestAPILFSUpload(t *testing.T) { req := newRequest(t, p, "dummy5") session.MakeRequest(t, req, http.StatusOK) - meta, err = models.GetLFSMetaObjectByOid(repo.ID, p.Oid) + meta, err = git_model.GetLFSMetaObjectByOid(repo.ID, p.Oid) assert.NoError(t, err) assert.NotNil(t, meta) }) @@ -426,7 +426,7 @@ func TestAPILFSUpload(t *testing.T) { assert.NoError(t, err) assert.True(t, exist) - meta, err := models.GetLFSMetaObjectByOid(repo.ID, p.Oid) + meta, err := git_model.GetLFSMetaObjectByOid(repo.ID, p.Oid) assert.NoError(t, err) assert.NotNil(t, meta) }) @@ -441,7 +441,7 @@ func TestAPILFSVerify(t *testing.T) { content := []byte("dummy3") oid := storeObjectInRepo(t, repo.ID, &content) - defer models.RemoveLFSMetaObjectByOid(repo.ID, oid) + defer git_model.RemoveLFSMetaObjectByOid(repo.ID, oid) session := loginUser(t, "user2") diff --git a/integrations/lfs_getobject_test.go b/integrations/lfs_getobject_test.go index e9f0c58022..4b6bb140d3 100644 --- a/integrations/lfs_getobject_test.go +++ b/integrations/lfs_getobject_test.go @@ -12,7 +12,7 @@ import ( "net/http/httptest" "testing" - "code.gitea.io/gitea/models" + git_model "code.gitea.io/gitea/models/git" repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/json" @@ -28,7 +28,7 @@ func storeObjectInRepo(t *testing.T, repositoryID int64, content *[]byte) string pointer, err := lfs.GeneratePointer(bytes.NewReader(*content)) assert.NoError(t, err) - _, err = models.NewLFSMetaObject(&models.LFSMetaObject{Pointer: pointer, RepositoryID: repositoryID}) + _, err = git_model.NewLFSMetaObject(&git_model.LFSMetaObject{Pointer: pointer, RepositoryID: repositoryID}) assert.NoError(t, err) contentStore := lfs.NewContentStore() exist, err := contentStore.Exists(pointer) @@ -44,7 +44,7 @@ func storeAndGetLfs(t *testing.T, content *[]byte, extraHeader *http.Header, exp repo, err := repo_model.GetRepositoryByOwnerAndName("user2", "repo1") assert.NoError(t, err) oid := storeObjectInRepo(t, repo.ID, content) - defer models.RemoveLFSMetaObjectByOid(repo.ID, oid) + defer git_model.RemoveLFSMetaObjectByOid(repo.ID, oid) session := loginUser(t, "user2") diff --git a/integrations/repo_tag_test.go b/integrations/repo_tag_test.go index ef7a11422e..793cf724eb 100644 --- a/integrations/repo_tag_test.go +++ b/integrations/repo_tag_test.go @@ -10,6 +10,7 @@ import ( "testing" "code.gitea.io/gitea/models" + git_model "code.gitea.io/gitea/models/git" repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/models/unittest" user_model "code.gitea.io/gitea/models/user" @@ -32,12 +33,12 @@ func TestCreateNewTagProtected(t *testing.T) { err := release.CreateNewTag(git.DefaultContext, owner, repo, "master", "v-1", "first tag") assert.NoError(t, err) - err = models.InsertProtectedTag(&models.ProtectedTag{ + err = git_model.InsertProtectedTag(&git_model.ProtectedTag{ RepoID: repo.ID, NamePattern: "v-*", }) assert.NoError(t, err) - err = models.InsertProtectedTag(&models.ProtectedTag{ + err = git_model.InsertProtectedTag(&git_model.ProtectedTag{ RepoID: repo.ID, NamePattern: "v-1.1", AllowlistUserIDs: []int64{repo.OwnerID}, @@ -87,11 +88,11 @@ func TestCreateNewTagProtected(t *testing.T) { assert.NoError(t, err) } - protectedTags, err := models.GetProtectedTags(repo.ID) + protectedTags, err := git_model.GetProtectedTags(repo.ID) assert.NoError(t, err) for _, protectedTag := range protectedTags { - err = models.DeleteProtectedTag(protectedTag) + err = git_model.DeleteProtectedTag(protectedTag) assert.NoError(t, err) } } |