diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2021-11-24 15:56:24 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-24 15:56:24 +0800 |
commit | c97d66d23cf14e88514cccb88c393d21db51ab7a (patch) | |
tree | 625857bea77befb61847c01bf17aac1177255787 /integrations | |
parent | 754fdd8f9c2b1e4e78d507fd414968334cf586fd (diff) | |
download | gitea-c97d66d23cf14e88514cccb88c393d21db51ab7a.tar.gz gitea-c97d66d23cf14e88514cccb88c393d21db51ab7a.zip |
Move repofiles from modules/repofiles to services/repository/files (#17774)
* Move repofiles from modules to services
* rename services/repository/repofiles -> services/repository/files
* Fix test
Co-authored-by: 6543 <6543@obermui.de>
Diffstat (limited to 'integrations')
-rw-r--r-- | integrations/api_repo_file_helpers.go | 6 | ||||
-rw-r--r-- | integrations/pull_update_test.go | 18 | ||||
-rw-r--r-- | integrations/repofiles_delete_test.go | 24 | ||||
-rw-r--r-- | integrations/repofiles_update_test.go | 30 |
4 files changed, 39 insertions, 39 deletions
diff --git a/integrations/api_repo_file_helpers.go b/integrations/api_repo_file_helpers.go index 1dba136de9..ef3b8c610b 100644 --- a/integrations/api_repo_file_helpers.go +++ b/integrations/api_repo_file_helpers.go @@ -6,12 +6,12 @@ package integrations import ( "code.gitea.io/gitea/models" - "code.gitea.io/gitea/modules/repofiles" api "code.gitea.io/gitea/modules/structs" + files_service "code.gitea.io/gitea/services/repository/files" ) func createFileInBranch(user *models.User, repo *models.Repository, treePath, branchName, content string) (*api.FileResponse, error) { - opts := &repofiles.UpdateRepoFileOptions{ + opts := &files_service.UpdateRepoFileOptions{ OldBranch: branchName, TreePath: treePath, Content: content, @@ -19,7 +19,7 @@ func createFileInBranch(user *models.User, repo *models.Repository, treePath, br Author: nil, Committer: nil, } - return repofiles.CreateOrUpdateRepoFile(repo, user, opts) + return files_service.CreateOrUpdateRepoFile(repo, user, opts) } func createFile(user *models.User, repo *models.Repository, treePath string) (*api.FileResponse, error) { diff --git a/integrations/pull_update_test.go b/integrations/pull_update_test.go index 43cfe7debf..d7ea676b79 100644 --- a/integrations/pull_update_test.go +++ b/integrations/pull_update_test.go @@ -12,9 +12,9 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/unittest" - "code.gitea.io/gitea/modules/repofiles" pull_service "code.gitea.io/gitea/services/pull" repo_service "code.gitea.io/gitea/services/repository" + files_service "code.gitea.io/gitea/services/repository/files" "github.com/stretchr/testify/assert" ) @@ -97,22 +97,22 @@ func createOutdatedPR(t *testing.T, actor, forkOrg *models.User) *models.PullReq assert.NotEmpty(t, headRepo) //create a commit on base Repo - _, err = repofiles.CreateOrUpdateRepoFile(baseRepo, actor, &repofiles.UpdateRepoFileOptions{ + _, err = files_service.CreateOrUpdateRepoFile(baseRepo, actor, &files_service.UpdateRepoFileOptions{ TreePath: "File_A", Message: "Add File A", Content: "File A", IsNewFile: true, OldBranch: "master", NewBranch: "master", - Author: &repofiles.IdentityOptions{ + Author: &files_service.IdentityOptions{ Name: actor.Name, Email: actor.Email, }, - Committer: &repofiles.IdentityOptions{ + Committer: &files_service.IdentityOptions{ Name: actor.Name, Email: actor.Email, }, - Dates: &repofiles.CommitDateOptions{ + Dates: &files_service.CommitDateOptions{ Author: time.Now(), Committer: time.Now(), }, @@ -120,22 +120,22 @@ func createOutdatedPR(t *testing.T, actor, forkOrg *models.User) *models.PullReq assert.NoError(t, err) //create a commit on head Repo - _, err = repofiles.CreateOrUpdateRepoFile(headRepo, actor, &repofiles.UpdateRepoFileOptions{ + _, err = files_service.CreateOrUpdateRepoFile(headRepo, actor, &files_service.UpdateRepoFileOptions{ TreePath: "File_B", Message: "Add File on PR branch", Content: "File B", IsNewFile: true, OldBranch: "master", NewBranch: "newBranch", - Author: &repofiles.IdentityOptions{ + Author: &files_service.IdentityOptions{ Name: actor.Name, Email: actor.Email, }, - Committer: &repofiles.IdentityOptions{ + Committer: &files_service.IdentityOptions{ Name: actor.Name, Email: actor.Email, }, - Dates: &repofiles.CommitDateOptions{ + Dates: &files_service.CommitDateOptions{ Author: time.Now(), Committer: time.Now(), }, diff --git a/integrations/repofiles_delete_test.go b/integrations/repofiles_delete_test.go index eb73348950..8490f8d3a7 100644 --- a/integrations/repofiles_delete_test.go +++ b/integrations/repofiles_delete_test.go @@ -10,22 +10,22 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/unittest" - "code.gitea.io/gitea/modules/repofiles" api "code.gitea.io/gitea/modules/structs" "code.gitea.io/gitea/modules/test" + files_service "code.gitea.io/gitea/services/repository/files" "github.com/stretchr/testify/assert" ) -func getDeleteRepoFileOptions(repo *models.Repository) *repofiles.DeleteRepoFileOptions { - return &repofiles.DeleteRepoFileOptions{ +func getDeleteRepoFileOptions(repo *models.Repository) *files_service.DeleteRepoFileOptions { + return &files_service.DeleteRepoFileOptions{ LastCommitID: "", OldBranch: repo.DefaultBranch, NewBranch: repo.DefaultBranch, TreePath: "README.md", Message: "Deletes README.md", SHA: "4b4851ad51df6a7d9f25c979345979eaeb5b349f", - Author: &repofiles.IdentityOptions{ + Author: &files_service.IdentityOptions{ Name: "Bob Smith", Email: "bob@smith.com", }, @@ -80,7 +80,7 @@ func testDeleteRepoFile(t *testing.T, u *url.URL) { opts := getDeleteRepoFileOptions(repo) t.Run("Delete README.md file", func(t *testing.T) { - fileResponse, err := repofiles.DeleteRepoFile(repo, doer, opts) + fileResponse, err := files_service.DeleteRepoFile(repo, doer, opts) assert.NoError(t, err) expectedFileResponse := getExpectedDeleteFileResponse(u) assert.NotNil(t, fileResponse) @@ -92,7 +92,7 @@ func testDeleteRepoFile(t *testing.T, u *url.URL) { }) t.Run("Verify README.md has been deleted", func(t *testing.T) { - fileResponse, err := repofiles.DeleteRepoFile(repo, doer, opts) + fileResponse, err := files_service.DeleteRepoFile(repo, doer, opts) assert.Nil(t, fileResponse) expectedError := "repository file does not exist [path: " + opts.TreePath + "]" assert.EqualError(t, err, expectedError) @@ -122,7 +122,7 @@ func testDeleteRepoFileWithoutBranchNames(t *testing.T, u *url.URL) { opts.NewBranch = "" t.Run("Delete README.md without Branch Name", func(t *testing.T) { - fileResponse, err := repofiles.DeleteRepoFile(repo, doer, opts) + fileResponse, err := files_service.DeleteRepoFile(repo, doer, opts) assert.NoError(t, err) expectedFileResponse := getExpectedDeleteFileResponse(u) assert.NotNil(t, fileResponse) @@ -151,7 +151,7 @@ func TestDeleteRepoFileErrors(t *testing.T) { t.Run("Bad branch", func(t *testing.T) { opts := getDeleteRepoFileOptions(repo) opts.OldBranch = "bad_branch" - fileResponse, err := repofiles.DeleteRepoFile(repo, doer, opts) + fileResponse, err := files_service.DeleteRepoFile(repo, doer, opts) assert.Error(t, err) assert.Nil(t, fileResponse) expectedError := "branch does not exist [name: " + opts.OldBranch + "]" @@ -162,7 +162,7 @@ func TestDeleteRepoFileErrors(t *testing.T) { opts := getDeleteRepoFileOptions(repo) origSHA := opts.SHA opts.SHA = "bad_sha" - fileResponse, err := repofiles.DeleteRepoFile(repo, doer, opts) + fileResponse, err := files_service.DeleteRepoFile(repo, doer, opts) assert.Nil(t, fileResponse) assert.Error(t, err) expectedError := "sha does not match [given: " + opts.SHA + ", expected: " + origSHA + "]" @@ -172,7 +172,7 @@ func TestDeleteRepoFileErrors(t *testing.T) { t.Run("New branch already exists", func(t *testing.T) { opts := getDeleteRepoFileOptions(repo) opts.NewBranch = "develop" - fileResponse, err := repofiles.DeleteRepoFile(repo, doer, opts) + fileResponse, err := files_service.DeleteRepoFile(repo, doer, opts) assert.Nil(t, fileResponse) assert.Error(t, err) expectedError := "branch already exists [name: " + opts.NewBranch + "]" @@ -182,7 +182,7 @@ func TestDeleteRepoFileErrors(t *testing.T) { t.Run("TreePath is empty:", func(t *testing.T) { opts := getDeleteRepoFileOptions(repo) opts.TreePath = "" - fileResponse, err := repofiles.DeleteRepoFile(repo, doer, opts) + fileResponse, err := files_service.DeleteRepoFile(repo, doer, opts) assert.Nil(t, fileResponse) assert.Error(t, err) expectedError := "path contains a malformed path component [path: ]" @@ -192,7 +192,7 @@ func TestDeleteRepoFileErrors(t *testing.T) { t.Run("TreePath is a git directory:", func(t *testing.T) { opts := getDeleteRepoFileOptions(repo) opts.TreePath = ".git" - fileResponse, err := repofiles.DeleteRepoFile(repo, doer, opts) + fileResponse, err := files_service.DeleteRepoFile(repo, doer, opts) assert.Nil(t, fileResponse) assert.Error(t, err) expectedError := "path contains a malformed path component [path: " + opts.TreePath + "]" diff --git a/integrations/repofiles_update_test.go b/integrations/repofiles_update_test.go index 9e99b36ae4..fe0e2c21c6 100644 --- a/integrations/repofiles_update_test.go +++ b/integrations/repofiles_update_test.go @@ -12,16 +12,16 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/git" - "code.gitea.io/gitea/modules/repofiles" "code.gitea.io/gitea/modules/setting" api "code.gitea.io/gitea/modules/structs" "code.gitea.io/gitea/modules/test" + files_service "code.gitea.io/gitea/services/repository/files" "github.com/stretchr/testify/assert" ) -func getCreateRepoFileOptions(repo *models.Repository) *repofiles.UpdateRepoFileOptions { - return &repofiles.UpdateRepoFileOptions{ +func getCreateRepoFileOptions(repo *models.Repository) *files_service.UpdateRepoFileOptions { + return &files_service.UpdateRepoFileOptions{ OldBranch: repo.DefaultBranch, NewBranch: repo.DefaultBranch, TreePath: "new/file.txt", @@ -33,8 +33,8 @@ func getCreateRepoFileOptions(repo *models.Repository) *repofiles.UpdateRepoFile } } -func getUpdateRepoFileOptions(repo *models.Repository) *repofiles.UpdateRepoFileOptions { - return &repofiles.UpdateRepoFileOptions{ +func getUpdateRepoFileOptions(repo *models.Repository) *files_service.UpdateRepoFileOptions { + return &files_service.UpdateRepoFileOptions{ OldBranch: repo.DefaultBranch, NewBranch: repo.DefaultBranch, TreePath: "README.md", @@ -198,7 +198,7 @@ func TestCreateOrUpdateRepoFileForCreate(t *testing.T) { opts := getCreateRepoFileOptions(repo) // test - fileResponse, err := repofiles.CreateOrUpdateRepoFile(repo, doer, opts) + fileResponse, err := files_service.CreateOrUpdateRepoFile(repo, doer, opts) // asserts assert.NoError(t, err) @@ -234,7 +234,7 @@ func TestCreateOrUpdateRepoFileForUpdate(t *testing.T) { opts := getUpdateRepoFileOptions(repo) // test - fileResponse, err := repofiles.CreateOrUpdateRepoFile(repo, doer, opts) + fileResponse, err := files_service.CreateOrUpdateRepoFile(repo, doer, opts) // asserts assert.NoError(t, err) @@ -269,7 +269,7 @@ func TestCreateOrUpdateRepoFileForUpdateWithFileMove(t *testing.T) { opts.TreePath = "README_new.md" // new file name, README_new.md // test - fileResponse, err := repofiles.CreateOrUpdateRepoFile(repo, doer, opts) + fileResponse, err := files_service.CreateOrUpdateRepoFile(repo, doer, opts) // asserts assert.NoError(t, err) @@ -319,7 +319,7 @@ func TestCreateOrUpdateRepoFileWithoutBranchNames(t *testing.T) { opts.NewBranch = "" // test - fileResponse, err := repofiles.CreateOrUpdateRepoFile(repo, doer, opts) + fileResponse, err := files_service.CreateOrUpdateRepoFile(repo, doer, opts) // asserts assert.NoError(t, err) @@ -349,7 +349,7 @@ func TestCreateOrUpdateRepoFileErrors(t *testing.T) { t.Run("bad branch", func(t *testing.T) { opts := getUpdateRepoFileOptions(repo) opts.OldBranch = "bad_branch" - fileResponse, err := repofiles.CreateOrUpdateRepoFile(repo, doer, opts) + fileResponse, err := files_service.CreateOrUpdateRepoFile(repo, doer, opts) assert.Error(t, err) assert.Nil(t, fileResponse) expectedError := "branch does not exist [name: " + opts.OldBranch + "]" @@ -360,7 +360,7 @@ func TestCreateOrUpdateRepoFileErrors(t *testing.T) { opts := getUpdateRepoFileOptions(repo) origSHA := opts.SHA opts.SHA = "bad_sha" - fileResponse, err := repofiles.CreateOrUpdateRepoFile(repo, doer, opts) + fileResponse, err := files_service.CreateOrUpdateRepoFile(repo, doer, opts) assert.Nil(t, fileResponse) assert.Error(t, err) expectedError := "sha does not match [given: " + opts.SHA + ", expected: " + origSHA + "]" @@ -370,7 +370,7 @@ func TestCreateOrUpdateRepoFileErrors(t *testing.T) { t.Run("new branch already exists", func(t *testing.T) { opts := getUpdateRepoFileOptions(repo) opts.NewBranch = "develop" - fileResponse, err := repofiles.CreateOrUpdateRepoFile(repo, doer, opts) + fileResponse, err := files_service.CreateOrUpdateRepoFile(repo, doer, opts) assert.Nil(t, fileResponse) assert.Error(t, err) expectedError := "branch already exists [name: " + opts.NewBranch + "]" @@ -380,7 +380,7 @@ func TestCreateOrUpdateRepoFileErrors(t *testing.T) { t.Run("treePath is empty:", func(t *testing.T) { opts := getUpdateRepoFileOptions(repo) opts.TreePath = "" - fileResponse, err := repofiles.CreateOrUpdateRepoFile(repo, doer, opts) + fileResponse, err := files_service.CreateOrUpdateRepoFile(repo, doer, opts) assert.Nil(t, fileResponse) assert.Error(t, err) expectedError := "path contains a malformed path component [path: ]" @@ -390,7 +390,7 @@ func TestCreateOrUpdateRepoFileErrors(t *testing.T) { t.Run("treePath is a git directory:", func(t *testing.T) { opts := getUpdateRepoFileOptions(repo) opts.TreePath = ".git" - fileResponse, err := repofiles.CreateOrUpdateRepoFile(repo, doer, opts) + fileResponse, err := files_service.CreateOrUpdateRepoFile(repo, doer, opts) assert.Nil(t, fileResponse) assert.Error(t, err) expectedError := "path contains a malformed path component [path: " + opts.TreePath + "]" @@ -400,7 +400,7 @@ func TestCreateOrUpdateRepoFileErrors(t *testing.T) { t.Run("create file that already exists", func(t *testing.T) { opts := getCreateRepoFileOptions(repo) opts.TreePath = "README.md" //already exists - fileResponse, err := repofiles.CreateOrUpdateRepoFile(repo, doer, opts) + fileResponse, err := files_service.CreateOrUpdateRepoFile(repo, doer, opts) assert.Nil(t, fileResponse) assert.Error(t, err) expectedError := "repository file already exists [path: " + opts.TreePath + "]" |