Merge pull request '[API]Add:count' (#27) from wonderful/gitea-1156:develop into develop
This commit is contained in:
commit
fc715cd29b
|
@ -765,6 +765,9 @@ func Routes() *web.Route {
|
|||
m.Group("/contributors", func() {
|
||||
m.Get("", report.GetContributors) //获取仓库的所有构建者信息 ****
|
||||
})
|
||||
m.Group("/count", func() {
|
||||
m.Get("", viewfile.GetCommitCount) //****
|
||||
})
|
||||
m.Group("/hooks", func() {
|
||||
m.Combo("").Get(repo.ListHooks).
|
||||
Post(bind(api.CreateHookOption{}), repo.CreateHook)
|
||||
|
|
|
@ -359,3 +359,10 @@ type swaggerResponseContributorsDtoList struct {
|
|||
// in: body
|
||||
Body []models.ContributorsDto `json:"body"`
|
||||
}
|
||||
|
||||
// CountDTO
|
||||
// swagger:response CountDTO
|
||||
type swaggerCountDTO struct {
|
||||
//in: body
|
||||
Body viewfile.CountDTO `json:"body"`
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ import (
|
|||
"code.gitea.io/gitea/modules/context"
|
||||
"code.gitea.io/gitea/modules/git"
|
||||
"code.gitea.io/gitea/modules/repofiles"
|
||||
repo_module "code.gitea.io/gitea/modules/repository"
|
||||
)
|
||||
|
||||
func FindFiles(ctx *context.APIContext) {
|
||||
|
@ -217,3 +218,117 @@ func LatestRelease(ctx *context.APIContext) {
|
|||
ctx.JSON(http.StatusOK, release)
|
||||
|
||||
}
|
||||
|
||||
type CountDTO struct {
|
||||
Branch struct {
|
||||
CommitCount int64 `json:"commit_count"`
|
||||
BranchName string `json:"branch_name"`
|
||||
} `json:"branch"`
|
||||
ReleaseCount int64 `json:"release_count"`
|
||||
TagCount int64 `json:"tag_count"`
|
||||
BranchCount int64 `json:"branch_count"`
|
||||
}
|
||||
|
||||
func GetCommitCount(ctx *context.APIContext) {
|
||||
// swagger:operation GET /repos/{owner}/{repo}/count repository Count
|
||||
// ---
|
||||
// summary: Get commit quantity by branch which is a custom interface ****
|
||||
// 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
|
||||
// - name: ref
|
||||
// in: query
|
||||
// description: "The name of the commit/branch/tag. Default the repository’s default branch (usually master)"
|
||||
// type: string
|
||||
// required: false
|
||||
// responses:
|
||||
// "200":
|
||||
// "$ref": "#/responses/CountDTO"
|
||||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
|
||||
ref := ctx.QueryTrim("ref") // determine whether the ref empty
|
||||
if ref == "" {
|
||||
ref = ctx.Params(":ref")
|
||||
if ref == "" {
|
||||
ref = ctx.Repo.Repository.DefaultBranch
|
||||
}
|
||||
}
|
||||
var err error
|
||||
if ctx.Repo.GitRepo == nil {
|
||||
|
||||
repoPath := models.RepoPath(ctx.Repo.Owner.Name, ctx.Repo.Repository.Name)
|
||||
ctx.Repo.GitRepo, err = git.OpenRepository(repoPath)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "RepoRef Invalid repo"+repoPath, err)
|
||||
return
|
||||
|
||||
}
|
||||
defer func() {
|
||||
|
||||
// If it's been set to nil then assume someone else has closed it
|
||||
if ctx.Repo.GitRepo != nil {
|
||||
ctx.Repo.GitRepo.Close()
|
||||
}
|
||||
}()
|
||||
}
|
||||
//Get the commit object of the ref
|
||||
commit, err2 := ctx.Repo.GitRepo.GetCommit(ref)
|
||||
if err2 != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "ctx.Repo.GitRepo.GetCommit", err)
|
||||
return
|
||||
}
|
||||
|
||||
ctx.Repo.Commit = commit
|
||||
// Get the count of the commit
|
||||
CommitCount, err := ctx.Repo.Commit.CommitsCount()
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "Get the CommitsCount", err)
|
||||
return
|
||||
}
|
||||
|
||||
opts := models.FindReleasesOptions{
|
||||
ListOptions: models.ListOptions{
|
||||
Page: 1,
|
||||
PageSize: 1000,
|
||||
},
|
||||
|
||||
IncludeDrafts: true,
|
||||
IncludeTags: true,
|
||||
}
|
||||
// Get the release object of the ref
|
||||
ReleaseCount, err3 := models.GetReleaseCountByRepoID(ctx.Repo.Repository.ID, opts)
|
||||
if err3 != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "GetReleaseCountByRepoId", err)
|
||||
return
|
||||
}
|
||||
|
||||
branches, _, err := repo_module.GetBranchesNoLimit(ctx.Repo.Repository)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "GetBranches", err)
|
||||
return
|
||||
}
|
||||
// Get the tag object
|
||||
Tags, err4 := ctx.Repo.GitRepo.GetTags()
|
||||
if err4 != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "GetTags", err)
|
||||
return
|
||||
}
|
||||
countDTO := &CountDTO{}
|
||||
countDTO.Branch.CommitCount = CommitCount
|
||||
countDTO.Branch.BranchName = ref
|
||||
countDTO.BranchCount = int64(len(branches))
|
||||
countDTO.TagCount = int64(len(Tags))
|
||||
countDTO.ReleaseCount = ReleaseCount
|
||||
ctx.JSON(http.StatusOK, countDTO)
|
||||
}
|
||||
|
|
|
@ -3621,6 +3621,48 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"/repos/{owner}/{repo}/count": {
|
||||
"get": {
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"repository"
|
||||
],
|
||||
"summary": "Get commit quantity by branch \twhich is a custom interface ****",
|
||||
"operationId": "Count",
|
||||
"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
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "The name of the commit/branch/tag. Default the repository’s default branch (usually master)",
|
||||
"name": "ref",
|
||||
"in": "query"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"$ref": "#/responses/CountDTO"
|
||||
},
|
||||
"404": {
|
||||
"$ref": "#/responses/notFound"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/repos/{owner}/{repo}/editorconfig/{filepath}": {
|
||||
"get": {
|
||||
"produces": [
|
||||
|
@ -13415,6 +13457,42 @@
|
|||
},
|
||||
"x-go-package": "code.gitea.io/gitea/models"
|
||||
},
|
||||
"CountDTO": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"branch": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"branch_name": {
|
||||
"type": "string",
|
||||
"x-go-name": "BranchName"
|
||||
},
|
||||
"commit_count": {
|
||||
"type": "integer",
|
||||
"format": "int64",
|
||||
"x-go-name": "CommitCount"
|
||||
}
|
||||
},
|
||||
"x-go-name": "Branch"
|
||||
},
|
||||
"branch_count": {
|
||||
"type": "integer",
|
||||
"format": "int64",
|
||||
"x-go-name": "BranchCount"
|
||||
},
|
||||
"release_count": {
|
||||
"type": "integer",
|
||||
"format": "int64",
|
||||
"x-go-name": "ReleaseCount"
|
||||
},
|
||||
"tag_count": {
|
||||
"type": "integer",
|
||||
"format": "int64",
|
||||
"x-go-name": "TagCount"
|
||||
}
|
||||
},
|
||||
"x-go-package": "code.gitea.io/gitea/routers/api/v1/viewfile"
|
||||
},
|
||||
"CreateAccessTokenOption": {
|
||||
"description": "CreateAccessTokenOption options when create access token",
|
||||
"type": "object",
|
||||
|
@ -18261,6 +18339,12 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"CountDTO": {
|
||||
"description": "CountDTO",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/CountDTO"
|
||||
}
|
||||
},
|
||||
"CronList": {
|
||||
"description": "CronList",
|
||||
"schema": {
|
||||
|
|
Loading…
Reference in New Issue