新增:获取分支、标签数量接口

This commit is contained in:
yystopf 2022-12-29 15:52:38 +08:00
parent f625463cf9
commit 2fb40f7877
3 changed files with 28 additions and 2 deletions

View File

@ -24,3 +24,8 @@ type TagCommit struct {
Author *gitea_api.CommitUser `json:"author"`
Message string `json:"message"`
}
type RepoBranchAndTagCount struct {
BranchCount int `json:"branch_count"`
TagCount int `json:"tag_count"`
}

View File

@ -68,6 +68,7 @@ func Routers(ctx gocontext.Context) *web.Route {
m.Post("/transfer", reqOwner(), bind(gitea_api.TransferRepoOption{}), repo.Transfer)
m.Get("/branch_name_set", context.ReferencesGitRepo(), repo.BranchNameSet)
m.Get("/tag_name_set", context.ReferencesGitRepo(), repo.TagNameSet)
m.Get("/branch_tag_count", context.ReferencesGitRepo(), repo.BranchTagCount)
m.Group("/branches", func() {
m.Get("/branches_slice", context.ReferencesGitRepo(), repo.ListBranchesSlice)
}, reqRepoReader(unit_model.TypeCode))

View File

@ -10,7 +10,7 @@ import (
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/routers/api/v1/utils"
"code.gitlink.org.cn/Gitlink/gitea_hat.git/modules/convert"
"code.gitlink.org.cn/Gitlink/gitea_hat.git/modules/structs"
hat_api "code.gitlink.org.cn/Gitlink/gitea_hat.git/modules/structs"
)
func ListTags(ctx *context.APIContext) {
@ -22,7 +22,7 @@ func ListTags(ctx *context.APIContext) {
return
}
apiTags := make([]*structs.Tag, len(tags))
apiTags := make([]*hat_api.Tag, len(tags))
for i := range tags {
convertTag, err := convert.ToTag(ctx.Repo.Repository, ctx.Repo.GitRepo, tags[i])
if err != nil {
@ -44,6 +44,26 @@ func ListTags(ctx *context.APIContext) {
ctx.JSON(http.StatusOK, &apiTags)
}
func BranchTagCount(ctx *context.APIContext) {
_, tagsTotal, err := ctx.Repo.GitRepo.GetTagInfos(0, 0)
if err != nil {
ctx.Error(http.StatusInternalServerError, "GetTagInfos", err)
return
}
_, branchesTotal, err := ctx.Repo.GitRepo.GetBranchNames(0, 0)
if err != nil {
ctx.Error(http.StatusInternalServerError, "GetBrancheNames", err)
return
}
result := hat_api.RepoBranchAndTagCount{
BranchCount: branchesTotal,
TagCount: tagsTotal,
}
ctx.JSON(http.StatusOK, result)
}
func BranchNameSet(ctx *context.APIContext) {
searchName := ctx.Params("name")