github status api

This commit is contained in:
Brad Rydzewski 2015-05-09 20:46:32 -07:00
parent 7f162c80b9
commit d07c0cb80d
4 changed files with 17 additions and 12 deletions

View file

@ -38,7 +38,7 @@ func main() {
session := session.New(settings.Session) session := session.New(settings.Session)
eventbus_ := eventbus.New() eventbus_ := eventbus.New()
queue_ := queue.New() queue_ := queue.New()
updater := runner.NewUpdater(eventbus_, store) updater := runner.NewUpdater(eventbus_, store, remote)
runner_ := runner.Runner{Updater: updater} runner_ := runner.Runner{Updater: updater}
go run(&runner_, queue_) go run(&runner_, queue_)

View file

@ -79,14 +79,14 @@ func (r *Runner) Run(w *queue.Work) error {
w.Build.State = common.StateError w.Build.State = common.StateError
w.Build.Finished = time.Now().UTC().Unix() w.Build.Finished = time.Now().UTC().Unix()
w.Build.Duration = w.Build.Finished - w.Build.Started w.Build.Duration = w.Build.Finished - w.Build.Started
r.SetBuild(w.Repo, w.Build) r.SetBuild(w.User, w.Repo, w.Build)
} }
}() }()
// marks the build as running // marks the build as running
w.Build.Started = time.Now().UTC().Unix() w.Build.Started = time.Now().UTC().Unix()
w.Build.State = common.StateRunning w.Build.State = common.StateRunning
err := r.SetBuild(w.Repo, w.Build) err := r.SetBuild(w.User, w.Repo, w.Build)
if err != nil { if err != nil {
return err return err
} }
@ -177,7 +177,7 @@ func (r *Runner) Run(w *queue.Work) error {
break break
} }
} }
err = r.SetBuild(w.Repo, w.Build) err = r.SetBuild(w.User, w.Repo, w.Build)
if err != nil { if err != nil {
return err return err
} }

View file

@ -3,31 +3,32 @@ package builtin
import ( import (
"encoding/json" "encoding/json"
"io" "io"
//"io/ioutil"
"github.com/drone/drone/common" "github.com/drone/drone/common"
"github.com/drone/drone/datastore" "github.com/drone/drone/datastore"
"github.com/drone/drone/eventbus" "github.com/drone/drone/eventbus"
"github.com/drone/drone/remote"
) )
type Updater interface { type Updater interface {
SetBuild(*common.Repo, *common.Build) error SetBuild(*common.User, *common.Repo, *common.Build) error
SetTask(*common.Repo, *common.Build, *common.Task) error SetTask(*common.Repo, *common.Build, *common.Task) error
SetLogs(*common.Repo, *common.Build, *common.Task, io.ReadCloser) error SetLogs(*common.Repo, *common.Build, *common.Task, io.ReadCloser) error
} }
// NewUpdater returns an implementation of the Updater interface // NewUpdater returns an implementation of the Updater interface
// that directly modifies the database and sends messages to the bus. // that directly modifies the database and sends messages to the bus.
func NewUpdater(bus eventbus.Bus, store datastore.Datastore) Updater { func NewUpdater(bus eventbus.Bus, store datastore.Datastore, rem remote.Remote) Updater {
return &updater{bus, store} return &updater{bus, store, rem}
} }
type updater struct { type updater struct {
bus eventbus.Bus bus eventbus.Bus
store datastore.Datastore store datastore.Datastore
remote remote.Remote
} }
func (u *updater) SetBuild(r *common.Repo, b *common.Build) error { func (u *updater) SetBuild(user *common.User, r *common.Repo, b *common.Build) error {
err := u.store.SetBuildState(r.FullName, b) err := u.store.SetBuildState(r.FullName, b)
if err != nil { if err != nil {
return err return err
@ -42,6 +43,11 @@ func (u *updater) SetBuild(r *common.Repo, b *common.Build) error {
u.store.SetRepo(repo) u.store.SetRepo(repo)
} }
} }
// err = u.remote.Status(user, r, b, "")
// if err != nil {
//
// }
} }
msg, err := json.Marshal(b) msg, err := json.Marshal(b)

View file

@ -46,7 +46,6 @@ func GetLogin(c *gin.Context) {
// exit if authorization fails // exit if authorization fails
if c.Writer.Status() != 200 { if c.Writer.Status() != 200 {
log.Errorf("authorization failed.")
return return
} }