Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support MarketeplacePurchaseEvent #789

Merged
merged 6 commits into from Nov 22, 2017
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions github/activity_events.go
Expand Up @@ -56,6 +56,8 @@ func (e *Event) ParsePayload() (payload interface{}, err error) {
payload = &IssuesEvent{}
case "LabelEvent":
payload = &LabelEvent{}
case "MarketplacePurchaseEvent":
payload = &MarketplacePurchaseEvent{}
case "MemberEvent":
payload = &MemberEvent{}
case "MembershipEvent":
Expand Down
16 changes: 16 additions & 0 deletions github/event_types.go
Expand Up @@ -268,6 +268,22 @@ type LabelEvent struct {
Installation *Installation `json:"installation,omitempty"`
}

// MarketplacePurchaseEvent is triggered when a user purchases, cancels, or changes
// their GitHub Marketplace plan.
// Webhook event name "marketplace_purchase".
//
// Github API docs: https://developer.github.com/v3/activity/events/types/#marketplacepurchaseevent
type MarketplacePurchaseEvent struct {
Action *string `json:"action,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be nice to add a comment here documenting possible action values, like in the events above and below.

// Action is the action that was performed. Possible values are:
// "purchased", "cancelled", "changed".


// The following fields are only populated by Webhook events.
EffectiveDate *Timestamp `json:"effective_date,omitempty"`
MarketplacePurchase *MarketplacePurchase `json:"marketplace_purchase,omitempty"`
PreviousMarketplacePurchase *MarketplacePurchase `json:"previous_marketplace_purchase,omitempty"`
Sender *User `json:"sender,omitempty"`
Installation *Installation `json:"installation,omitempty"`
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll need to break the fields into two sections. The event API payload fields (of which, there's only one, action):

image

And Webhook payload fields, which are all the rest. You should put them under a // The following fields are only populated by Webhook events. comment. Something like this:

type MarketplacePurchaseEvent struct {
	// Action is the action that was performed. Possible values are:
	// "purchased", "cancelled", or "changed".
	Action *string `json:"action,omitempty"`

	// The following fields are only populated by Webhook events.
	...
}

See structs right above and below the one you added for reference.

Copy link
Member

@dmitshur dmitshur Nov 19, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additionally, you'll need to add an implicit Installation *Installation `json:"installation,omitempty"` field. Its existence is documented at https://developer.github.com/webhooks/#payloads. Put it at the very bottom; see other events in this file as reference.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay @shurcooL, will fix these. thanks 👍 .


// MemberEvent is triggered when a user is added as a collaborator to a repository.
// The Webhook event name is "member".
//
Expand Down
48 changes: 48 additions & 0 deletions github/github-accessors.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions github/messages.go
Expand Up @@ -53,6 +53,7 @@ var (
"issue_comment": "IssueCommentEvent",
"issues": "IssuesEvent",
"label": "LabelEvent",
"marketplace_purchase": "MarketplacePurchaseEvent",
"member": "MemberEvent",
"membership": "MembershipEvent",
"milestone": "MilestoneEvent",
Expand Down
4 changes: 4 additions & 0 deletions github/messages_test.go
Expand Up @@ -210,6 +210,10 @@ func TestParseWebHook(t *testing.T) {
payload: &LabelEvent{},
messageType: "label",
},
{
payload: &MarketplacePurchaseEvent{},
messageType: "marketplace_purchase",
},
{
payload: &MemberEvent{},
messageType: "member",
Expand Down