From 9ed96af13b1a8124d151dbe17115ecc6562c1466 Mon Sep 17 00:00:00 2001 From: Brad Rydzewski Date: Tue, 14 Oct 2014 21:53:27 -0700 Subject: [PATCH 1/3] modified Gitter api to use constants when comparing status --- plugin/notify/gitter.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/plugin/notify/gitter.go b/plugin/notify/gitter.go index db9433ea..15b7fb86 100644 --- a/plugin/notify/gitter.go +++ b/plugin/notify/gitter.go @@ -24,11 +24,11 @@ type Gitter struct { func (g *Gitter) Send(context *model.Request) error { switch { - case context.Commit.Status == "Started" && g.Started: + case context.Commit.Status == model.StatusStarted && g.Started: return g.sendStarted(context) - case context.Commit.Status == "Success" && g.Success: + case context.Commit.Status == model.StatusSuccess && g.Success: return g.sendSuccess(context) - case context.Commit.Status == "Failure" && g.Failure: + case context.Commit.Status == model.StatusFailure && g.Failure: return g.sendFailure(context) } @@ -70,9 +70,8 @@ func (g *Gitter) send(msg string) error { // create headers headers := make(map[string]string) + headers["Accept"] = "application/json" headers["Authorization"] = fmt.Sprintf("Bearer %s", g.Token) - go sendJson(url, payload, headers) - - return nil + return sendJson(url, payload, headers) } From 64cd7cdf6ad384f1b615362852ed7c4f373644be Mon Sep 17 00:00:00 2001 From: Brad Rydzewski Date: Tue, 14 Oct 2014 21:53:39 -0700 Subject: [PATCH 2/3] updated yaml --- .drone.yml | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/.drone.yml b/.drone.yml index e01e0ff4..f64aea78 100644 --- a/.drone.yml +++ b/.drone.yml @@ -17,12 +17,15 @@ services: - postgres - mysql notify: + email: + recipients: + - brad@drone.io gitter: - room_id: 76f5e5ec935c5b40259a + room_id: $$GITTER_ROOM token: $$GITTER_KEY on_started: false - on_success: false - on_failure: false + on_success: true + on_failure: true publish: s3: @@ -34,3 +37,5 @@ publish: source: packaging/output/ target: $DRONE_BRANCH/ recursive: true + when: + owner: drone From d0afc3df946985f80e8e03176c493a1535443249 Mon Sep 17 00:00:00 2001 From: Brad Rydzewski Date: Tue, 14 Oct 2014 22:43:29 -0700 Subject: [PATCH 3/3] returning error from notification sendJson for debugging --- plugin/notify/notification.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/plugin/notify/notification.go b/plugin/notify/notification.go index d3b2de6a..982be477 100644 --- a/plugin/notify/notification.go +++ b/plugin/notify/notification.go @@ -105,11 +105,14 @@ func getBuildUrl(context *model.Request) string { // helper fuction to sent HTTP Post requests // with JSON data as the payload. -func sendJson(url string, payload []byte, headers map[string]string) { +func sendJson(url string, payload []byte, headers map[string]string) error { client := &http.Client{} buf := bytes.NewBuffer(payload) req, err := http.NewRequest("POST", url, buf) + if err != nil { + return err + } req.Header.Set("Content-Type", "application/json") if headers != nil { @@ -120,7 +123,8 @@ func sendJson(url string, payload []byte, headers map[string]string) { resp, err := client.Do(req) if err != nil { - return + return err } resp.Body.Close() + return nil }