diff --git a/drone.go b/drone.go
index 95d131145..e8f92a7d6 100644
--- a/drone.go
+++ b/drone.go
@@ -79,15 +79,8 @@ func main() {
repo.GET("/builds", server.GetBuilds)
repo.GET("/builds/:number", server.GetBuild)
- //TODO repo.POST("/builds/:number", server.RestartBuild)
- //TODO repo.DELETE("/builds/:number", server.CancelBuild)
- repo.GET("/builds/:number/tasks", server.GetTasks)
- repo.GET("/builds/:number/tasks/:task", server.GetTask)
- repo.GET("/builds/:number/tasks/:task/log", server.GetTaskLogs)
-
- // repo.GET("/status/:number/status/:context", server.GetStatus)
- repo.GET("/status/:number", server.GetStatusList)
- repo.POST("/status/:number", server.PostStatus)
+ repo.GET("/logs/:number/:task", server.GetBuildLogs)
+ repo.POST("/status/:number", server.PostBuildStatus)
}
}
diff --git a/server/builds.go b/server/builds.go
index 0929617dc..23549ab5d 100644
--- a/server/builds.go
+++ b/server/builds.go
@@ -1,9 +1,12 @@
package server
import (
+ "io"
"strconv"
+ "github.com/drone/drone/common"
"github.com/gin-gonic/gin"
+ "github.com/gin-gonic/gin/binding"
)
// GetBuild accepts a request to retrieve a build
@@ -28,7 +31,7 @@ func GetBuild(c *gin.Context) {
}
}
-// GetBuild accepts a request to retrieve a list
+// GetBuilds accepts a request to retrieve a list
// of builds from the datastore for the given repository.
//
// GET /api/builds/:owner/:name
@@ -43,3 +46,52 @@ func GetBuilds(c *gin.Context) {
c.JSON(200, builds)
}
}
+
+// GetBuildLogs accepts a request to retrieve logs from the
+// datastore for the given repository, build and task
+// number.
+//
+// GET /api/repos/:owner/:name/logs/:number/:task
+//
+func GetBuildLogs(c *gin.Context) {
+ store := ToDatastore(c)
+ repo := ToRepo(c)
+ full, _ := strconv.ParseBool(c.Params.ByName("full"))
+ build, _ := strconv.Atoi(c.Params.ByName("number"))
+ task, _ := strconv.Atoi(c.Params.ByName("task"))
+
+ r, err := store.LogReader(repo.FullName, build, task)
+ if err != nil {
+ c.Fail(404, err)
+ } else if full {
+ io.Copy(c.Writer, r)
+ } else {
+ io.Copy(c.Writer, io.LimitReader(r, 2000000))
+ }
+}
+
+// PostBuildStatus accepts a request to create a new build
+// status. The created user status is returned in JSON
+// format if successful.
+//
+// POST /api/repos/:owner/:name/status/:number
+//
+func PostBuildStatus(c *gin.Context) {
+ store := ToDatastore(c)
+ repo := ToRepo(c)
+ num, err := strconv.Atoi(c.Params.ByName("number"))
+ if err != nil {
+ c.Fail(400, err)
+ return
+ }
+ in := &common.Status{}
+ if !c.BindWith(in, binding.JSON) {
+ c.AbortWithStatus(400)
+ return
+ }
+ if err := store.SetStatus(repo.Name, num, in); err != nil {
+ c.Fail(400, err)
+ } else {
+ c.JSON(201, in)
+ }
+}
diff --git a/server/repos.go b/server/repos.go
index 3d30850a9..8133f156c 100644
--- a/server/repos.go
+++ b/server/repos.go
@@ -234,6 +234,42 @@ func PostRepo(c *gin.Context) {
c.JSON(200, r)
}
+// Unubscribe accapets a request to unsubscribe the
+// currently authenticated user to the repository.
+//
+// DEL /api/subscribers/:owner/:name
+//
+func Unsubscribe(c *gin.Context) {
+ store := ToDatastore(c)
+ repo := ToRepo(c)
+ user := ToUser(c)
+
+ err := store.DelSubscriber(user.Login, repo.FullName)
+ if err != nil {
+ c.Fail(400, err)
+ } else {
+ c.Writer.WriteHeader(200)
+ }
+}
+
+// Subscribe accapets a request to subscribe the
+// currently authenticated user to the repository.
+//
+// POST /api/subscriber/:owner/:name
+//
+func Subscribe(c *gin.Context) {
+ store := ToDatastore(c)
+ repo := ToRepo(c)
+ user := ToUser(c)
+
+ err := store.SetSubscriber(user.Login, repo.FullName)
+ if err != nil {
+ c.Fail(400, err)
+ } else {
+ c.JSON(200, &common.Subscriber{Subscribed: true})
+ }
+}
+
// perms is a helper function that returns user permissions
// for a particular repository.
func perms(remote remote.Remote, u *common.User, r *common.Repo) *common.Perm {
diff --git a/server/static/index.html b/server/static/index.html
index 3cd12b6a8..9157f055c 100644
--- a/server/static/index.html
+++ b/server/static/index.html
@@ -27,7 +27,6 @@
-
@@ -37,4 +36,4 @@