Skip to content
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

improve the releases api paging #5831

Merged
merged 3 commits into from
Jan 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions custom/conf/app.ini.sample
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,8 @@ MIN_INTERVAL = 10m
ENABLE_SWAGGER = true
; Max number of items in a page
MAX_RESPONSE_ITEMS = 50
; Default paging number of api
DEFAULT_PAGING_NUM = 30

[i18n]
LANGS = en-US,zh-CN,zh-HK,zh-TW,de-DE,fr-FR,nl-NL,lv-LV,ru-RU,uk-UA,ja-JP,es-ES,pt-BR,pl-PL,bg-BG,it-IT,fi-FI,tr-TR,cs-CZ,sr-SP,sv-SE,ko-KR
Expand Down
1 change: 1 addition & 0 deletions docs/content/doc/advanced/config-cheat-sheet.en-us.md
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ Values containing `#` or `;` must be quoted using `` ` `` or `"""`.

- `ENABLE_SWAGGER`: **true**: Enables /api/swagger, /api/v1/swagger etc. endpoints. True or false; default is true.
- `MAX_RESPONSE_ITEMS`: **50**: Max number of items in a page.
- `DEFAULT_PAGING_NUM`: **30**: Default paging number of api.

## i18n (`i18n`)

Expand Down
8 changes: 7 additions & 1 deletion docs/content/doc/advanced/config-cheat-sheet.zh-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,13 @@ menu:
- `PULL`: **300**: 内部仓库间拉取的超时时间,单位秒
- `GC`: **60**: git仓库GC的超时时间,单位秒

## markup (`markup`)
## API (`api`)

- `ENABLE_SWAGGER`: **true**: 是否启用swagger路由 /api/swagger, /api/v1/swagger etc. endpoints. True 或 false; 默认是 true.
- `MAX_RESPONSE_ITEMS`: **50**: 一个页面最大的项目数。
- `DEFAULT_PAGING_NUM`: **30**: API中默认分页条数。

## Markup (`markup`)

外部渲染工具支持,你可以用你熟悉的文档渲染工具. 比如一下将新增一个名字为 `asciidoc` 的渲染工具which is followed `markup.` ini section. And there are some config items below.

Expand Down
2 changes: 2 additions & 0 deletions modules/setting/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -557,9 +557,11 @@ var (
API = struct {
EnableSwagger bool
MaxResponseItems int
DefaultPagingNum int
}{
EnableSwagger: true,
MaxResponseItems: 50,
DefaultPagingNum: 30,
}

U2F = struct {
Expand Down
18 changes: 17 additions & 1 deletion routers/api/v1/repo/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package repo
import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/setting"

api "code.gitea.io/sdk/gitea"
)
Expand Down Expand Up @@ -55,6 +56,20 @@ func GetRelease(ctx *context.APIContext) {
ctx.JSON(200, release.APIFormat())
}

func getPagesInfo(ctx *context.APIContext) (int, int) {
page := ctx.QueryInt("page")
if page == 0 {
page = 1
}
perPage := ctx.QueryInt("per_page")
lafriks marked this conversation as resolved.
Show resolved Hide resolved
if perPage == 0 {
perPage = setting.API.DefaultPagingNum
} else if perPage > setting.API.MaxResponseItems {
perPage = setting.API.MaxResponseItems
}
return page, perPage
}

// ListReleases list a repository's releases
func ListReleases(ctx *context.APIContext) {
// swagger:operation GET /repos/{owner}/{repo}/releases repository repoListReleases
Expand All @@ -76,10 +91,11 @@ func ListReleases(ctx *context.APIContext) {
// responses:
// "200":
// "$ref": "#/responses/ReleaseList"
page, limit := getPagesInfo(ctx)
releases, err := models.GetReleasesByRepoID(ctx.Repo.Repository.ID, models.FindReleasesOptions{
IncludeDrafts: ctx.Repo.AccessMode >= models.AccessModeWrite,
IncludeTags: false,
}, 1, 2147483647)
}, page, limit)
if err != nil {
ctx.Error(500, "GetReleasesByRepoID", err)
return
Expand Down