add a new branchTagCount

This commit is contained in:
hang 2021-10-14 11:10:03 +08:00
parent a6ac790d1a
commit 6576006a78
4 changed files with 124 additions and 1 deletions

View File

@ -8,6 +8,12 @@ import (
"time"
)
//add
type RepoBranchAndTagCount struct {
BranchCount int `json:"branch_count"`
TagCount int64 `json:"tag_count"`
}
// Permission represents a set of permissions
type Permission struct {
Admin bool `json:"admin"`

View File

@ -12,6 +12,7 @@ import (
"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/routers/api/v1/utils"
)
@ -123,3 +124,46 @@ func GetTag(ctx *context.APIContext) {
ctx.JSON(http.StatusOK, convert.ToAnnotatedTag(ctx.Repo.Repository, tag, commit))
}
}
func GetRepoBranchAndTagCount(ctx *context.APIContext) {
// swagger:operation GET /repos/{owner}/{repo}/branch_tag_count repository repoBranchAndTagCountGet
// ---
// summary: Get branche and tag of a repository
// 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"
tagsCountTotal, err := ctx.Repo.GitRepo.GetTagCount()
if err != nil {
ctx.Error(http.StatusInternalServerError, "GetTagCount", err)
return
}
repo := ctx.Repo.Repository
branches, err := repo_module.GetBranches(repo)
if err != nil {
ctx.ServerError("GetBranches", err)
return
}
var branchCount int
for range branches {
branchCount += 1
}
result := api.RepoBranchAndTagCount{
BranchCount: branchCount,
TagCount: tagsCountTotal,
}
ctx.JSON(http.StatusOK, result)
}

View File

@ -79,6 +79,13 @@ type swaggerResponseTag struct {
Body api.Tag `json:"body"`
}
// RepoBranchAndTagCount
// swagger:response RepoBranchAndTagCount
type swaggerResponseRepoBranchAndTagCount struct {
// in:body
Body api.RepoBranchAndTagCount `json:"body"`
}
// AnnotatedTag
// swagger:response AnnotatedTag
type swaggerResponseAnnotatedTag struct {

View File

@ -2363,6 +2363,39 @@
}
}
},
"/repos/{owner}/{repo}/branch_tag_count": {
"get": {
"produces": [
"application/json"
],
"tags": [
"repository"
],
"summary": "Get branche and tag of a repository",
"operationId": "repoBranchAndTagCountGet",
"parameters": [
{
"type": "string",
"description": "owner of the repo",
"name": "owner",
"in": "path",
"required": true
},
{
"type": "string",
"description": "name of the repo",
"name": "repo",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"$ref": "#/responses/RepoBranchAndTagCount"
}
}
}
},
"/repos/{owner}/{repo}/branches": {
"get": {
"produces": [
@ -14679,6 +14712,11 @@
"type": "string",
"x-go-name": "Body"
},
"changed_files": {
"type": "integer",
"format": "int64",
"x-go-name": "ChangedFiles"
},
"closed_at": {
"type": "string",
"format": "date-time",
@ -14689,6 +14727,11 @@
"format": "int64",
"x-go-name": "Comments"
},
"commit_num": {
"type": "integer",
"format": "int64",
"x-go-name": "CommitNum"
},
"created_at": {
"type": "string",
"format": "date-time",
@ -15033,6 +15076,23 @@
},
"x-go-package": "code.gitea.io/gitea/modules/structs"
},
"RepoBranchAndTagCount": {
"description": "add",
"type": "object",
"properties": {
"branch_count": {
"type": "integer",
"format": "int64",
"x-go-name": "BranchCount"
},
"tag_count": {
"type": "integer",
"format": "int64",
"x-go-name": "TagCount"
}
},
"x-go-package": "code.gitea.io/gitea/modules/structs"
},
"RepoCommit": {
"type": "object",
"title": "RepoCommit contains information of a commit in the context of a repository.",
@ -16399,6 +16459,12 @@
}
}
},
"RepoBranchAndTagCount": {
"description": "RepoBranchAndTagCount",
"schema": {
"$ref": "#/definitions/RepoBranchAndTagCount"
}
},
"Repository": {
"description": "Repository",
"schema": {
@ -16724,4 +16790,4 @@
"TOTPHeader": []
}
]
}
}