add: tags list page info
This commit is contained in:
parent
d78a760be7
commit
15882844c6
|
@ -186,6 +186,16 @@ func (repo *Repository) GetTag(name string) (*Tag, error) {
|
|||
return tag, nil
|
||||
}
|
||||
|
||||
func (repo *Repository) GetTagCount() (int64, error) {
|
||||
stdout, err := NewCommand("tag").RunInDir(repo.Path)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
tagNames := strings.Split(strings.TrimRight(stdout, "\n"), "\n")
|
||||
return int64(len(tagNames)), nil
|
||||
}
|
||||
|
||||
// GetTagInfos returns all tag infos of the repository.
|
||||
func (repo *Repository) GetTagInfos(page, pageSize int) ([]*Tag, error) {
|
||||
// TODO this a slow implementation, makes one git command per tag
|
||||
|
|
|
@ -5,7 +5,10 @@
|
|||
package repo
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
"code.gitea.io/gitea/modules/convert"
|
||||
|
@ -56,6 +59,22 @@ func ListTags(ctx *context.APIContext) {
|
|||
apiTags[i] = convert.ToTag(ctx.Repo.Repository, tags[i])
|
||||
}
|
||||
|
||||
tagsCountTotal, err := ctx.Repo.GitRepo.GetTagCount()
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "GetTagCount", err)
|
||||
return
|
||||
}
|
||||
|
||||
pageCount := int(math.Ceil(float64(tagsCountTotal) / float64(listOpts.PageSize)))
|
||||
ctx.Header().Set("X-Page", strconv.Itoa(listOpts.Page))
|
||||
ctx.Header().Set("X-PerPage", strconv.Itoa(listOpts.PageSize))
|
||||
ctx.Header().Set("X-Total", strconv.FormatInt(tagsCountTotal, 10))
|
||||
ctx.Header().Set("X-PageCount", strconv.Itoa(pageCount))
|
||||
ctx.Header().Set("X-HasMore", strconv.FormatBool(listOpts.Page < pageCount))
|
||||
|
||||
ctx.SetLinkHeader(int(tagsCountTotal), listOpts.PageSize)
|
||||
ctx.Header().Set("X-Total-Count", fmt.Sprintf("%d", tagsCountTotal))
|
||||
|
||||
ctx.JSON(http.StatusOK, &apiTags)
|
||||
}
|
||||
|
||||
|
|
|
@ -53,6 +53,21 @@ type swaggerResponseBranchProtectionList struct {
|
|||
// TagList
|
||||
// swagger:response TagList
|
||||
type swaggerResponseTagList struct {
|
||||
// The current page
|
||||
Page int `json:"X-Page"`
|
||||
|
||||
// Commits per page
|
||||
PerPage int `json:"X-PerPage"`
|
||||
|
||||
// Total commit count
|
||||
Total int `json:"X-Total"`
|
||||
|
||||
// Total number of pages
|
||||
PageCount int `json:"X-PageCount"`
|
||||
|
||||
// True if there is another page
|
||||
HasMore bool `json:"X-HasMore"`
|
||||
|
||||
// in:body
|
||||
Body []api.Tag `json:"body"`
|
||||
}
|
||||
|
|
|
@ -16379,6 +16379,32 @@
|
|||
"items": {
|
||||
"$ref": "#/definitions/Tag"
|
||||
}
|
||||
},
|
||||
"headers": {
|
||||
"X-HasMore": {
|
||||
"type": "boolean",
|
||||
"description": "True if there is another page"
|
||||
},
|
||||
"X-Page": {
|
||||
"type": "integer",
|
||||
"format": "int64",
|
||||
"description": "The current page"
|
||||
},
|
||||
"X-PageCount": {
|
||||
"type": "integer",
|
||||
"format": "int64",
|
||||
"description": "Total number of pages"
|
||||
},
|
||||
"X-PerPage": {
|
||||
"type": "integer",
|
||||
"format": "int64",
|
||||
"description": "Commits per page"
|
||||
},
|
||||
"X-Total": {
|
||||
"type": "integer",
|
||||
"format": "int64",
|
||||
"description": "Total commit count"
|
||||
}
|
||||
}
|
||||
},
|
||||
"Team": {
|
||||
|
|
Loading…
Reference in New Issue