woodpecker/pkg/handler/builds.go

71 lines
1.5 KiB
Go
Raw Normal View History

2014-02-07 10:10:01 +00:00
package handler
import (
"net/http"
"github.com/drone/drone/pkg/database"
. "github.com/drone/drone/pkg/model"
)
2014-07-30 22:29:13 +00:00
type BuildResult struct {
Status string
}
2014-02-07 10:10:01 +00:00
// Returns the combined stdout / stderr for an individual Build.
func BuildOut(w http.ResponseWriter, r *http.Request, u *User, repo *Repo) error {
2014-04-06 22:03:51 +00:00
branch := r.FormValue("branch")
if branch == "" {
branch = "master"
}
2014-02-07 10:10:01 +00:00
hash := r.FormValue(":commit")
labl := r.FormValue(":label")
// get the commit from the database
commit, err := database.GetCommitBranchHash(branch, hash, repo.ID)
2014-02-07 10:10:01 +00:00
if err != nil {
return err
}
// get the build from the database
build, err := database.GetBuildSlug(labl, commit.ID)
if err != nil {
return err
}
return RenderText(w, build.Stdout, http.StatusOK)
}
2014-07-30 22:29:13 +00:00
// Returns the combined stdout / stderr for an individual Build.
func BuildStatus(w http.ResponseWriter, r *http.Request, repo *Repo) error {
branch := r.FormValue("branch")
if branch == "" {
branch = "master"
}
hash := r.FormValue(":commit")
labl := r.FormValue(":label")
// get the commit from the database
commit, err := database.GetCommitBranchHash(branch, hash, repo.ID)
if err != nil {
return err
}
// get the build from the database
build, err := database.GetBuildSlug(labl, commit.ID)
if err != nil {
return err
}
build_result := BuildResult{build.Status}
return RenderJson(w, build_result)
}
2014-02-07 10:10:01 +00:00
// Returns the gzipped stdout / stderr for an individual Build
func BuildOutGzip(w http.ResponseWriter, r *http.Request, u *User) error {
// TODO
return nil
}