Add status.json page
This commit is contained in:
parent
4f0585bee3
commit
4f779ea920
3 changed files with 55 additions and 0 deletions
|
@ -227,6 +227,7 @@ func setupHandlers() {
|
|||
|
||||
// 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/status.json", handler.PublicHandler(handler.BuildStatus))
|
||||
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.Post("/:host/:owner/:name/commit/:commit/rebuild", handler.RepoAdminHandler(rebuild.CommitRebuild))
|
||||
|
|
|
@ -7,6 +7,10 @@ import (
|
|||
. "github.com/drone/drone/pkg/model"
|
||||
)
|
||||
|
||||
type BuildResult struct {
|
||||
Status string
|
||||
}
|
||||
|
||||
// Returns the combined stdout / stderr for an individual Build.
|
||||
func BuildOut(w http.ResponseWriter, r *http.Request, u *User, repo *Repo) error {
|
||||
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)
|
||||
}
|
||||
|
||||
// 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
|
||||
func BuildOutGzip(w http.ResponseWriter, r *http.Request, u *User) error {
|
||||
// TODO
|
||||
|
|
|
@ -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
|
||||
// the currently authenticated User and requested Repository
|
||||
// in the method signature, in addition to handling an error
|
||||
// as the return value.
|
||||
|
||||
type RepoHandler func(w http.ResponseWriter, r *http.Request, user *User, repo *Repo) error
|
||||
|
||||
func (h RepoHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
|
|
Loading…
Reference in a new issue