diff --git a/plugin/notify/github/github.go b/plugin/notify/github/github.go index 38c6f3028..2fcb81d53 100644 --- a/plugin/notify/github/github.go +++ b/plugin/notify/github/github.go @@ -21,7 +21,7 @@ const ( ) const ( - StatusPending = "peding" + StatusPending = "pending" StatusSuccess = "success" StatusFailure = "failure" StatusError = "error" @@ -69,15 +69,15 @@ func (g GitHub) Send(context *model.Request) error { context.Repo.Host, context.Repo.Owner, context.Repo.Name, - context.Commit.Sha, - target, - getDesc(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{ Token: &oauth.Token{AccessToken: token}, } diff --git a/plugin/notify/github/github_test.go b/plugin/notify/github/github_test.go new file mode 100644 index 000000000..7f905b208 --- /dev/null +++ b/plugin/notify/github/github_test.go @@ -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) + }) + }) +} diff --git a/plugin/notify/webhook.go b/plugin/notify/webhook.go index 22d325636..998cc1605 100644 --- a/plugin/notify/webhook.go +++ b/plugin/notify/webhook.go @@ -40,7 +40,6 @@ func (w *Webhook) send(context *model.Request) error { return err } - // loop through and email recipients for _, url := range w.URL { go sendJson(url, payload) } diff --git a/server/handler/hook.go b/server/handler/hook.go index b6bfed288..6591b5c96 100644 --- a/server/handler/hook.go +++ b/server/handler/hook.go @@ -107,10 +107,15 @@ func (h *HookHandler) PostHook(w http.ResponseWriter, r *http.Request) error { } //fmt.Printf("%s", yml) + owner, err := h.users.Find(repo.UserID) + if err != nil { + return badRequest{err} + } // drop the items on the queue go func() { h.queue <- &model.Request{ + User: owner, Host: httputil.GetURL(r), Repo: repo, Commit: &c, diff --git a/server/worker/worker.go b/server/worker/worker.go index 5b1aafd34..7a7b15d03 100644 --- a/server/worker/worker.go +++ b/server/worker/worker.go @@ -165,9 +165,6 @@ func (w *worker) Execute(r *model.Request) { // notify all listeners that the build is finished commitc.Publish(r) - // todo(bradrydzewski) update github status API - // todo(bradrydzewski) send email notifications - // send all "finished" notifications if script.Notifications != nil { script.Notifications.Send(r)