From 76bcdecd21e7aa63734564715563392fa64ad0a6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fran=C3=A7ois=20de=20Metz?= <francois@2metz.fr>
Date: Mon, 6 Mar 2017 12:34:41 +0000
Subject: [PATCH] Respond 200 when receiving a ping event. (#2492)

---
 plugins/inputs/webhooks/github/github_webhooks.go      | 9 ++++++---
 plugins/inputs/webhooks/github/github_webhooks_test.go | 4 ++++
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/plugins/inputs/webhooks/github/github_webhooks.go b/plugins/inputs/webhooks/github/github_webhooks.go
index 139c7697..a31c6fdf 100644
--- a/plugins/inputs/webhooks/github/github_webhooks.go
+++ b/plugins/inputs/webhooks/github/github_webhooks.go
@@ -34,9 +34,10 @@ func (gh *GithubWebhook) eventHandler(w http.ResponseWriter, r *http.Request) {
 		w.WriteHeader(http.StatusBadRequest)
 		return
 	}
-
-	p := e.NewMetric()
-	gh.acc.AddFields("github_webhooks", p.Fields(), p.Tags(), p.Time())
+	if e != nil {
+		p := e.NewMetric()
+		gh.acc.AddFields("github_webhooks", p.Fields(), p.Tags(), p.Time())
+	}
 
 	w.WriteHeader(http.StatusOK)
 }
@@ -84,6 +85,8 @@ func NewEvent(data []byte, name string) (Event, error) {
 		return generateEvent(data, &MembershipEvent{})
 	case "page_build":
 		return generateEvent(data, &PageBuildEvent{})
+	case "ping":
+		return nil, nil
 	case "public":
 		return generateEvent(data, &PublicEvent{})
 	case "pull_request":
diff --git a/plugins/inputs/webhooks/github/github_webhooks_test.go b/plugins/inputs/webhooks/github/github_webhooks_test.go
index 7bee5372..0ec99172 100644
--- a/plugins/inputs/webhooks/github/github_webhooks_test.go
+++ b/plugins/inputs/webhooks/github/github_webhooks_test.go
@@ -25,6 +25,10 @@ func TestCommitCommentEvent(t *testing.T) {
 	GithubWebhookRequest("commit_comment", CommitCommentEventJSON(), t)
 }
 
+func TestPingEvent(t *testing.T) {
+	GithubWebhookRequest("ping", "", t)
+}
+
 func TestDeleteEvent(t *testing.T) {
 	GithubWebhookRequest("delete", DeleteEventJSON(), t)
 }
-- 
GitLab