add:branch_tag_count

This commit is contained in:
hang 2021-11-22 09:49:23 +08:00
parent 3e44c82aea
commit b3399ea04d
6 changed files with 59 additions and 4 deletions

View File

@ -48,3 +48,8 @@ type CreateTagOption struct {
Message string `json:"message"`
Target string `json:"target"`
}
type RepoBranchAndTagCount struct {
BranchCount int `json:"branch_count"`
TagCount int `json:"tag_count"`
}

View File

@ -797,6 +797,10 @@ func Routes() *web.Route {
m.Get("/*", repo.GetReadmeContentsByPath)
})
m.Get("/commits_slice", repo.GetAllCommitsSliceByTime)
// m.Get("/branchtagcount", repo.BranchTagCount)
m.Group("/branch_tag_count", func() {
m.Get("", repo.BranchTagCount)
}, reqRepoReader(models.UnitTypeCode), context.ReferencesGitRepo(true))
m.Group("/tags", func() {
m.Get("", repo.ListTags)
m.Get("/*", repo.GetTag)

View File

@ -133,7 +133,7 @@ func ListPullRequests(ctx *context.APIContext) {
func GetPullRequest(ctx *context.APIContext) {
// swagger:operation GET /repos/{owner}/{repo}/pulls/{index} repository repoGetPullRequest
// ---
// summary: Get a pull request
// summary: Get a pull request ***
// produces:
// - application/json
// parameters:

View File

@ -14,6 +14,7 @@ import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/convert"
repo_module "code.gitea.io/gitea/modules/repository"
api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/web"
"code.gitea.io/gitea/routers/api/v1/utils"
@ -277,3 +278,42 @@ func DeleteTag(ctx *context.APIContext) {
ctx.Status(http.StatusNoContent)
}
func BranchTagCount(ctx *context.APIContext) {
// swagger:operation GET /repos/{owner}/{repo}/branch_tag_count repository repoBranchTagCount
// ---
// summary: List a repository's tags***
// produces:
// - application/json
// parameters:
// - name: owner
// in: path
// description: owner of the repo
// type: string
// required: true
// - name: repo
// in: path
// description: name of the repo
// type: string
// required: true
// responses:
// "200":
// "$ref": "#/responses/RepoBranchAndTagCount"
tags, err := ctx.Repo.GitRepo.GetTagInfos(0, 0) // tags info
if err != nil {
ctx.Error(http.StatusInternalServerError, "GetTags", err)
return
}
repo := ctx.Repo.Repository
_, countAll, err := repo_module.GetBranches(repo, -1, -1) //get count of the branch
if err != nil {
ctx.ServerError("GetBranches", err)
return
}
result := api.RepoBranchAndTagCount{
BranchCount: countAll,
TagCount: len(tags),
}
ctx.JSON(http.StatusOK, result)
}

View File

@ -64,6 +64,12 @@ type swaggerResponseWikiList struct {
Body api.WikiesResponse `json:"body"`
}
// RepoBranchAndTagCount
// swagger:response RepoBranchAndTagCount
type swaggerResponseRepoBranchAndTagCount struct {
Body api.RepoBranchAndTagCount `json:"body"`
}
// TagList
// swagger:response TagList
type swaggerResponseTagList struct {

View File

@ -2539,8 +2539,8 @@
"tags": [
"repository"
],
"summary": "Get branche and tag of a repository",
"operationId": "repoBranchAndTagCountGet",
"summary": "List a repository's tags***",
"operationId": "repoBranchTagCount",
"parameters": [
{
"type": "string",
@ -7271,7 +7271,7 @@
"tags": [
"repository"
],
"summary": "Get a pull request",
"summary": "Get a pull request ***",
"operationId": "repoGetPullRequest",
"parameters": [
{