|
-
-
-
-
-
- package repo
-
- import (
- "code.gitea.io/gitea/modules/context"
- "code.gitea.io/gitea/modules/git"
- api "code.gitea.io/gitea/modules/structs"
- "code.gitea.io/gitea/routers/api/v1/convert"
- )
-
-
- func GetBranch(ctx *context.APIContext) {
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- if ctx.Repo.TreePath != "" {
-
-
-
- ctx.NotFound()
- return
- }
- branch, err := ctx.Repo.Repository.GetBranch(ctx.Repo.BranchName)
- if err != nil {
- if git.IsErrBranchNotExist(err) {
- ctx.NotFound(err)
- } else {
- ctx.Error(500, "GetBranch", err)
- }
- return
- }
-
- c, err := branch.GetCommit()
- if err != nil {
- ctx.Error(500, "GetCommit", err)
- return
- }
-
- ctx.JSON(200, convert.ToBranch(ctx.Repo.Repository, branch, c))
- }
-
-
- func ListBranches(ctx *context.APIContext) {
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- branches, err := ctx.Repo.Repository.GetBranches()
- if err != nil {
- ctx.Error(500, "GetBranches", err)
- return
- }
-
- apiBranches := make([]*api.Branch, len(branches))
- for i := range branches {
- c, err := branches[i].GetCommit()
- if err != nil {
- ctx.Error(500, "GetCommit", err)
- return
- }
- apiBranches[i] = convert.ToBranch(ctx.Repo.Repository, branches[i], c)
- }
-
- ctx.JSON(200, &apiBranches)
- }
|