Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse webhooks for GitHub App installations. #157

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion bot-components/GitHub_subscriptions.ml
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,13 @@ let push_event_info_of_json json =
in
{owner; repo; base_ref; commits_msg}

let installation_info_of_json json =
let open Yojson.Basic.Util in
let installation = json |> member "installation" in
let installation_id = installation |> member "id" |> to_int in
let owner = installation |> member "account" |> member "login" |> to_string in
{owner; installation_id}

type msg =
| IssueOpened of issue_info
| IssueClosed of issue_info
Expand All @@ -163,6 +170,8 @@ type msg =
| CheckSuiteCreated of check_suite_info
| CheckSuiteRequested of check_suite_info
| PushEvent of push_info
| GitHubAppInstallation of github_app_install_info
| GitHubAppDeletion of github_app_install_info
| UnsupportedEvent of string

let github_action ~event ~action json =
Expand Down Expand Up @@ -195,6 +204,10 @@ let github_action ~event ~action json =
Ok (CheckRunCreated (check_run_info_of_json json))
| "check_suite", "requested" ->
Ok (CheckSuiteRequested (check_suite_info_of_json json))
| "installation", ("created" | "unsuspend") ->
Ok (GitHubAppInstallation (installation_info_of_json json))
| "installation", ("deleted" | "suspend") ->
Ok (GitHubAppDeletion (installation_info_of_json json))
| _ ->
Ok (UnsupportedEvent "Unsupported GitHub action.")

Expand All @@ -206,7 +219,8 @@ let github_event ~event json =
| "issue_comment"
| "pull_request_review"
| "check_run"
| "check_suite" ->
| "check_suite"
| "installation" ->
github_action ~event ~action:(json |> member "action" |> to_string) json
| "push" ->
Ok (PushEvent (push_event_info_of_json json))
Expand Down
2 changes: 2 additions & 0 deletions bot-components/GitHub_subscriptions.mli
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ type msg =
| CheckSuiteCreated of check_suite_info
| CheckSuiteRequested of check_suite_info
| PushEvent of push_info
| GitHubAppInstallation of github_app_install_info
| GitHubAppDeletion of github_app_install_info
| UnsupportedEvent of string

val receive_github :
Expand Down
2 changes: 2 additions & 0 deletions bot-components/GitHub_types.mli
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,5 @@ type check_run =
; url: string
; title: string
; text: string }

type github_app_install_info = {owner: string; installation_id: int}