2019-05-07 03:12:51 +02:00
|
|
|
// Copyright 2018 The go-github AUTHORS. All rights reserved.
|
|
|
|
//
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package github
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Event represents a GitHub event.
|
|
|
|
type Event struct {
|
|
|
|
Type *string `json:"type,omitempty"`
|
|
|
|
Public *bool `json:"public,omitempty"`
|
|
|
|
RawPayload *json.RawMessage `json:"payload,omitempty"`
|
|
|
|
Repo *Repository `json:"repo,omitempty"`
|
|
|
|
Actor *User `json:"actor,omitempty"`
|
|
|
|
Org *Organization `json:"org,omitempty"`
|
|
|
|
CreatedAt *time.Time `json:"created_at,omitempty"`
|
|
|
|
ID *string `json:"id,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e Event) String() string {
|
|
|
|
return Stringify(e)
|
|
|
|
}
|
|
|
|
|
|
|
|
// ParsePayload parses the event payload. For recognized event types,
|
|
|
|
// a value of the corresponding struct type will be returned.
|
|
|
|
func (e *Event) ParsePayload() (payload interface{}, err error) {
|
|
|
|
switch *e.Type {
|
2021-10-26 09:19:21 +02:00
|
|
|
case "BranchProtectionRuleEvent":
|
|
|
|
payload = &BranchProtectionRuleEvent{}
|
2019-05-07 03:12:51 +02:00
|
|
|
case "CheckRunEvent":
|
|
|
|
payload = &CheckRunEvent{}
|
|
|
|
case "CheckSuiteEvent":
|
|
|
|
payload = &CheckSuiteEvent{}
|
|
|
|
case "CommitCommentEvent":
|
|
|
|
payload = &CommitCommentEvent{}
|
2021-08-10 11:49:43 +02:00
|
|
|
case "ContentReferenceEvent":
|
|
|
|
payload = &ContentReferenceEvent{}
|
2019-05-07 03:12:51 +02:00
|
|
|
case "CreateEvent":
|
|
|
|
payload = &CreateEvent{}
|
|
|
|
case "DeleteEvent":
|
|
|
|
payload = &DeleteEvent{}
|
2020-07-31 16:22:34 +02:00
|
|
|
case "DeployKeyEvent":
|
|
|
|
payload = &DeployKeyEvent{}
|
2019-05-07 03:12:51 +02:00
|
|
|
case "DeploymentEvent":
|
|
|
|
payload = &DeploymentEvent{}
|
|
|
|
case "DeploymentStatusEvent":
|
|
|
|
payload = &DeploymentStatusEvent{}
|
|
|
|
case "ForkEvent":
|
|
|
|
payload = &ForkEvent{}
|
|
|
|
case "GitHubAppAuthorizationEvent":
|
|
|
|
payload = &GitHubAppAuthorizationEvent{}
|
|
|
|
case "GollumEvent":
|
|
|
|
payload = &GollumEvent{}
|
|
|
|
case "InstallationEvent":
|
|
|
|
payload = &InstallationEvent{}
|
|
|
|
case "InstallationRepositoriesEvent":
|
|
|
|
payload = &InstallationRepositoriesEvent{}
|
|
|
|
case "IssueCommentEvent":
|
|
|
|
payload = &IssueCommentEvent{}
|
|
|
|
case "IssuesEvent":
|
|
|
|
payload = &IssuesEvent{}
|
|
|
|
case "LabelEvent":
|
|
|
|
payload = &LabelEvent{}
|
|
|
|
case "MarketplacePurchaseEvent":
|
|
|
|
payload = &MarketplacePurchaseEvent{}
|
|
|
|
case "MemberEvent":
|
|
|
|
payload = &MemberEvent{}
|
|
|
|
case "MembershipEvent":
|
|
|
|
payload = &MembershipEvent{}
|
2020-07-31 16:22:34 +02:00
|
|
|
case "MetaEvent":
|
|
|
|
payload = &MetaEvent{}
|
2019-05-07 03:12:51 +02:00
|
|
|
case "MilestoneEvent":
|
|
|
|
payload = &MilestoneEvent{}
|
|
|
|
case "OrganizationEvent":
|
|
|
|
payload = &OrganizationEvent{}
|
|
|
|
case "OrgBlockEvent":
|
|
|
|
payload = &OrgBlockEvent{}
|
2020-07-31 16:22:34 +02:00
|
|
|
case "PackageEvent":
|
|
|
|
payload = &PackageEvent{}
|
2019-05-07 03:12:51 +02:00
|
|
|
case "PageBuildEvent":
|
|
|
|
payload = &PageBuildEvent{}
|
|
|
|
case "PingEvent":
|
|
|
|
payload = &PingEvent{}
|
|
|
|
case "ProjectEvent":
|
|
|
|
payload = &ProjectEvent{}
|
|
|
|
case "ProjectCardEvent":
|
|
|
|
payload = &ProjectCardEvent{}
|
|
|
|
case "ProjectColumnEvent":
|
|
|
|
payload = &ProjectColumnEvent{}
|
|
|
|
case "PublicEvent":
|
|
|
|
payload = &PublicEvent{}
|
|
|
|
case "PullRequestEvent":
|
|
|
|
payload = &PullRequestEvent{}
|
|
|
|
case "PullRequestReviewEvent":
|
|
|
|
payload = &PullRequestReviewEvent{}
|
|
|
|
case "PullRequestReviewCommentEvent":
|
|
|
|
payload = &PullRequestReviewCommentEvent{}
|
2021-08-10 11:49:43 +02:00
|
|
|
case "PullRequestTargetEvent":
|
|
|
|
payload = &PullRequestTargetEvent{}
|
2019-05-07 03:12:51 +02:00
|
|
|
case "PushEvent":
|
|
|
|
payload = &PushEvent{}
|
|
|
|
case "ReleaseEvent":
|
|
|
|
payload = &ReleaseEvent{}
|
|
|
|
case "RepositoryEvent":
|
|
|
|
payload = &RepositoryEvent{}
|
2020-07-31 16:22:34 +02:00
|
|
|
case "RepositoryDispatchEvent":
|
|
|
|
payload = &RepositoryDispatchEvent{}
|
2019-05-07 03:12:51 +02:00
|
|
|
case "RepositoryVulnerabilityAlertEvent":
|
|
|
|
payload = &RepositoryVulnerabilityAlertEvent{}
|
2020-07-31 16:22:34 +02:00
|
|
|
case "StarEvent":
|
|
|
|
payload = &StarEvent{}
|
2019-05-07 03:12:51 +02:00
|
|
|
case "StatusEvent":
|
|
|
|
payload = &StatusEvent{}
|
|
|
|
case "TeamEvent":
|
|
|
|
payload = &TeamEvent{}
|
|
|
|
case "TeamAddEvent":
|
|
|
|
payload = &TeamAddEvent{}
|
2020-07-31 16:22:34 +02:00
|
|
|
case "UserEvent":
|
|
|
|
payload = &UserEvent{}
|
2019-05-07 03:12:51 +02:00
|
|
|
case "WatchEvent":
|
|
|
|
payload = &WatchEvent{}
|
2021-08-10 11:49:43 +02:00
|
|
|
case "WorkflowDispatchEvent":
|
|
|
|
payload = &WorkflowDispatchEvent{}
|
2021-10-26 09:19:21 +02:00
|
|
|
case "WorkflowJobEvent":
|
|
|
|
payload = &WorkflowJobEvent{}
|
2021-08-10 11:49:43 +02:00
|
|
|
case "WorkflowRunEvent":
|
|
|
|
payload = &WorkflowRunEvent{}
|
2019-05-07 03:12:51 +02:00
|
|
|
}
|
|
|
|
err = json.Unmarshal(*e.RawPayload, &payload)
|
|
|
|
return payload, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Payload returns the parsed event payload. For recognized event types,
|
|
|
|
// a value of the corresponding struct type will be returned.
|
|
|
|
//
|
|
|
|
// Deprecated: Use ParsePayload instead, which returns an error
|
|
|
|
// rather than panics if JSON unmarshaling raw payload fails.
|
|
|
|
func (e *Event) Payload() (payload interface{}) {
|
|
|
|
var err error
|
|
|
|
payload, err = e.ParsePayload()
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return payload
|
|
|
|
}
|