Merge pull request '新增/{repo}/branch_tag_count接口' (#32) from wonderful/gitea-1120-rc1:fix_pulls into develop

This commit is contained in:
jasder 2021-10-14 11:39:40 +08:00
commit 987ac773f6
5 changed files with 123 additions and 4 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

@ -702,7 +702,6 @@ func RegisterRoutes(m *macaron.Macaron) {
m.Get("/*", viewfile.ReadmeByPath) // reqRepoReader(models.UnitTypeCode),
})
m.Group("/count", func() {
m.Get("", viewfile.CommitCount) //****
})
@ -717,7 +716,6 @@ func RegisterRoutes(m *macaron.Macaron) {
m.Group("/contributors", func() {
m.Get("", report.GetContributors) //获取仓库的所有构建者信息 ****
})
m.Combo("").Get(reqAnyRepoReader(), repo.Get).
Delete(reqToken(), reqOwner(), repo.Delete).
Patch(reqToken(), reqAdmin(), bind(api.EditRepoOption{}), context.RepoRef(), repo.Edit)
@ -725,7 +723,6 @@ func RegisterRoutes(m *macaron.Macaron) {
m.Combo("/notifications").
Get(reqToken(), notify.ListRepoNotifications).
Put(reqToken(), notify.ReadRepoNotifications)
m.Group("/wikies", func() {
m.Combo("").Get(repo.WikiList).
Post(bind(api.WikiOption{}), repo.CreateWiki)
@ -809,6 +806,9 @@ func RegisterRoutes(m *macaron.Macaron) {
m.Group("/tags", func() {
m.Get("", repo.ListTags)
}, reqRepoReader(models.UnitTypeCode), context.ReferencesGitRepo(true))
m.Group("/branch_tag_count", func() {
m.Get("", repo.GetRepoBranchAndTagCount)
}, reqRepoReader(models.UnitTypeCode), context.ReferencesGitRepo(true))
m.Group("/keys", func() {
m.Combo("").Get(repo.ListDeployKeys).
Post(bind(api.CreateKeyOption{}), repo.CreateDeployKey)

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,42 @@ 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
}
result := api.RepoBranchAndTagCount{
BranchCount: len(branches),
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": []
}
]
}
}