github status API now functioning properly

This commit is contained in:
Brad Rydzewski 2014-08-03 21:28:51 -07:00
parent 2450cda3c5
commit 4a5dce76cd
5 changed files with 61 additions and 10 deletions

View file

@ -21,7 +21,7 @@ const (
) )
const ( const (
StatusPending = "peding" StatusPending = "pending"
StatusSuccess = "success" StatusSuccess = "success"
StatusFailure = "failure" StatusFailure = "failure"
StatusError = "error" StatusError = "error"
@ -69,15 +69,15 @@ func (g GitHub) Send(context *model.Request) error {
context.Repo.Host, context.Repo.Host,
context.Repo.Owner, context.Repo.Owner,
context.Repo.Name, context.Repo.Name,
context.Commit.Sha,
target,
getDesc(context.Commit.Status),
getStatus(context.Commit.Status), getStatus(context.Commit.Status),
context.User.Token, getDesc(context.Commit.Status),
target,
context.Commit.Sha,
context.User.Access,
) )
} }
func send(host, owner, repo, ref, status, target, desc, token string) error { func send(host, owner, repo, status, desc, target, ref, token string) error {
transport := &oauth.Transport{ transport := &oauth.Transport{
Token: &oauth.Token{AccessToken: token}, Token: &oauth.Token{AccessToken: token},
} }

View file

@ -0,0 +1,50 @@
package github
import (
"testing"
"github.com/drone/drone/shared/model"
"github.com/franela/goblin"
)
func Test_Client(t *testing.T) {
g := goblin.Goblin(t)
g.Describe("Github Status", func() {
g.It("Should get a status", func() {
g.Assert(getStatus(model.StatusEnqueue)).Equal(StatusPending)
g.Assert(getStatus(model.StatusStarted)).Equal(StatusPending)
g.Assert(getStatus(model.StatusSuccess)).Equal(StatusSuccess)
g.Assert(getStatus(model.StatusFailure)).Equal(StatusFailure)
g.Assert(getStatus(model.StatusError)).Equal(StatusError)
g.Assert(getStatus(model.StatusKilled)).Equal(StatusError)
g.Assert(getStatus(model.StatusNone)).Equal(StatusError)
})
g.It("Should get a description", func() {
g.Assert(getDesc(model.StatusEnqueue)).Equal(DescPending)
g.Assert(getDesc(model.StatusStarted)).Equal(DescPending)
g.Assert(getDesc(model.StatusSuccess)).Equal(DescSuccess)
g.Assert(getDesc(model.StatusFailure)).Equal(DescFailure)
g.Assert(getDesc(model.StatusError)).Equal(DescError)
g.Assert(getDesc(model.StatusKilled)).Equal(DescError)
g.Assert(getDesc(model.StatusNone)).Equal(DescError)
})
g.It("Should get a target url", func() {
var (
url = "https://drone.io"
host = "github.com"
owner = "drone"
repo = "go-bitbucket"
branch = "master"
commit = "0c0cf4ece975efdfcf6daa78b03d4e84dd257da7"
)
var got = getTarget(url, host, owner, repo, branch, commit)
var want = "https://drone.io/github.com/drone/go-bitbucket/master/0c0cf4ece975efdfcf6daa78b03d4e84dd257da7"
g.Assert(got).Equal(want)
})
})
}

View file

@ -40,7 +40,6 @@ func (w *Webhook) send(context *model.Request) error {
return err return err
} }
// loop through and email recipients
for _, url := range w.URL { for _, url := range w.URL {
go sendJson(url, payload) go sendJson(url, payload)
} }

View file

@ -107,10 +107,15 @@ func (h *HookHandler) PostHook(w http.ResponseWriter, r *http.Request) error {
} }
//fmt.Printf("%s", yml) //fmt.Printf("%s", yml)
owner, err := h.users.Find(repo.UserID)
if err != nil {
return badRequest{err}
}
// drop the items on the queue // drop the items on the queue
go func() { go func() {
h.queue <- &model.Request{ h.queue <- &model.Request{
User: owner,
Host: httputil.GetURL(r), Host: httputil.GetURL(r),
Repo: repo, Repo: repo,
Commit: &c, Commit: &c,

View file

@ -165,9 +165,6 @@ func (w *worker) Execute(r *model.Request) {
// notify all listeners that the build is finished // notify all listeners that the build is finished
commitc.Publish(r) commitc.Publish(r)
// todo(bradrydzewski) update github status API
// todo(bradrydzewski) send email notifications
// send all "finished" notifications // send all "finished" notifications
if script.Notifications != nil { if script.Notifications != nil {
script.Notifications.Send(r) script.Notifications.Send(r)