-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add API to serve blob or LFS file content #19689
Merged
Merged
Changes from 11 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
9342e4f
Add LFS API
qwerty287 cc3a410
Update routers/api/v1/repo/file.go
qwerty287 0bf5784
Merge branch 'main' into lfs-api
qwerty287 562ab9f
Apply suggestions
qwerty287 65b0876
Apply suggestions
qwerty287 a938479
Update routers/api/v1/repo/file.go
qwerty287 13d91dc
Report errors
qwerty287 08d0a8a
Merge branch 'main' into lfs-api
qwerty287 58340e4
Merge branch 'main' into lfs-api
qwerty287 b30ce9a
ADd test
qwerty287 1172441
Merge branch 'main' into lfs-api
qwerty287 95b7466
Use own repo for test
qwerty287 97d5110
Use different repo name
qwerty287 1532e23
Merge branch 'main' into lfs-api
qwerty287 0a0b2c1
Improve handling
qwerty287 f90b218
Slight restructures
zeripath deb9b06
Merge remote-tracking branch 'origin' into lfs-api
zeripath 14166cf
Merge branch 'main' into lfs-api
lunny File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright 2022 The Gitea Authors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package integrations | ||
|
||
import ( | ||
"net/http" | ||
"net/url" | ||
"os" | ||
"testing" | ||
|
||
"code.gitea.io/gitea/modules/util" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestAPIGetRawFileOrLFS(t *testing.T) { | ||
defer prepareTestEnv(t)() | ||
|
||
// Test with raw file | ||
req := NewRequest(t, "GET", "/api/v1/repos/user2/repo1/media/README.md") | ||
resp := MakeRequest(t, req, http.StatusOK) | ||
assert.Equal(t, "# repo1\n\nDescription for repo1", resp.Body.String()) | ||
|
||
// Test with LFS | ||
httpContext := NewAPITestContext(t, "user2", "repo1") | ||
|
||
onGiteaRun(t, func(t *testing.T, u *url.URL) { | ||
u.Path = httpContext.GitPath() | ||
dstPath, err := os.MkdirTemp("", httpContext.Reponame) | ||
assert.NoError(t, err) | ||
defer util.RemoveAll(dstPath) | ||
|
||
u.Path = httpContext.GitPath() | ||
u.User = url.UserPassword("user2", userPassword) | ||
|
||
t.Run("Clone", doGitClone(dstPath, u)) | ||
|
||
dstPath2, err := os.MkdirTemp("", httpContext.Reponame) | ||
assert.NoError(t, err) | ||
defer util.RemoveAll(dstPath2) | ||
|
||
t.Run("Partial Clone", doPartialGitClone(dstPath2, u)) | ||
|
||
lfs, _ := lfsCommitAndPushTest(t, dstPath) | ||
|
||
reqLFS := NewRequest(t, "GET", "/api/v1/repos/user2/repo1/media/"+lfs) | ||
respLFS := MakeRequestNilResponseRecorder(t, reqLFS, http.StatusOK) | ||
assert.Equal(t, littleSize, respLFS.Length) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure, but seems like we need to do some cleanup here in order to not conflict with other tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed it t create a new repo and delete it afterwards.