Skip to content

Commit d028bba

Browse files
authored
[#61]: evPushSender can be null or missing (#60)
1 parent 0acfc52 commit d028bba

File tree

5 files changed

+285
-5
lines changed

5 files changed

+285
-5
lines changed

examples/servant/src/Main.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ type PushHookAPI
3535

3636
pushHook :: RepoWebhookEvent -> ((), PushEvent) -> Handler ()
3737
pushHook _ (_, ev) = liftIO $ do
38-
putStrLn $ (show . whUserLogin . evPushSender) ev ++ " pushed a commit causing HEAD SHA to become:"
38+
putStrLn $ (show . whUserLogin . fromJust . evPushSender) ev ++ " pushed a commit causing HEAD SHA to become:"
3939
print $ (fromJust . evPushHeadSha) ev
4040

4141
-- Issue Comment Hook
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
{
2+
"ref": "refs/heads/gh-readonly-queue/main/pr-3072-287d30540ac5a1acc57d0bdc138fa81dee315f48",
3+
"before": "a6bd77bbe77ee6ae8f9686621b192d70fcf83e2b",
4+
"after": "0000000000000000000000000000000000000000",
5+
"repository": {
6+
"id": 353322834,
7+
"node_id": "MDEwOJllG9zcXaRcvknzNYyTzM4OUQD=",
8+
"name": "infra-core",
9+
"full_name": "some-organization/infra-core",
10+
"private": true,
11+
"owner": {
12+
"name": "some-organization",
13+
"email": null,
14+
"login": "some-organization",
15+
"id": 52709322,
16+
"node_id": "MDEyO9ky2ZuaXpFdhlGvjbzNzczMTO3Y",
17+
"avatar_url": "https://avatars.githubusercontent.com/u/52709322?v=4",
18+
"gravatar_id": "",
19+
"url": "https://api.github.com/users/some-organization",
20+
"html_url": "https://github.com/some-organization",
21+
"followers_url": "https://api.github.com/users/some-organization/followers",
22+
"following_url": "https://api.github.com/users/some-organization/following{/other_user}",
23+
"gists_url": "https://api.github.com/users/some-organization/gists{/gist_id}",
24+
"starred_url": "https://api.github.com/users/some-organization/starred{/owner}{/repo}",
25+
"subscriptions_url": "https://api.github.com/users/some-organization/subscriptions",
26+
"organizations_url": "https://api.github.com/users/some-organization/orgs",
27+
"repos_url": "https://api.github.com/users/some-organization/repos",
28+
"events_url": "https://api.github.com/users/some-organization/events{/privacy}",
29+
"received_events_url": "https://api.github.com/users/some-organization/received_events",
30+
"type": "Organization",
31+
"site_admin": false
32+
},
33+
"html_url": "https://github.com/some-organization/infra-core",
34+
"description": "Homo sapiens non urinat in ventum",
35+
"fork": false,
36+
"url": "https://github.com/some-organization/infra-core",
37+
"forks_url": "https://api.github.com/repos/some-organization/infra-core/forks",
38+
"keys_url": "https://api.github.com/repos/some-organization/infra-core/keys{/key_id}",
39+
"collaborators_url": "https://api.github.com/repos/some-organization/infra-core/collaborators{/collaborator}",
40+
"teams_url": "https://api.github.com/repos/some-organization/infra-core/teams",
41+
"hooks_url": "https://api.github.com/repos/some-organization/infra-core/hooks",
42+
"issue_events_url": "https://api.github.com/repos/some-organization/infra-core/issues/events{/number}",
43+
"events_url": "https://api.github.com/repos/some-organization/infra-core/events",
44+
"assignees_url": "https://api.github.com/repos/some-organization/infra-core/assignees{/user}",
45+
"branches_url": "https://api.github.com/repos/some-organization/infra-core/branches{/branch}",
46+
"tags_url": "https://api.github.com/repos/some-organization/infra-core/tags",
47+
"blobs_url": "https://api.github.com/repos/some-organization/infra-core/git/blobs{/sha}",
48+
"git_tags_url": "https://api.github.com/repos/some-organization/infra-core/git/tags{/sha}",
49+
"git_refs_url": "https://api.github.com/repos/some-organization/infra-core/git/refs{/sha}",
50+
"trees_url": "https://api.github.com/repos/some-organization/infra-core/git/trees{/sha}",
51+
"statuses_url": "https://api.github.com/repos/some-organization/infra-core/statuses/{sha}",
52+
"languages_url": "https://api.github.com/repos/some-organization/infra-core/languages",
53+
"stargazers_url": "https://api.github.com/repos/some-organization/infra-core/stargazers",
54+
"contributors_url": "https://api.github.com/repos/some-organization/infra-core/contributors",
55+
"subscribers_url": "https://api.github.com/repos/some-organization/infra-core/subscribers",
56+
"subscription_url": "https://api.github.com/repos/some-organization/infra-core/subscription",
57+
"commits_url": "https://api.github.com/repos/some-organization/infra-core/commits{/sha}",
58+
"git_commits_url": "https://api.github.com/repos/some-organization/infra-core/git/commits{/sha}",
59+
"comments_url": "https://api.github.com/repos/some-organization/infra-core/comments{/number}",
60+
"issue_comment_url": "https://api.github.com/repos/some-organization/infra-core/issues/comments{/number}",
61+
"contents_url": "https://api.github.com/repos/some-organization/infra-core/contents/{+path}",
62+
"compare_url": "https://api.github.com/repos/some-organization/infra-core/compare/{base}...{head}",
63+
"merges_url": "https://api.github.com/repos/some-organization/infra-core/merges",
64+
"archive_url": "https://api.github.com/repos/some-organization/infra-core/{archive_format}{/ref}",
65+
"downloads_url": "https://api.github.com/repos/some-organization/infra-core/downloads",
66+
"issues_url": "https://api.github.com/repos/some-organization/infra-core/issues{/number}",
67+
"pulls_url": "https://api.github.com/repos/some-organization/infra-core/pulls{/number}",
68+
"milestones_url": "https://api.github.com/repos/some-organization/infra-core/milestones{/number}",
69+
"notifications_url": "https://api.github.com/repos/some-organization/infra-core/notifications{?since,all,participating}",
70+
"labels_url": "https://api.github.com/repos/some-organization/infra-core/labels{/name}",
71+
"releases_url": "https://api.github.com/repos/some-organization/infra-core/releases{/id}",
72+
"deployments_url": "https://api.github.com/repos/some-organization/infra-core/deployments",
73+
"created_at": 1618165822,
74+
"updated_at": "2022-11-07T17:04:28Z",
75+
"pushed_at": 1670262117,
76+
"git_url": "git://github.com/some-organization/infra-core.git",
77+
"ssh_url": "[email protected]:some-organization/infra-core.git",
78+
"clone_url": "https://github.com/some-organization/infra-core.git",
79+
"svn_url": "https://github.com/some-organization/infra-core",
80+
"homepage": "https://github.com/orgs/some-organization/projects/7",
81+
"size": 23932,
82+
"stargazers_count": 4,
83+
"watchers_count": 4,
84+
"language": "Brainfuck",
85+
"has_issues": true,
86+
"has_projects": true,
87+
"has_downloads": true,
88+
"has_wiki": true,
89+
"has_pages": false,
90+
"has_discussions": true,
91+
"forks_count": 1,
92+
"mirror_url": null,
93+
"archived": false,
94+
"disabled": false,
95+
"open_issues_count": 130,
96+
"license": {
97+
"key": "other",
98+
"name": "Other",
99+
"spdx_id": "NOASSERTION",
100+
"url": null,
101+
"node_id": "MDc6GTjlW5ZZzAT="
102+
},
103+
"allow_forking": false,
104+
"is_template": false,
105+
"web_commit_signoff_required": false,
106+
"topics": [
107+
108+
],
109+
"visibility": "private",
110+
"forks": 1,
111+
"open_issues": 130,
112+
"watchers": 4,
113+
"default_branch": "main",
114+
"stargazers": 4,
115+
"master_branch": "main",
116+
"organization": "some-organization"
117+
},
118+
"pusher": {
119+
"name": "none"
120+
},
121+
"organization": {
122+
"login": "some-organization",
123+
"id": 52709322,
124+
"node_id": "MDEyO9kZyFua2pXhGlvdjbzNcMzOTYz3",
125+
"url": "https://api.github.com/orgs/some-organization",
126+
"repos_url": "https://api.github.com/orgs/some-organization/repos",
127+
"events_url": "https://api.github.com/orgs/some-organization/events",
128+
"hooks_url": "https://api.github.com/orgs/some-organization/hooks",
129+
"issues_url": "https://api.github.com/orgs/some-organization/issues",
130+
"members_url": "https://api.github.com/orgs/some-organization/members{/member}",
131+
"public_members_url": "https://api.github.com/orgs/some-organization/public_members{/member}",
132+
"avatar_url": "https://avatars.githubusercontent.com/u/52709322?v=4",
133+
"description": "Plurality Media"
134+
},
135+
"installation": {
136+
"id": 17816238,
137+
"node_id": "MDIzklOdGunVcFm0WauSW9z5GFdsGb0FW9uaTMgM3zcNjg4="
138+
},
139+
"created": false,
140+
"deleted": true,
141+
"forced": false,
142+
"base_ref": null,
143+
"compare": "https://github.com/some-organization/infra-core/compare/a6bd77bbe77e...000000000000",
144+
"commits": [
145+
146+
],
147+
"head_commit": null
148+
}

github-webhooks.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ extra-source-files:
6969
fixtures/pull-request-event.json
7070
fixtures/pull-request-review-comment-event.json
7171
fixtures/pull-request-review-event.json
72+
fixtures/push-event-without-sender.json
7273
fixtures/push-event.json
7374
fixtures/release-event.json
7475
fixtures/repository-event.json

spec/DecodeEventsSpec.hs

Lines changed: 125 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ spec = do
7070
it "can decode PullRequestReviewCommentEvent" $ fixtureShouldMatch "fixtures/pull-request-review-comment-event.json" pullRequestReviewCommentEventFixture
7171
it "can decode PullRequestReviewEvent" $ fixtureShouldMatch "fixtures/pull-request-review-event.json" pullRequestReviewEventFixture
7272
it "can decode PushEvent" $ fixtureShouldMatch "fixtures/push-event.json" pushEventFixture
73+
it "can decode PushEvent without sender" $ fixtureShouldMatch "fixtures/push-event-without-sender.json" pushEventFixtureWithoutSender
7374
it "can decode ReleaseEvent" $ fixtureShouldMatch "fixtures/release-event.json" releaseEventFixture
7475
it "can decode RepositoryEvent" $ fixtureShouldMatch "fixtures/repository-event.json" repositoryEventFixture
7576
it "can decode StatusEvent" $ fixtureShouldMatch "fixtures/status-event.json" statusEventFixture
@@ -5631,7 +5632,7 @@ pushEventFixture = PushEvent
56315632
}
56325633
, evPushOrganization = Nothing
56335634
, evPushSender =
5634-
HookUser
5635+
Just $ HookUser
56355636
{ whUserLogin = "baxterthehacker"
56365637
, whUserId = 6752317
56375638
, whUserNodeId = "MDg6Q2hlY2tSdW4xMjg2MjAyMjg="
@@ -5653,6 +5654,129 @@ pushEventFixture = PushEvent
56535654
}
56545655
}
56555656

