mirror of
https://codeberg.org/forgejo/forgejo
synced 2024-11-25 11:16:11 +01:00
Merge pull request '[GITEA] Fix API inconsistencies' (#2182) from gusted/forgejo-api-fixes into forgejo-dependency
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/2182 Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org>
This commit is contained in:
commit
c023e6d23f
|
@ -545,5 +545,5 @@ func RenameUser(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Trace("User name changed: %s -> %s", oldName, newName)
|
log.Trace("User name changed: %s -> %s", oldName, newName)
|
||||||
ctx.Status(http.StatusOK)
|
ctx.Status(http.StatusNoContent)
|
||||||
}
|
}
|
||||||
|
|
|
@ -256,7 +256,9 @@ func GetArchive(ctx *context.APIContext) {
|
||||||
// ---
|
// ---
|
||||||
// summary: Get an archive of a repository
|
// summary: Get an archive of a repository
|
||||||
// produces:
|
// produces:
|
||||||
// - application/json
|
// - application/octet-stream
|
||||||
|
// - application/zip
|
||||||
|
// - application/gzip
|
||||||
// parameters:
|
// parameters:
|
||||||
// - name: owner
|
// - name: owner
|
||||||
// in: path
|
// in: path
|
||||||
|
@ -337,7 +339,17 @@ func download(ctx *context.APIContext, archiveName string, archiver *repo_model.
|
||||||
}
|
}
|
||||||
defer fr.Close()
|
defer fr.Close()
|
||||||
|
|
||||||
|
contentType := ""
|
||||||
|
switch archiver.Type {
|
||||||
|
case git.ZIP:
|
||||||
|
contentType = "application/zip"
|
||||||
|
case git.TARGZ:
|
||||||
|
// Per RFC6713.
|
||||||
|
contentType = "application/gzip"
|
||||||
|
}
|
||||||
|
|
||||||
ctx.ServeContent(fr, &context.ServeHeaderOptions{
|
ctx.ServeContent(fr, &context.ServeHeaderOptions{
|
||||||
|
ContentType: contentType,
|
||||||
Filename: downloadName,
|
Filename: downloadName,
|
||||||
LastModified: archiver.CreatedUnix.AsLocalTime(),
|
LastModified: archiver.CreatedUnix.AsLocalTime(),
|
||||||
})
|
})
|
||||||
|
|
4
templates/swagger/v1_json.tmpl
generated
4
templates/swagger/v1_json.tmpl
generated
|
@ -3533,7 +3533,9 @@
|
||||||
"/repos/{owner}/{repo}/archive/{archive}": {
|
"/repos/{owner}/{repo}/archive/{archive}": {
|
||||||
"get": {
|
"get": {
|
||||||
"produces": [
|
"produces": [
|
||||||
"application/json"
|
"application/octet-stream",
|
||||||
|
"application/zip",
|
||||||
|
"application/gzip"
|
||||||
],
|
],
|
||||||
"tags": [
|
"tags": [
|
||||||
"repository"
|
"repository"
|
||||||
|
|
|
@ -254,14 +254,14 @@ func TestAPIRenameUser(t *testing.T) {
|
||||||
// required
|
// required
|
||||||
"new_name": "User2",
|
"new_name": "User2",
|
||||||
}).AddTokenAuth(token)
|
}).AddTokenAuth(token)
|
||||||
MakeRequest(t, req, http.StatusOK)
|
MakeRequest(t, req, http.StatusNoContent)
|
||||||
|
|
||||||
urlStr = fmt.Sprintf("/api/v1/admin/users/%s/rename", "User2")
|
urlStr = fmt.Sprintf("/api/v1/admin/users/%s/rename", "User2")
|
||||||
req = NewRequestWithValues(t, "POST", urlStr, map[string]string{
|
req = NewRequestWithValues(t, "POST", urlStr, map[string]string{
|
||||||
// required
|
// required
|
||||||
"new_name": "User2-2-2",
|
"new_name": "User2-2-2",
|
||||||
}).AddTokenAuth(token)
|
}).AddTokenAuth(token)
|
||||||
MakeRequest(t, req, http.StatusOK)
|
MakeRequest(t, req, http.StatusNoContent)
|
||||||
|
|
||||||
req = NewRequestWithValues(t, "POST", urlStr, map[string]string{
|
req = NewRequestWithValues(t, "POST", urlStr, map[string]string{
|
||||||
// required
|
// required
|
||||||
|
@ -281,7 +281,7 @@ func TestAPIRenameUser(t *testing.T) {
|
||||||
// required
|
// required
|
||||||
"new_name": "user2",
|
"new_name": "user2",
|
||||||
}).AddTokenAuth(token)
|
}).AddTokenAuth(token)
|
||||||
MakeRequest(t, req, http.StatusOK)
|
MakeRequest(t, req, http.StatusNoContent)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAPICron(t *testing.T) {
|
func TestAPICron(t *testing.T) {
|
||||||
|
|
|
@ -32,18 +32,21 @@ func TestAPIDownloadArchive(t *testing.T) {
|
||||||
bs, err := io.ReadAll(resp.Body)
|
bs, err := io.ReadAll(resp.Body)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Len(t, bs, 320)
|
assert.Len(t, bs, 320)
|
||||||
|
assert.EqualValues(t, "application/zip", resp.Header().Get("Content-Type"))
|
||||||
|
|
||||||
link, _ = url.Parse(fmt.Sprintf("/api/v1/repos/%s/%s/archive/master.tar.gz", user2.Name, repo.Name))
|
link, _ = url.Parse(fmt.Sprintf("/api/v1/repos/%s/%s/archive/master.tar.gz", user2.Name, repo.Name))
|
||||||
resp = MakeRequest(t, NewRequest(t, "GET", link.String()).AddTokenAuth(token), http.StatusOK)
|
resp = MakeRequest(t, NewRequest(t, "GET", link.String()).AddTokenAuth(token), http.StatusOK)
|
||||||
bs, err = io.ReadAll(resp.Body)
|
bs, err = io.ReadAll(resp.Body)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Len(t, bs, 266)
|
assert.Len(t, bs, 266)
|
||||||
|
assert.EqualValues(t, "application/gzip", resp.Header().Get("Content-Type"))
|
||||||
|
|
||||||
link, _ = url.Parse(fmt.Sprintf("/api/v1/repos/%s/%s/archive/master.bundle", user2.Name, repo.Name))
|
link, _ = url.Parse(fmt.Sprintf("/api/v1/repos/%s/%s/archive/master.bundle", user2.Name, repo.Name))
|
||||||
resp = MakeRequest(t, NewRequest(t, "GET", link.String()).AddTokenAuth(token), http.StatusOK)
|
resp = MakeRequest(t, NewRequest(t, "GET", link.String()).AddTokenAuth(token), http.StatusOK)
|
||||||
bs, err = io.ReadAll(resp.Body)
|
bs, err = io.ReadAll(resp.Body)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Len(t, bs, 382)
|
assert.Len(t, bs, 382)
|
||||||
|
assert.EqualValues(t, "application/octet-stream", resp.Header().Get("Content-Type"))
|
||||||
|
|
||||||
link, _ = url.Parse(fmt.Sprintf("/api/v1/repos/%s/%s/archive/master", user2.Name, repo.Name))
|
link, _ = url.Parse(fmt.Sprintf("/api/v1/repos/%s/%s/archive/master", user2.Name, repo.Name))
|
||||||
MakeRequest(t, NewRequest(t, "GET", link.String()).AddTokenAuth(token), http.StatusBadRequest)
|
MakeRequest(t, NewRequest(t, "GET", link.String()).AddTokenAuth(token), http.StatusBadRequest)
|
||||||
|
|
Loading…
Reference in a new issue