diff --git a/github/github.go b/github/github.go index 08b066f..2b5c933 100644 --- a/github/github.go +++ b/github/github.go @@ -47,6 +47,7 @@ const ( OrganizationEvent Event = "organization" OrgBlockEvent Event = "org_block" PageBuildEvent Event = "page_build" + PingEvent Event = "ping" ProjectCardEvent Event = "project_card" ProjectColumnEvent Event = "project_column" ProjectEvent Event = "project" @@ -221,6 +222,10 @@ func (hook Webhook) ParsePayload(w http.ResponseWriter, r *http.Request) { var p PageBuildPayload json.Unmarshal([]byte(payload), &p) hook.runProcessPayloadFunc(fn, p, hd) + case PingEvent: + var p PingPayload + json.Unmarshal([]byte(payload), &p) + hook.runProcessPayloadFunc(fn, p, hd) case ProjectCardEvent: var p ProjectCardPayload json.Unmarshal([]byte(payload), &p) diff --git a/github/github_test.go b/github/github_test.go index 07a0793..af606ca 100644 --- a/github/github_test.go +++ b/github/github_test.go @@ -59,6 +59,7 @@ func TestMain(m *testing.M) { OrganizationEvent, OrgBlockEvent, PageBuildEvent, + PingEvent, ProjectCardEvent, ProjectColumnEvent, ProjectEvent, @@ -2742,6 +2743,48 @@ func TestPageBuildEvent(t *testing.T) { Equal(t, resp.StatusCode, http.StatusOK) } +func TestPingEvent(t *testing.T) { + + payload := `{ + "zen": "Keep it logically awesome.", + "hook_id": 20081052, + "hook": { + "type": "App", + "id": 20081052, + "name": "web", + "active": true, + "events": [ + "pull_request" + ], + "config": { + "content_type": "json", + "insecure_ssl": "0", + "secret": "********", + "url": "https://ngrok.io/webhook" + }, + "updated_at": "2018-01-15T10:48:54Z", + "created_at": "2018-01-15T10:48:54Z", + "app_id": 8157 + } +} +` + + req, err := http.NewRequest("POST", "http://127.0.0.1:3010/webhooks", bytes.NewBuffer([]byte(payload))) + req.Header.Set("Content-Type", "application/json") + req.Header.Set("X-Github-Event", "ping") + req.Header.Set("X-Hub-Signature", "sha1=f82267eb5c6408d5986209da906747f57c11b33b") + + Equal(t, err, nil) + + client := &http.Client{} + resp, err := client.Do(req) + Equal(t, err, nil) + + defer resp.Body.Close() + + Equal(t, resp.StatusCode, http.StatusOK) +} + func TestProjectCardEvent(t *testing.T) { payload := `{ diff --git a/github/payload.go b/github/payload.go index e247c09..dbf8ed1 100644 --- a/github/payload.go +++ b/github/payload.go @@ -2162,6 +2162,27 @@ type PageBuildPayload struct { } `json:"sender"` } +// PingPayload contains the information for GitHub's ping hook event +type PingPayload struct { + HookID int `json:"hook_id"` + Hook struct { + Type string `json:"type"` + ID int64 `json:"id"` + Name string `json:"name"` + Active bool `json:"active"` + Events []string `json:"events"` + AppID int `json:"app_id"` + Config struct { + ContentType string `json:"content_type"` + InsecureSSL int `json:"insecure_ssl"` + Secret string `json:"secret"` + URL string `json:"url"` + } `json:"config"` + CreatedAt time.Time `json:"created_at"` + UpdatedAt time.Time `json:"updated_at"` + } `json:"hook"` +} + // ProjectCardPayload contains the information for GitHub's project_payload hook event type ProjectCardPayload struct { Action string `json:"action"`