|
@@ -0,0 +1,52 @@
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+package repo
|
|
|
+
|
|
|
+import (
|
|
|
+
|
|
|
+ api "github.com/gogits/go-gogs-client"
|
|
|
+
|
|
|
+ "github.com/gogits/gogs/modules/middleware"
|
|
|
+ "github.com/gogits/gogs/routers/api/v1/convert"
|
|
|
+)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+func GetBranch(ctx *middleware.Context) {
|
|
|
+ branch, err := ctx.Repo.Repository.GetBranch(ctx.Params(":id"))
|
|
|
+ if err != nil {
|
|
|
+
|
|
|
+ return
|
|
|
+ }
|
|
|
+ c, err := branch.GetCommit()
|
|
|
+ if err != nil {
|
|
|
+
|
|
|
+ return
|
|
|
+ }
|
|
|
+ ctx.JSON(200, convert.ToApiBranch(branch,c))
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+func ListBranches(ctx *middleware.Context) {
|
|
|
+
|
|
|
+
|
|
|
+ Branches, err := ctx.Repo.Repository.GetBranches()
|
|
|
+ if err != nil {
|
|
|
+
|
|
|
+ return
|
|
|
+ }
|
|
|
+ apiBranches := make([]*api.Branch, len(Branches))
|
|
|
+ for i := range Branches {
|
|
|
+ c, err := Branches[i].GetCommit()
|
|
|
+ if err != nil {
|
|
|
+
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ apiBranches[i] = convert.ToApiBranch(Branches[i],c)
|
|
|
+ }
|
|
|
+
|
|
|
+ ctx.JSON(200, &apiBranches)
|
|
|
+}
|