@@ -7,124 +7,9 @@ package github
7
7
8
8
import (
9
9
"context"
10
- "encoding/json"
11
10
"fmt"
12
- "time"
13
11
)
14
12
15
- // Event represents a GitHub event.
16
- type Event struct {
17
- Type * string `json:"type,omitempty"`
18
- Public * bool `json:"public,omitempty"`
19
- RawPayload * json.RawMessage `json:"payload,omitempty"`
20
- Repo * Repository `json:"repo,omitempty"`
21
- Actor * User `json:"actor,omitempty"`
22
- Org * Organization `json:"org,omitempty"`
23
- CreatedAt * time.Time `json:"created_at,omitempty"`
24
- ID * string `json:"id,omitempty"`
25
- }
26
-
27
- func (e Event ) String () string {
28
- return Stringify (e )
29
- }
30
-
31
- // ParsePayload parses the event payload. For recognized event types,
32
- // a value of the corresponding struct type will be returned.
33
- func (e * Event ) ParsePayload () (payload interface {}, err error ) {
34
- switch * e .Type {
35
- case "CheckRunEvent" :
36
- payload = & CheckRunEvent {}
37
- case "CheckSuiteEvent" :
38
- payload = & CheckSuiteEvent {}
39
- case "CommitCommentEvent" :
40
- payload = & CommitCommentEvent {}
41
- case "CreateEvent" :
42
- payload = & CreateEvent {}
43
- case "DeleteEvent" :
44
- payload = & DeleteEvent {}
45
- case "DeploymentEvent" :
46
- payload = & DeploymentEvent {}
47
- case "DeploymentStatusEvent" :
48
- payload = & DeploymentStatusEvent {}
49
- case "ForkEvent" :
50
- payload = & ForkEvent {}
51
- case "GollumEvent" :
52
- payload = & GollumEvent {}
53
- case "InstallationEvent" :
54
- payload = & InstallationEvent {}
55
- case "InstallationRepositoriesEvent" :
56
- payload = & InstallationRepositoriesEvent {}
57
- case "IssueCommentEvent" :
58
- payload = & IssueCommentEvent {}
59
- case "IssuesEvent" :
60
- payload = & IssuesEvent {}
61
- case "LabelEvent" :
62
- payload = & LabelEvent {}
63
- case "MarketplacePurchaseEvent" :
64
- payload = & MarketplacePurchaseEvent {}
65
- case "MemberEvent" :
66
- payload = & MemberEvent {}
67
- case "MembershipEvent" :
68
- payload = & MembershipEvent {}
69
- case "MilestoneEvent" :
70
- payload = & MilestoneEvent {}
71
- case "OrganizationEvent" :
72
- payload = & OrganizationEvent {}
73
- case "OrgBlockEvent" :
74
- payload = & OrgBlockEvent {}
75
- case "PageBuildEvent" :
76
- payload = & PageBuildEvent {}
77
- case "PingEvent" :
78
- payload = & PingEvent {}
79
- case "ProjectEvent" :
80
- payload = & ProjectEvent {}
81
- case "ProjectCardEvent" :
82
- payload = & ProjectCardEvent {}
83
- case "ProjectColumnEvent" :
84
- payload = & ProjectColumnEvent {}
85
- case "PublicEvent" :
86
- payload = & PublicEvent {}
87
- case "PullRequestEvent" :
88
- payload = & PullRequestEvent {}
89
- case "PullRequestReviewEvent" :
90
- payload = & PullRequestReviewEvent {}
91
- case "PullRequestReviewCommentEvent" :
92
- payload = & PullRequestReviewCommentEvent {}
93
- case "PushEvent" :
94
- payload = & PushEvent {}
95
- case "ReleaseEvent" :
96
- payload = & ReleaseEvent {}
97
- case "RepositoryEvent" :
98
- payload = & RepositoryEvent {}
99
- case "RepositoryVulnerabilityAlertEvent" :
100
- payload = & RepositoryVulnerabilityAlertEvent {}
101
- case "StatusEvent" :
102
- payload = & StatusEvent {}
103
- case "TeamEvent" :
104
- payload = & TeamEvent {}
105
- case "TeamAddEvent" :
106
- payload = & TeamAddEvent {}
107
- case "WatchEvent" :
108
- payload = & WatchEvent {}
109
- }
110
- err = json .Unmarshal (* e .RawPayload , & payload )
111
- return payload , err
112
- }
113
-
114
- // Payload returns the parsed event payload. For recognized event types,
115
- // a value of the corresponding struct type will be returned.
116
- //
117
- // Deprecated: Use ParsePayload instead, which returns an error
118
- // rather than panics if JSON unmarshaling raw payload fails.
119
- func (e * Event ) Payload () (payload interface {}) {
120
- var err error
121
- payload , err = e .ParsePayload ()
122
- if err != nil {
123
- panic (err )
124
- }
125
- return payload
126
- }
127
-
128
13
// ListEvents drinks from the firehose of all public events across GitHub.
129
14
//
130
15
// GitHub API docs: https://developer.github.com/v3/activity/events/#list-public-events
0 commit comments