diff --git a/modules/structs/repo_tag.go b/modules/structs/repo_tag.go index f360b4d32..e6dc90c0b 100644 --- a/modules/structs/repo_tag.go +++ b/modules/structs/repo_tag.go @@ -53,3 +53,7 @@ type RepoBranchAndTagCount struct { BranchCount int `json:"branch_count"` TagCount int `json:"tag_count"` } + +type BranchNameSet struct { + BranchName []*string `json:"branch_name"` +} diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go index 17f95d016..bbaa465c7 100644 --- a/routers/api/v1/api.go +++ b/routers/api/v1/api.go @@ -839,7 +839,7 @@ func Routes() *web.Route { m.Get("/*", repo.GetReadmeContentsByPath) }) m.Get("/commits_slice", repo.GetAllCommitsSliceByTime) - // m.Get("/branchtagcount", repo.BranchTagCount) + m.Get("/branch_name_set", repo.BranchNameSet) m.Group("/branch_tag_count", func() { m.Get("", repo.BranchTagCount) }, reqRepoReader(models.UnitTypeCode), context.ReferencesGitRepo(true)) diff --git a/routers/api/v1/repo/tag.go b/routers/api/v1/repo/tag.go index 33a0a5c6b..3ad3ed0a0 100644 --- a/routers/api/v1/repo/tag.go +++ b/routers/api/v1/repo/tag.go @@ -14,6 +14,7 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/convert" + "code.gitea.io/gitea/modules/log" repo_module "code.gitea.io/gitea/modules/repository" api "code.gitea.io/gitea/modules/structs" "code.gitea.io/gitea/modules/web" @@ -306,7 +307,7 @@ func BranchTagCount(ctx *context.APIContext) { return } repo := ctx.Repo.Repository - _, countAll, err := repo_module.GetBranches(repo, -1, -1) //get count of the branch + _, countAll, err := repo_module.GetBranches(repo, 0, 0) //get count of the branch if err != nil { ctx.ServerError("GetBranches", err) return @@ -317,3 +318,49 @@ func BranchTagCount(ctx *context.APIContext) { } ctx.JSON(http.StatusOK, result) } + +func BranchNameSet(ctx *context.APIContext) { + // swagger:operation GET /repos/{owner}/{repo}/branch_name_set repository repoBranchNameSet + // --- + // summary: List a repository's branch name*** + // 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/BranchNameSet" + + repo := ctx.Repo.Repository + branches, _, err := repo_module.GetBranches(repo, 0, 0) //get count of the branch + if err != nil { + ctx.ServerError("GetBranches", err) + return + } + + var branchNameSet = make([]*string, 0) + + // var branchNameSet [len(branches)]string + for _, branch := range branches { + + log.Info("branches is \n", branch.Name) + branchNameSet = append(branchNameSet, &branch.Name) + + } + + result := api.BranchNameSet{ + BranchName: branchNameSet, + } + + ctx.JSON(http.StatusOK, result) + +} diff --git a/routers/api/v1/swagger/repo.go b/routers/api/v1/swagger/repo.go index 0226ee205..d2448a0ae 100644 --- a/routers/api/v1/swagger/repo.go +++ b/routers/api/v1/swagger/repo.go @@ -72,6 +72,12 @@ type swaggerResponseRepoBranchAndTagCount struct { Body api.RepoBranchAndTagCount `json:"body"` } +// BranchNameSet +// swagger:response BranchNameSet +type swaggerResponseBranchNameSet struct { + Body api.BranchNameSet `json:"body"` +} + // TagList // swagger:response TagList type swaggerResponseTagList struct { diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index 9c81d080c..423bcac28 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -2424,6 +2424,39 @@ } } }, + "/repos/{owner}/{repo}/branch_name_set": { + "get": { + "produces": [ + "application/json" + ], + "tags": [ + "repository" + ], + "summary": "List a repository's branch name***", + "operationId": "repoBranchNameSet", + "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/BranchNameSet" + } + } + } + }, "/repos/{owner}/{repo}/branch_protections": { "get": { "produces": [ @@ -13037,6 +13070,19 @@ }, "x-go-package": "code.gitea.io/gitea/modules/structs" }, + "BranchNameSet": { + "type": "object", + "properties": { + "branch_name": { + "type": "array", + "items": { + "type": "string" + }, + "x-go-name": "BranchName" + } + }, + "x-go-package": "code.gitea.io/gitea/modules/structs" + }, "BranchProtection": { "description": "BranchProtection represents a branch protection for a repository", "type": "object", @@ -18331,6 +18377,15 @@ } } }, + "BranchNameSet": { + "description": "BranchNameSet", + "schema": { + "$ref": "#/definitions/BranchNameSet" + }, + "headers": { + "body": {} + } + }, "BranchProtection": { "description": "BranchProtection", "schema": {