You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

branch.go 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // Copyright 2016 The Gogs Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package repo
  5. import (
  6. api "code.gitea.io/sdk/gitea"
  7. "code.gitea.io/gitea/modules/context"
  8. "code.gitea.io/gitea/routers/api/v1/convert"
  9. )
  10. // GetBranch get a branch of a repository
  11. // see https://github.com/gogits/go-gogs-client/wiki/Repositories#get-branch
  12. func GetBranch(ctx *context.APIContext) {
  13. branch, err := ctx.Repo.Repository.GetBranch(ctx.Params(":branchname"))
  14. if err != nil {
  15. ctx.Error(500, "GetBranch", err)
  16. return
  17. }
  18. c, err := branch.GetCommit()
  19. if err != nil {
  20. ctx.Error(500, "GetCommit", err)
  21. return
  22. }
  23. ctx.JSON(200, convert.ToBranch(branch, c))
  24. }
  25. // ListBranches list all the branches of a repository
  26. // see https://github.com/gogits/go-gogs-client/wiki/Repositories#list-branches
  27. func ListBranches(ctx *context.APIContext) {
  28. branches, err := ctx.Repo.Repository.GetBranches()
  29. if err != nil {
  30. ctx.Error(500, "GetBranches", err)
  31. return
  32. }
  33. apiBranches := make([]*api.Branch, len(branches))
  34. for i := range branches {
  35. c, err := branches[i].GetCommit()
  36. if err != nil {
  37. ctx.Error(500, "GetCommit", err)
  38. return
  39. }
  40. apiBranches[i] = convert.ToBranch(branches[i], c)
  41. }
  42. ctx.JSON(200, &apiBranches)
  43. }