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

Honor DEFAULT_PAGING_NUM for API #11805

Merged
merged 5 commits into from
Jun 9, 2020
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
9 changes: 8 additions & 1 deletion integrations/api_repo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"testing"

"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/setting"
api "code.gitea.io/gitea/modules/structs"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -57,6 +58,12 @@ func TestAPISearchRepo(t *testing.T) {
user4 := models.AssertExistsAndLoadBean(t, &models.User{ID: 20}).(*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
techknowlogick marked this conversation as resolved.
Show resolved Hide resolved

// Map of expected results, where key is user for login
type expectedResults map[*models.User]struct {
count int
Expand All @@ -79,7 +86,7 @@ func TestAPISearchRepo(t *testing.T) {
user: {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},
user: {count: 10},
user2: {count: 10}},
Expand Down
7 changes: 7 additions & 0 deletions integrations/release_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"testing"
"time"

"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/test"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -106,6 +107,12 @@ func TestCreateReleaseDraft(t *testing.T) {
func TestCreateReleasePaging(t *testing.T) {
defer prepareTestEnv(t)()

oldAPIDefaultNum := setting.API.DefaultPagingNum
defer func() {
setting.API.DefaultPagingNum = oldAPIDefaultNum
}()
setting.API.DefaultPagingNum = 10

session := loginUser(t, "user2")
// Create enaugh releases to have paging
for i := 0; i < 12; i++ {
Expand Down
2 changes: 1 addition & 1 deletion modules/convert/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
// ToCorrectPageSize makes sure page size is in allowed range.
func ToCorrectPageSize(size int) int {
if size <= 0 {
size = 10
size = setting.API.DefaultPagingNum
} else if size > setting.API.MaxResponseItems {
size = setting.API.MaxResponseItems
}
Expand Down
6 changes: 0 additions & 6 deletions routers/api/v1/repo/topic.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,12 +275,6 @@ func TopicSearch(ctx *context.APIContext) {
kw := ctx.Query("q")

listOptions := utils.GetListOptions(ctx)
if listOptions.Page < 1 {
listOptions.Page = 1
}
if listOptions.PageSize < 1 {
listOptions.PageSize = 10
}

topics, err := models.FindTopics(&models.FindTopicOptions{
Keyword: kw,
Expand Down
7 changes: 0 additions & 7 deletions routers/repo/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,6 @@ func Releases(ctx *context.Context) {
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)
if err != nil {
ctx.ServerError("GetReleasesByRepoID", err)
Expand Down