chore: Remove `GetFileResponseFromCommit`
- Introduced in2262811e40
and removed in275d4b7e3f
.
This commit is contained in:
parent
039a679ccb
commit
1ee9e88809
|
@ -223,7 +223,6 @@ code.gitea.io/gitea/services/repository
|
||||||
|
|
||||||
code.gitea.io/gitea/services/repository/files
|
code.gitea.io/gitea/services/repository/files
|
||||||
ContentType.String
|
ContentType.String
|
||||||
GetFileResponseFromCommit
|
|
||||||
|
|
||||||
code.gitea.io/gitea/services/webhook
|
code.gitea.io/gitea/services/webhook
|
||||||
NewNotifier
|
NewNotifier
|
||||||
|
|
|
@ -33,19 +33,6 @@ func GetFilesResponseFromCommit(ctx context.Context, repo *repo_model.Repository
|
||||||
return filesResponse, nil
|
return filesResponse, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetFileResponseFromCommit Constructs a FileResponse from a Commit object
|
|
||||||
func GetFileResponseFromCommit(ctx context.Context, repo *repo_model.Repository, commit *git.Commit, branch, treeName string) (*api.FileResponse, error) {
|
|
||||||
fileContents, _ := GetContents(ctx, repo, treeName, branch, false) // ok if fails, then will be nil
|
|
||||||
fileCommitResponse, _ := GetFileCommitResponse(repo, commit) // ok if fails, then will be nil
|
|
||||||
verification := GetPayloadCommitVerification(ctx, commit)
|
|
||||||
fileResponse := &api.FileResponse{
|
|
||||||
Content: fileContents,
|
|
||||||
Commit: fileCommitResponse,
|
|
||||||
Verification: verification,
|
|
||||||
}
|
|
||||||
return fileResponse, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// constructs a FileResponse with the file at the index from FilesResponse
|
// constructs a FileResponse with the file at the index from FilesResponse
|
||||||
func GetFileResponseFromFilesResponse(filesResponse *api.FilesResponse, index int) *api.FileResponse {
|
func GetFileResponseFromFilesResponse(filesResponse *api.FilesResponse, index int) *api.FileResponse {
|
||||||
content := &api.ContentsResponse{}
|
content := &api.ContentsResponse{}
|
||||||
|
|
|
@ -6,15 +6,7 @@ package files
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"code.gitea.io/gitea/models/db"
|
|
||||||
repo_model "code.gitea.io/gitea/models/repo"
|
|
||||||
"code.gitea.io/gitea/models/unittest"
|
|
||||||
"code.gitea.io/gitea/modules/gitrepo"
|
|
||||||
"code.gitea.io/gitea/modules/setting"
|
|
||||||
api "code.gitea.io/gitea/modules/structs"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestCleanUploadFileName(t *testing.T) {
|
func TestCleanUploadFileName(t *testing.T) {
|
||||||
|
@ -32,84 +24,3 @@ func TestCleanUploadFileName(t *testing.T) {
|
||||||
assert.EqualValues(t, expectedCleanName, cleanName)
|
assert.EqualValues(t, expectedCleanName, cleanName)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func getExpectedFileResponse() *api.FileResponse {
|
|
||||||
treePath := "README.md"
|
|
||||||
sha := "4b4851ad51df6a7d9f25c979345979eaeb5b349f"
|
|
||||||
encoding := "base64"
|
|
||||||
content := "IyByZXBvMQoKRGVzY3JpcHRpb24gZm9yIHJlcG8x"
|
|
||||||
selfURL := setting.AppURL + "api/v1/repos/user2/repo1/contents/" + treePath + "?ref=master"
|
|
||||||
htmlURL := setting.AppURL + "user2/repo1/src/branch/master/" + treePath
|
|
||||||
gitURL := setting.AppURL + "api/v1/repos/user2/repo1/git/blobs/" + sha
|
|
||||||
downloadURL := setting.AppURL + "user2/repo1/raw/branch/master/" + treePath
|
|
||||||
return &api.FileResponse{
|
|
||||||
Content: &api.ContentsResponse{
|
|
||||||
Name: treePath,
|
|
||||||
Path: treePath,
|
|
||||||
SHA: sha,
|
|
||||||
LastCommitSHA: "65f1bf27bc3bf70f64657658635e66094edbcb4d",
|
|
||||||
Type: "file",
|
|
||||||
Size: 30,
|
|
||||||
Encoding: &encoding,
|
|
||||||
Content: &content,
|
|
||||||
URL: &selfURL,
|
|
||||||
HTMLURL: &htmlURL,
|
|
||||||
GitURL: &gitURL,
|
|
||||||
DownloadURL: &downloadURL,
|
|
||||||
Links: &api.FileLinksResponse{
|
|
||||||
Self: &selfURL,
|
|
||||||
GitURL: &gitURL,
|
|
||||||
HTMLURL: &htmlURL,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
Commit: &api.FileCommitResponse{
|
|
||||||
CommitMeta: api.CommitMeta{
|
|
||||||
URL: "https://try.gitea.io/api/v1/repos/user2/repo1/git/commits/65f1bf27bc3bf70f64657658635e66094edbcb4d",
|
|
||||||
SHA: "65f1bf27bc3bf70f64657658635e66094edbcb4d",
|
|
||||||
},
|
|
||||||
HTMLURL: "https://try.gitea.io/user2/repo1/commit/65f1bf27bc3bf70f64657658635e66094edbcb4d",
|
|
||||||
Author: &api.CommitUser{
|
|
||||||
Identity: api.Identity{
|
|
||||||
Name: "user1",
|
|
||||||
Email: "address1@example.com",
|
|
||||||
},
|
|
||||||
Date: "2017-03-19T20:47:59Z",
|
|
||||||
},
|
|
||||||
Committer: &api.CommitUser{
|
|
||||||
Identity: api.Identity{
|
|
||||||
Name: "Ethan Koenig",
|
|
||||||
Email: "ethantkoenig@gmail.com",
|
|
||||||
},
|
|
||||||
Date: "2017-03-19T20:47:59Z",
|
|
||||||
},
|
|
||||||
Parents: []*api.CommitMeta{},
|
|
||||||
Message: "Initial commit\n",
|
|
||||||
Tree: &api.CommitMeta{
|
|
||||||
URL: "https://try.gitea.io/api/v1/repos/user2/repo1/git/trees/2a2f1d4670728a2e10049e345bd7a276468beab6",
|
|
||||||
SHA: "2a2f1d4670728a2e10049e345bd7a276468beab6",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
Verification: &api.PayloadCommitVerification{
|
|
||||||
Verified: false,
|
|
||||||
Reason: "gpg.error.not_signed_commit",
|
|
||||||
Signature: "",
|
|
||||||
Payload: "",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestGetFileResponseFromCommit(t *testing.T) {
|
|
||||||
unittest.PrepareTestEnv(t)
|
|
||||||
|
|
||||||
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
|
|
||||||
branch := repo.DefaultBranch
|
|
||||||
treePath := "README.md"
|
|
||||||
gitRepo, _ := gitrepo.OpenRepository(db.DefaultContext, repo)
|
|
||||||
defer gitRepo.Close()
|
|
||||||
commit, _ := gitRepo.GetBranchCommit(branch)
|
|
||||||
expectedFileResponse := getExpectedFileResponse()
|
|
||||||
|
|
||||||
fileResponse, err := GetFileResponseFromCommit(db.DefaultContext, repo, commit, branch, treePath)
|
|
||||||
require.NoError(t, err)
|
|
||||||
assert.EqualValues(t, expectedFileResponse, fileResponse)
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue