...
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 "BranchProtectionRuleEvent":
34 payload = &BranchProtectionRuleEvent{}
35 case "CheckRunEvent":
36 payload = &CheckRunEvent{}
37 case "CheckSuiteEvent":
38 payload = &CheckSuiteEvent{}
39 case "CodeScanningAlertEvent":
40 payload = &CodeScanningAlertEvent{}
41 case "CommitCommentEvent":
42 payload = &CommitCommentEvent{}
43 case "ContentReferenceEvent":
44 payload = &ContentReferenceEvent{}
45 case "CreateEvent":
46 payload = &CreateEvent{}
47 case "DeleteEvent":
48 payload = &DeleteEvent{}
49 case "DeployKeyEvent":
50 payload = &DeployKeyEvent{}
51 case "DeploymentEvent":
52 payload = &DeploymentEvent{}
53 case "DeploymentStatusEvent":
54 payload = &DeploymentStatusEvent{}
55 case "DiscussionEvent":
56 payload = &DiscussionEvent{}
57 case "ForkEvent":
58 payload = &ForkEvent{}
59 case "GitHubAppAuthorizationEvent":
60 payload = &GitHubAppAuthorizationEvent{}
61 case "GollumEvent":
62 payload = &GollumEvent{}
63 case "InstallationEvent":
64 payload = &InstallationEvent{}
65 case "InstallationRepositoriesEvent":
66 payload = &InstallationRepositoriesEvent{}
67 case "IssueCommentEvent":
68 payload = &IssueCommentEvent{}
69 case "IssuesEvent":
70 payload = &IssuesEvent{}
71 case "LabelEvent":
72 payload = &LabelEvent{}
73 case "MarketplacePurchaseEvent":
74 payload = &MarketplacePurchaseEvent{}
75 case "MemberEvent":
76 payload = &MemberEvent{}
77 case "MembershipEvent":
78 payload = &MembershipEvent{}
79 case "MetaEvent":
80 payload = &MetaEvent{}
81 case "MilestoneEvent":
82 payload = &MilestoneEvent{}
83 case "OrganizationEvent":
84 payload = &OrganizationEvent{}
85 case "OrgBlockEvent":
86 payload = &OrgBlockEvent{}
87 case "PackageEvent":
88 payload = &PackageEvent{}
89 case "PageBuildEvent":
90 payload = &PageBuildEvent{}
91 case "PingEvent":
92 payload = &PingEvent{}
93 case "ProjectEvent":
94 payload = &ProjectEvent{}
95 case "ProjectCardEvent":
96 payload = &ProjectCardEvent{}
97 case "ProjectColumnEvent":
98 payload = &ProjectColumnEvent{}
99 case "PublicEvent":
100 payload = &PublicEvent{}
101 case "PullRequestEvent":
102 payload = &PullRequestEvent{}
103 case "PullRequestReviewEvent":
104 payload = &PullRequestReviewEvent{}
105 case "PullRequestReviewCommentEvent":
106 payload = &PullRequestReviewCommentEvent{}
107 case "PullRequestReviewThreadEvent":
108 payload = &PullRequestReviewThreadEvent{}
109 case "PullRequestTargetEvent":
110 payload = &PullRequestTargetEvent{}
111 case "PushEvent":
112 payload = &PushEvent{}
113 case "ReleaseEvent":
114 payload = &ReleaseEvent{}
115 case "RepositoryEvent":
116 payload = &RepositoryEvent{}
117 case "RepositoryDispatchEvent":
118 payload = &RepositoryDispatchEvent{}
119 case "RepositoryImportEvent":
120 payload = &RepositoryImportEvent{}
121 case "RepositoryVulnerabilityAlertEvent":
122 payload = &RepositoryVulnerabilityAlertEvent{}
123 case "SecretScanningAlertEvent":
124 payload = &SecretScanningAlertEvent{}
125 case "StarEvent":
126 payload = &StarEvent{}
127 case "StatusEvent":
128 payload = &StatusEvent{}
129 case "TeamEvent":
130 payload = &TeamEvent{}
131 case "TeamAddEvent":
132 payload = &TeamAddEvent{}
133 case "UserEvent":
134 payload = &UserEvent{}
135 case "WatchEvent":
136 payload = &WatchEvent{}
137 case "WorkflowDispatchEvent":
138 payload = &WorkflowDispatchEvent{}
139 case "WorkflowJobEvent":
140 payload = &WorkflowJobEvent{}
141 case "WorkflowRunEvent":
142 payload = &WorkflowRunEvent{}
143 }
144 err = json.Unmarshal(*e.RawPayload, &payload)
145 return payload, err
146 }
147
148
149
150
151
152
153 func (e *Event) Payload() (payload interface{}) {
154 var err error
155 payload, err = e.ParsePayload()
156 if err != nil {
157 panic(err)
158 }
159 return payload
160 }
161
View as plain text