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/branch.go5
-rw-r--r--routers/api/v1/repo/collaborators.go9
-rw-r--r--routers/api/v1/repo/commits.go8
-rw-r--r--routers/api/v1/repo/fork.go2
-rw-r--r--routers/api/v1/repo/hook.go17
-rw-r--r--routers/api/v1/repo/issue.go6
-rw-r--r--routers/api/v1/repo/issue_comment.go28
-rw-r--r--routers/api/v1/repo/issue_stopwatch.go7
-rw-r--r--routers/api/v1/repo/issue_tracked_time.go31
-rw-r--r--routers/api/v1/repo/key.go24
-rw-r--r--routers/api/v1/repo/label.go7
-rw-r--r--routers/api/v1/repo/milestone.go4
-rw-r--r--routers/api/v1/repo/pull.go10
-rw-r--r--routers/api/v1/repo/pull_review.go14
-rw-r--r--routers/api/v1/repo/release.go4
-rw-r--r--routers/api/v1/repo/repo.go3
-rw-r--r--routers/api/v1/repo/star.go2
-rw-r--r--routers/api/v1/repo/status.go4
-rw-r--r--routers/api/v1/repo/subscriber.go2
-rw-r--r--routers/api/v1/repo/tag.go3
-rw-r--r--routers/api/v1/repo/topic.go33
21 files changed, 157 insertions, 66 deletions
diff --git a/routers/api/v1/repo/branch.go b/routers/api/v1/repo/branch.go
index 85c1681dfe..8653b0bc80 100644
--- a/routers/api/v1/repo/branch.go
+++ b/routers/api/v1/repo/branch.go
@@ -282,9 +282,8 @@ func ListBranches(ctx *context.APIContext) {
}
}
- ctx.SetLinkHeader(int(totalNumOfBranches), listOptions.PageSize)
- ctx.Header().Set("X-Total-Count", fmt.Sprintf("%d", totalNumOfBranches))
- ctx.Header().Set("Access-Control-Expose-Headers", "X-Total-Count, Link")
+ ctx.SetLinkHeader(totalNumOfBranches, listOptions.PageSize)
+ ctx.SetTotalCountHeader(int64(totalNumOfBranches))
ctx.JSON(http.StatusOK, &apiBranches)
}
diff --git a/routers/api/v1/repo/collaborators.go b/routers/api/v1/repo/collaborators.go
index 078af1f6ff..d636220f62 100644
--- a/routers/api/v1/repo/collaborators.go
+++ b/routers/api/v1/repo/collaborators.go
@@ -47,15 +47,24 @@ func ListCollaborators(ctx *context.APIContext) {
// "200":
// "$ref": "#/responses/UserList"
+ count, err := ctx.Repo.Repository.CountCollaborators()
+ if err != nil {
+ ctx.InternalServerError(err)
+ return
+ }
+
collaborators, err := ctx.Repo.Repository.GetCollaborators(utils.GetListOptions(ctx))
if err != nil {
ctx.Error(http.StatusInternalServerError, "ListCollaborators", err)
return
}
+
users := make([]*api.User, len(collaborators))
for i, collaborator := range collaborators {
users[i] = convert.ToUser(collaborator.User, ctx.User)
}
+
+ ctx.SetTotalCountHeader(count)
ctx.JSON(http.StatusOK, users)
}
diff --git a/routers/api/v1/repo/commits.go b/routers/api/v1/repo/commits.go
index f2fd901efa..975b9cab2a 100644
--- a/routers/api/v1/repo/commits.go
+++ b/routers/api/v1/repo/commits.go
@@ -200,16 +200,16 @@ func GetAllCommits(ctx *context.APIContext) {
}
}
+ ctx.SetLinkHeader(int(commitsCountTotal), listOptions.PageSize)
+ ctx.SetTotalCountHeader(commitsCountTotal)
+
// kept for backwards compatibility
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(listOptions.Page < pageCount))
-
- ctx.SetLinkHeader(int(commitsCountTotal), listOptions.PageSize)
- ctx.Header().Set("X-Total-Count", fmt.Sprintf("%d", commitsCountTotal))
- ctx.Header().Set("Access-Control-Expose-Headers", "X-Total-Count, X-PerPage, X-Total, X-PageCount, X-HasMore, Link")
+ ctx.AppendAccessControlExposeHeaders("X-Page", "X-PerPage", "X-Total", "X-PageCount", "X-HasMore")
ctx.JSON(http.StatusOK, &apiCommits)
}
diff --git a/routers/api/v1/repo/fork.go b/routers/api/v1/repo/fork.go
index 55fcefaccc..a3f9aa14f9 100644
--- a/routers/api/v1/repo/fork.go
+++ b/routers/api/v1/repo/fork.go
@@ -62,6 +62,8 @@ func ListForks(ctx *context.APIContext) {
}
apiForks[i] = convert.ToRepo(fork, access)
}
+
+ ctx.SetTotalCountHeader(int64(ctx.Repo.Repository.NumForks))
ctx.JSON(http.StatusOK, apiForks)
}
diff --git a/routers/api/v1/repo/hook.go b/routers/api/v1/repo/hook.go
index da0a2c501c..74860fd72f 100644
--- a/routers/api/v1/repo/hook.go
+++ b/routers/api/v1/repo/hook.go
@@ -48,9 +48,20 @@ func ListHooks(ctx *context.APIContext) {
// "200":
// "$ref": "#/responses/HookList"
- hooks, err := models.GetWebhooksByRepoID(ctx.Repo.Repository.ID, utils.GetListOptions(ctx))
+ opts := &models.ListWebhookOptions{
+ ListOptions: utils.GetListOptions(ctx),
+ RepoID: ctx.Repo.Repository.ID,
+ }
+
+ count, err := models.CountWebhooksByOpts(opts)
if err != nil {
- ctx.Error(http.StatusInternalServerError, "GetWebhooksByRepoID", err)
+ ctx.InternalServerError(err)
+ return
+ }
+
+ hooks, err := models.ListWebhooksByOpts(opts)
+ if err != nil {
+ ctx.InternalServerError(err)
return
}
@@ -58,6 +69,8 @@ func ListHooks(ctx *context.APIContext) {
for i := range hooks {
apiHooks[i] = convert.ToHook(ctx.Repo.RepoLink, hooks[i])
}
+
+ ctx.SetTotalCountHeader(count)
ctx.JSON(http.StatusOK, &apiHooks)
}
diff --git a/routers/api/v1/repo/issue.go b/routers/api/v1/repo/issue.go
index 7395d4fdd4..ff003b840b 100644
--- a/routers/api/v1/repo/issue.go
+++ b/routers/api/v1/repo/issue.go
@@ -232,8 +232,7 @@ func SearchIssues(ctx *context.APIContext) {
}
ctx.SetLinkHeader(int(filteredCount), setting.UI.IssuePagingNum)
- ctx.Header().Set("X-Total-Count", fmt.Sprintf("%d", filteredCount))
- ctx.Header().Set("Access-Control-Expose-Headers", "X-Total-Count, Link")
+ ctx.SetTotalCountHeader(filteredCount)
ctx.JSON(http.StatusOK, convert.ToAPIIssueList(issues))
}
@@ -442,8 +441,7 @@ func ListIssues(ctx *context.APIContext) {
}
ctx.SetLinkHeader(int(filteredCount), listOptions.PageSize)
- ctx.Header().Set("X-Total-Count", fmt.Sprintf("%d", filteredCount))
- ctx.Header().Set("Access-Control-Expose-Headers", "X-Total-Count, Link")
+ ctx.SetTotalCountHeader(filteredCount)
ctx.JSON(http.StatusOK, convert.ToAPIIssueList(issues))
}
diff --git a/routers/api/v1/repo/issue_comment.go b/routers/api/v1/repo/issue_comment.go
index d62ca81314..13e7de46b1 100644
--- a/routers/api/v1/repo/issue_comment.go
+++ b/routers/api/v1/repo/issue_comment.go
@@ -68,17 +68,25 @@ func ListIssueComments(ctx *context.APIContext) {
}
issue.Repo = ctx.Repo.Repository
- comments, err := models.FindComments(models.FindCommentsOptions{
+ opts := &models.FindCommentsOptions{
IssueID: issue.ID,
Since: since,
Before: before,
Type: models.CommentTypeComment,
- })
+ }
+
+ comments, err := models.FindComments(opts)
if err != nil {
ctx.Error(http.StatusInternalServerError, "FindComments", err)
return
}
+ totalCount, err := models.CountComments(opts)
+ if err != nil {
+ ctx.InternalServerError(err)
+ return
+ }
+
if err := models.CommentList(comments).LoadPosters(); err != nil {
ctx.Error(http.StatusInternalServerError, "LoadPosters", err)
return
@@ -89,6 +97,8 @@ func ListIssueComments(ctx *context.APIContext) {
comment.Issue = issue
apiComments[i] = convert.ToComment(comments[i])
}
+
+ ctx.SetTotalCountHeader(totalCount)
ctx.JSON(http.StatusOK, &apiComments)
}
@@ -138,18 +148,26 @@ func ListRepoIssueComments(ctx *context.APIContext) {
return
}
- comments, err := models.FindComments(models.FindCommentsOptions{
+ opts := &models.FindCommentsOptions{
ListOptions: utils.GetListOptions(ctx),
RepoID: ctx.Repo.Repository.ID,
Type: models.CommentTypeComment,
Since: since,
Before: before,
- })
+ }
+
+ comments, err := models.FindComments(opts)
if err != nil {
ctx.Error(http.StatusInternalServerError, "FindComments", err)
return
}
+ totalCount, err := models.CountComments(opts)
+ if err != nil {
+ ctx.InternalServerError(err)
+ return
+ }
+
if err = models.CommentList(comments).LoadPosters(); err != nil {
ctx.Error(http.StatusInternalServerError, "LoadPosters", err)
return
@@ -171,6 +189,8 @@ func ListRepoIssueComments(ctx *context.APIContext) {
for i := range comments {
apiComments[i] = convert.ToComment(comments[i])
}
+
+ ctx.SetTotalCountHeader(totalCount)
ctx.JSON(http.StatusOK, &apiComments)
}
diff --git a/routers/api/v1/repo/issue_stopwatch.go b/routers/api/v1/repo/issue_stopwatch.go
index a4a2261b9a..82a9ffe10b 100644
--- a/routers/api/v1/repo/issue_stopwatch.go
+++ b/routers/api/v1/repo/issue_stopwatch.go
@@ -225,11 +225,18 @@ func GetStopwatches(ctx *context.APIContext) {
return
}
+ count, err := models.CountUserStopwatches(ctx.User.ID)
+ if err != nil {
+ ctx.InternalServerError(err)
+ return
+ }
+
apiSWs, err := convert.ToStopWatches(sws)
if err != nil {
ctx.Error(http.StatusInternalServerError, "APIFormat", err)
return
}
+ ctx.SetTotalCountHeader(count)
ctx.JSON(http.StatusOK, apiSWs)
}
diff --git a/routers/api/v1/repo/issue_tracked_time.go b/routers/api/v1/repo/issue_tracked_time.go
index b27b746eb2..e9d8fbab26 100644
--- a/routers/api/v1/repo/issue_tracked_time.go
+++ b/routers/api/v1/repo/issue_tracked_time.go
@@ -83,7 +83,7 @@ func ListTrackedTimes(ctx *context.APIContext) {
return
}
- opts := models.FindTrackedTimesOptions{
+ opts := &models.FindTrackedTimesOptions{
ListOptions: utils.GetListOptions(ctx),
RepositoryID: ctx.Repo.Repository.ID,
IssueID: issue.ID,
@@ -119,6 +119,12 @@ func ListTrackedTimes(ctx *context.APIContext) {
}
}
+ count, err := models.CountTrackedTimes(opts)
+ if err != nil {
+ ctx.InternalServerError(err)
+ return
+ }
+
trackedTimes, err := models.GetTrackedTimes(opts)
if err != nil {
ctx.Error(http.StatusInternalServerError, "GetTrackedTimes", err)
@@ -128,6 +134,8 @@ func ListTrackedTimes(ctx *context.APIContext) {
ctx.Error(http.StatusInternalServerError, "LoadAttributes", err)
return
}
+
+ ctx.SetTotalCountHeader(count)
ctx.JSON(http.StatusOK, convert.ToTrackedTimeList(trackedTimes))
}
@@ -423,7 +431,7 @@ func ListTrackedTimesByUser(ctx *context.APIContext) {
return
}
- opts := models.FindTrackedTimesOptions{
+ opts := &models.FindTrackedTimesOptions{
UserID: user.ID,
RepositoryID: ctx.Repo.Repository.ID,
}
@@ -493,7 +501,7 @@ func ListTrackedTimesByRepository(ctx *context.APIContext) {
return
}
- opts := models.FindTrackedTimesOptions{
+ opts := &models.FindTrackedTimesOptions{
ListOptions: utils.GetListOptions(ctx),
RepositoryID: ctx.Repo.Repository.ID,
}
@@ -530,6 +538,12 @@ func ListTrackedTimesByRepository(ctx *context.APIContext) {
}
}
+ count, err := models.CountTrackedTimes(opts)
+ if err != nil {
+ ctx.InternalServerError(err)
+ return
+ }
+
trackedTimes, err := models.GetTrackedTimes(opts)
if err != nil {
ctx.Error(http.StatusInternalServerError, "GetTrackedTimes", err)
@@ -539,6 +553,8 @@ func ListTrackedTimesByRepository(ctx *context.APIContext) {
ctx.Error(http.StatusInternalServerError, "LoadAttributes", err)
return
}
+
+ ctx.SetTotalCountHeader(count)
ctx.JSON(http.StatusOK, convert.ToTrackedTimeList(trackedTimes))
}
@@ -573,7 +589,7 @@ func ListMyTrackedTimes(ctx *context.APIContext) {
// "200":
// "$ref": "#/responses/TrackedTimeList"
- opts := models.FindTrackedTimesOptions{
+ opts := &models.FindTrackedTimesOptions{
ListOptions: utils.GetListOptions(ctx),
UserID: ctx.User.ID,
}
@@ -584,6 +600,12 @@ func ListMyTrackedTimes(ctx *context.APIContext) {
return
}
+ count, err := models.CountTrackedTimes(opts)
+ if err != nil {
+ ctx.InternalServerError(err)
+ return
+ }
+
trackedTimes, err := models.GetTrackedTimes(opts)
if err != nil {
ctx.Error(http.StatusInternalServerError, "GetTrackedTimesByUser", err)
@@ -595,5 +617,6 @@ func ListMyTrackedTimes(ctx *context.APIContext) {
return
}
+ ctx.SetTotalCountHeader(count)
ctx.JSON(http.StatusOK, convert.ToTrackedTimeList(trackedTimes))
}
diff --git a/routers/api/v1/repo/key.go b/routers/api/v1/repo/key.go
index 903cef7104..98ee2b4de5 100644
--- a/routers/api/v1/repo/key.go
+++ b/routers/api/v1/repo/key.go
@@ -75,26 +75,29 @@ func ListDeployKeys(ctx *context.APIContext) {
// "200":
// "$ref": "#/responses/DeployKeyList"
- var keys []*models.DeployKey
- var err error
+ opts := &models.ListDeployKeysOptions{
+ ListOptions: utils.GetListOptions(ctx),
+ RepoID: ctx.Repo.Repository.ID,
+ KeyID: ctx.FormInt64("key_id"),
+ Fingerprint: ctx.FormString("fingerprint"),
+ }
- fingerprint := ctx.FormString("fingerprint")
- keyID := ctx.FormInt64("key_id")
- if fingerprint != "" || keyID != 0 {
- keys, err = models.SearchDeployKeys(ctx.Repo.Repository.ID, keyID, fingerprint)
- } else {
- keys, err = models.ListDeployKeys(ctx.Repo.Repository.ID, utils.GetListOptions(ctx))
+ keys, err := models.ListDeployKeys(opts)
+ if err != nil {
+ ctx.InternalServerError(err)
+ return
}
+ count, err := models.CountDeployKeys(opts)
if err != nil {
- ctx.Error(http.StatusInternalServerError, "ListDeployKeys", err)
+ ctx.InternalServerError(err)
return
}
apiLink := composeDeployKeysAPILink(ctx.Repo.Owner.Name + "/" + ctx.Repo.Repository.Name)
apiKeys := make([]*api.DeployKey, len(keys))
for i := range keys {
- if err = keys[i].GetContent(); err != nil {
+ if err := keys[i].GetContent(); err != nil {
ctx.Error(http.StatusInternalServerError, "GetContent", err)
return
}
@@ -104,6 +107,7 @@ func ListDeployKeys(ctx *context.APIContext) {
}
}
+ ctx.SetTotalCountHeader(count)
ctx.JSON(http.StatusOK, &apiKeys)
}
diff --git a/routers/api/v1/repo/label.go b/routers/api/v1/repo/label.go
index ca0d8392b8..1de5705aa2 100644
--- a/routers/api/v1/repo/label.go
+++ b/routers/api/v1/repo/label.go
@@ -55,6 +55,13 @@ func ListLabels(ctx *context.APIContext) {
return
}
+ count, err := models.CountLabelsByRepoID(ctx.Repo.Repository.ID)
+ if err != nil {
+ ctx.InternalServerError(err)
+ return
+ }
+
+ ctx.SetTotalCountHeader(count)
ctx.JSON(http.StatusOK, convert.ToLabelList(labels))
}
diff --git a/routers/api/v1/repo/milestone.go b/routers/api/v1/repo/milestone.go
index 07b3897bc1..be1da18c5d 100644
--- a/routers/api/v1/repo/milestone.go
+++ b/routers/api/v1/repo/milestone.go
@@ -57,7 +57,7 @@ func ListMilestones(ctx *context.APIContext) {
// "200":
// "$ref": "#/responses/MilestoneList"
- milestones, err := models.GetMilestones(models.GetMilestonesOption{
+ milestones, total, err := models.GetMilestones(models.GetMilestonesOption{
ListOptions: utils.GetListOptions(ctx),
RepoID: ctx.Repo.Repository.ID,
State: api.StateType(ctx.FormString("state")),
@@ -72,6 +72,8 @@ func ListMilestones(ctx *context.APIContext) {
for i := range milestones {
apiMilestones[i] = convert.ToAPIMilestone(milestones[i])
}
+
+ ctx.SetTotalCountHeader(total)
ctx.JSON(http.StatusOK, &apiMilestones)
}
diff --git a/routers/api/v1/repo/pull.go b/routers/api/v1/repo/pull.go
index 9be6228bfd..0a903101c7 100644
--- a/routers/api/v1/repo/pull.go
+++ b/routers/api/v1/repo/pull.go
@@ -119,8 +119,7 @@ func ListPullRequests(ctx *context.APIContext) {
}
ctx.SetLinkHeader(int(maxResults), listOptions.PageSize)
- ctx.Header().Set("X-Total-Count", fmt.Sprintf("%d", maxResults))
- ctx.Header().Set("Access-Control-Expose-Headers", "X-Total-Count, Link")
+ ctx.SetTotalCountHeader(maxResults)
ctx.JSON(http.StatusOK, &apiPrs)
}
@@ -1232,13 +1231,14 @@ func GetPullRequestCommits(ctx *context.APIContext) {
apiCommits = append(apiCommits, apiCommit)
}
- ctx.SetLinkHeader(int(totalNumberOfCommits), listOptions.PageSize)
+ ctx.SetLinkHeader(totalNumberOfCommits, listOptions.PageSize)
+ ctx.SetTotalCountHeader(int64(totalNumberOfCommits))
ctx.Header().Set("X-Page", strconv.Itoa(listOptions.Page))
ctx.Header().Set("X-PerPage", strconv.Itoa(listOptions.PageSize))
- ctx.Header().Set("X-Total-Count", fmt.Sprintf("%d", totalNumberOfCommits))
ctx.Header().Set("X-PageCount", strconv.Itoa(totalNumberOfPages))
ctx.Header().Set("X-HasMore", strconv.FormatBool(listOptions.Page < totalNumberOfPages))
- ctx.Header().Set("Access-Control-Expose-Headers", "X-Total-Count, X-PerPage, X-Total, X-PageCount, X-HasMore, Link")
+ ctx.AppendAccessControlExposeHeaders("X-Page", "X-PerPage", "X-PageCount", "X-HasMore")
+
ctx.JSON(http.StatusOK, &apiCommits)
}
diff --git a/routers/api/v1/repo/pull_review.go b/routers/api/v1/repo/pull_review.go
index 323904f45c..55b5178305 100644
--- a/routers/api/v1/repo/pull_review.go
+++ b/routers/api/v1/repo/pull_review.go
@@ -78,14 +78,21 @@ func ListPullReviews(ctx *context.APIContext) {
return
}
- allReviews, err := models.FindReviews(models.FindReviewOptions{
+ opts := models.FindReviewOptions{
ListOptions: utils.GetListOptions(ctx),
Type: models.ReviewTypeUnknown,
IssueID: pr.IssueID,
- })
+ }
+
+ allReviews, err := models.FindReviews(opts)
+ if err != nil {
+ ctx.InternalServerError(err)
+ return
+ }
+ count, err := models.CountReviews(opts)
if err != nil {
- ctx.Error(http.StatusInternalServerError, "FindReviews", err)
+ ctx.InternalServerError(err)
return
}
@@ -95,6 +102,7 @@ func ListPullReviews(ctx *context.APIContext) {
return
}
+ ctx.SetTotalCountHeader(count)
ctx.JSON(http.StatusOK, &apiReviews)
}
diff --git a/routers/api/v1/repo/release.go b/routers/api/v1/repo/release.go
index 97b90079f2..6438c6e9b4 100644
--- a/routers/api/v1/repo/release.go
+++ b/routers/api/v1/repo/release.go
@@ -5,7 +5,6 @@
package repo
import (
- "fmt"
"net/http"
"code.gitea.io/gitea/models"
@@ -142,8 +141,7 @@ func ListReleases(ctx *context.APIContext) {
}
ctx.SetLinkHeader(int(filteredCount), listOptions.PageSize)
- ctx.Header().Set("X-Total-Count", fmt.Sprint(filteredCount))
- ctx.Header().Set("Access-Control-Expose-Headers", "X-Total-Count, Link")
+ ctx.SetTotalCountHeader(filteredCount)
ctx.JSON(http.StatusOK, rels)
}
diff --git a/routers/api/v1/repo/repo.go b/routers/api/v1/repo/repo.go
index d222c9b080..0f85d917d1 100644
--- a/routers/api/v1/repo/repo.go
+++ b/routers/api/v1/repo/repo.go
@@ -230,8 +230,7 @@ func Search(ctx *context.APIContext) {
}
ctx.SetLinkHeader(int(count), opts.PageSize)
- ctx.Header().Set("X-Total-Count", fmt.Sprintf("%d", count))
- ctx.Header().Set("Access-Control-Expose-Headers", "X-Total-Count, Link")
+ ctx.SetTotalCountHeader(count)
ctx.JSON(http.StatusOK, api.SearchResults{
OK: true,
Data: results,
diff --git a/routers/api/v1/repo/star.go b/routers/api/v1/repo/star.go
index 3af0a4ac12..5fa42c3244 100644
--- a/routers/api/v1/repo/star.go
+++ b/routers/api/v1/repo/star.go
@@ -52,5 +52,7 @@ func ListStargazers(ctx *context.APIContext) {
for i, stargazer := range stargazers {
users[i] = convert.ToUser(stargazer, ctx.User)
}
+
+ ctx.SetTotalCountHeader(int64(ctx.Repo.Repository.NumStars))
ctx.JSON(http.StatusOK, users)
}
diff --git a/routers/api/v1/repo/status.go b/routers/api/v1/repo/status.go
index 841f60bb56..b884432f73 100644
--- a/routers/api/v1/repo/status.go
+++ b/routers/api/v1/repo/status.go
@@ -204,8 +204,7 @@ func getCommitStatuses(ctx *context.APIContext, sha string) {
}
ctx.SetLinkHeader(int(maxResults), listOptions.PageSize)
- ctx.Header().Set("X-Total-Count", fmt.Sprintf("%d", maxResults))
- ctx.Header().Set("Access-Control-Expose-Headers", "X-Total-Count, Link")
+ ctx.SetTotalCountHeader(maxResults)
ctx.JSON(http.StatusOK, apiStatuses)
}
@@ -267,5 +266,6 @@ func GetCombinedCommitStatusByRef(ctx *context.APIContext) {
combiStatus := convert.ToCombinedStatus(statuses, convert.ToRepo(repo, ctx.Repo.AccessMode))
+ // TODO: ctx.SetTotalCountHeader(count)
ctx.JSON(http.StatusOK, combiStatus)
}
diff --git a/routers/api/v1/repo/subscriber.go b/routers/api/v1/repo/subscriber.go
index 37bf3c29d4..dae92969ba 100644
--- a/routers/api/v1/repo/subscriber.go
+++ b/routers/api/v1/repo/subscriber.go
@@ -52,5 +52,7 @@ func ListSubscribers(ctx *context.APIContext) {
for i, subscriber := range subscribers {
users[i] = convert.ToUser(subscriber, ctx.User)
}
+
+ ctx.SetTotalCountHeader(int64(ctx.Repo.Repository.NumWatches))
ctx.JSON(http.StatusOK, users)
}
diff --git a/routers/api/v1/repo/tag.go b/routers/api/v1/repo/tag.go
index c95fb63f85..8d42e63a48 100644
--- a/routers/api/v1/repo/tag.go
+++ b/routers/api/v1/repo/tag.go
@@ -50,7 +50,7 @@ func ListTags(ctx *context.APIContext) {
listOpts := utils.GetListOptions(ctx)
- tags, err := ctx.Repo.GitRepo.GetTagInfos(listOpts.Page, listOpts.PageSize)
+ tags, total, err := ctx.Repo.GitRepo.GetTagInfos(listOpts.Page, listOpts.PageSize)
if err != nil {
ctx.Error(http.StatusInternalServerError, "GetTags", err)
return
@@ -61,6 +61,7 @@ func ListTags(ctx *context.APIContext) {
apiTags[i] = convert.ToTag(ctx.Repo.Repository, tags[i])
}
+ ctx.SetTotalCountHeader(int64(total))
ctx.JSON(http.StatusOK, &apiTags)
}
diff --git a/routers/api/v1/repo/topic.go b/routers/api/v1/repo/topic.go
index a7c52e0bcc..fc277cb3fe 100644
--- a/routers/api/v1/repo/topic.go
+++ b/routers/api/v1/repo/topic.go
@@ -47,12 +47,13 @@ func ListTopics(ctx *context.APIContext) {
// "200":
// "$ref": "#/responses/TopicNames"
- topics, err := models.FindTopics(&models.FindTopicOptions{
+ opts := &models.FindTopicOptions{
ListOptions: utils.GetListOptions(ctx),
RepoID: ctx.Repo.Repository.ID,
- })
+ }
+
+ topics, total, err := models.FindTopics(opts)
if err != nil {
- log.Error("ListTopics failed: %v", err)
ctx.InternalServerError(err)
return
}
@@ -61,6 +62,8 @@ func ListTopics(ctx *context.APIContext) {
for i, topic := range topics {
topicNames[i] = topic.Name
}
+
+ ctx.SetTotalCountHeader(total)
ctx.JSON(http.StatusOK, map[string]interface{}{
"topics": topicNames,
})
@@ -164,15 +167,15 @@ func AddTopic(ctx *context.APIContext) {
}
// Prevent adding more topics than allowed to repo
- topics, err := models.FindTopics(&models.FindTopicOptions{
+ count, err := models.CountTopics(&models.FindTopicOptions{
RepoID: ctx.Repo.Repository.ID,
})
if err != nil {
- log.Error("AddTopic failed: %v", err)
+ log.Error("CountTopics failed: %v", err)
ctx.InternalServerError(err)
return
}
- if len(topics) >= 25 {
+ if count >= 25 {
ctx.JSON(http.StatusUnprocessableEntity, map[string]interface{}{
"message": "Exceeding maximum allowed topics per repo.",
})
@@ -269,21 +272,13 @@ func TopicSearch(ctx *context.APIContext) {
// "403":
// "$ref": "#/responses/forbidden"
- if ctx.User == nil {
- ctx.Error(http.StatusForbidden, "UserIsNil", "Only owners could change the topics.")
- return
+ opts := &models.FindTopicOptions{
+ Keyword: ctx.FormString("q"),
+ ListOptions: utils.GetListOptions(ctx),
}
- kw := ctx.FormString("q")
-
- listOptions := utils.GetListOptions(ctx)
-
- topics, err := models.FindTopics(&models.FindTopicOptions{
- Keyword: kw,
- ListOptions: listOptions,
- })
+ topics, total, err := models.FindTopics(opts)
if err != nil {
- log.Error("SearchTopics failed: %v", err)
ctx.InternalServerError(err)
return
}
@@ -292,6 +287,8 @@ func TopicSearch(ctx *context.APIContext) {
for i, topic := range topics {
topicResponses[i] = convert.ToTopicResponse(topic)
}
+
+ ctx.SetTotalCountHeader(total)
ctx.JSON(http.StatusOK, map[string]interface{}{
"topics": topicResponses,
})