Skip to content

Commit

Permalink
Enhancement to Add Support for Discussions Webhook Event (google#2221)
Browse files Browse the repository at this point in the history
This commit has changes to enable support to receive Discussions Webhook Events, to fix google#2221.
Changes include:
- Addition of event type for this type of event
- Changes for identification and mapping of DiscussionEvent
- Addition / Modification of relevent tests
- Addition of files created by go generate
  • Loading branch information
maniSbindra committed Dec 15, 2021
1 parent fef3638 commit 5ebd892
Show file tree
Hide file tree
Showing 8 changed files with 1,016 additions and 1 deletion.
2 changes: 2 additions & 0 deletions github/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ func (e *Event) ParsePayload() (payload interface{}, err error) {
payload = &DeploymentEvent{}
case "DeploymentStatusEvent":
payload = &DeploymentStatusEvent{}
case "DiscussionEvent":
payload = &DiscussionEvent{}
case "ForkEvent":
payload = &ForkEvent{}
case "GitHubAppAuthorizationEvent":
Expand Down
53 changes: 53 additions & 0 deletions github/event_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,59 @@ type DeploymentStatusEvent struct {
Installation *Installation `json:"installation,omitempty"`
}

// DiscussionEvent represents a webhook event for a discussion.
// The Webhook event name is "discussion".
//
// GitHub API docs: https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#discussion
type DiscussionEvent struct {
// Action is the action that was performed. Possible values are:
// created, edited, deleted, pinned, unpinned, locked, unlocked,
// transferred, category_changed, answered, or unanswered.
Action *string `json:"action,omitempty"`
Discussion *Discussion `json:"discussion,omitempty"`
Repo *Repository `json:"repository,omitempty"`
Org *Organization `json:"organization,omitempty"`
Sender *User `json:"sender,omitempty"`
Installation *Installation `json:"installation,omitempty"`
}

// Discussion represents a discussion in a GitHub DiscussionEvent.
type Discussion struct {
RepositoryURL *string `json:"repository_url,omitempty"`
DiscussionCategory *DiscussionCategory `json:"category,omitempty"`
AnswerHtmlUrl *string `json:"answer_html_url,omitempty"`
AnswerChosenAt *string `json:"answer_chosen_at,omitempty"`
AnswerChosenBy *string `json:"answer_chosen_by,omitempty"`
HTMLURL *string `json:"html_url,omitempty"`
ID *int64 `json:"id,omitempty"`
NodeID *string `json:"node_id,omitempty"`
Number *int64 `json:"number,omitempty"`
Title *string `json:"title,omitempty"`
User *User `json:"user,omitempty"`
State *string `json:"state,omitempty"`
Locked *bool `json:"locked,omitempty"`
Comments *int `json:"comments,omitempty"`
CreatedAt *Timestamp `json:"created_at,omitempty"`
UpdatedAt *Timestamp `json:"updated_at,omitempty"`
AuthorAssociation *string `json:"author_association,omitempty"`
ActiveLockReason *string `json:"active_lock_reason,omitempty"`
Body *string `json:"body,omitempty"`
}

// DiscussionCategory represents a discussion category in a GitHub DiscussionEvent.
type DiscussionCategory struct {
ID *int64 `json:"id,omitempty"`
NodeID *string `json:"node_id,omitempty"`
RepositoryID *int64 `json:"repository_id,omitempty"`
Emoji *string `json:"emoji,omitempty"`
Name *string `json:"name,omitempty"`
Description *string `json:"description,omitempty"`
CreatedAt *Timestamp `json:"created_at,omitempty"`
UpdatedAt *Timestamp `json:"updated_at,omitempty"`
Slug *string `json:"slug,omitempty"`
IsAnswerable *bool `json:"is_answerable,omitempty"`
}

// ForkEvent is triggered when a user forks a repository.
// The Webhook event name is "fork".
//
Expand Down
Loading

0 comments on commit 5ebd892

Please sign in to comment.