From b0b867f2d5ec7c0139fad20ab0fe9267dcd8312b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Peignier?= Date: Sat, 24 Sep 2016 21:10:19 -0700 Subject: [PATCH] Add installation webhook events Add support for the new webhooks event for installations. See: https://developer.github.com/early-access/integrations/webhooks/ Closes #434. Change-Id: I74d3d50cb6b350322fc4515ad70097f0f70ae478 --- github/activity_events.go | 4 ++++ github/event_types.go | 34 ++++++++++++++++++++++++++++++ github/messages.go | 44 ++++++++++++++++++++------------------- 3 files changed, 61 insertions(+), 21 deletions(-) diff --git a/github/activity_events.go b/github/activity_events.go index a0e5f08..6bf38b4 100644 --- a/github/activity_events.go +++ b/github/activity_events.go @@ -45,6 +45,10 @@ func (e *Event) Payload() (payload interface{}) { payload = &ForkEvent{} case "GollumEvent": payload = &GollumEvent{} + case "IntegrationInstallationEvent": + payload = &IntegrationInstallationEvent{} + case "IntegrationInstallationRepositoriesEvent": + payload = &IntegrationInstallationRepositoriesEvent{} case "IssueActivityEvent": payload = &IssueActivityEvent{} case "IssueCommentEvent": diff --git a/github/event_types.go b/github/event_types.go index 20f509a..da18f71 100644 --- a/github/event_types.go +++ b/github/event_types.go @@ -146,6 +146,40 @@ type EditChange struct { } `json:"body,omitempty"` } +// IntegrationInstallationEvent is triggered when an integration is created or deleted. +// The Webhook event name is "integration_installation". +// +// GitHub docs: https://developer.github.com/early-access/integrations/webhooks/#integrationinstallationevent +type IntegrationInstallationEvent struct { + // The action that was performed. Possible values for an "integration_installation" + // event are: "created", "deleted". + Action *string `json:"action,omitempty"` + Installation *Installation `json:"installation,omitempty"` + Sender *User `json:"sender,omitempty"` +} + +// IntegrationInstallationRepositoriesEvent is triggered when an integration repository +// is added or removed. The Webhook event name is "integration_installation_repositories". +// +// GitHub docs: https://developer.github.com/early-access/integrations/webhooks/#integrationinstallationrepositoriesevent +type IntegrationInstallationRepositoriesEvent struct { + // The action that was performed. Possible values for an "integration_installation_repositories" + // event are: "added", "removed". + Action *string `json:"action,omitempty"` + Installation *Installation `json:"installation,omitempty"` + RepositoriesAdded []*Repository `json:"repositories_added,omitempty"` + RepositoriesRemoved []*Repository `json:"repositories_removed,omitempty"` + Sender *User `json:"sender,omitempty"` +} + +// Installation represents a GitHub integration installation. +type Installation struct { + ID *int `json:"id,omitempty"` + Account *User `json:"account,omitempty"` + AccessTokensURL *string `json:"access_tokens_url,omitempty"` + RepositoriesURL *string `json:"repositories_url,omitempty"` +} + // IssueCommentEvent is triggered when an issue comment is created on an issue // or pull request. // The Webhook event name is "issue_comment". diff --git a/github/messages.go b/github/messages.go index 33cbed3..eedb190 100644 --- a/github/messages.go +++ b/github/messages.go @@ -38,27 +38,29 @@ const ( var ( // eventTypeMapping maps webhooks types to their corresponding go-github struct types. eventTypeMapping = map[string]string{ - "commit_comment": "CommitCommentEvent", - "create": "CreateEvent", - "delete": "DeleteEvent", - "deployment": "DeploymentEvent", - "deployment_status": "DeploymentStatusEvent", - "fork": "ForkEvent", - "gollum": "GollumEvent", - "issue_comment": "IssueCommentEvent", - "issues": "IssuesEvent", - "member": "MemberEvent", - "membership": "MembershipEvent", - "page_build": "PageBuildEvent", - "public": "PublicEvent", - "pull_request_review_comment": "PullRequestReviewCommentEvent", - "pull_request": "PullRequestEvent", - "push": "PushEvent", - "repository": "RepositoryEvent", - "release": "ReleaseEvent", - "status": "StatusEvent", - "team_add": "TeamAddEvent", - "watch": "WatchEvent", + "commit_comment": "CommitCommentEvent", + "create": "CreateEvent", + "delete": "DeleteEvent", + "deployment": "DeploymentEvent", + "deployment_status": "DeploymentStatusEvent", + "fork": "ForkEvent", + "gollum": "GollumEvent", + "integration_installation": "IntegrationInstallationEvent", + "integration_installation_repositories": "IntegrationInstallationRepositoriesEvent", + "issue_comment": "IssueCommentEvent", + "issues": "IssuesEvent", + "member": "MemberEvent", + "membership": "MembershipEvent", + "page_build": "PageBuildEvent", + "public": "PublicEvent", + "pull_request_review_comment": "PullRequestReviewCommentEvent", + "pull_request": "PullRequestEvent", + "push": "PushEvent", + "repository": "RepositoryEvent", + "release": "ReleaseEvent", + "status": "StatusEvent", + "team_add": "TeamAddEvent", + "watch": "WatchEvent", } )