summaryrefslogtreecommitdiffstats
path: root/routers/api/v1/repo
diff options
context:
space:
mode:
Diffstat (limited to 'routers/api/v1/repo')
-rw-r--r--routers/api/v1/repo/collaborators.go11
-rw-r--r--routers/api/v1/repo/commits.go29
-rw-r--r--routers/api/v1/repo/fork.go12
-rw-r--r--routers/api/v1/repo/hook.go11
-rw-r--r--routers/api/v1/repo/issue.go51
-rw-r--r--routers/api/v1/repo/issue_comment.go18
-rw-r--r--routers/api/v1/repo/issue_reaction.go11
-rw-r--r--routers/api/v1/repo/issue_stopwatch.go12
-rw-r--r--routers/api/v1/repo/issue_subscription.go11
-rw-r--r--routers/api/v1/repo/issue_tracked_time.go32
-rw-r--r--routers/api/v1/repo/key.go12
-rw-r--r--routers/api/v1/repo/label.go11
-rw-r--r--routers/api/v1/repo/milestone.go12
-rw-r--r--routers/api/v1/repo/pull.go19
-rw-r--r--routers/api/v1/repo/release.go35
-rw-r--r--routers/api/v1/repo/repo.go23
-rw-r--r--routers/api/v1/repo/star.go11
-rw-r--r--routers/api/v1/repo/status.go33
-rw-r--r--routers/api/v1/repo/subscriber.go11
-rw-r--r--routers/api/v1/repo/topic.go34
20 files changed, 299 insertions, 100 deletions
diff --git a/routers/api/v1/repo/collaborators.go b/routers/api/v1/repo/collaborators.go
index aec389ab31..e99bc7b621 100644
--- a/routers/api/v1/repo/collaborators.go
+++ b/routers/api/v1/repo/collaborators.go
@@ -13,6 +13,7 @@ import (
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/convert"
api "code.gitea.io/gitea/modules/structs"
+ "code.gitea.io/gitea/routers/api/v1/utils"
)
// ListCollaborators list a repository's collaborators
@@ -33,11 +34,19 @@ func ListCollaborators(ctx *context.APIContext) {
// description: name of the repo
// type: string
// required: true
+ // - name: page
+ // in: query
+ // description: page number of results to return (1-based)
+ // type: integer
+ // - name: limit
+ // in: query
+ // description: page size of results, maximum page size is 50
+ // type: integer
// responses:
// "200":
// "$ref": "#/responses/UserList"
- collaborators, err := ctx.Repo.Repository.GetCollaborators()
+ collaborators, err := ctx.Repo.Repository.GetCollaborators(utils.GetListOptions(ctx))
if err != nil {
ctx.Error(http.StatusInternalServerError, "ListCollaborators", err)
return
diff --git a/routers/api/v1/repo/commits.go b/routers/api/v1/repo/commits.go
index d8777eaf3a..f7da1698dc 100644
--- a/routers/api/v1/repo/commits.go
+++ b/routers/api/v1/repo/commits.go
@@ -16,6 +16,7 @@ import (
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/setting"
api "code.gitea.io/gitea/modules/structs"
+ "code.gitea.io/gitea/routers/api/v1/utils"
)
// GetSingleCommit get a commit via
@@ -92,7 +93,11 @@ func GetAllCommits(ctx *context.APIContext) {
// type: string
// - name: page
// in: query
- // description: page number of requested commits
+ // description: page number of results to return (1-based)
+ // type: integer
+ // - name: limit
+ // in: query
+ // description: page size of results, maximum page size is 50
// type: integer
// responses:
// "200":
@@ -117,9 +122,13 @@ func GetAllCommits(ctx *context.APIContext) {
}
defer gitRepo.Close()
- page := ctx.QueryInt("page")
- if page <= 0 {
- page = 1
+ listOptions := utils.GetListOptions(ctx)
+ if listOptions.Page <= 0 {
+ listOptions.Page = 1
+ }
+
+ if listOptions.PageSize > git.CommitsRangeSize {
+ listOptions.PageSize = git.CommitsRangeSize
}
sha := ctx.Query("sha")
@@ -154,10 +163,10 @@ func GetAllCommits(ctx *context.APIContext) {
return
}
- pageCount := int(math.Ceil(float64(commitsCountTotal) / float64(git.CommitsRangeSize)))
+ pageCount := int(math.Ceil(float64(commitsCountTotal) / float64(listOptions.PageSize)))
// Query commits
- commits, err := baseCommit.CommitsByRange(page)
+ commits, err := baseCommit.CommitsByRange(listOptions.Page, listOptions.PageSize)
if err != nil {
ctx.ServerError("CommitsByRange", err)
return
@@ -181,13 +190,13 @@ func GetAllCommits(ctx *context.APIContext) {
i++
}
- ctx.SetLinkHeader(int(commitsCountTotal), git.CommitsRangeSize)
+ ctx.SetLinkHeader(int(commitsCountTotal), listOptions.PageSize)
- ctx.Header().Set("X-Page", strconv.Itoa(page))
- ctx.Header().Set("X-PerPage", strconv.Itoa(git.CommitsRangeSize))
+ ctx.Header().Set("X-Page", strconv.Itoa(listOptions.Page))
+ ctx.Header().Set("X-PerPage", strconv.Itoa(listOptions.PageSize))
ctx.Header().Set("X-Total", strconv.FormatInt(commitsCountTotal, 10))
ctx.Header().Set("X-PageCount", strconv.Itoa(pageCount))
- ctx.Header().Set("X-HasMore", strconv.FormatBool(page < pageCount))
+ ctx.Header().Set("X-HasMore", strconv.FormatBool(listOptions.Page < pageCount))
ctx.JSON(http.StatusOK, &apiCommits)
}
diff --git a/routers/api/v1/repo/fork.go b/routers/api/v1/repo/fork.go
index 0bf7fc6cef..3536b7f43a 100644
--- a/routers/api/v1/repo/fork.go
+++ b/routers/api/v1/repo/fork.go
@@ -1,4 +1,5 @@
// Copyright 2016 The Gogs Authors. All rights reserved.
+// Copyright 2020 The Gitea Authors.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
@@ -11,6 +12,7 @@ import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/context"
api "code.gitea.io/gitea/modules/structs"
+ "code.gitea.io/gitea/routers/api/v1/utils"
repo_service "code.gitea.io/gitea/services/repository"
)
@@ -32,11 +34,19 @@ func ListForks(ctx *context.APIContext) {
// description: name of the repo
// type: string
// required: true
+ // - name: page
+ // in: query
+ // description: page number of results to return (1-based)
+ // type: integer
+ // - name: limit
+ // in: query
+ // description: page size of results, maximum page size is 50
+ // type: integer
// responses:
// "200":
// "$ref": "#/responses/RepositoryList"
- forks, err := ctx.Repo.Repository.GetForks()
+ forks, err := ctx.Repo.Repository.GetForks(utils.GetListOptions(ctx))
if err != nil {
ctx.Error(http.StatusInternalServerError, "GetForks", err)
return
diff --git a/routers/api/v1/repo/hook.go b/routers/api/v1/repo/hook.go
index 7fd7cd1be3..7fc5680c4f 100644
--- a/routers/api/v1/repo/hook.go
+++ b/routers/api/v1/repo/hook.go
@@ -1,4 +1,5 @@
// Copyright 2014 The Gogs Authors. All rights reserved.
+// Copyright 2020 The Gitea Authors.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
@@ -34,11 +35,19 @@ func ListHooks(ctx *context.APIContext) {
// description: name of the repo
// type: string
// required: true
+ // - name: page
+ // in: query
+ // description: page number of results to return (1-based)
+ // type: integer
+ // - name: limit
+ // in: query
+ // description: page size of results, maximum page size is 50
+ // type: integer
// responses:
// "200":
// "$ref": "#/responses/HookList"
- hooks, err := models.GetWebhooksByRepoID(ctx.Repo.Repository.ID)
+ hooks, err := models.GetWebhooksByRepoID(ctx.Repo.Repository.ID, utils.GetListOptions(ctx))
if err != nil {
ctx.Error(http.StatusInternalServerError, "GetWebhooksByRepoID", err)
return
diff --git a/routers/api/v1/repo/issue.go b/routers/api/v1/repo/issue.go
index c480f2a46f..c400ec6f3c 100644
--- a/routers/api/v1/repo/issue.go
+++ b/routers/api/v1/repo/issue.go
@@ -19,6 +19,7 @@ import (
api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/timeutil"
"code.gitea.io/gitea/modules/util"
+ "code.gitea.io/gitea/routers/api/v1/utils"
issue_service "code.gitea.io/gitea/services/issue"
)
@@ -38,10 +39,6 @@ func SearchIssues(ctx *context.APIContext) {
// in: query
// description: comma separated list of labels. Fetch only issues that have any of this labels. Non existent labels are discarded
// type: string
- // - name: page
- // in: query
- // description: page number of requested issues
- // type: integer
// - name: q
// in: query
// description: search string
@@ -55,6 +52,10 @@ func SearchIssues(ctx *context.APIContext) {
// in: query
// description: filter by type (issues / pulls) if set
// type: string
+ // - name: page
+ // in: query
+ // description: page number of requested issues
+ // type: integer
// responses:
// "200":
// "$ref": "#/responses/IssueList"
@@ -72,7 +73,9 @@ func SearchIssues(ctx *context.APIContext) {
// find repos user can access (for issue search)
repoIDs := make([]int64, 0)
opts := &models.SearchRepoOptions{
- PageSize: 15,
+ ListOptions: models.ListOptions{
+ PageSize: 15,
+ },
Private: false,
AllPublic: true,
TopicOnly: false,
@@ -146,9 +149,11 @@ func SearchIssues(ctx *context.APIContext) {
// This would otherwise return all issues if no issues were found by the search.
if len(keyword) == 0 || len(issueIDs) > 0 || len(labelIDs) > 0 {
issues, err = models.Issues(&models.IssuesOptions{
+ ListOptions: models.ListOptions{
+ Page: ctx.QueryInt("page"),
+ PageSize: setting.UI.IssuePagingNum,
+ },
RepoIDs: repoIDs,
- Page: ctx.QueryInt("page"),
- PageSize: setting.UI.IssuePagingNum,
IsClosed: isClosed,
IssueIDs: issueIDs,
LabelIDs: labelIDs,
@@ -198,10 +203,6 @@ func ListIssues(ctx *context.APIContext) {
// in: query
// description: comma separated list of labels. Fetch only issues that have any of this labels. Non existent labels are discarded
// type: string
- // - name: page
- // in: query
- // description: page number of requested issues
- // type: integer
// - name: q
// in: query
// description: search string
@@ -210,6 +211,14 @@ func ListIssues(ctx *context.APIContext) {
// in: query
// description: filter by type (issues / pulls) if set
// type: string
+ // - name: page
+ // in: query
+ // description: page number of results to return (1-based)
+ // type: integer
+ // - name: limit
+ // in: query
+ // description: page size of results, maximum page size is 50
+ // type: integer
// responses:
// "200":
// "$ref": "#/responses/IssueList"
@@ -245,6 +254,11 @@ func ListIssues(ctx *context.APIContext) {
}
}
+ listOptions := utils.GetListOptions(ctx)
+ if ctx.QueryInt("limit") == 0 {
+ listOptions.PageSize = setting.UI.IssuePagingNum
+ }
+
var isPull util.OptionalBool
switch ctx.Query("type") {
case "pulls":
@@ -259,13 +273,12 @@ func ListIssues(ctx *context.APIContext) {
// This would otherwise return all issues if no issues were found by the search.
if len(keyword) == 0 || len(issueIDs) > 0 || len(labelIDs) > 0 {
issues, err = models.Issues(&models.IssuesOptions{
- RepoIDs: []int64{ctx.Repo.Repository.ID},
- Page: ctx.QueryInt("page"),
- PageSize: setting.UI.IssuePagingNum,
- IsClosed: isClosed,
- IssueIDs: issueIDs,
- LabelIDs: labelIDs,
- IsPull: isPull,
+ ListOptions: listOptions,
+ RepoIDs: []int64{ctx.Repo.Repository.ID},
+ IsClosed: isClosed,
+ IssueIDs: issueIDs,
+ LabelIDs: labelIDs,
+ IsPull: isPull,
})
}
@@ -279,7 +292,7 @@ func ListIssues(ctx *context.APIContext) {
apiIssues[i] = issues[i].APIFormat()
}
- ctx.SetLinkHeader(ctx.Repo.Repository.NumIssues, setting.UI.IssuePagingNum)
+ ctx.SetLinkHeader(ctx.Repo.Repository.NumIssues, listOptions.PageSize)
ctx.JSON(http.StatusOK, &apiIssues)
}
diff --git a/routers/api/v1/repo/issue_comment.go b/routers/api/v1/repo/issue_comment.go
index 6b0e388194..6b7c2beac4 100644
--- a/routers/api/v1/repo/issue_comment.go
+++ b/routers/api/v1/repo/issue_comment.go
@@ -1,4 +1,5 @@
// Copyright 2015 The Gogs Authors. All rights reserved.
+// Copyright 2020 The Gitea Authors.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
@@ -117,6 +118,14 @@ func ListRepoIssueComments(ctx *context.APIContext) {
// description: if provided, only comments updated before the provided time are returned.
// type: string
// format: date-time
+ // - name: page
+ // in: query
+ // description: page number of results to return (1-based)
+ // type: integer
+ // - name: limit
+ // in: query
+ // description: page size of results, maximum page size is 50
+ // type: integer
// responses:
// "200":
// "$ref": "#/responses/CommentList"
@@ -128,10 +137,11 @@ func ListRepoIssueComments(ctx *context.APIContext) {
}
comments, err := models.FindComments(models.FindCommentsOptions{
- RepoID: ctx.Repo.Repository.ID,
- Since: since,
- Before: before,
- Type: models.CommentTypeComment,
+ ListOptions: utils.GetListOptions(ctx),
+ RepoID: ctx.Repo.Repository.ID,
+ Type: models.CommentTypeComment,
+ Since: since,
+ Before: before,
})
if err != nil {
ctx.Error(http.StatusInternalServerError, "FindComments", err)
diff --git a/routers/api/v1/repo/issue_reaction.go b/routers/api/v1/repo/issue_reaction.go
index 9c1322b3fe..5e49ea4aae 100644
--- a/routers/api/v1/repo/issue_reaction.go
+++ b/routers/api/v1/repo/issue_reaction.go
@@ -11,6 +11,7 @@ import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/context"
api "code.gitea.io/gitea/modules/structs"
+ "code.gitea.io/gitea/routers/api/v1/utils"
)
// GetIssueCommentReactions list reactions of a comment from an issue
@@ -245,6 +246,14 @@ func GetIssueReactions(ctx *context.APIContext) {
// type: integer
// format: int64
// required: true
+ // - name: page
+ // in: query
+ // description: page number of results to return (1-based)
+ // type: integer
+ // - name: limit
+ // in: query
+ // description: page size of results, maximum page size is 50
+ // type: integer
// responses:
// "200":
// "$ref": "#/responses/ReactionList"
@@ -266,7 +275,7 @@ func GetIssueReactions(ctx *context.APIContext) {
return
}
- reactions, err := models.FindIssueReactions(issue)
+ reactions, err := models.FindIssueReactions(issue, utils.GetListOptions(ctx))
if err != nil {
ctx.Error(http.StatusInternalServerError, "FindIssueReactions", err)
return
diff --git a/routers/api/v1/repo/issue_stopwatch.go b/routers/api/v1/repo/issue_stopwatch.go
index 3b7c20d4d3..01faa0d6b1 100644
--- a/routers/api/v1/repo/issue_stopwatch.go
+++ b/routers/api/v1/repo/issue_stopwatch.go
@@ -9,6 +9,7 @@ import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/context"
+ "code.gitea.io/gitea/routers/api/v1/utils"
)
// StartIssueStopwatch creates a stopwatch for the given issue.
@@ -197,6 +198,15 @@ func GetStopwatches(ctx *context.APIContext) {
// swagger:operation GET /user/stopwatches user userGetStopWatches
// ---
// summary: Get list of all existing stopwatches
+ // parameters:
+ // - name: page
+ // in: query
+ // description: page number of results to return (1-based)
+ // type: integer
+ // - name: limit
+ // in: query
+ // description: page size of results, maximum page size is 50
+ // type: integer
// consumes:
// - application/json
// produces:
@@ -205,7 +215,7 @@ func GetStopwatches(ctx *context.APIContext) {
// "200":
// "$ref": "#/responses/StopWatchList"
- sws, err := models.GetUserStopwatches(ctx.User.ID)
+ sws, err := models.GetUserStopwatches(ctx.User.ID, utils.GetListOptions(ctx))
if err != nil {
ctx.Error(http.StatusInternalServerError, "GetUserStopwatches", err)
return
diff --git a/routers/api/v1/repo/issue_subscription.go b/routers/api/v1/repo/issue_subscription.go
index 153b01de61..274da966fd 100644
--- a/routers/api/v1/repo/issue_subscription.go
+++ b/routers/api/v1/repo/issue_subscription.go
@@ -9,6 +9,7 @@ import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/context"
+ "code.gitea.io/gitea/routers/api/v1/utils"
)
// AddIssueSubscription Subscribe user to issue
@@ -158,6 +159,14 @@ func GetIssueSubscribers(ctx *context.APIContext) {
// type: integer
// format: int64
// required: true
+ // - name: page
+ // in: query
+ // description: page number of results to return (1-based)
+ // type: integer
+ // - name: limit
+ // in: query
+ // description: page size of results, maximum page size is 50
+ // type: integer
// responses:
// "200":
// "$ref": "#/responses/UserList"
@@ -175,7 +184,7 @@ func GetIssueSubscribers(ctx *context.APIContext) {
return
}
- iwl, err := models.GetIssueWatchers(issue.ID)
+ iwl, err := models.GetIssueWatchers(issue.ID, utils.GetListOptions(ctx))
if err != nil {
ctx.Error(http.StatusInternalServerError, "GetIssueWatchers", err)
return
diff --git a/routers/api/v1/repo/issue_tracked_time.go b/routers/api/v1/repo/issue_tracked_time.go
index 323bf67d8e..9bad19a2e7 100644
--- a/routers/api/v1/repo/issue_tracked_time.go
+++ b/routers/api/v1/repo/issue_tracked_time.go
@@ -51,6 +51,14 @@ func ListTrackedTimes(ctx *context.APIContext) {
// description: Only show times updated before the given time. This is a timestamp in RFC 3339 format
// type: string
// format: date-time
+ // - name: page
+ // in: query
+ // description: page number of results to return (1-based)
+ // type: integer
+ // - name: limit
+ // in: query
+ // description: page size of results, maximum page size is 50
+ // type: integer
// responses:
// "200":
// "$ref": "#/responses/TrackedTimeList"
@@ -72,6 +80,7 @@ func ListTrackedTimes(ctx *context.APIContext) {
}
opts := models.FindTrackedTimesOptions{
+ ListOptions: utils.GetListOptions(ctx),
RepositoryID: ctx.Repo.Repository.ID,
IssueID: issue.ID,
}
@@ -435,6 +444,14 @@ func ListTrackedTimesByRepository(ctx *context.APIContext) {
// description: Only show times updated before the given time. This is a timestamp in RFC 3339 format
// type: string
// format: date-time
+ // - name: page
+ // in: query
+ // description: page number of results to return (1-based)
+ // type: integer
+ // - name: limit
+ // in: query
+ // description: page size of results, maximum page size is 50
+ // type: integer
// responses:
// "200":
// "$ref": "#/responses/TrackedTimeList"
@@ -449,6 +466,7 @@ func ListTrackedTimesByRepository(ctx *context.APIContext) {
}
opts := models.FindTrackedTimesOptions{
+ ListOptions: utils.GetListOptions(ctx),
RepositoryID: ctx.Repo.Repository.ID,
}
@@ -495,6 +513,15 @@ func ListMyTrackedTimes(ctx *context.APIContext) {
// swagger:operation GET /user/times user userCurrentTrackedTimes
// ---
// summary: List the current user's tracked times
+ // parameters:
+ // - name: page
+ // in: query
+ // description: page number of results to return (1-based)
+ // type: integer
+ // - name: limit
+ // in: query
+ // description: page size of results, maximum page size is 50
+ // type: integer
// produces:
// - application/json
// parameters:
@@ -512,7 +539,10 @@ func ListMyTrackedTimes(ctx *context.APIContext) {
// "200":
// "$ref": "#/responses/TrackedTimeList"
- opts := models.FindTrackedTimesOptions{UserID: ctx.User.ID}
+ opts := models.FindTrackedTimesOptions{
+ ListOptions: utils.GetListOptions(ctx),
+ UserID: ctx.User.ID,
+ }
var err error
if opts.CreatedBeforeUnix, opts.CreatedAfterUnix, err = utils.GetQueryBeforeSince(ctx); err != nil {
diff --git a/routers/api/v1/repo/key.go b/routers/api/v1/repo/key.go
index 4ced8ec42f..4039100e1f 100644
--- a/routers/api/v1/repo/key.go
+++ b/routers/api/v1/repo/key.go
@@ -1,4 +1,5 @@
// Copyright 2015 The Gogs Authors. All rights reserved.
+// Copyright 2020 The Gitea Authors.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
@@ -13,6 +14,7 @@ import (
"code.gitea.io/gitea/modules/convert"
"code.gitea.io/gitea/modules/setting"
api "code.gitea.io/gitea/modules/structs"
+ "code.gitea.io/gitea/routers/api/v1/utils"
)
// appendPrivateInformation appends the owner and key type information to api.PublicKey
@@ -60,6 +62,14 @@ func ListDeployKeys(ctx *context.APIContext) {
// in: query
// description: fingerprint of the key
// type: string
+ // - name: page
+ // in: query
+ // description: page number of results to return (1-based)
+ // type: integer
+ // - name: limit
+ // in: query
+ // description: page size of results, maximum page size is 50
+ // type: integer
// responses:
// "200":
// "$ref": "#/responses/DeployKeyList"
@@ -72,7 +82,7 @@ func ListDeployKeys(ctx *context.APIContext) {
if fingerprint != "" || keyID != 0 {
keys, err = models.SearchDeployKeys(ctx.Repo.Repository.ID, keyID, fingerprint)
} else {
- keys, err = models.ListDeployKeys(ctx.Repo.Repository.ID)
+ keys, err = models.ListDeployKeys(ctx.Repo.Repository.ID, utils.GetListOptions(ctx))
}
if err != nil {
diff --git a/routers/api/v1/repo/label.go b/routers/api/v1/repo/label.go
index 16c905878d..6d438610be 100644
--- a/routers/api/v1/repo/label.go
+++ b/routers/api/v1/repo/label.go
@@ -12,6 +12,7 @@ import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/context"
api "code.gitea.io/gitea/modules/structs"
+ "code.gitea.io/gitea/routers/api/v1/utils"
)
// ListLabels list all the labels of a repository
@@ -32,11 +33,19 @@ func ListLabels(ctx *context.APIContext) {
// description: name of the repo
// type: string
// required: true
+ // - name: page
+ // in: query
+ // description: page number of results to return (1-based)
+ // type: integer
+ // - name: limit
+ // in: query
+ // description: page size of results, maximum page size is 50
+ // type: integer
// responses:
// "200":
// "$ref": "#/responses/LabelList"
- labels, err := models.GetLabelsByRepoID(ctx.Repo.Repository.ID, ctx.Query("sort"))
+ labels, err := models.GetLabelsByRepoID(ctx.Repo.Repository.ID, ctx.Query("sort"), utils.GetListOptions(ctx))
if err != nil {
ctx.Error(http.StatusInternalServerError, "GetLabelsByRepoID", err)
return
diff --git a/routers/api/v1/repo/milestone.go b/routers/api/v1/repo/milestone.go
index a979e2b69b..f3bb4386cb 100644
--- a/routers/api/v1/repo/milestone.go
+++ b/routers/api/v1/repo/milestone.go
@@ -1,4 +1,5 @@
// Copyright 2016 The Gogs Authors. All rights reserved.
+// Copyright 2020 The Gitea Authors.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
@@ -12,6 +13,7 @@ import (
"code.gitea.io/gitea/modules/context"
api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/timeutil"
+ "code.gitea.io/gitea/routers/api/v1/utils"
)
// ListMilestones list milestones for a repository
@@ -36,11 +38,19 @@ func ListMilestones(ctx *context.APIContext) {
// in: query
// description: Milestone state, Recognised values are open, closed and all. Defaults to "open"
// type: string
+ // - name: page
+ // in: query
+ // description: page number of results to return (1-based)
+ // type: integer
+ // - name: limit
+ // in: query
+ // description: page size of results, maximum page size is 50
+ // type: integer
// responses:
// "200":
// "$ref": "#/responses/MilestoneList"
- milestones, err := models.GetMilestonesByRepoID(ctx.Repo.Repository.ID, api.StateType(ctx.Query("state")))
+ milestones, err := models.GetMilestonesByRepoID(ctx.Repo.Repository.ID, api.StateType(ctx.Query("state")), utils.GetListOptions(ctx))
if err != nil {
ctx.Error(http.StatusInternalServerError, "GetMilestonesByRepoID", err)
return
diff --git a/routers/api/v1/repo/pull.go b/routers/api/v1/repo/pull.go
index e2e6c2799b..1abc2806f8 100644
--- a/routers/api/v1/repo/pull.go
+++ b/routers/api/v1/repo/pull.go
@@ -19,6 +19,7 @@ import (
"code.gitea.io/gitea/modules/notification"
api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/timeutil"
+ "code.gitea.io/gitea/routers/api/v1/utils"
issue_service "code.gitea.io/gitea/services/issue"
pull_service "code.gitea.io/gitea/services/pull"
)
@@ -41,10 +42,6 @@ func ListPullRequests(ctx *context.APIContext, form api.ListPullRequestsOptions)
// description: name of the repo
// type: string
// required: true
- // - name: page
- // in: query
- // description: Page number
- // type: integer
// - name: state
// in: query
// description: "State of pull request: open or closed (optional)"
@@ -68,12 +65,22 @@ func ListPullRequests(ctx *context.APIContext, form api.ListPullRequestsOptions)
// items:
// type: integer
// format: int64
+ // - name: page
+ // in: query
+ // description: page number of results to return (1-based)
+ // type: integer
+ // - name: limit
+ // in: query
+ // description: page size of results, maximum page size is 50
+ // type: integer
// responses:
// "200":
// "$ref": "#/responses/PullRequestList"
+ listOptions := utils.GetListOptions(ctx)
+
prs, maxResults, err := models.PullRequests(ctx.Repo.Repository.ID, &models.PullRequestsOptions{
- Page: ctx.QueryInt("page"),
+ ListOptions: listOptions,
State: ctx.QueryTrim("state"),
SortType: ctx.QueryTrim("sort"),
Labels: ctx.QueryStrings("labels"),
@@ -106,7 +113,7 @@ func ListPullRequests(ctx *context.APIContext, form api.ListPullRequestsOptions)
apiPrs[i] = convert.ToAPIPullRequest(prs[i])
}
- ctx.SetLinkHeader(int(maxResults), models.ItemsPerPage)
+ ctx.SetLinkHeader(int(maxResults), listOptions.PageSize)
ctx.JSON(http.StatusOK, &apiPrs)
}
diff --git a/routers/api/v1/repo/release.go b/routers/api/v1/repo/release.go
index f94d6ba635..5a04fbeec2 100644
--- a/routers/api/v1/repo/release.go
+++ b/routers/api/v1/repo/release.go
@@ -9,8 +9,8 @@ import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/context"
- "code.gitea.io/gitea/modules/setting"
api "code.gitea.io/gitea/modules/structs"
+ "code.gitea.io/gitea/routers/api/v1/utils"
releaseservice "code.gitea.io/gitea/services/release"
)
@@ -59,20 +59,6 @@ func GetRelease(ctx *context.APIContext) {
ctx.JSON(http.StatusOK, release.APIFormat())
}
-func getPagesInfo(ctx *context.APIContext) (int, int) {
- page := ctx.QueryInt("page")
- if page == 0 {
- page = 1
- }
- perPage := ctx.QueryInt("per_page")
- 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
@@ -91,23 +77,32 @@ func ListReleases(ctx *context.APIContext) {
// description: name of the repo
// type: string
// required: true
+ // - name: per_page
+ // in: query
+ // description: items count every page wants to load
+ // type: integer
+ // deprecated: true
// - name: page
// in: query
- // description: page wants to load
+ // description: page number of results to return (1-based)
// type: integer
- // - name: per_page
+ // - name: limit
// in: query
- // description: items count every page wants to load
+ // description: page size of results, maximum page size is 50
// type: integer
// responses:
// "200":
// "$ref": "#/responses/ReleaseList"
+ listOptions := utils.GetListOptions(ctx)
+ if ctx.QueryInt("per_page") != 0 {
+ listOptions.PageSize = ctx.QueryInt("per_page")
+ }
- page, limit := getPagesInfo(ctx)
releases, err := models.GetReleasesByRepoID(ctx.Repo.Repository.ID, models.FindReleasesOptions{
+ ListOptions: listOptions,
IncludeDrafts: ctx.Repo.AccessMode >= models.AccessModeWrite,
IncludeTags: false,
- }, page, limit)
+ })
if err != nil {
ctx.Error(http.StatusInternalServerError, "GetReleasesByRepoID", err)
return
diff --git a/routers/api/v1/repo/repo.go b/routers/api/v1/repo/repo.go
index a13f6ebe0d..61c522bc05 100644
--- a/routers/api/v1/repo/repo.go
+++ b/routers/api/v1/repo/repo.go
@@ -16,7 +16,6 @@ import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/auth"
"code.gitea.io/gitea/modules/context"
- "code.gitea.io/gitea/modules/convert"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/graceful"
"code.gitea.io/gitea/modules/log"
@@ -27,6 +26,7 @@ import (
api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/modules/validation"
+ "code.gitea.io/gitea/routers/api/v1/utils"
mirror_service "code.gitea.io/gitea/services/mirror"
repo_service "code.gitea.io/gitea/services/repository"
)
@@ -91,14 +91,6 @@ func Search(ctx *context.APIContext) {
// in: query
// description: include template repositories this user has access to (defaults to true)
// type: boolean
- // - name: page
- // in: query
- // description: page number of results to return (1-based)
- // type: integer
- // - name: limit
- // in: query
- // description: page size of results, maximum page size is 50
- // type: integer
// - name: mode
// in: query
// description: type of repository to search for. Supported values are
@@ -119,6 +111,14 @@ func Search(ctx *context.APIContext) {
// description: sort order, either "asc" (ascending) or "desc" (descending).
// Default is "asc", ignored if "sort" is not specified.
// type: string
+ // - name: page
+ // in: query
+ // description: page number of results to return (1-based)
+ // type: integer
+ // - name: limit
+ // in: query
+ // description: page size of results, maximum page size is 50
+ // type: integer
// responses:
// "200":
// "$ref": "#/responses/SearchResults"
@@ -126,12 +126,11 @@ func Search(ctx *context.APIContext) {
// "$ref": "#/responses/validationError"
opts := &models.SearchRepoOptions{
+ ListOptions: utils.GetListOptions(ctx),
Actor: ctx.User,
Keyword: strings.Trim(ctx.Query("q"), " "),
OwnerID: ctx.QueryInt64("uid"),
PriorityOwnerID: ctx.QueryInt64("priority_owner_id"),
- Page: ctx.QueryInt("page"),
- PageSize: convert.ToCorrectPageSize(ctx.QueryInt("limit")),
TopicOnly: ctx.QueryBool("topic"),
Collaborate: util.OptionalBoolNone,
Private: ctx.IsSigned && (ctx.Query("private") == "" || ctx.QueryBool("private")),
@@ -214,7 +213,7 @@ func Search(ctx *context.APIContext) {
results[i] = repo.APIFormat(accessMode)
}
- ctx.SetLinkHeader(int(count), setting.API.MaxResponseItems)
+ ctx.SetLinkHeader(int(count), opts.PageSize)
ctx.Header().Set("X-Total-Count", fmt.Sprintf("%d", count))
ctx.JSON(http.StatusOK, api.SearchResults{
OK: true,
diff --git a/routers/api/v1/repo/star.go b/routers/api/v1/repo/star.go
index 65a99d442a..c68f8f2744 100644
--- a/routers/api/v1/repo/star.go
+++ b/routers/api/v1/repo/star.go
@@ -10,6 +10,7 @@ import (
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/convert"
api "code.gitea.io/gitea/modules/structs"
+ "code.gitea.io/gitea/routers/api/v1/utils"
)
// ListStargazers list a repository's stargazers
@@ -30,11 +31,19 @@ func ListStargazers(ctx *context.APIContext) {
// description: name of the repo
// type: string
// required: true
+ // - name: page
+ // in: query
+ // description: page number of results to return (1-based)
+ // type: integer
+ // - name: limit
+ // in: query
+ // description: page size of results, maximum page size is 50
+ // type: integer
// responses:
// "200":
// "$ref": "#/responses/UserList"
- stargazers, err := ctx.Repo.Repository.GetStargazers(-1)
+ stargazers, err := ctx.Repo.Repository.GetStargazers(utils.GetListOptions(ctx))
if err != nil {
ctx.Error(http.StatusInternalServerError, "GetStargazers", err)
return
diff --git a/routers/api/v1/repo/status.go b/routers/api/v1/repo/status.go
index b6b3d495ca..6ce71cc911 100644
--- a/routers/api/v1/repo/status.go
+++ b/routers/api/v1/repo/status.go
@@ -12,6 +12,7 @@ import (
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/repofiles"
api "code.gitea.io/gitea/modules/structs"
+ "code.gitea.io/gitea/routers/api/v1/utils"
)
// NewCommitStatus creates a new CommitStatus
@@ -89,11 +90,6 @@ func GetCommitStatuses(ctx *context.APIContext) {
// description: sha of the commit
// type: string
// required: true
- // - name: page
- // in: query
- // description: page number of results
- // type: integer
- // required: false
// - name: sort
// in: query
// description: type of sort
@@ -106,6 +102,14 @@ func GetCommitStatuses(ctx *context.APIContext) {
// type: string
// enum: [pending, success, error, failure, warning]
// required: false
+ // - name: page
+ // in: query
+ // description: page number of results to return (1-based)
+ // type: integer
+ // - name: limit
+ // in: query
+ // description: page size of results, maximum page size is 50
+ // type: integer
// responses:
// "200":
// "$ref": "#/responses/StatusList"
@@ -138,11 +142,6 @@ func GetCommitStatusesByRef(ctx *context.APIContext) {
// description: name of branch/tag/commit
// type: string
// required: true
- // - name: page
- // in: query
- // description: page number of results
- // type: integer
- // required: false
// - name: sort
// in: query
// description: type of sort
@@ -155,6 +154,14 @@ func GetCommitStatusesByRef(ctx *context.APIContext) {
// type: string
// enum: [pending, success, error, failure, warning]
// required: false
+ // - name: page
+ // in: query
+ // description: page number of results to return (1-based)
+ // type: integer
+ // - name: limit
+ // in: query
+ // description: page size of results, maximum page size is 50
+ // type: integer
// responses:
// "200":
// "$ref": "#/responses/StatusList"
@@ -202,9 +209,9 @@ func getCommitStatuses(ctx *context.APIContext, sha string) {
repo := ctx.Repo.Repository
statuses, _, err := models.GetCommitStatuses(repo, sha, &models.CommitStatusOptions{
- Page: ctx.QueryInt("page"),
- SortType: ctx.QueryTrim("sort"),
- State: ctx.QueryTrim("state"),
+ ListOptions: utils.GetListOptions(ctx),
+ SortType: ctx.QueryTrim("sort"),
+ State: ctx.QueryTrim("state"),
})
if err != nil {
ctx.Error(http.StatusInternalServerError, "GetCommitStatuses", fmt.Errorf("GetCommitStatuses[%s, %s, %d]: %v", repo.FullName(), sha, ctx.QueryInt("page"), err))
diff --git a/routers/api/v1/repo/subscriber.go b/routers/api/v1/repo/subscriber.go
index 352f842884..d3cd8ccc3b 100644
--- a/routers/api/v1/repo/subscriber.go
+++ b/routers/api/v1/repo/subscriber.go
@@ -10,6 +10,7 @@ import (
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/convert"
api "code.gitea.io/gitea/modules/structs"
+ "code.gitea.io/gitea/routers/api/v1/utils"
)
// ListSubscribers list a repo's subscribers (i.e. watchers)
@@ -30,11 +31,19 @@ func ListSubscribers(ctx *context.APIContext) {
// description: name of the repo
// type: string
// required: true
+ // - name: page
+ // in: query
+ // description: page number of results to return (1-based)
+ // type: integer
+ // - name: limit
+ // in: query
+ // description: page size of results, maximum page size is 50
+ // type: integer
// responses:
// "200":
// "$ref": "#/responses/UserList"
- subscribers, err := ctx.Repo.Repository.GetWatchers(0)
+ subscribers, err := ctx.Repo.Repository.GetWatchers(utils.GetListOptions(ctx))
if err != nil {
ctx.Error(http.StatusInternalServerError, "GetWatchers", err)
return
diff --git a/routers/api/v1/repo/topic.go b/routers/api/v1/repo/topic.go
index 0c56f2a769..530b92a10d 100644
--- a/routers/api/v1/repo/topic.go
+++ b/routers/api/v1/repo/topic.go
@@ -13,6 +13,7 @@ import (
"code.gitea.io/gitea/modules/convert"
"code.gitea.io/gitea/modules/log"
api "code.gitea.io/gitea/modules/structs"
+ "code.gitea.io/gitea/routers/api/v1/utils"
)
// ListTopics returns list of current topics for repo
@@ -33,12 +34,21 @@ func ListTopics(ctx *context.APIContext) {
// description: name of the repo
// type: string
// required: true
+ // - name: page
+ // in: query
+ // description: page number of results to return (1-based)
+ // type: integer
+ // - name: limit
+ // in: query
+ // description: page size of results, maximum page size is 50
+ // type: integer
// responses:
// "200":
// "$ref": "#/responses/TopicNames"
topics, err := models.FindTopics(&models.FindTopicOptions{
- RepoID: ctx.Repo.Repository.ID,
+ ListOptions: utils.GetListOptions(ctx),
+ RepoID: ctx.Repo.Repository.ID,
})
if err != nil {
log.Error("ListTopics failed: %v", err)
@@ -231,7 +241,7 @@ func DeleteTopic(ctx *context.APIContext) {
}
// TopicSearch search for creating topic
-func TopicSearch(ctx *context.Context) {
+func TopicSearch(ctx *context.APIContext) {
// swagger:operation GET /topics/search repository topicSearch
// ---
// summary: search topics via keyword
@@ -243,6 +253,14 @@ func TopicSearch(ctx *context.Context) {
// description: keywords to search
// required: true
// type: string
+ // - name: page
+ // in: query
+ // description: page number of results to return (1-based)
+ // type: integer
+ // - name: limit
+ // in: query
+ // description: page size of results, maximum page size is 50
+ // type: integer
// responses:
// "200":
// "$ref": "#/responses/TopicListResponse"
@@ -256,9 +274,17 @@ func TopicSearch(ctx *context.Context) {
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,
- Limit: 10,
+ Keyword: kw,
+ ListOptions: listOptions,
})
if err != nil {
log.Error("SearchTopics failed: %v", err)