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

branch.go 1.7 kB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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 "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. // Getting the branch requested
  14. branch, err := ctx.Repo.Repository.GetBranch(ctx.Params(":branchname"))
  15. if err != nil {
  16. ctx.APIError(500, "Repository.GetBranch", err)
  17. return
  18. }
  19. // Getting the last commit of the branch
  20. c, err := branch.GetCommit()
  21. if err != nil {
  22. ctx.APIError(500, "Branch.GetCommit", err)
  23. return
  24. }
  25. // Converting to API format and send payload
  26. ctx.JSON(200, convert.ToApiBranch(branch,c))
  27. }
  28. // Temporary: https://gist.github.com/sapk/df64347ff218baf4a277#list-branches
  29. // https://github.com/gogits/go-gogs-client/wiki/Repositories-Branches#list-branches
  30. func ListBranches(ctx *middleware.Context) {
  31. // Listing of branches
  32. Branches, err := ctx.Repo.Repository.GetBranches()
  33. if err != nil {
  34. ctx.APIError(500, "Repository.GetBranches", err)
  35. return
  36. }
  37. // Getting the last commit of each branch
  38. apiBranches := make([]*api.Branch, len(Branches))
  39. for i := range Branches {
  40. c, err := Branches[i].GetCommit()
  41. if err != nil {
  42. ctx.APIError(500, "Branch.GetCommit", err)
  43. return
  44. }
  45. // Converting to API format
  46. apiBranches[i] = convert.ToApiBranch(Branches[i],c)
  47. }
  48. // Sending the payload
  49. ctx.JSON(200, &apiBranches)
  50. }