branch.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. api "github.com/gogits/go-gogs-client"
  7. "github.com/gogits/gogs/modules/middleware"
  8. "github.com/gogits/gogs/routers/api/v1/convert"
  9. )
  10. // Temporary: https://gist.github.com/sapk/df64347ff218baf4a277#get-a-branch
  11. // https://github.com/gogits/go-gogs-client/wiki/Repositories-Branches#get-a-branch
  12. func GetBranch(ctx *middleware.Context) {
  13. branch, err := ctx.Repo.Repository.GetBranch(ctx.Params(":id"))
  14. if err != nil {
  15. //TODO handle error
  16. return
  17. }
  18. c, err := branch.GetCommit()
  19. if err != nil {
  20. //TODO handle error
  21. return
  22. }
  23. ctx.JSON(200, convert.ToApiBranch(branch,c))
  24. }
  25. // Temporary: https://gist.github.com/sapk/df64347ff218baf4a277#list-branches
  26. // https://github.com/gogits/go-gogs-client/wiki/Repositories-Branches#list-branches
  27. func ListBranches(ctx *middleware.Context) {
  28. Branches, err := ctx.Repo.Repository.GetBranches()
  29. if err != nil {
  30. //TODO handle error
  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. //TODO handle error
  38. continue
  39. }
  40. apiBranches[i] = convert.ToApiBranch(Branches[i],c)
  41. }
  42. ctx.JSON(200, &apiBranches)
  43. }