An open API service indexing awesome lists of open source software.

https://github.com/puretype/github_webhook

An Elixir library to handle GitHub webhooks with ease
https://github.com/puretype/github_webhook

elixir github webhooks

Last synced: about 2 months ago
JSON representation

An Elixir library to handle GitHub webhooks with ease

Awesome Lists containing this project

README

          

# GitHubWebhook

A fork from [gh_webhook_plug](https://github.com/emilsoman/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:

```elixir
defmodule MyApp.Endpoint do

plug GitHubWebhook,
secret: "secret",
path: "/github_webhook",
action: {MyApp.GithubWebhook, :handle}

# Rest of the plugs
end
```

so you can write the handler like so:

```elixir
defmodule MyApp.GithubWebhook do
@spec handle(Plug.Conn.t(), map(), Keyword.t()) :: any()
def handle(conn, payload, opts) do
# Handle webhook payload here
# opts contains additional values from headers

# Return value of this function is ignored
end
end
```

## Configuration

The below variables can be set in your `config/config.exs` or via options to the plug:

```elixir
config :github_webhook,
# Secret set in webhook settings page of the Github repository
secret: "foobar",
# Path that will be intercepted by GhWebhookPlug
path: "/api/github_webhook",
# Module and function that will be used to handle the webhook payload
action: {MyApp.GithubWebhook, :handle}
```

The following options are read at compile-time, and so therefore must be set in `config/config.exs`:

```elixir
config :github_webhook,
# JSON library used for decoding the incoming request
json_library: Jason
```

## Installation

The package can be installed by adding `github_webhook` to your list of dependencies in `mix.exs`:

```elixir
def deps do
[
{:github_webhook, "~> 0.2"}
]
end
```

The docs can be found at .