removed builds table since not being used in the near term

This commit is contained in:
Brad
2014-06-07 12:57:20 -07:00
parent 90df70d109
commit 1fff27a28c
19 changed files with 122 additions and 646 deletions

View File

@@ -4,7 +4,6 @@ import (
"net/http"
"time"
"github.com/drone/drone/server/resource/build"
"github.com/drone/drone/server/resource/commit"
"github.com/drone/drone/server/resource/repo"
"github.com/gorilla/pat"
@@ -59,24 +58,24 @@ func (h *BadgeHandler) GetStatus(w http.ResponseWriter, r *http.Request) error {
}
// get the latest commit
commit, _ := h.commits.FindLatest(arepo.ID, branch)
c, _ := h.commits.FindLatest(arepo.ID, branch)
// if no commit was found then display
// the 'none' badge
if commit == nil {
if c == nil {
w.Write(badgeNone)
return nil
}
// determine which badge to load
switch commit.Status {
case build.StatusSuccess:
switch c.Status {
case commit.StatusSuccess:
w.Write(badgeSuccess)
case build.StatusFailure:
case commit.StatusFailure:
w.Write(badgeFailure)
case build.StatusError:
case commit.StatusError:
w.Write(badgeError)
case build.StatusEnqueue, build.StatusStarted:
case commit.StatusEnqueue, commit.StatusStarted:
w.Write(badgeStarted)
default:
w.Write(badgeNone)

View File

@@ -1,145 +0,0 @@
package handler
import (
"encoding/json"
"net/http"
"strconv"
"github.com/drone/drone/server/resource/build"
"github.com/drone/drone/server/resource/commit"
"github.com/drone/drone/server/resource/perm"
"github.com/drone/drone/server/resource/repo"
"github.com/drone/drone/server/session"
"github.com/gorilla/pat"
)
type BuildHandler struct {
builds build.BuildManager
commits commit.CommitManager
repos repo.RepoManager
perms perm.PermManager
sess session.Session
}
func NewBuildHandler(repos repo.RepoManager, commits commit.CommitManager, builds build.BuildManager,
perms perm.PermManager, sess session.Session) *BuildHandler {
return &BuildHandler{builds, commits, repos, perms, sess}
}
// GetCommit gets the commit for the repository, branch and sha.
// GET /v1/repos/{host}/{owner}/{name}/branches/{branch}/commits/{commit}/builds/{build}
func (h *BuildHandler) GetBuild(w http.ResponseWriter, r *http.Request) error {
var host, owner, name = parseRepo(r)
var branch = r.FormValue(":branch")
var sha = r.FormValue(":commit")
var num, _ = strconv.Atoi(r.FormValue(":build"))
// get the user form the session.
user := h.sess.User(r)
// get the repository from the database.
repo, err := h.repos.FindName(host, owner, name)
if err != nil {
return notFound{err}
}
// user must have read access to the repository.
if ok, _ := h.perms.Read(user, repo); !ok {
return notFound{err}
}
// get the commit information for the specified hash
commit, err := h.commits.FindSha(repo.ID, branch, sha)
if err != nil {
return notFound{err}
}
// get the builds for the hash
build, err := h.builds.FindNumber(commit.ID, int64(num))
if err != nil {
return notFound{err}
}
return json.NewEncoder(w).Encode(build)
}
// GetBuilds gets the list of builds for a commit.
// GET /v1/repos/{host}/{owner}/{name}/branches/{branch}/commits/{commit}/builds
func (h *BuildHandler) GetBuilds(w http.ResponseWriter, r *http.Request) error {
var host, owner, name = parseRepo(r)
var branch = r.FormValue(":branch")
var sha = r.FormValue(":commit")
// get the user form the session.
user := h.sess.User(r)
// get the repository from the database.
repo, err := h.repos.FindName(host, owner, name)
if err != nil {
return notFound{err}
}
// user must have read access to the repository.
if ok, _ := h.perms.Read(user, repo); !ok {
return notFound{err}
}
// get the commit information for the specified hash
commit, err := h.commits.FindSha(repo.ID, branch, sha)
if err != nil {
return notFound{err}
}
// get the builds for the hash
builds, err := h.builds.List(commit.ID)
if err != nil {
return notFound{err}
}
return json.NewEncoder(w).Encode(builds)
}
// GetOut gets the console output for a build. If the build is in-progress it
// returns a link to the websocket (I think ...)
// GET /v1/repos/{host}/{owner}/{name}/branches/{branch}/commits/{commit}/builds/{build}/out
func (h *BuildHandler) GetOut(w http.ResponseWriter, r *http.Request) error {
var host, owner, name = parseRepo(r)
var branch = r.FormValue(":branch")
var sha = r.FormValue(":commit")
var num, _ = strconv.Atoi(r.FormValue(":build"))
// get the user form the session.
user := h.sess.User(r)
// get the repository from the database.
repo, err := h.repos.FindName(host, owner, name)
if err != nil {
return notFound{err}
}
// user must have read access to the repository.
if ok, _ := h.perms.Read(user, repo); !ok {
return notFound{err}
}
// get the commit information for the specified hash
commit, err := h.commits.FindSha(repo.ID, branch, sha)
if err != nil {
return notFound{err}
}
// get the builds for the hash
out, err := h.builds.FindOutput(commit.ID, int64(num))
if err != nil {
return notFound{err}
}
w.Write(out)
return nil
}
func (h *BuildHandler) Register(r *pat.Router) {
r.Get("/v1/repos/{host}/{owner}/{name}/branches/{branch}/commits/{commit}/builds/{build}/console", errorHandler(h.GetOut))
r.Get("/v1/repos/{host}/{owner}/{name}/branches/{branch}/commits/{commit}/builds/{build}", errorHandler(h.GetBuild))
r.Get("/v1/repos/{host}/{owner}/{name}/branches/{branch}/commits/{commit}/builds", errorHandler(h.GetBuilds))
}

View File

@@ -79,6 +79,41 @@ func (h *CommitHandler) GetCommit(w http.ResponseWriter, r *http.Request) error
return json.NewEncoder(w).Encode(commit)
}
// GetCommitOutput gets the commit's stdout.
// GET /v1/repos/{host}/{owner}/{name}/branches/{branch}/commits/{commit}/console
func (h *CommitHandler) GetCommitOutput(w http.ResponseWriter, r *http.Request) error {
var host, owner, name = parseRepo(r)
var branch = r.FormValue(":branch")
var sha = r.FormValue(":commit")
// get the user form the session.
user := h.sess.User(r)
// get the repository from the database.
repo, err := h.repos.FindName(host, owner, name)
if err != nil {
return notFound{err}
}
// user must have read access to the repository.
if ok, _ := h.perms.Read(user, repo); !ok {
return notFound{err}
}
commit, err := h.commits.FindSha(repo.ID, branch, sha)
if err != nil {
return notFound{err}
}
output, err := h.commits.FindOutput(commit.ID)
if err != nil {
return notFound{err}
}
w.Write(output)
return nil
}
// PostCommit gets the commit for the repository and schedules to re-build.
// GET /v1/repos/{host}/{owner}/{name}/branches/{branch}/commits/{commit}
func (h *CommitHandler) PostCommit(w http.ResponseWriter, r *http.Request) error {
@@ -86,6 +121,7 @@ func (h *CommitHandler) PostCommit(w http.ResponseWriter, r *http.Request) error
}
func (h *CommitHandler) Register(r *pat.Router) {
r.Get("/v1/repos/{host}/{owner}/{name}/branches/{branch}/commits/{commit}/console", errorHandler(h.GetCommitOutput))
r.Get("/v1/repos/{host}/{owner}/{name}/branches/{branch}/commits/{commit}", errorHandler(h.GetCommit))
r.Post("/v1/repos/{host}/{owner}/{name}/branches/{branch}/commits/{commit}", errorHandler(h.PostCommit)).Queries("action", "rebuild")
r.Get("/v1/repos/{host}/{owner}/{name}/branches/{branch}/commits", errorHandler(h.GetFeed))

View File

@@ -4,7 +4,6 @@ import (
"fmt"
"net/http"
"github.com/drone/drone/server/resource/build"
"github.com/drone/drone/server/resource/commit"
"github.com/drone/drone/server/resource/config"
"github.com/drone/drone/server/resource/repo"
@@ -16,13 +15,11 @@ type HookHandler struct {
users user.UserManager
repos repo.RepoManager
commits commit.CommitManager
builds build.BuildManager
conf *config.Config
}
func NewHookHandler(users user.UserManager, repos repo.RepoManager, commits commit.CommitManager,
builds build.BuildManager, conf *config.Config) *HookHandler {
return &HookHandler{users, repos, commits, builds, conf}
func NewHookHandler(users user.UserManager, repos repo.RepoManager, commits commit.CommitManager, conf *config.Config) *HookHandler {
return &HookHandler{users, repos, commits, conf}
}
// PostHook receives a post-commit hook from GitHub, Bitbucket, etc
@@ -90,16 +87,6 @@ func (h *HookHandler) PostHook(w http.ResponseWriter, r *http.Request) error {
return badRequest{err}
}
b := build.Build{
CommitID: c.ID,
Status: c.Status,
Number: 1,
}
// inser the build entry into the database
if err := h.builds.Insert(&b); err != nil {
return internalServerError{err}
}
fmt.Printf("%#v", hook)
fmt.Printf("%s", script)

View File

@@ -4,7 +4,6 @@ import (
"net/http"
"github.com/drone/drone/server/render"
"github.com/drone/drone/server/resource/build"
"github.com/drone/drone/server/resource/commit"
"github.com/drone/drone/server/resource/perm"
"github.com/drone/drone/server/resource/repo"
@@ -18,16 +17,13 @@ type SiteHandler struct {
users user.UserManager
repos repo.RepoManager
commits commit.CommitManager
builds build.BuildManager
perms perm.PermManager
sess session.Session
render render.Render
}
func NewSiteHandler(users user.UserManager,
repos repo.RepoManager, commits commit.CommitManager, builds build.BuildManager,
perms perm.PermManager, sess session.Session, render render.Render) *SiteHandler {
return &SiteHandler{users, repos, commits, builds, perms, sess, render}
func NewSiteHandler(users user.UserManager, repos repo.RepoManager, commits commit.CommitManager, perms perm.PermManager, sess session.Session, render render.Render) *SiteHandler {
return &SiteHandler{users, repos, commits, perms, sess, render}
}
// GetIndex serves the root domain request. This is forwarded to the dashboard
@@ -102,8 +98,6 @@ func (s *SiteHandler) GetRepo(w http.ResponseWriter, r *http.Request) error {
Branches []*commit.Commit
Commits []*commit.Commit
Commit *commit.Commit
Builds []*build.Build
Build *build.Build
}{User: usr, Repo: arepo}
// if commit details are provided we should retrieve the build details
@@ -113,10 +107,6 @@ func (s *SiteHandler) GetRepo(w http.ResponseWriter, r *http.Request) error {
if err != nil {
return s.render(w, "404.html", nil)
}
data.Build, err = s.builds.FindNumber(data.Commit.ID, 1)
if err != nil {
return s.render(w, "404.html", nil)
}
return s.render(w, "repo_commit.html", &data)
}