diff --git a/modules/structs/repo_tag.go b/modules/structs/repo_tag.go index 64fdff2..acc3ba1 100644 --- a/modules/structs/repo_tag.go +++ b/modules/structs/repo_tag.go @@ -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"` +} diff --git a/routers/hat/hat.go b/routers/hat/hat.go index 21722ca..48bc83d 100644 --- a/routers/hat/hat.go +++ b/routers/hat/hat.go @@ -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)) diff --git a/routers/hat/repo/tag.go b/routers/hat/repo/tag.go index 01ece2a..f92f23d 100644 --- a/routers/hat/repo/tag.go +++ b/routers/hat/repo/tag.go @@ -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")