Skip to content

Commit 4085174

Browse files
committed
Remove useless function and test
1 parent 992dc2b commit 4085174

File tree

2 files changed

+0
-110
lines changed

2 files changed

+0
-110
lines changed

services/repository/files/file.go

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,6 @@ func GetFilesResponseFromCommit(ctx context.Context, repo *repo_model.Repository
3838
return filesResponse, nil
3939
}
4040

41-
// GetFileResponseFromCommit Constructs a FileResponse from a Commit object
42-
func GetFileResponseFromCommit(ctx context.Context, repo *repo_model.Repository, commit *git.Commit, branch, treeName string) (*api.FileResponse, error) {
43-
fileContents, _ := GetContents(ctx, repo, treeName, branch, false) // ok if fails, then will be nil
44-
fileCommitResponse, _ := GetFileCommitResponse(repo, commit) // ok if fails, then will be nil
45-
verification := GetPayloadCommitVerification(ctx, commit)
46-
fileResponse := &api.FileResponse{
47-
Content: fileContents,
48-
Commit: fileCommitResponse,
49-
Verification: verification,
50-
}
51-
return fileResponse, nil
52-
}
53-
5441
// constructs a FileResponse with the file at the index from FilesResponse
5542
func GetFileResponseFromFilesResponse(filesResponse *api.FilesResponse, index int) *api.FileResponse {
5643
content := &api.ContentsResponse{}

services/repository/files/file_test.go

Lines changed: 0 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,6 @@ package files
55

66
import (
77
"testing"
8-
"time"
9-
10-
"code.gitea.io/gitea/models/unittest"
11-
"code.gitea.io/gitea/modules/gitrepo"
12-
"code.gitea.io/gitea/modules/setting"
13-
api "code.gitea.io/gitea/modules/structs"
14-
"code.gitea.io/gitea/services/contexttest"
158

169
"github.com/stretchr/testify/assert"
1710
)
@@ -31,93 +24,3 @@ func TestCleanUploadFileName(t *testing.T) {
3124
assert.Equal(t, expectedCleanName, cleanName)
3225
})
3326
}
34-
35-
func getExpectedFileResponse() *api.FileResponse {
36-
treePath := "README.md"
37-
sha := "4b4851ad51df6a7d9f25c979345979eaeb5b349f"
38-
encoding := "base64"
39-
content := "IyByZXBvMQoKRGVzY3JpcHRpb24gZm9yIHJlcG8x"
40-
selfURL := setting.AppURL + "api/v1/repos/user2/repo1/contents/" + treePath + "?ref=master"
41-
htmlURL := setting.AppURL + "user2/repo1/src/branch/master/" + treePath
42-
gitURL := setting.AppURL + "api/v1/repos/user2/repo1/git/blobs/" + sha
43-
downloadURL := setting.AppURL + "user2/repo1/raw/branch/master/" + treePath
44-
return &api.FileResponse{
45-
Content: &api.ContentsResponse{
46-
Name: treePath,
47-
Path: treePath,
48-
SHA: sha,
49-
LastCommitSHA: "65f1bf27bc3bf70f64657658635e66094edbcb4d",
50-
LastCommitterDate: time.Date(2017, time.March, 19, 16, 47, 59, 0, time.FixedZone("", -14400)),
51-
LastAuthorDate: time.Date(2017, time.March, 19, 16, 47, 59, 0, time.FixedZone("", -14400)),
52-
Type: "file",
53-
Size: 30,
54-
Encoding: &encoding,
55-
Content: &content,
56-
URL: &selfURL,
57-
HTMLURL: &htmlURL,
58-
GitURL: &gitURL,
59-
DownloadURL: &downloadURL,
60-
Links: &api.FileLinksResponse{
61-
Self: &selfURL,
62-
GitURL: &gitURL,
63-
HTMLURL: &htmlURL,
64-
},
65-
},
66-
Commit: &api.FileCommitResponse{
67-
CommitMeta: api.CommitMeta{
68-
URL: "https://try.gitea.io/api/v1/repos/user2/repo1/git/commits/65f1bf27bc3bf70f64657658635e66094edbcb4d",
69-
SHA: "65f1bf27bc3bf70f64657658635e66094edbcb4d",
70-
},
71-
HTMLURL: "https://try.gitea.io/user2/repo1/commit/65f1bf27bc3bf70f64657658635e66094edbcb4d",
72-
Author: &api.CommitUser{
73-
Identity: api.Identity{
74-
Name: "user1",
75-
76-
},
77-
Date: "2017-03-19T20:47:59Z",
78-
},
79-
Committer: &api.CommitUser{
80-
Identity: api.Identity{
81-
Name: "Ethan Koenig",
82-
83-
},
84-
Date: "2017-03-19T20:47:59Z",
85-
},
86-
Parents: []*api.CommitMeta{},
87-
Message: "Initial commit\n",
88-
Tree: &api.CommitMeta{
89-
URL: "https://try.gitea.io/api/v1/repos/user2/repo1/git/trees/2a2f1d4670728a2e10049e345bd7a276468beab6",
90-
SHA: "2a2f1d4670728a2e10049e345bd7a276468beab6",
91-
},
92-
},
93-
Verification: &api.PayloadCommitVerification{
94-
Verified: false,
95-
Reason: "gpg.error.not_signed_commit",
96-
Signature: "",
97-
Payload: "",
98-
},
99-
}
100-
}
101-
102-
func TestGetFileResponseFromCommit(t *testing.T) {
103-
unittest.PrepareTestEnv(t)
104-
ctx, _ := contexttest.MockContext(t, "user2/repo1")
105-
ctx.SetPathParam("id", "1")
106-
contexttest.LoadRepo(t, ctx, 1)
107-
contexttest.LoadRepoCommit(t, ctx)
108-
contexttest.LoadUser(t, ctx, 2)
109-
contexttest.LoadGitRepo(t, ctx)
110-
defer ctx.Repo.GitRepo.Close()
111-
112-
repo := ctx.Repo.Repository
113-
branch := repo.DefaultBranch
114-
treePath := "README.md"
115-
gitRepo, _ := gitrepo.OpenRepository(ctx, repo)
116-
defer gitRepo.Close()
117-
commit, _ := gitRepo.GetBranchCommit(branch)
118-
expectedFileResponse := getExpectedFileResponse()
119-
120-
fileResponse, err := GetFileResponseFromCommit(ctx, repo, commit, branch, treePath)
121-
assert.NoError(t, err)
122-
assert.Equal(t, expectedFileResponse, fileResponse)
123-
}

0 commit comments

Comments
 (0)