branch.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // Copyright 2014 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. //TODO change for merge
  7. api "github.com/gogits/go-gogs-client"
  8. "github.com/gogits/gogs/modules/middleware"
  9. "github.com/gogits/gogs/routers/api/v1/convert"
  10. )
  11. //TODO add to github.com/gogits/go-gogs-client
  12. // https://github.com/gogits/go-gogs-client/wiki/Repositories#get-branch
  13. func GetBranch(ctx *middleware.Context) {
  14. branch, err := ctx.Repo.Repository.GetBranch(ctx.Params(":id"))
  15. if err != nil {
  16. //TODO handle error
  17. return
  18. }
  19. c, err := branch.GetCommit()
  20. if err != nil {
  21. //TODO handle error
  22. return
  23. }
  24. ctx.JSON(200, convert.ToApiBranch(branch,c))
  25. }
  26. //TODO add to github.com/gogits/go-gogs-client
  27. // https://github.com/gogits/go-gogs-client/wiki/Repositories#list-branches
  28. func ListBranches(ctx *middleware.Context) {
  29. Branches, err := ctx.Repo.Repository.GetBranches()
  30. if err != nil {
  31. //TODO handle error
  32. return
  33. }
  34. apiBranches := make([]*api.Branch, len(Branches))
  35. for i := range Branches {
  36. c, err := Branches[i].GetCommit()
  37. if err != nil {
  38. //TODO handle error
  39. continue
  40. }
  41. apiBranches[i] = convert.ToApiBranch(Branches[i],c)
  42. }
  43. ctx.JSON(200, &apiBranches)
  44. }