mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-06-17 11:59:30 +00:00
api: GitBlob consistent naming
This commit is contained in:
parent
402a85a9b6
commit
07e8684a61
6 changed files with 13 additions and 13 deletions
|
@ -3,8 +3,8 @@
|
||||||
|
|
||||||
package structs
|
package structs
|
||||||
|
|
||||||
// GitBlobResponse represents a git blob
|
// GitBlob represents a git blob
|
||||||
type GitBlobResponse struct {
|
type GitBlob struct {
|
||||||
Content string `json:"content"`
|
Content string `json:"content"`
|
||||||
Encoding string `json:"encoding"`
|
Encoding string `json:"encoding"`
|
||||||
URL string `json:"url"`
|
URL string `json:"url"`
|
||||||
|
|
|
@ -30,12 +30,12 @@ func GetBlob(ctx *context.APIContext) {
|
||||||
// required: true
|
// required: true
|
||||||
// - name: sha
|
// - name: sha
|
||||||
// in: path
|
// in: path
|
||||||
// description: sha of the commit
|
// description: sha of the blob to retrieve
|
||||||
// type: string
|
// type: string
|
||||||
// required: true
|
// required: true
|
||||||
// responses:
|
// responses:
|
||||||
// "200":
|
// "200":
|
||||||
// "$ref": "#/responses/GitBlobResponse"
|
// "$ref": "#/responses/GitBlob"
|
||||||
// "400":
|
// "400":
|
||||||
// "$ref": "#/responses/error"
|
// "$ref": "#/responses/error"
|
||||||
// "404":
|
// "404":
|
||||||
|
|
|
@ -231,11 +231,11 @@ type swaggerGitTreeResponse struct {
|
||||||
Body api.GitTreeResponse `json:"body"`
|
Body api.GitTreeResponse `json:"body"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// GitBlobResponse
|
// GitBlob
|
||||||
// swagger:response GitBlobResponse
|
// swagger:response GitBlob
|
||||||
type swaggerGitBlobResponse struct {
|
type swaggerGitBlob struct {
|
||||||
// in: body
|
// in: body
|
||||||
Body api.GitBlobResponse `json:"body"`
|
Body api.GitBlob `json:"body"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Commit
|
// Commit
|
||||||
|
|
|
@ -250,8 +250,8 @@ func GetContents(ctx context.Context, repo *repo_model.Repository, treePath, ref
|
||||||
return contentsResponse, nil
|
return contentsResponse, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetBlobBySHA get the GitBlobResponse of a repository using a sha hash.
|
// GetBlobBySHA get the GitBlob of a repository using a sha hash.
|
||||||
func GetBlobBySHA(ctx context.Context, repo *repo_model.Repository, gitRepo *git.Repository, sha string) (*api.GitBlobResponse, error) {
|
func GetBlobBySHA(ctx context.Context, repo *repo_model.Repository, gitRepo *git.Repository, sha string) (*api.GitBlob, error) {
|
||||||
gitBlob, err := gitRepo.GetBlob(sha)
|
gitBlob, err := gitRepo.GetBlob(sha)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -263,7 +263,7 @@ func GetBlobBySHA(ctx context.Context, repo *repo_model.Repository, gitRepo *git
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return &api.GitBlobResponse{
|
return &api.GitBlob{
|
||||||
SHA: gitBlob.ID.String(),
|
SHA: gitBlob.ID.String(),
|
||||||
URL: repo.APIURL() + "/git/blobs/" + url.PathEscape(gitBlob.ID.String()),
|
URL: repo.APIURL() + "/git/blobs/" + url.PathEscape(gitBlob.ID.String()),
|
||||||
Size: gitBlob.Size(),
|
Size: gitBlob.Size(),
|
||||||
|
|
|
@ -192,7 +192,7 @@ func TestGetBlobBySHA(t *testing.T) {
|
||||||
defer gitRepo.Close()
|
defer gitRepo.Close()
|
||||||
|
|
||||||
gbr, err := GetBlobBySHA(db.DefaultContext, repo, gitRepo, "65f1bf27bc3bf70f64657658635e66094edbcb4d")
|
gbr, err := GetBlobBySHA(db.DefaultContext, repo, gitRepo, "65f1bf27bc3bf70f64657658635e66094edbcb4d")
|
||||||
expectedGBR := &api.GitBlobResponse{
|
expectedGBR := &api.GitBlob{
|
||||||
Content: "dHJlZSAyYTJmMWQ0NjcwNzI4YTJlMTAwNDllMzQ1YmQ3YTI3NjQ2OGJlYWI2CmF1dGhvciB1c2VyMSA8YWRkcmVzczFAZXhhbXBsZS5jb20+IDE0ODk5NTY0NzkgLTA0MDAKY29tbWl0dGVyIEV0aGFuIEtvZW5pZyA8ZXRoYW50a29lbmlnQGdtYWlsLmNvbT4gMTQ4OTk1NjQ3OSAtMDQwMAoKSW5pdGlhbCBjb21taXQK",
|
Content: "dHJlZSAyYTJmMWQ0NjcwNzI4YTJlMTAwNDllMzQ1YmQ3YTI3NjQ2OGJlYWI2CmF1dGhvciB1c2VyMSA8YWRkcmVzczFAZXhhbXBsZS5jb20+IDE0ODk5NTY0NzkgLTA0MDAKY29tbWl0dGVyIEV0aGFuIEtvZW5pZyA8ZXRoYW50a29lbmlnQGdtYWlsLmNvbT4gMTQ4OTk1NjQ3OSAtMDQwMAoKSW5pdGlhbCBjb21taXQK",
|
||||||
Encoding: "base64",
|
Encoding: "base64",
|
||||||
URL: "https://try.gitea.io/api/v1/repos/user2/repo1/git/blobs/65f1bf27bc3bf70f64657658635e66094edbcb4d",
|
URL: "https://try.gitea.io/api/v1/repos/user2/repo1/git/blobs/65f1bf27bc3bf70f64657658635e66094edbcb4d",
|
||||||
|
|
|
@ -37,7 +37,7 @@ func TestAPIReposGitBlobs(t *testing.T) {
|
||||||
// Test a public repo that anyone can GET the blob of
|
// Test a public repo that anyone can GET the blob of
|
||||||
req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/git/blobs/%s", user2.Name, repo1.Name, repo1ReadmeSHA)
|
req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/git/blobs/%s", user2.Name, repo1.Name, repo1ReadmeSHA)
|
||||||
resp := MakeRequest(t, req, http.StatusOK)
|
resp := MakeRequest(t, req, http.StatusOK)
|
||||||
var gitBlobResponse api.GitBlobResponse
|
var gitBlobResponse api.GitBlob
|
||||||
DecodeJSON(t, resp, &gitBlobResponse)
|
DecodeJSON(t, resp, &gitBlobResponse)
|
||||||
assert.NotNil(t, gitBlobResponse)
|
assert.NotNil(t, gitBlobResponse)
|
||||||
expectedContent := "dHJlZSAyYTJmMWQ0NjcwNzI4YTJlMTAwNDllMzQ1YmQ3YTI3NjQ2OGJlYWI2CmF1dGhvciB1c2VyMSA8YWRkcmVzczFAZXhhbXBsZS5jb20+IDE0ODk5NTY0NzkgLTA0MDAKY29tbWl0dGVyIEV0aGFuIEtvZW5pZyA8ZXRoYW50a29lbmlnQGdtYWlsLmNvbT4gMTQ4OTk1NjQ3OSAtMDQwMAoKSW5pdGlhbCBjb21taXQK"
|
expectedContent := "dHJlZSAyYTJmMWQ0NjcwNzI4YTJlMTAwNDllMzQ1YmQ3YTI3NjQ2OGJlYWI2CmF1dGhvciB1c2VyMSA8YWRkcmVzczFAZXhhbXBsZS5jb20+IDE0ODk5NTY0NzkgLTA0MDAKY29tbWl0dGVyIEV0aGFuIEtvZW5pZyA8ZXRoYW50a29lbmlnQGdtYWlsLmNvbT4gMTQ4OTk1NjQ3OSAtMDQwMAoKSW5pdGlhbCBjb21taXQK"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue