Repository: google/go-github
Pull request #1163 (2019-04-22 12:33:51)

Support new webhook events and actions
Fixes: #1160 

- Adding new possible value for actions for several existing events (IssueEvent, OrganizationEvent, PullRequestEvent, ReleaseEvent, and RepositoryEvent).
- Adding 3 new events (DeployKeyEvent, MetaEvent, and StarEvent).

codecov[bot]: # [Codecov](https://codecov.io/gh/google/go-github/pull/1163?src=pr&el=h1) Report
> Merging [#1163](https://codecov.io/gh/google/go-github/pull/1163?src=pr&el=desc) into [master](https://codecov.io/gh/google/go-github/commit/b9c250381aece318ad10fbd79a7e1e7ff61e4a12?src=pr&el=desc) will **increase** coverage by `0.03%`.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/google/go-github/pull/1163/graphs/tree.svg?width=650&token=EgYjGjZlI0&height=150&src=pr)](https://codecov.io/gh/google/go-github/pull/1163?src=pr&el=tree)

```diff
@@            Coverage Diff            @@
##           master   #1163      +/-   ##
=========================================
+ Coverage   70.17%   70.2%   +0.03%     
=========================================
  Files          84      84              
  Lines        5824    5830       +6     
=========================================
+ Hits         4087    4093       +6     
  Misses        952     952              
  Partials      785     785
```


| [Impacted Files](https://codecov.io/gh/google/go-github/pull/1163?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [github/event\_types.go](https://codecov.io/gh/google/go-github/pull/1163/diff?src=pr&el=tree#diff-Z2l0aHViL2V2ZW50X3R5cGVzLmdv) | `100% <ø> (ø)` | :arrow_up: |
| [github/messages.go](https://codecov.io/gh/google/go-github/pull/1163/diff?src=pr&el=tree#diff-Z2l0aHViL21lc3NhZ2VzLmdv) | `82.85% <ø> (ø)` | :arrow_up: |
| [github/event.go](https://codecov.io/gh/google/go-github/pull/1163/diff?src=pr&el=tree#diff-Z2l0aHViL2V2ZW50Lmdv) | `91.48% <100%> (+0.58%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/google/go-github/pull/1163?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/google/go-github/pull/1163?src=pr&el=footer). Last update [b9c2503...2f9d6ed](https://codecov.io/gh/google/go-github/pull/1163?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

joshuabezaleel: Hey @gmlewis , I am really sorry that I had to close the previous PR and make another PR. I do not know why but I can not run the `go generate./...` command work on my previous machine so I made this PR from another machine. This PR should have already resolved the review that you commented earlier and also the result of running `go generate` command.

Thank you very much! :slightly_smiling_face: 
joshuabezaleel: > Thanks for keeping us up-to-date with the new APIs :)

Thank you very much for the opportunity, @gmlewis and @gauntface ! The pleasure is all mine! :slightly_smiling_face: 

Patch:
diff --git a/github/event.go b/github/event.go
index 04c8845a..0ba8f46a 100644
--- a/github/event.go
+++ b/github/event.go
@@ -40,6 +40,8 @@ func (e *Event) ParsePayload() (payload interface{}, err error) {
 		payload = &CreateEvent{}
 	case "DeleteEvent":
 		payload = &DeleteEvent{}
+	case "DeployKeyEvent":
+		payload = &DeployKeyEvent{}
 	case "DeploymentEvent":
 		payload = &DeploymentEvent{}
 	case "DeploymentStatusEvent":
@@ -66,6 +68,8 @@ func (e *Event) ParsePayload() (payload interface{}, err error) {
 		payload = &MemberEvent{}
 	case "MembershipEvent":
 		payload = &MembershipEvent{}
+	case "MetaEvent":
+		payload = &MetaEvent{}
 	case "MilestoneEvent":
 		payload = &MilestoneEvent{}
 	case "OrganizationEvent":
@@ -98,6 +102,8 @@ func (e *Event) ParsePayload() (payload interface{}, err error) {
 		payload = &RepositoryEvent{}
 	case "RepositoryVulnerabilityAlertEvent":
 		payload = &RepositoryVulnerabilityAlertEvent{}
+	case "StarEvent":
+		payload = &StarEvent{}
 	case "StatusEvent":
 		payload = &StatusEvent{}
 	case "TeamEvent":
diff --git a/github/event_types.go b/github/event_types.go
index 27498a94..0be42e4c 100644
--- a/github/event_types.go
+++ b/github/event_types.go
@@ -19,7 +19,7 @@ type RequestedAction struct {
 // GitHub API docs: https://developer.github.com/v3/activity/events/types/#checkrunevent
 type CheckRunEvent struct {
 	CheckRun *CheckRun `json:"check_run,omitempty"`
-	// The action performed. Can be "created", "updated", "rerequested" or "requested_action".
+	// The action performed. Possible values are: "created", "updated", "rerequested" or "requested_action".
 	Action *string `json:"action,omitempty"`
 
 	// The following fields are only populated by Webhook events.
@@ -38,7 +38,7 @@ type CheckRunEvent struct {
 // GitHub API docs: https://developer.github.com/v3/activity/events/types/#checksuiteevent
 type CheckSuiteEvent struct {
 	CheckSuite *CheckSuite `json:"check_suite,omitempty"`
-	// The action performed. Can be "completed", "requested" or "re-requested".
+	// The action performed. Possible values are: "completed", "requested" or "re-requested".
 	Action *string `json:"action,omitempty"`
 
 	// The following fields are only populated by Webhook events.
@@ -103,6 +103,19 @@ type DeleteEvent struct {
 	Installation *Installation `json:"installation,omitempty"`
 }
 
+// DeployKeyEvent is triggered when a deploy key is added or removed from a repository.
+// The Webhook event name is "deploy_key".
+//
+// GitHub API docs: https://developer.github.com/v3/activity/events/types/#deploykeyevent
+type DeployKeyEvent struct {
+	// Action is the action that was performed. Possible values are:
+	// "created" or "deleted".
+	Action *string `json:"action,omitempty"`
+
+	// The deploy key resource.
+	Key *Key `json:"key,omitempty"`
+}
+
 // DeploymentEvent represents a deployment.
 // The Webhook event name is "deployment".
 //
@@ -153,7 +166,7 @@ type ForkEvent struct {
 //
 // GitHub API docs: https://developer.github.com/v3/activity/events/types/#githubappauthorizationevent
 type GitHubAppAuthorizationEvent struct {
-	// The action performed. Can be "revoked".
+	// The action performed. Possible value is: "revoked".
 	Action *string `json:"action,omitempty"`
 
 	// The following fields are only populated by Webhook events.
@@ -285,14 +298,17 @@ type IssueCommentEvent struct {
 	Installation *Installation `json:"installation,omitempty"`
 }
 
-// IssuesEvent is triggered when an issue is assigned, unassigned, labeled,
-// unlabeled, opened, closed, or reopened.
+// IssuesEvent is triggered when an issue is opened, edited, deleted, transferred,
+// pinned, unpinned, closed, reopened, assigned, unassigned, labeled, unlabeled,
+// locked, unlocked, milestoned, or demilestoned.
 // The Webhook event name is "issues".
 //
 // GitHub API docs: https://developer.github.com/v3/activity/events/types/#issuesevent
 type IssuesEvent struct {
-	// Action is the action that was performed. Possible values are: "assigned",
-	// "unassigned", "labeled", "unlabeled", "opened", "closed", "reopened", "edited".
+	// Action is the action that was performed. Possible values are: "opened",
+	// "edited", "deleted", "transferred", "pinned", "unpinned", "closed", "reopened",
+	// "assigned", "unassigned", "labeled", "unlabeled", "locked", "unlocked",
+	// "milestoned", or "demilestoned".
 	Action   *string `json:"action,omitempty"`
 	Issue    *Issue  `json:"issue,omitempty"`
 	Assignee *User   `json:"assignee,omitempty"`
@@ -376,6 +392,23 @@ type MembershipEvent struct {
 	Installation *Installation `json:"installation,omitempty"`
 }
 
+// MetaEvent is triggered when the webhook that this event is configured on is deleted.
+// This event will only listen for changes to the particular hook the event is installed on.
+// Therefore, it must be selected for each hook that you'd like to receive meta events for.
+// The Webhook event name is "meta".
+//
+// GitHub API docs: https://developer.github.com/v3/activity/events/types/#metaevent
+type MetaEvent struct {
+	// Action is the action that was performed. Possible value is: "deleted".
+	Action *string `json:"action,omitempty"`
+	// The ID of the modified webhook.
+	HookID *int64 `json:"hook_id,omitempty"`
+	// The modified webhook.
+	// This will contain different keys based on the type of webhook it is: repository,
+	// organization, business, app, or GitHub Marketplace.
+	Hook *Hook `json:"hook,omitempty"`
+}
+
 // MilestoneEvent is triggered when a milestone is created, closed, opened, edited, or deleted.
 // The Webhook event name is "milestone".
 //
@@ -394,17 +427,18 @@ type MilestoneEvent struct {
 	Installation *Installation `json:"installation,omitempty"`
 }
 
-// OrganizationEvent is triggered when a user is added, removed, or invited to an organization.
+// OrganizationEvent is triggered when an organization is deleted and renamed, and when a user is added,
+// removed, or invited to an organization.
 // Events of this type are not visible in timelines. These events are only used to trigger organization hooks.
 // Webhook event name is "organization".
 //
 // GitHub API docs: https://developer.github.com/v3/activity/events/types/#organizationevent
 type OrganizationEvent struct {
 	// Action is the action that was performed.
-	// Can be one of "member_added", "member_removed", or "member_invited".
+	// Possible values are: "deleted", "renamed", "member_added", "member_removed", or "member_invited".
 	Action *string `json:"action,omitempty"`
 
-	// Invitaion is the invitation for the user or email if the action is "member_invited".
+	// Invitation is the invitation for the user or email if the action is "member_invited".
 	Invitation *Invitation `json:"invitation,omitempty"`
 
 	// Membership is the membership between the user and the organization.
@@ -527,18 +561,20 @@ type PublicEvent struct {
 	Installation *Installation `json:"installation,omitempty"`
 }
 
-// PullRequestEvent is triggered when a pull request is assigned, unassigned,
-// labeled, unlabeled, opened, closed, reopened, or synchronized.
+// PullRequestEvent is triggered when a pull request is assigned, unassigned, labeled,
+// unlabeled, opened, edited, closed, reopened, synchronize, ready_for_review,
+// locked, unlocked, a pull request review is requested, or a review request is removed.
 // The Webhook event name is "pull_request".
 //
 // GitHub API docs: https://developer.github.com/v3/activity/events/types/#pullrequestevent
 type PullRequestEvent struct {
 	// Action is the action that was performed. Possible values are:
 	// "assigned", "unassigned", "review_requested", "review_request_removed", "labeled", "unlabeled",
-	// "opened", "closed", "ready_for_review", "reopened", "synchronize", "edited".
-	// If the action is "closed" and the merged key is false,
-	// the pull request was closed with unmerged commits. If the action is "closed"
-	// and the merged key is true, the pull request was merged.
+	// "opened", "edited", "closed", "ready_for_review", "locked", "unlocked", or "reopened".
+	// If the action is "closed" and the "merged" key is "false", the pull request was closed with unmerged commits.
+	// If the action is "closed" and the "merged" key is "true", the pull request was merged.
+	// While webhooks are also triggered when a pull request is synchronized, Events API timelines
+	// don't include pull request events with the "synchronize" action.
 	Action      *string      `json:"action,omitempty"`
 	Assignee    *User        `json:"assignee,omitempty"`
 	Number      *int         `json:"number,omitempty"`
@@ -697,12 +733,14 @@ type PushEventRepoOwner struct {
 	Email *string `json:"email,omitempty"`
 }
 
-// ReleaseEvent is triggered when a release is published.
+// ReleaseEvent is triggered when a release is published, unpublished, created,
+// edited, deleted, or prerelased.
 // The Webhook event name is "release".
 //
 // GitHub API docs: https://developer.github.com/v3/activity/events/types/#releaseevent
 type ReleaseEvent struct {
-	// Action is the action that was performed. Possible value is: "published".
+	// Action is the action that was performed. Possible values are: "published", "unpublished",
+	// "created", "edited", "deleted", or "prereleased".
 	Action  *string            `json:"action,omitempty"`
 	Release *RepositoryRelease `json:"release,omitempty"`
 
@@ -712,7 +750,9 @@ type ReleaseEvent struct {
 	Installation *Installation `json:"installation,omitempty"`
 }
 
-// RepositoryEvent is triggered when a repository is created.
+// RepositoryEvent is triggered when a repository is created, archived, unarchived,
+// renamed, edited, transferred, made public, or made private. Organization hooks are
+// also trigerred when a repository is deleted.
 // The Webhook event name is "repository".
 //
 // Events of this type are not visible in timelines, they are only used to
@@ -720,8 +760,9 @@ type ReleaseEvent struct {
 //
 // GitHub API docs: https://developer.github.com/v3/activity/events/types/#repositoryevent
 type RepositoryEvent struct {
-	// Action is the action that was performed. Possible values are: "created", "deleted",
-	// "publicized", "privatized".
+	// Action is the action that was performed. Possible values are: "created",
+	// "deleted" (organization hooks only), "archived", "unarchived", "edited", "renamed",
+	// "transferred", "publicized", or "privatized".
 	Action *string     `json:"action,omitempty"`
 	Repo   *Repository `json:"repository,omitempty"`
 
@@ -735,7 +776,7 @@ type RepositoryEvent struct {
 //
 // GitHub API docs: https://developer.github.com/v3/activity/events/types/#repositoryvulnerabilityalertevent
 type RepositoryVulnerabilityAlertEvent struct {
-	// Action is the action that was performed. This can be: "create", "dismiss", "resolve".
+	// Action is the action that was performed. Possible values are: "create", "dismiss", "resolve".
 	Action *string `json:"action,omitempty"`
 
 	//The security alert of the vulnerable dependency.
@@ -752,6 +793,18 @@ type RepositoryVulnerabilityAlertEvent struct {
 	} `json:"alert,omitempty"`
 }
 
+// StarEvent is triggered when a star is added or removed from a repository.
+// The Webhook event name is "star".
+//
+// GitHub API docs: https://developer.github.com/v3/activity/events/types/#starevent
+type StarEvent struct {
+	// Action is the action that was performed. Possible values are: "created" or "deleted".
+	Action *string `json:"action,omitempty"`
+
+	// StarredAt is the time the star was created. It will be null for the "deleted" action.
+	StarredAt *Timestamp `json:"starred_at,omitempty"`
+}
+
 // StatusEvent is triggered when the status of a Git commit changes.
 // The Webhook event name is "status".
 //
diff --git a/github/github-accessors.go b/github/github-accessors.go
index 1366ebbc..6bc19de8 100644
--- a/github/github-accessors.go
+++ b/github/github-accessors.go
@@ -1996,6 +1996,22 @@ func (d *DeleteEvent) GetSender() *User {
 	return d.Sender
 }
 
+// GetAction returns the Action field if it's non-nil, zero value otherwise.
+func (d *DeployKeyEvent) GetAction() string {
+	if d == nil || d.Action == nil {
+		return ""
+	}
+	return *d.Action
+}
+
+// GetKey returns the Key field.
+func (d *DeployKeyEvent) GetKey() *Key {
+	if d == nil {
+		return nil
+	}
+	return d.Key
+}
+
 // GetCreatedAt returns the CreatedAt field if it's non-nil, zero value otherwise.
 func (d *Deployment) GetCreatedAt() Timestamp {
 	if d == nil || d.CreatedAt == nil {
@@ -5252,6 +5268,30 @@ func (m *MembershipEvent) GetTeam() *Team {
 	return m.Team
 }
 
+// GetAction returns the Action field if it's non-nil, zero value otherwise.
+func (m *MetaEvent) GetAction() string {
+	if m == nil || m.Action == nil {
+		return ""
+	}
+	return *m.Action
+}
+
+// GetHook returns the Hook field.
+func (m *MetaEvent) GetHook() *Hook {
+	if m == nil {
+		return nil
+	}
+	return m.Hook
+}
+
+// GetHookID returns the HookID field if it's non-nil, zero value otherwise.
+func (m *MetaEvent) GetHookID() int64 {
+	if m == nil || m.HookID == nil {
+		return 0
+	}
+	return *m.HookID
+}
+
 // GetHTMLURL returns the HTMLURL field if it's non-nil, zero value otherwise.
 func (m *Metric) GetHTMLURL() string {
 	if m == nil || m.HTMLURL == nil {
@@ -10652,6 +10692,22 @@ func (s *SourceImportAuthor) GetURL() string {
 	return *s.URL
 }
 
+// GetAction returns the Action field if it's non-nil, zero value otherwise.
+func (s *StarEvent) GetAction() string {
+	if s == nil || s.Action == nil {
+		return ""
+	}
+	return *s.Action
+}
+
+// GetStarredAt returns the StarredAt field if it's non-nil, zero value otherwise.
+func (s *StarEvent) GetStarredAt() Timestamp {
+	if s == nil || s.StarredAt == nil {
+		return Timestamp{}
+	}
+	return *s.StarredAt
+}
+
 // GetStarredAt returns the StarredAt field if it's non-nil, zero value otherwise.
 func (s *Stargazer) GetStarredAt() Timestamp {
 	if s == nil || s.StarredAt == nil {
diff --git a/github/messages.go b/github/messages.go
index e8c624a7..ac7c17f3 100644
--- a/github/messages.go
+++ b/github/messages.go
@@ -46,6 +46,7 @@ var (
 		"commit_comment":                 "CommitCommentEvent",
 		"create":                         "CreateEvent",
 		"delete":                         "DeleteEvent",
+		"deploy_key":                     "DeployKeyEvent",
 		"deployment":                     "DeploymentEvent",
 		"deployment_status":              "DeploymentStatusEvent",
 		"fork":                           "ForkEvent",
@@ -58,6 +59,7 @@ var (
 		"marketplace_purchase":           "MarketplacePurchaseEvent",
 		"member":                         "MemberEvent",
 		"membership":                     "MembershipEvent",
+		"meta":                           "MetaEvent",
 		"milestone":                      "MilestoneEvent",
 		"organization":                   "OrganizationEvent",
 		"org_block":                      "OrgBlockEvent",
@@ -74,6 +76,7 @@ var (
 		"repository":                     "RepositoryEvent",
 		"repository_vulnerability_alert": "RepositoryVulnerabilityAlertEvent",
 		"release":                        "ReleaseEvent",
+		"star":                           "StarEvent",
 		"status":                         "StatusEvent",
 		"team":                           "TeamEvent",
 		"team_add":                       "TeamAddEvent",


Test patch:
diff --git a/github/messages_test.go b/github/messages_test.go
index bde9d76b..105904c6 100644
--- a/github/messages_test.go
+++ b/github/messages_test.go
@@ -202,6 +202,10 @@ func TestParseWebHook(t *testing.T) {
 			payload:     &DeleteEvent{},
 			messageType: "delete",
 		},
+		{
+			payload:     &DeployKeyEvent{},
+			messageType: "deploy_key",
+		},
 		{
 			payload:     &DeploymentEvent{},
 			messageType: "deployment",
@@ -251,6 +255,10 @@ func TestParseWebHook(t *testing.T) {
 			payload:     &MembershipEvent{},
 			messageType: "membership",
 		},
+		{
+			payload:     &MetaEvent{},
+			messageType: "meta",
+		},
 		{
 			payload:     &MilestoneEvent{},
 			messageType: "milestone",
@@ -315,6 +323,10 @@ func TestParseWebHook(t *testing.T) {
 			payload:     &RepositoryVulnerabilityAlertEvent{},
 			messageType: "repository_vulnerability_alert",
 		},
+		{
+			payload:     &StarEvent{},
+			messageType: "star",
+		},
 		{
 			payload:     &StatusEvent{},
 			messageType: "status",