You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A fork from gh_webhook_plug, with some additional functionality:
deserializes the payload into an Elixir data structure
pass along webhook headers in a keyword list
updates for OTP functionality and updated Elixir conventions
uses the X-Hub-Signature-256 header for verification
make sure that you have configured a secret for your webhook
Usage
Inside a Phoenix application, in the Endpoint module:
defmoduleMyApp.EndpointdoplugGitHubWebhook,secret: "secret",path: "/github_webhook",action: {MyApp.GithubWebhook,:handle}# Rest of the plugsend
so you can write the handler like so:
defmoduleMyApp.GithubWebhookdo@spechandle(Plug.Conn.t(),map(),Keyword.t())::any()defhandle(conn,payload,opts)do# Handle webhook payload here# opts contains additional values from headers# Return value of this function is ignoredendend
Configuration
The below variables can be set in your config/config.exs or via options to the plug:
config:github_webhook,# Secret set in webhook settings page of the Github repositorysecret: "foobar",# Path that will be intercepted by GhWebhookPlugpath: "/api/github_webhook",# Module and function that will be used to handle the webhook payloadaction: {MyApp.GithubWebhook,:handle}
The following options are read at compile-time, and so therefore must be set in config/config.exs:
config:github_webhook,# JSON library used for decoding the incoming requestjson_library: Jason
Installation
The package can be installed by adding github_webhook to your list of dependencies in mix.exs: