Opis zadania do stworzenia agregator webhook’ów.
Przykładowo, w celu odbierania naszych webhooków, będziemy chcieli wystawić POST API, na adresie:
na którym nasza usługa będzie przyjmować JSON’a z informacjami odnośnie wydarzenia które powstało na Githubie.
Następnie, całą naszą odebraną wiadomość, będziemy zapisywać w bazie danych:
Ważnym elementem jest próba automatyzacji tego w taki sposób, byśmy nie musieli tworzyć rozbudowanego rekordu w bazie MySQL samemu, dla każdej usługi format Webhook’ów może być inny i ponowne definiowanie ich w bazie danych, w momencie kiedy chcemy dodać jakaś usługę, byłoby bardzo męczące i problematyczne.
Poniżej znajduje się przykładowa ramka, z webhook’a Github’a.
{
"action": "completed",
"check_suite": {
"id": 11474097815,
"node_id": "CS_kwDOJFq9ec8AAAACq-jWlw",
"head_branch": "master",
"head_sha": "da8013944471bf7ad65c6739a9efde9770c70571",
"status": "completed",
"conclusion": "success",
"url": "https://api.github.com/repos/PRz-Racing-Team/PRTHub-front/check-suites/11474097815",
"before": "91546e32d360a235474921cf5dd7ea6d0a8d8aa0",
"after": "da8013944471bf7ad65c6739a9efde9770c70571",
"pull_requests": [
],
"app": {
"id": 85455,
"slug": "cloudflare-pages",
"node_id": "MDM6QXBwODU0NTU=",
"owner": {
"login": "cloudflare",
"id": 314135,
"node_id": "MDEyOk9yZ2FuaXphdGlvbjMxNDEzNQ==",
"avatar_url": "https://avatars.githubusercontent.com/u/314135?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/cloudflare",
"html_url": "https://github.com/cloudflare",
"followers_url": "https://api.github.com/users/cloudflare/followers",
"following_url": "https://api.github.com/users/cloudflare/following{/other_user}",
"gists_url": "https://api.github.com/users/cloudflare/gists{/gist_id}",
"starred_url": "https://api.github.com/users/cloudflare/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/cloudflare/subscriptions",
"organizations_url": "https://api.github.com/users/cloudflare/orgs",
"repos_url": "https://api.github.com/users/cloudflare/repos",
"events_url": "https://api.github.com/users/cloudflare/events{/privacy}",
"received_events_url": "https://api.github.com/users/cloudflare/received_events",
"type": "Organization",
"site_admin": false
},
"name": "Cloudflare Pages",
"description": "",
"external_url": "https://pages.cloudflare.com/",
"html_url": "https://github.com/apps/cloudflare-pages",
"created_at": "2020-10-19T20:23:00Z",
"updated_at": "2021-01-12T18:19:30Z",
"permissions": {
"checks": "write",
"contents": "read",
"deployments": "write",
"metadata": "read",
"pull_requests": "write"
},
"events": [
"pull_request",
"push"
]
},
"created_at": "2023-03-10T08:05:39Z",
"updated_at": "2023-03-10T08:07:46Z",
"rerequestable": true,
"runs_rerequestable": true,
"latest_check_runs_count": 1,
"check_runs_url": "https://api.github.com/repos/PRz-Racing-Team/PRTHub-front/check-suites/11474097815/check-runs",
"head_commit": {
"id": "da8013944471bf7ad65c6739a9efde9770c70571",
"tree_id": "6837da45883ed6cbbcd31ae8bc38ff768eb34169",
"message": "Added layout with cards to sponsors panel.",
"timestamp": "2023-03-09T00:12:44Z",
"author": {
"name": "WiktoriaCzech",
"email": "czech.wiktoria1@gmail.com"
},
"committer": {
"name": "WiktoriaCzech",
"email": "czech.wiktoria1@gmail.com"
}
}
},
"repository": {
"id": 609926521,
"node_id": "R_kgDOJFq9eQ",
"name": "PRTHub-front",
"full_name": "PRz-Racing-Team/PRTHub-front",
"private": true,
"owner": {
"login": "PRz-Racing-Team",
"id": 64755388,
"node_id": "MDEyOk9yZ2FuaXphdGlvbjY0NzU1Mzg4",
"avatar_url": "https://avatars.githubusercontent.com/u/64755388?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/PRz-Racing-Team",
"html_url": "https://github.com/PRz-Racing-Team",
"followers_url": "https://api.github.com/users/PRz-Racing-Team/followers",
"following_url": "https://api.github.com/users/PRz-Racing-Team/following{/other_user}",
"gists_url": "https://api.github.com/users/PRz-Racing-Team/gists{/gist_id}",
"starred_url": "https://api.github.com/users/PRz-Racing-Team/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/PRz-Racing-Team/subscriptions",
"organizations_url": "https://api.github.com/users/PRz-Racing-Team/orgs",
"repos_url": "https://api.github.com/users/PRz-Racing-Team/repos",
"events_url": "https://api.github.com/users/PRz-Racing-Team/events{/privacy}",
"received_events_url": "https://api.github.com/users/PRz-Racing-Team/received_events",
"type": "Organization",
"site_admin": false
},
"html_url": "https://github.com/PRz-Racing-Team/PRTHub-front",
"description": "Frontend do projektu PRTHub ",
"fork": false,
"url": "https://api.github.com/repos/PRz-Racing-Team/PRTHub-front",
"forks_url": "https://api.github.com/repos/PRz-Racing-Team/PRTHub-front/forks",
"keys_url": "https://api.github.com/repos/PRz-Racing-Team/PRTHub-front/keys{/key_id}",
"collaborators_url": "https://api.github.com/repos/PRz-Racing-Team/PRTHub-front/collaborators{/collaborator}",
"teams_url": "https://api.github.com/repos/PRz-Racing-Team/PRTHub-front/teams",
"hooks_url": "https://api.github.com/repos/PRz-Racing-Team/PRTHub-front/hooks",
"issue_events_url": "https://api.github.com/repos/PRz-Racing-Team/PRTHub-front/issues/events{/number}",
"events_url": "https://api.github.com/repos/PRz-Racing-Team/PRTHub-front/events",
"assignees_url": "https://api.github.com/repos/PRz-Racing-Team/PRTHub-front/assignees{/user}",
"branches_url": "https://api.github.com/repos/PRz-Racing-Team/PRTHub-front/branches{/branch}",
"tags_url": "https://api.github.com/repos/PRz-Racing-Team/PRTHub-front/tags",
"blobs_url": "https://api.github.com/repos/PRz-Racing-Team/PRTHub-front/git/blobs{/sha}",
"git_tags_url": "https://api.github.com/repos/PRz-Racing-Team/PRTHub-front/git/tags{/sha}",
"git_refs_url": "https://api.github.com/repos/PRz-Racing-Team/PRTHub-front/git/refs{/sha}",
"trees_url": "https://api.github.com/repos/PRz-Racing-Team/PRTHub-front/git/trees{/sha}",
"statuses_url": "https://api.github.com/repos/PRz-Racing-Team/PRTHub-front/statuses/{sha}",
"languages_url": "https://api.github.com/repos/PRz-Racing-Team/PRTHub-front/languages",
"stargazers_url": "https://api.github.com/repos/PRz-Racing-Team/PRTHub-front/stargazers",
"contributors_url": "https://api.github.com/repos/PRz-Racing-Team/PRTHub-front/contributors",
"subscribers_url": "https://api.github.com/repos/PRz-Racing-Team/PRTHub-front/subscribers",
"subscription_url": "https://api.github.com/repos/PRz-Racing-Team/PRTHub-front/subscription",
"commits_url": "https://api.github.com/repos/PRz-Racing-Team/PRTHub-front/commits{/sha}",
"git_commits_url": "https://api.github.com/repos/PRz-Racing-Team/PRTHub-front/git/commits{/sha}",
"comments_url": "https://api.github.com/repos/PRz-Racing-Team/PRTHub-front/comments{/number}",
"issue_comment_url": "https://api.github.com/repos/PRz-Racing-Team/PRTHub-front/issues/comments{/number}",
"contents_url": "https://api.github.com/repos/PRz-Racing-Team/PRTHub-front/contents/{+path}",
"compare_url": "https://api.github.com/repos/PRz-Racing-Team/PRTHub-front/compare/{base}...{head}",
"merges_url": "https://api.github.com/repos/PRz-Racing-Team/PRTHub-front/merges",
"archive_url": "https://api.github.com/repos/PRz-Racing-Team/PRTHub-front/{archive_format}{/ref}",
"downloads_url": "https://api.github.com/repos/PRz-Racing-Team/PRTHub-front/downloads",
"issues_url": "https://api.github.com/repos/PRz-Racing-Team/PRTHub-front/issues{/number}",
"pulls_url": "https://api.github.com/repos/PRz-Racing-Team/PRTHub-front/pulls{/number}",
"milestones_url": "https://api.github.com/repos/PRz-Racing-Team/PRTHub-front/milestones{/number}",
"notifications_url": "https://api.github.com/repos/PRz-Racing-Team/PRTHub-front/notifications{?since,all,participating}",
"labels_url": "https://api.github.com/repos/PRz-Racing-Team/PRTHub-front/labels{/name}",
"releases_url": "https://api.github.com/repos/PRz-Racing-Team/PRTHub-front/releases{/id}",
"deployments_url": "https://api.github.com/repos/PRz-Racing-Team/PRTHub-front/deployments",
"created_at": "2023-03-05T16:45:00Z",
"updated_at": "2023-03-05T16:52:09Z",
"pushed_at": "2023-03-10T08:05:38Z",
"git_url": "git://github.com/PRz-Racing-Team/PRTHub-front.git",
"ssh_url": "git@github.com:PRz-Racing-Team/PRTHub-front.git",
"clone_url": "https://github.com/PRz-Racing-Team/PRTHub-front.git",
"svn_url": "https://github.com/PRz-Racing-Team/PRTHub-front",
"homepage": null,
"size": 26755,
"stargazers_count": 0,
"watchers_count": 0,
"language": "JavaScript",
"has_issues": true,
"has_projects": true,
"has_downloads": true,
"has_wiki": false,
"has_pages": false,
"has_discussions": false,
"forks_count": 0,
"mirror_url": null,
"archived": false,
"disabled": false,
"open_issues_count": 0,
"license": null,
"allow_forking": false,
"is_template": false,
"web_commit_signoff_required": false,
"topics": [
],
"visibility": "private",
"forks": 0,
"open_issues": 0,
"watchers": 0,
"default_branch": "master"
},
"organization": {
"login": "PRz-Racing-Team",
"id": 64755388,
"node_id": "MDEyOk9yZ2FuaXphdGlvbjY0NzU1Mzg4",
"url": "https://api.github.com/orgs/PRz-Racing-Team",
"repos_url": "https://api.github.com/orgs/PRz-Racing-Team/repos",
"events_url": "https://api.github.com/orgs/PRz-Racing-Team/events",
"hooks_url": "https://api.github.com/orgs/PRz-Racing-Team/hooks",
"issues_url": "https://api.github.com/orgs/PRz-Racing-Team/issues",
"members_url": "https://api.github.com/orgs/PRz-Racing-Team/members{/member}",
"public_members_url": "https://api.github.com/orgs/PRz-Racing-Team/public_members{/member}",
"avatar_url": "https://avatars.githubusercontent.com/u/64755388?v=4",
"description": ""
},
"sender": {
"login": "WiktoriaCzech",
"id": 103213435,
"node_id": "U_kgDOBibpew",
"avatar_url": "https://avatars.githubusercontent.com/u/103213435?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/WiktoriaCzech",
"html_url": "https://github.com/WiktoriaCzech",
"followers_url": "https://api.github.com/users/WiktoriaCzech/followers",
"following_url": "https://api.github.com/users/WiktoriaCzech/following{/other_user}",
"gists_url": "https://api.github.com/users/WiktoriaCzech/gists{/gist_id}",
"starred_url": "https://api.github.com/users/WiktoriaCzech/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/WiktoriaCzech/subscriptions",
"organizations_url": "https://api.github.com/users/WiktoriaCzech/orgs",
"repos_url": "https://api.github.com/users/WiktoriaCzech/repos",
"events_url": "https://api.github.com/users/WiktoriaCzech/events{/privacy}",
"received_events_url": "https://api.github.com/users/WiktoriaCzech/received_events",
"type": "User",
"site_admin": false
}
}