5657+
pushEventFixtureWithoutSender :: PushEvent
5658+
pushEventFixtureWithoutSender =
5659+
PushEvent
5660+
{ evPushRef = "refs/heads/gh-readonly-queue/main/pr-3072-287d30540ac5a1acc57d0bdc138fa81dee315f48",
5661+
evPushHeadSha = Just "0000000000000000000000000000000000000000",
5662+
evPushBeforeSha = Just "a6bd77bbe77ee6ae8f9686621b192d70fcf83e2b",
5663+
evPushCreated = False,
5664+
evPushDeleted = True,
5665+
evPushForced = False,
5666+
evPushBaseRef = Nothing,
5667+
evPushCompareUrl = URL "https://github.com/some-organization/infra-core/compare/a6bd77bbe77e...000000000000",
5668+
evPushCommits = Just V.empty,
5669+
evPushHeadCommit = Nothing,
5670+
evPushRepository =
5671+
HookRepository
5672+
{ whRepoId = 353322834,
5673+
whRepoNodeId = "MDEwOJllG9zcXaRcvknzNYyTzM4OUQD=",
5674+
whRepoName = "infra-core",
5675+
whRepoFullName = "some-organization/infra-core",
5676+
whRepoOwner =
5677+
Right
5678+
( HookUser
5679+
{ whUserLogin = "some-organization",
5680+
whUserId = 52709322,
5681+
whUserNodeId = "MDEyO9ky2ZuaXpFdhlGvjbzNzczMTO3Y",
5682+
whUserAvatarUrl = URL "https://avatars.githubusercontent.com/u/52709322?v=4",
5683+
whUserGravatarId = URL "",
5684+
whUserUrl = URL "https://api.github.com/users/some-organization",
5685+
whUserHtmlUrl = URL "https://github.com/some-organization",
5686+
whUserFollowersUrl = URL "https://api.github.com/users/some-organization/followers",
5687+
whUserFollowingUrl = URL "https://api.github.com/users/some-organization/following{/other_user}",
5688+
whUserGistsUrl = URL "https://api.github.com/users/some-organization/gists{/gist_id}",
5689+
whUserStarredUrl = URL "https://api.github.com/users/some-organization/starred{/owner}{/repo}",
5690+
whUserSubscriptionsUrl = URL "https://api.github.com/users/some-organization/subscriptions",
5691+
whUserOrganizationsUrl = URL "https://api.github.com/users/some-organization/orgs",
5692+
whUserReposUrl = URL "https://api.github.com/users/some-organization/repos",
5693+
whUserEventsUrl = URL "https://api.github.com/users/some-organization/events{/privacy}",
5694+
whUserReceivedEventsUrl = URL "https://api.github.com/users/some-organization/received_events",
5695+
whUserType = OwnerOrganization,
5696+
whUserIsAdminOfSite = False
5697+
}
5698+
),
5699+
whRepoIsPrivate = True,
5700+
whRepoHtmlUrl = URL "https://github.com/some-organization/infra-core",
5701+
whRepoDescription = "Homo sapiens non urinat in ventum",
5702+
whRepoIsAFork = False,
5703+
whRepoUrl = URL "https://github.com/some-organization/infra-core",
5704+
whRepoForksUrl = URL "https://api.github.com/repos/some-organization/infra-core/forks",
5705+
whRepoKeysUrl = URL "https://api.github.com/repos/some-organization/infra-core/keys{/key_id}",
5706+
whRepoCollaboratorsUrl = URL "https://api.github.com/repos/some-organization/infra-core/collaborators{/collaborator}",
5707+
whRepoTeamsUrl = URL "https://api.github.com/repos/some-organization/infra-core/teams",
5708+
whRepoHooksUrl = URL "https://api.github.com/repos/some-organization/infra-core/hooks",
5709+
whRepoIssueEventsUrl = URL "https://api.github.com/repos/some-organization/infra-core/issues/events{/number}",
5710+
whRepoEventsUrl = URL "https://api.github.com/repos/some-organization/infra-core/events",
5711+
whRepoAssigneesUrl = URL "https://api.github.com/repos/some-organization/infra-core/assignees{/user}",
5712+
whRepoBranchesUrl = URL "https://api.github.com/repos/some-organization/infra-core/branches{/branch}",
5713+
whRepoTagsUrl = URL "https://api.github.com/repos/some-organization/infra-core/tags",
5714+
whRepoBlobsUrl = URL "https://api.github.com/repos/some-organization/infra-core/git/blobs{/sha}",
5715+
whRepoGitTagsUrl = URL "https://api.github.com/repos/some-organization/infra-core/git/tags{/sha}",
5716+
whRepoGitRefsUrl = URL "https://api.github.com/repos/some-organization/infra-core/git/refs{/sha}",
5717+
whRepoTreesUrl = URL "https://api.github.com/repos/some-organization/infra-core/git/trees{/sha}",
5718+
whRepoStatusesUrl = URL "https://api.github.com/repos/some-organization/infra-core/statuses/{sha}",
5719+
whRepoLanguagesUrl = URL "https://api.github.com/repos/some-organization/infra-core/languages",
5720+
whRepoStargazersUrl = URL "https://api.github.com/repos/some-organization/infra-core/stargazers",
5721+
whRepoContributorsUrl = URL "https://api.github.com/repos/some-organization/infra-core/contributors",
5722+
whRepoSubscribersUrl = URL "https://api.github.com/repos/some-organization/infra-core/subscribers",
5723+
whRepoSubscriptionUrl = URL "https://api.github.com/repos/some-organization/infra-core/subscription",
5724+
whRepoCommitsUrl = URL "https://api.github.com/repos/some-organization/infra-core/commits{/sha}",
5725+
whRepoGitCommitsUrl = URL "https://api.github.com/repos/some-organization/infra-core/git/commits{/sha}",
5726+
whRepoCommentsUrl = URL "https://api.github.com/repos/some-organization/infra-core/comments{/number}",
5727+
whRepoIssueCommentsUrl = URL "https://api.github.com/repos/some-organization/infra-core/issues/comments{/number}",
5728+
whRepoContentsUrl = URL "https://api.github.com/repos/some-organization/infra-core/contents/{+path}",
5729+
whRepoCompareUrl = URL "https://api.github.com/repos/some-organization/infra-core/compare/{base}...{head}",
5730+
whRepoMergesUrl = URL "https://api.github.com/repos/some-organization/infra-core/merges",
5731+
whRepoArchiveUrl = URL "https://api.github.com/repos/some-organization/infra-core/{archive_format}{/ref}",
5732+
whRepoDownloadsUrl = URL "https://api.github.com/repos/some-organization/infra-core/downloads",
5733+
whRepoIssuesUrl = URL "https://api.github.com/repos/some-organization/infra-core/issues{/number}",
5734+
whRepoPullsUrl = URL "https://api.github.com/repos/some-organization/infra-core/pulls{/number}",
5735+
whRepoMilestonesUrl = URL "https://api.github.com/repos/some-organization/infra-core/milestones{/number}",
5736+
whRepoNotificationsUrl = URL "https://api.github.com/repos/some-organization/infra-core/notifications{?since,all,participating}",
5737+
whRepoLabelsUrl = URL "https://api.github.com/repos/some-organization/infra-core/labels{/name}",
5738+
whRepoReleasesUrl = URL "https://api.github.com/repos/some-organization/infra-core/releases{/id}",
5739+
whRepoCreatedAt = read "2021-04-11 18:30:22Z",
5740+
whRepoUpdatedAt = read "2022-11-07 17:04:28Z",
5741+
whRepoPushedAt = read "2022-12-05 17:41:57Z",
5742+
whRepoGitUrl = URL "git://github.com/some-organization/infra-core.git",
5743+
whRepoSshUrl = URL "[email protected]:some-organization/infra-core.git",
5744+
whRepoCloneUrl = URL "https://github.com/some-organization/infra-core.git",
5745+
whRepoSvnUrl = URL "https://github.com/some-organization/infra-core",
5746+
whRepoHomepage = Just (URL "https://github.com/orgs/some-organization/projects/7"),
5747+
whRepoSize = 23932,
5748+
whRepoStargazersCount = 4,
5749+
whRepoWatchersCount = 4,
5750+
whRepoLanguage = Just "Brainfuck",
5751+
whRepoHasIssues = True,
5752+
whRepoHasDownloads = True,
5753+
whRepoHasWiki = True,
5754+
whRepoHasPages = False,
5755+
whRepoForkCount = 1,
5756+
whRepoMirrorUrl = Nothing,
5757+
whRepoOpenIssuesCount = 130,
5758+
whRepoDefaultBranchName = "main"
5759+
},
5760+
evPushOrganization =
5761+
Just
5762+
( HookOrganization
5763+
{ whOrgLogin = "some-organization",
5764+
whOrgId = 52709322,
5765+
whOrgNodeId = "MDEyO9kZyFua2pXhGlvdjbzNcMzOTYz3",
5766+
whOrgUrl = URL "https://api.github.com/orgs/some-organization",
5767+
whOrgReposUrl = URL "https://api.github.com/orgs/some-organization/repos",
5768+
whOrgEventsUrl = URL "https://api.github.com/orgs/some-organization/events",
5769+
whOrgHooksUrl = Just (URL "https://api.github.com/orgs/some-organization/hooks"),
5770+
whOrgIssuesUrl = Just (URL "https://api.github.com/orgs/some-organization/issues"),
5771+
whOrgMembersUrl = URL "https://api.github.com/orgs/some-organization/members{/member}",
5772+
whOrgPublicMembersUrl = URL "https://api.github.com/orgs/some-organization/public_members{/member}",
5773+
whOrgAvatarUrl = URL "https://avatars.githubusercontent.com/u/52709322?v=4",
5774+
whOrgDescription = "Plurality Media"
5775+
}
5776+
),
5777+
evPushSender = Nothing
5778+
}
5779+
56565780
releaseEventFixture :: ReleaseEvent
56575781
releaseEventFixture = ReleaseEvent
56585782
{ evReleaseEventAction = ReleasePublishedAction

0 commit comments

Comments
 (0)