From 813e2f06fe5b9cd86c427f7b27d9a389d7c8364a Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Sun, 29 Aug 2021 11:45:58 +0800 Subject: [PATCH 1/2] Add release default page and set it to 10 --- custom/conf/app.example.ini | 1 + docs/content/doc/advanced/config-cheat-sheet.en-us.md | 1 + docs/content/doc/advanced/config-cheat-sheet.zh-cn.md | 5 +++++ modules/setting/repository.go | 9 ++++++--- routers/web/repo/release.go | 10 ++++++++-- 5 files changed, 21 insertions(+), 5 deletions(-) diff --git a/custom/conf/app.example.ini b/custom/conf/app.example.ini index e262a38ee9888..40d5742effb02 100644 --- a/custom/conf/app.example.ini +++ b/custom/conf/app.example.ini @@ -907,6 +907,7 @@ PATH = ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Comma-separated list of allowed file extensions (`.zip`), mime types (`text/plain`) or wildcard type (`image/*`, `audio/*`, `video/*`). Empty value or `*/*` allows all types. ;ALLOWED_TYPES = +;DEFAULT_PAGING_NUM = 10 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; diff --git a/docs/content/doc/advanced/config-cheat-sheet.en-us.md b/docs/content/doc/advanced/config-cheat-sheet.en-us.md index 23f125f4da38b..242189f5b0f54 100644 --- a/docs/content/doc/advanced/config-cheat-sheet.en-us.md +++ b/docs/content/doc/advanced/config-cheat-sheet.en-us.md @@ -115,6 +115,7 @@ Values containing `#` or `;` must be quoted using `` ` `` or `"""`. ### Repository - Release (`repository.release`) - `ALLOWED_TYPES`: **\**: Comma-separated list of allowed file extensions (`.zip`), mime types (`text/plain`) or wildcard type (`image/*`, `audio/*`, `video/*`). Empty value or `*/*` allows all types. +- `DEFAULT_PAGING_NUM`: **10**: The default paging number of releases user interface ### Repository - Signing (`repository.signing`) diff --git a/docs/content/doc/advanced/config-cheat-sheet.zh-cn.md b/docs/content/doc/advanced/config-cheat-sheet.zh-cn.md index 5c3d69ecfdfb7..fcbf49f1ab8b5 100644 --- a/docs/content/doc/advanced/config-cheat-sheet.zh-cn.md +++ b/docs/content/doc/advanced/config-cheat-sheet.zh-cn.md @@ -36,6 +36,11 @@ menu: - `MAX_CREATION_LIMIT`: 全局最大每个用户创建的git工程数目, `-1` 表示没限制。 - `PULL_REQUEST_QUEUE_LENGTH`: 小心:合并请求测试队列的长度,尽量放大。 +### Repository - Release (`repository.release`) + +- `ALLOWED_TYPES`: **\**: 允许扩展名的列表,用逗号分隔 (`.zip`), mime 类型 (`text/plain`) 或者匹配符号 (`image/*`, `audio/*`, `video/*`). 空值或者 `*/*` 允许所有类型。 +- `DEFAULT_PAGING_NUM`: **10**: 默认的发布版本页面分页。 + ## UI (`ui`) - `EXPLORE_PAGING_NUM`: 探索页面每页显示的仓库数量。 diff --git a/modules/setting/repository.go b/modules/setting/repository.go index c2a6357d94622..f981809427b88 100644 --- a/modules/setting/repository.go +++ b/modules/setting/repository.go @@ -87,7 +87,8 @@ var ( } `ini:"repository.issue"` Release struct { - AllowedTypes string + AllowedTypes string + DefaultPagingNum int } `ini:"repository.release"` Signing struct { @@ -223,9 +224,11 @@ var ( }, Release: struct { - AllowedTypes string + AllowedTypes string + DefaultPagingNum int }{ - AllowedTypes: "", + AllowedTypes: "", + DefaultPagingNum: 10, }, // Signing settings diff --git a/routers/web/repo/release.go b/routers/web/repo/release.go index d37955c559c92..bed63a552d5c5 100644 --- a/routers/web/repo/release.go +++ b/routers/web/repo/release.go @@ -13,7 +13,6 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/context" - "code.gitea.io/gitea/modules/convert" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/markup" "code.gitea.io/gitea/modules/markup/markdown" @@ -93,11 +92,18 @@ func releasesOrTags(ctx *context.Context, isTagList bool) { writeAccess := ctx.Repo.CanWrite(models.UnitTypeReleases) ctx.Data["CanCreateRelease"] = writeAccess && !ctx.Repo.Repository.IsArchived + page := ctx.FormInt("limit") + if page == 0 { + page = setting.Repository.Release.DefaultPagingNum + } + if page > setting.API.MaxResponseItems { + page = setting.API.MaxResponseItems + } opts := models.FindReleasesOptions{ ListOptions: models.ListOptions{ Page: ctx.FormInt("page"), - PageSize: convert.ToCorrectPageSize(ctx.FormInt("limit")), + PageSize: page, }, IncludeDrafts: writeAccess && !isTagList, IncludeTags: isTagList, From 77dbff50e6c3142202071404282ce31f2c5855d5 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Sun, 29 Aug 2021 10:52:06 +0200 Subject: [PATCH 2/2] use limit --- routers/web/repo/release.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/routers/web/repo/release.go b/routers/web/repo/release.go index bed63a552d5c5..ef98790f52d31 100644 --- a/routers/web/repo/release.go +++ b/routers/web/repo/release.go @@ -92,18 +92,18 @@ func releasesOrTags(ctx *context.Context, isTagList bool) { writeAccess := ctx.Repo.CanWrite(models.UnitTypeReleases) ctx.Data["CanCreateRelease"] = writeAccess && !ctx.Repo.Repository.IsArchived - page := ctx.FormInt("limit") - if page == 0 { - page = setting.Repository.Release.DefaultPagingNum + limit := ctx.FormInt("limit") + if limit == 0 { + limit = setting.Repository.Release.DefaultPagingNum } - if page > setting.API.MaxResponseItems { - page = setting.API.MaxResponseItems + if limit > setting.API.MaxResponseItems { + limit = setting.API.MaxResponseItems } opts := models.FindReleasesOptions{ ListOptions: models.ListOptions{ Page: ctx.FormInt("page"), - PageSize: page, + PageSize: limit, }, IncludeDrafts: writeAccess && !isTagList, IncludeTags: isTagList,