12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- package repo
- import (
- api "github.com/gogits/go-gogs-client"
- "github.com/gogits/gogs/models"
- "github.com/gogits/gogs/modules/context"
- "github.com/gogits/gogs/routers/api/v1/convert"
- )
- func GetBranch(ctx *context.APIContext) {
- branch, err := ctx.Repo.Repository.GetBranch(ctx.Params("*"))
- if err != nil {
- if models.IsErrBranchNotExist(err) {
- ctx.Error(404, "GetBranch", 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(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(branches[i], c)
- }
- ctx.JSON(200, &apiBranches)
- }
|