...
1
2
3
4
5
6 package github
7
8 import (
9 "encoding/json"
10 "time"
11 )
12
13
14 type Event struct {
15 Type *string `json:"type,omitempty"`
16 Public *bool `json:"public,omitempty"`
17 RawPayload *json.RawMessage `json:"payload,omitempty"`
18 Repo *Repository `json:"repo,omitempty"`
19 Actor *User `json:"actor,omitempty"`
20 Org *Organization `json:"org,omitempty"`
21 CreatedAt *time.Time `json:"created_at,omitempty"`
22 ID *string `json:"id,omitempty"`
23 }
24
25 func (e Event) String() string {
26 return Stringify(e)
27 }
28
29
30
31 func (e *Event) ParsePayload() (payload interface{}, err error) {
32 switch *e.Type {
33 case "CheckRunEvent":
34 payload = &CheckRunEvent{}
35 case "CheckSuiteEvent":
36 payload = &CheckSuiteEvent{}
37 case "CommitCommentEvent":
38 payload = &CommitCommentEvent{}
39 case "ContentReferenceEvent":
40 payload = &ContentReferenceEvent{}
41 case "CreateEvent":
42 payload = &CreateEvent{}
43 case "DeleteEvent":
44 payload = &DeleteEvent{}
45 case "DeployKeyEvent":
46 payload = &DeployKeyEvent{}
47 case "DeploymentEvent":
48 payload = &DeploymentEvent{}
49 case "DeploymentStatusEvent":
50 payload = &DeploymentStatusEvent{}
51 case "ForkEvent":
52 payload = &ForkEvent{}
53 case "GitHubAppAuthorizationEvent":
54 payload = &GitHubAppAuthorizationEvent{}
55 case "GollumEvent":
56 payload = &GollumEvent{}
57 case "InstallationEvent":
58 payload = &InstallationEvent{}
59 case "InstallationRepositoriesEvent":
60 payload = &InstallationRepositoriesEvent{}
61 case "IssueCommentEvent":
62 payload = &IssueCommentEvent{}
63 case "IssuesEvent":
64 payload = &IssuesEvent{}
65 case "LabelEvent":
66 payload = &LabelEvent{}
67 case "MarketplacePurchaseEvent":
68 payload = &MarketplacePurchaseEvent{}
69 case "MemberEvent":
70 payload = &MemberEvent{}
71 case "MembershipEvent":
72 payload = &MembershipEvent{}
73 case "MetaEvent":
74 payload = &MetaEvent{}
75 case "MilestoneEvent":
76 payload = &MilestoneEvent{}
77 case "OrganizationEvent":
78 payload = &OrganizationEvent{}
79 case "OrgBlockEvent":
80 payload = &OrgBlockEvent{}
81 case "PackageEvent":
82 payload = &PackageEvent{}
83 case "PageBuildEvent":
84 payload = &PageBuildEvent{}
85 case "PingEvent":
86 payload = &PingEvent{}
87 case "ProjectEvent":
88 payload = &ProjectEvent{}
89 case "ProjectCardEvent":
90 payload = &ProjectCardEvent{}
91 case "ProjectColumnEvent":
92 payload = &ProjectColumnEvent{}
93 case "PublicEvent":
94 payload = &PublicEvent{}
95 case "PullRequestEvent":
96 payload = &PullRequestEvent{}
97 case "PullRequestReviewEvent":
98 payload = &PullRequestReviewEvent{}
99 case "PullRequestReviewCommentEvent":
100 payload = &PullRequestReviewCommentEvent{}
101 case "PushEvent":
102 payload = &PushEvent{}
103 case "ReleaseEvent":
104 payload = &ReleaseEvent{}
105 case "RepositoryEvent":
106 payload = &RepositoryEvent{}
107 case "RepositoryDispatchEvent":
108 payload = &RepositoryDispatchEvent{}
109 case "RepositoryVulnerabilityAlertEvent":
110 payload = &RepositoryVulnerabilityAlertEvent{}
111 case "StarEvent":
112 payload = &StarEvent{}
113 case "StatusEvent":
114 payload = &StatusEvent{}
115 case "TeamEvent":
116 payload = &TeamEvent{}
117 case "TeamAddEvent":
118 payload = &TeamAddEvent{}
119 case "UserEvent":
120 payload = &UserEvent{}
121 case "WatchEvent":
122 payload = &WatchEvent{}
123 case "WorkflowDispatchEvent":
124 payload = &WorkflowDispatchEvent{}
125 case "WorkflowRunEvent":
126 payload = &WorkflowRunEvent{}
127 }
128 err = json.Unmarshal(*e.RawPayload, &payload)
129 return payload, err
130 }
131
132
133
134
135
136
137 func (e *Event) Payload() (payload interface{}) {
138 var err error
139 payload, err = e.ParsePayload()
140 if err != nil {
141 panic(err)
142 }
143 return payload
144 }
145
View as plain text