woodpecker/server/builds.go

46 lines
879 B
Go
Raw Normal View History

2015-04-08 22:43:59 +00:00
package server
import (
"strconv"
"github.com/gin-gonic/gin"
)
// GetBuild accepts a request to retrieve a build
// from the datastore for the given repository and
// build number.
//
// GET /api/builds/:owner/:name/:number
//
func GetBuild(c *gin.Context) {
store := ToDatastore(c)
2015-04-08 22:43:59 +00:00
repo := ToRepo(c)
num, err := strconv.Atoi(c.Params.ByName("number"))
if err != nil {
c.Fail(400, err)
return
}
build, err := store.Build(repo.FullName, num)
2015-04-08 22:43:59 +00:00
if err != nil {
c.Fail(404, err)
} else {
c.JSON(200, build)
}
}
// GetBuild accepts a request to retrieve a list
// of builds from the datastore for the given repository.
//
// GET /api/builds/:owner/:name
//
func GetBuilds(c *gin.Context) {
store := ToDatastore(c)
2015-04-08 22:43:59 +00:00
repo := ToRepo(c)
builds, err := store.BuildList(repo.FullName)
2015-04-08 22:43:59 +00:00
if err != nil {
c.Fail(404, err)
} else {
c.JSON(200, builds)
}
}