summaryrefslogtreecommitdiffstats
path: root/routers/api/v1/repo/branch.go
diff options
context:
space:
mode:
authorAntoine GIRARD <sapk@sapk.fr>2016-01-15 19:24:03 +0100
committerAntoine GIRARD <sapk@sapk.fr>2016-01-28 20:51:19 +0100
commitc11c3b6c1125c8de1f86ea4d41eb88728d8e0b48 (patch)
tree051061e60ff43c1e740c9819a16e5ace15a38e1a /routers/api/v1/repo/branch.go
parent566163ab8257ba2b828985c2cc00f705341ba73f (diff)
downloadgitea-c11c3b6c1125c8de1f86ea4d41eb88728d8e0b48.tar.gz
gitea-c11c3b6c1125c8de1f86ea4d41eb88728d8e0b48.zip
Near ready
Diffstat (limited to 'routers/api/v1/repo/branch.go')
-rw-r--r--routers/api/v1/repo/branch.go52
1 files changed, 52 insertions, 0 deletions
diff --git a/routers/api/v1/repo/branch.go b/routers/api/v1/repo/branch.go
new file mode 100644
index 0000000000..ceff669656
--- /dev/null
+++ b/routers/api/v1/repo/branch.go
@@ -0,0 +1,52 @@
+// Copyright 2014 The Gogs Authors. All rights reserved.
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
+package repo
+
+import (
+ //TODO change for merge
+ api "github.com/gogits/go-gogs-client"
+
+ "github.com/gogits/gogs/modules/middleware"
+ "github.com/gogits/gogs/routers/api/v1/convert"
+)
+
+//TODO add to github.com/gogits/go-gogs-client
+// https://github.com/gogits/go-gogs-client/wiki/Repositories#get-branch
+func GetBranch(ctx *middleware.Context) {
+ branch, err := ctx.Repo.Repository.GetBranch(ctx.Params(":id"))
+ if err != nil {
+ //TODO handle error
+ return
+ }
+ c, err := branch.GetCommit()
+ if err != nil {
+ //TODO handle error
+ return
+ }
+ ctx.JSON(200, convert.ToApiBranch(branch,c))
+}
+
+//TODO add to github.com/gogits/go-gogs-client
+// https://github.com/gogits/go-gogs-client/wiki/Repositories#list-branches
+func ListBranches(ctx *middleware.Context) {
+
+
+ Branches, err := ctx.Repo.Repository.GetBranches()
+ if err != nil {
+ //TODO handle error
+ return
+ }
+ apiBranches := make([]*api.Branch, len(Branches))
+ for i := range Branches {
+ c, err := Branches[i].GetCommit()
+ if err != nil {
+ //TODO handle error
+ continue
+ }
+ apiBranches[i] = convert.ToApiBranch(Branches[i],c)
+ }
+
+ ctx.JSON(200, &apiBranches)
+}