Browse Source

Honor DEFAULT_PAGING_NUM for API (#11805)

* Honor DEFAULT_PAGING_NUM for API

* set pagination to 10 for tests

* lint

Co-authored-by: Lauris BH <lauris@nix.lv>
Co-authored-by: techknowlogick <techknowlogick@gitea.io>
for-closed-social
Cirno the Strongest 4 years ago
committed by GitHub
parent
commit
cefbf73aea
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 16 additions and 15 deletions
  1. +8
    -1
      integrations/api_repo_test.go
  2. +7
    -0
      integrations/release_test.go
  3. +1
    -1
      modules/convert/utils.go
  4. +0
    -6
      routers/api/v1/repo/topic.go
  5. +0
    -7
      routers/repo/release.go

+ 8
- 1
integrations/api_repo_test.go View File

@ -13,6 +13,7 @@ import (
"testing" "testing"
"code.gitea.io/gitea/models" "code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/setting"
api "code.gitea.io/gitea/modules/structs" api "code.gitea.io/gitea/modules/structs"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
@ -57,6 +58,12 @@ func TestAPISearchRepo(t *testing.T) {
user4 := models.AssertExistsAndLoadBean(t, &models.User{ID: 20}).(*models.User) user4 := models.AssertExistsAndLoadBean(t, &models.User{ID: 20}).(*models.User)
orgUser := models.AssertExistsAndLoadBean(t, &models.User{ID: 17}).(*models.User) orgUser := models.AssertExistsAndLoadBean(t, &models.User{ID: 17}).(*models.User)
oldAPIDefaultNum := setting.API.DefaultPagingNum
defer func() {
setting.API.DefaultPagingNum = oldAPIDefaultNum
}()
setting.API.DefaultPagingNum = 10
// Map of expected results, where key is user for login // Map of expected results, where key is user for login
type expectedResults map[*models.User]struct { type expectedResults map[*models.User]struct {
count int count int
@ -79,7 +86,7 @@ func TestAPISearchRepo(t *testing.T) {
user: {count: 10}, user: {count: 10},
user2: {count: 10}}, user2: {count: 10}},
}, },
{name: "RepositoriesDefaultMax10", requestURL: "/api/v1/repos/search?default&private=false", expectedResults: expectedResults{
{name: "RepositoriesDefault", requestURL: "/api/v1/repos/search?default&private=false", expectedResults: expectedResults{
nil: {count: 10}, nil: {count: 10},
user: {count: 10}, user: {count: 10},
user2: {count: 10}}, user2: {count: 10}},

+ 7
- 0
integrations/release_test.go View File

@ -10,6 +10,7 @@ import (
"testing" "testing"
"time" "time"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/test" "code.gitea.io/gitea/modules/test"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
@ -106,6 +107,12 @@ func TestCreateReleaseDraft(t *testing.T) {
func TestCreateReleasePaging(t *testing.T) { func TestCreateReleasePaging(t *testing.T) {
defer prepareTestEnv(t)() defer prepareTestEnv(t)()
oldAPIDefaultNum := setting.API.DefaultPagingNum
defer func() {
setting.API.DefaultPagingNum = oldAPIDefaultNum
}()
setting.API.DefaultPagingNum = 10
session := loginUser(t, "user2") session := loginUser(t, "user2")
// Create enaugh releases to have paging // Create enaugh releases to have paging
for i := 0; i < 12; i++ { for i := 0; i < 12; i++ {

+ 1
- 1
modules/convert/utils.go View File

@ -11,7 +11,7 @@ import (
// ToCorrectPageSize makes sure page size is in allowed range. // ToCorrectPageSize makes sure page size is in allowed range.
func ToCorrectPageSize(size int) int { func ToCorrectPageSize(size int) int {
if size <= 0 { if size <= 0 {
size = 10
size = setting.API.DefaultPagingNum
} else if size > setting.API.MaxResponseItems { } else if size > setting.API.MaxResponseItems {
size = setting.API.MaxResponseItems size = setting.API.MaxResponseItems
} }

+ 0
- 6
routers/api/v1/repo/topic.go View File

@ -275,12 +275,6 @@ func TopicSearch(ctx *context.APIContext) {
kw := ctx.Query("q") kw := ctx.Query("q")
listOptions := utils.GetListOptions(ctx) listOptions := utils.GetListOptions(ctx)
if listOptions.Page < 1 {
listOptions.Page = 1
}
if listOptions.PageSize < 1 {
listOptions.PageSize = 10
}
topics, err := models.FindTopics(&models.FindTopicOptions{ topics, err := models.FindTopics(&models.FindTopicOptions{
Keyword: kw, Keyword: kw,

+ 0
- 7
routers/repo/release.go View File

@ -69,13 +69,6 @@ func Releases(ctx *context.Context) {
IncludeTags: true, IncludeTags: true,
} }
if opts.ListOptions.Page <= 1 {
opts.ListOptions.Page = 1
}
if opts.ListOptions.PageSize <= 0 {
opts.ListOptions.Page = 10
}
releases, err := models.GetReleasesByRepoID(ctx.Repo.Repository.ID, opts) releases, err := models.GetReleasesByRepoID(ctx.Repo.Repository.ID, opts)
if err != nil { if err != nil {
ctx.ServerError("GetReleasesByRepoID", err) ctx.ServerError("GetReleasesByRepoID", err)

Loading…
Cancel
Save