forked from haskell-github/github
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWebhooks.hs
More file actions
291 lines (268 loc) · 13.3 KB
/
Copy pathWebhooks.hs
File metadata and controls
291 lines (268 loc) · 13.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
-----------------------------------------------------------------------------
-- |
-- License : BSD-3-Clause
-- Maintainer : Oleg Grenrus <oleg.grenrus@iki.fi>
--
module GitHub.Data.Webhooks where
import GitHub.Data.Id (Id)
import GitHub.Data.URL (URL)
import GitHub.Internal.Prelude
import Prelude ()
import qualified Data.Map as M
import qualified Data.Text as T
data RepoWebhook = RepoWebhook
{ repoWebhookUrl :: !URL
, repoWebhookTestUrl :: !URL
, repoWebhookId :: !(Id RepoWebhook)
, repoWebhookName :: !Text
, repoWebhookActive :: !Bool
, repoWebhookEvents :: !(Vector RepoWebhookEvent)
, repoWebhookConfig :: !(M.Map Text Text)
, repoWebhookLastResponse :: !RepoWebhookResponse
, repoWebhookUpdatedAt :: !UTCTime
, repoWebhookCreatedAt :: !UTCTime
}
deriving (Show, Data, Typeable, Eq, Ord, Generic)
instance NFData RepoWebhook where rnf = genericRnf
instance Binary RepoWebhook
-- | See <https://developer.github.com/webhooks/#events>.
data RepoWebhookEvent
= WebhookWildcardEvent
| WebhookCheckRunEvent
| WebhookCheckSuiteEvent
| WebhookCommitCommentEvent
| WebhookContentReferenceEvent
| WebhookCreateEvent
| WebhookDeleteEvent
| WebhookDeployKeyEvent
| WebhookDeploymentEvent
| WebhookDeploymentStatusEvent
| WebhookDownloadEvent
| WebhookFollowEvent
| WebhookForkEvent
| WebhookForkApplyEvent
| WebhookGitHubAppAuthorizationEvent
| WebhookGistEvent
| WebhookGollumEvent
| WebhookInstallationEvent
| WebhookInstallationRepositoriesEvent
| WebhookIssueCommentEvent
| WebhookIssuesEvent
| WebhookLabelEvent
| WebhookMarketplacePurchaseEvent
| WebhookMemberEvent
| WebhookMembershipEvent
| WebhookMetaEvent
| WebhookMilestoneEvent
| WebhookOrganizationEvent
| WebhookOrgBlockEvent
| WebhookPageBuildEvent
| WebhookPingEvent
| WebhookProjectCardEvent
| WebhookProjectColumnEvent
| WebhookProjectEvent
| WebhookPublicEvent
| WebhookPullRequestEvent
| WebhookPullRequestReviewEvent
| WebhookPullRequestReviewCommentEvent
| WebhookPushEvent
| WebhookRegistryPackageEvent
| WebhookReleaseEvent
| WebhookRepositoryEvent
| WebhookRepositoryImportEvent
| WebhookRepositoryVulnerabilityAlertEvent
| WebhookSecurityAdvisoryEvent
| WebhookStarEvent
| WebhookStatusEvent
| WebhookTeamEvent
| WebhookTeamAddEvent
| WebhookWatchEvent
deriving (Show, Data, Typeable, Eq, Ord, Generic)
instance NFData RepoWebhookEvent where rnf = genericRnf
instance Binary RepoWebhookEvent
data RepoWebhookResponse = RepoWebhookResponse
{ repoWebhookResponseCode :: !(Maybe Int)
, repoWebhookResponseStatus :: !Text
, repoWebhookResponseMessage :: !(Maybe Text)
}
deriving (Show, Data, Typeable, Eq, Ord, Generic)
instance NFData RepoWebhookResponse where rnf = genericRnf
instance Binary RepoWebhookResponse
data PingEvent = PingEvent
{ pingEventZen :: !Text
, pingEventHook :: !RepoWebhook
, pingEventHookId :: !(Id RepoWebhook)
}
deriving (Show, Data, Typeable, Eq, Ord, Generic)
instance NFData PingEvent where rnf = genericRnf
instance Binary PingEvent
data NewRepoWebhook = NewRepoWebhook
{ newRepoWebhookName :: !Text
, newRepoWebhookConfig :: !(M.Map Text Text)
, newRepoWebhookEvents :: !(Maybe (Vector RepoWebhookEvent))
, newRepoWebhookActive :: !(Maybe Bool)
}
deriving (Eq, Ord, Show, Typeable, Data, Generic)
instance NFData NewRepoWebhook where rnf = genericRnf
instance Binary NewRepoWebhook
data EditRepoWebhook = EditRepoWebhook
{ editRepoWebhookConfig :: !(Maybe (M.Map Text Text))
, editRepoWebhookEvents :: !(Maybe (Vector RepoWebhookEvent))
, editRepoWebhookAddEvents :: !(Maybe (Vector RepoWebhookEvent))
, editRepoWebhookRemoveEvents :: !(Maybe (Vector RepoWebhookEvent))
, editRepoWebhookActive :: !(Maybe Bool)
}
deriving (Eq, Ord, Show, Typeable, Data, Generic)
instance NFData EditRepoWebhook where rnf = genericRnf
instance Binary EditRepoWebhook
-- JSON instances
instance FromJSON RepoWebhookEvent where
parseJSON = withText "RepoWebhookEvent" $ \t -> case T.toLower t of
"*" -> pure WebhookWildcardEvent
"check_run" -> pure WebhookCheckRunEvent
"check_suite" -> pure WebhookCheckSuiteEvent
"commit_comment" -> pure WebhookCommitCommentEvent
"content_reference" -> pure WebhookContentReferenceEvent
"create" -> pure WebhookCreateEvent
"delete" -> pure WebhookDeleteEvent
"deploy_key" -> pure WebhookDeployKeyEvent
"deployment" -> pure WebhookDeploymentEvent
"deployment_status" -> pure WebhookDeploymentStatusEvent
"download" -> pure WebhookDownloadEvent
"follow" -> pure WebhookFollowEvent
"fork" -> pure WebhookForkEvent
"fork_apply" -> pure WebhookForkApplyEvent
"github_app_authorization" -> pure WebhookGitHubAppAuthorizationEvent
"gist" -> pure WebhookGistEvent
"gollum" -> pure WebhookGollumEvent
"installation" -> pure WebhookInstallationEvent
"installation_repositories" -> pure WebhookInstallationRepositoriesEvent
"issue_comment" -> pure WebhookIssueCommentEvent
"issues" -> pure WebhookIssuesEvent
"label" -> pure WebhookLabelEvent
"marketplace_purchase" -> pure WebhookMarketplacePurchaseEvent
"member" -> pure WebhookMemberEvent
"membership" -> pure WebhookMembershipEvent
"meta" -> pure WebhookMetaEvent
"milestone" -> pure WebhookMilestoneEvent
"organization" -> pure WebhookOrganizationEvent
"org_block" -> pure WebhookOrgBlockEvent
"page_build" -> pure WebhookPageBuildEvent
"ping" -> pure WebhookPingEvent
"project_card" -> pure WebhookProjectCardEvent
"project_column" -> pure WebhookProjectColumnEvent
"project" -> pure WebhookProjectEvent
"public" -> pure WebhookPublicEvent
"pull_request" -> pure WebhookPullRequestEvent
"pull_request_review" -> pure WebhookPullRequestReviewEvent
"pull_request_review_comment" -> pure WebhookPullRequestReviewCommentEvent
"push" -> pure WebhookPushEvent
"registry_package" -> pure WebhookRegistryPackageEvent
"release" -> pure WebhookReleaseEvent
"repository" -> pure WebhookRepositoryEvent
"repository_import" -> pure WebhookRepositoryImportEvent
"repository_vulnerability_alert" -> pure WebhookRepositoryVulnerabilityAlertEvent
"security_advisory" -> pure WebhookSecurityAdvisoryEvent
"star" -> pure WebhookStarEvent
"status" -> pure WebhookStatusEvent
"team" -> pure WebhookTeamEvent
"team_add" -> pure WebhookTeamAddEvent
"watch" -> pure WebhookWatchEvent
_ -> fail $ "Unknown RepoWebhookEvent: " <> T.unpack t
instance ToJSON RepoWebhookEvent where
toJSON WebhookWildcardEvent = String "*"
toJSON WebhookCheckRunEvent = String "check_run"
toJSON WebhookCheckSuiteEvent = String "check_suite"
toJSON WebhookCommitCommentEvent = String "commit_comment"
toJSON WebhookContentReferenceEvent = String "content_reference"
toJSON WebhookCreateEvent = String "create"
toJSON WebhookDeleteEvent = String "delete"
toJSON WebhookDeployKeyEvent = String "deploy_key"
toJSON WebhookDeploymentEvent = String "deployment"
toJSON WebhookDeploymentStatusEvent = String "deployment_status"
toJSON WebhookDownloadEvent = String "download"
toJSON WebhookFollowEvent = String "follow"
toJSON WebhookForkEvent = String "fork"
toJSON WebhookForkApplyEvent = String "fork_apply"
toJSON WebhookGitHubAppAuthorizationEvent = String "github_app_authorization"
toJSON WebhookGistEvent = String "gist"
toJSON WebhookGollumEvent = String "gollum"
toJSON WebhookInstallationEvent = String "installation"
toJSON WebhookInstallationRepositoriesEvent = String "installation_repositories"
toJSON WebhookIssueCommentEvent = String "issue_comment"
toJSON WebhookIssuesEvent = String "issues"
toJSON WebhookLabelEvent = String "label"
toJSON WebhookMarketplacePurchaseEvent = String "marketplace_purchase"
toJSON WebhookMemberEvent = String "member"
toJSON WebhookMembershipEvent = String "membership"
toJSON WebhookMetaEvent = String "meta"
toJSON WebhookMilestoneEvent = String "milestone"
toJSON WebhookOrganizationEvent = String "organization"
toJSON WebhookOrgBlockEvent = String "org_block"
toJSON WebhookPageBuildEvent = String "page_build"
toJSON WebhookPingEvent = String "ping"
toJSON WebhookProjectCardEvent = String "project_card"
toJSON WebhookProjectColumnEvent = String "project_column"
toJSON WebhookProjectEvent = String "project"
toJSON WebhookPublicEvent = String "public"
toJSON WebhookPullRequestEvent = String "pull_request"
toJSON WebhookPullRequestReviewEvent = String "pull_request_review"
toJSON WebhookPullRequestReviewCommentEvent = String "pull_request_review_comment"
toJSON WebhookPushEvent = String "push"
toJSON WebhookRegistryPackageEvent = String "registry_package"
toJSON WebhookReleaseEvent = String "release"
toJSON WebhookRepositoryEvent = String "repository"
toJSON WebhookRepositoryImportEvent = String "repository_import"
toJSON WebhookRepositoryVulnerabilityAlertEvent = String "repository_vulnerability_alert"
toJSON WebhookSecurityAdvisoryEvent = String "security_advisory"
toJSON WebhookStarEvent = String "star"
toJSON WebhookStatusEvent = String "status"
toJSON WebhookTeamEvent = String "team"
toJSON WebhookTeamAddEvent = String "team_add"
toJSON WebhookWatchEvent = String "watch"
instance FromJSON RepoWebhook where
parseJSON = withObject "RepoWebhook" $ \o -> RepoWebhook
<$> o .: "url"
<*> o .: "test_url"
<*> o .: "id"
<*> o .: "name"
<*> o .: "active"
<*> o .: "events"
<*> o .: "config"
<*> o .: "last_response"
<*> o .: "updated_at"
<*> o .: "created_at"
instance FromJSON RepoWebhookResponse where
parseJSON = withObject "RepoWebhookResponse" $ \o -> RepoWebhookResponse
<$> o .: "code"
<*> o .: "status"
<*> o .: "message"
instance ToJSON NewRepoWebhook where
toJSON (NewRepoWebhook { newRepoWebhookName = name
, newRepoWebhookConfig = config
, newRepoWebhookEvents = events
, newRepoWebhookActive = active
}) = object
[ "name" .= name
, "config" .= config
, "events" .= events
, "active" .= active
]
instance ToJSON EditRepoWebhook where
toJSON (EditRepoWebhook { editRepoWebhookConfig = config
, editRepoWebhookEvents = events
, editRepoWebhookAddEvents = addEvents
, editRepoWebhookRemoveEvents = removeEvents
, editRepoWebhookActive = active
}) = object
[ "config" .= config
, "events" .= events
, "add_events" .= addEvents
, "remove_events" .= removeEvents
, "active" .= active
]
instance FromJSON PingEvent where
parseJSON = withObject "PingEvent" $ \o -> PingEvent
<$> o .: "zen"
<*> o .: "hook"
<*> o .: "hook_id"