Add status.json page

This commit is contained in:
Kirill Zaitsev 2014-07-31 02:29:13 +04:00
parent 4f0585bee3
commit 4f779ea920
3 changed files with 55 additions and 0 deletions

View file

@ -227,6 +227,7 @@ func setupHandlers() {
// handlers for repository, commits and build details // handlers for repository, commits and build details
m.Get("/:host/:owner/:name/commit/:commit/build/:label/out.txt", handler.RepoHandler(handler.BuildOut)) m.Get("/:host/:owner/:name/commit/:commit/build/:label/out.txt", handler.RepoHandler(handler.BuildOut))
m.Get("/:host/:owner/:name/commit/:commit/build/:label/status.json", handler.PublicHandler(handler.BuildStatus))
m.Post("/:host/:owner/:name/commit/:commit/build/:label/rebuild", handler.RepoAdminHandler(rebuild.CommitRebuild)) m.Post("/:host/:owner/:name/commit/:commit/build/:label/rebuild", handler.RepoAdminHandler(rebuild.CommitRebuild))
m.Get("/:host/:owner/:name/commit/:commit/build/:label", handler.RepoHandler(handler.CommitShow)) m.Get("/:host/:owner/:name/commit/:commit/build/:label", handler.RepoHandler(handler.CommitShow))
m.Post("/:host/:owner/:name/commit/:commit/rebuild", handler.RepoAdminHandler(rebuild.CommitRebuild)) m.Post("/:host/:owner/:name/commit/:commit/rebuild", handler.RepoAdminHandler(rebuild.CommitRebuild))

View file

@ -7,6 +7,10 @@ import (
. "github.com/drone/drone/pkg/model" . "github.com/drone/drone/pkg/model"
) )
type BuildResult struct {
Status string
}
// Returns the combined stdout / stderr for an individual Build. // Returns the combined stdout / stderr for an individual Build.
func BuildOut(w http.ResponseWriter, r *http.Request, u *User, repo *Repo) error { func BuildOut(w http.ResponseWriter, r *http.Request, u *User, repo *Repo) error {
branch := r.FormValue("branch") branch := r.FormValue("branch")
@ -32,6 +36,33 @@ func BuildOut(w http.ResponseWriter, r *http.Request, u *User, repo *Repo) error
return RenderText(w, build.Stdout, http.StatusOK) return RenderText(w, build.Stdout, http.StatusOK)
} }
// 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)
}
// Returns the gzipped stdout / stderr for an individual Build // Returns the gzipped stdout / stderr for an individual Build
func BuildOutGzip(w http.ResponseWriter, r *http.Request, u *User) error { func BuildOutGzip(w http.ResponseWriter, r *http.Request, u *User) error {
// TODO // TODO

View file

@ -64,10 +64,33 @@ func (h AdminHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
} }
} }
// PublicHandler wraps the default http.HandlerFunc to include
// requested Repository in the method signature, in addition
// to handling an error as the return value.
type PublicHandler func(w http.ResponseWriter, r *http.Request, repo *Repo) error
func (h PublicHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// repository name from the URL parameters
hostParam := r.FormValue(":host")
userParam := r.FormValue(":owner")
nameParam := r.FormValue(":name")
repoName := fmt.Sprintf("%s/%s/%s", hostParam, userParam, nameParam)
repo, err := database.GetRepoSlug(repoName)
if err != nil || repo == nil {
RenderNotFound(w)
return
}
h(w, r, repo)
return
}
// RepoHandler wraps the default http.HandlerFunc to include // RepoHandler wraps the default http.HandlerFunc to include
// the currently authenticated User and requested Repository // the currently authenticated User and requested Repository
// in the method signature, in addition to handling an error // in the method signature, in addition to handling an error
// as the return value. // as the return value.
type RepoHandler func(w http.ResponseWriter, r *http.Request, user *User, repo *Repo) error type RepoHandler func(w http.ResponseWriter, r *http.Request, user *User, repo *Repo) error
func (h RepoHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { func (h RepoHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {