新增:获取仓库commit总数、标签总数、发行版总数、分支总数接口
This commit is contained in:
parent
751f11ca09
commit
e0bd2cd8d7
|
@ -97,6 +97,9 @@ func Routers() *web.Route {
|
||||||
m.Group("/contributors", func() {
|
m.Group("/contributors", func() {
|
||||||
m.Get("", repo.GetContributors)
|
m.Get("", repo.GetContributors)
|
||||||
})
|
})
|
||||||
|
m.Group("/count", func() {
|
||||||
|
m.Get("", context.ReferencesGitRepo(), repo.GetCommitCount)
|
||||||
|
})
|
||||||
}, repoAssignment())
|
}, repoAssignment())
|
||||||
})
|
})
|
||||||
m.Post("/orgs", reqToken(), bind(gitea_api.CreateOrgOption{}), org.Create)
|
m.Post("/orgs", reqToken(), bind(gitea_api.CreateOrgOption{}), org.Create)
|
||||||
|
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"code.gitea.io/gitea/models"
|
||||||
admin_model "code.gitea.io/gitea/models/admin"
|
admin_model "code.gitea.io/gitea/models/admin"
|
||||||
access_model "code.gitea.io/gitea/models/perm/access"
|
access_model "code.gitea.io/gitea/models/perm/access"
|
||||||
repo_model "code.gitea.io/gitea/models/repo"
|
repo_model "code.gitea.io/gitea/models/repo"
|
||||||
|
@ -489,3 +490,63 @@ func GetContributors(ctx *context.APIContext) {
|
||||||
|
|
||||||
ctx.JSON(http.StatusOK, list)
|
ctx.JSON(http.StatusOK, list)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type CountDTO struct {
|
||||||
|
Branch CountDTOBranch `json:"branch"`
|
||||||
|
ReleaseCount int64 `json:"release_count"`
|
||||||
|
TagCount int64 `json:"tag_count"`
|
||||||
|
BranchCount int64 `json:"branch_count"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type CountDTOBranch struct {
|
||||||
|
CommitCount int64 `json:"commit_count"`
|
||||||
|
BranchName string `json:"branch_name"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetCommitCount(ctx *context.APIContext) {
|
||||||
|
ref := ctx.FormString("ref")
|
||||||
|
if ref == "" {
|
||||||
|
ref = ctx.Repo.Repository.DefaultBranch
|
||||||
|
}
|
||||||
|
|
||||||
|
commit, err := ctx.Repo.GitRepo.GetCommit(ref)
|
||||||
|
if err != nil {
|
||||||
|
ctx.Error(http.StatusInternalServerError, "GetCommit", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
commitCount, err := commit.CommitsCount()
|
||||||
|
if err != nil {
|
||||||
|
ctx.Error(http.StatusInternalServerError, "CommitsCount", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
releaseCount, err := models.GetReleaseCountByRepoID(ctx.Repo.Repository.ID, models.FindReleasesOptions{IncludeDrafts: true, IncludeTags: true})
|
||||||
|
if err != nil {
|
||||||
|
ctx.Error(http.StatusInternalServerError, "GetReleaseCountByRepoID", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
branches, _, err := ctx.Repo.GitRepo.GetBranchNames(0, 0)
|
||||||
|
if err != nil {
|
||||||
|
ctx.Error(http.StatusInternalServerError, "GetBranchNames", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
tags, err := ctx.Repo.GitRepo.GetTags(0, 0)
|
||||||
|
if err != nil {
|
||||||
|
ctx.Error(http.StatusInternalServerError, "GetTags", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.JSON(http.StatusOK, CountDTO{
|
||||||
|
Branch: CountDTOBranch{
|
||||||
|
CommitCount: commitCount,
|
||||||
|
BranchName: ref,
|
||||||
|
},
|
||||||
|
BranchCount: int64(len(branches)),
|
||||||
|
TagCount: int64(len(tags)),
|
||||||
|
ReleaseCount: releaseCount,
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue