Skip to content

An Elixir Plug library that makes it easy to setup Github webhooks. Secret verification comes free.

Notifications You must be signed in to change notification settings

emilsoman/gh_webhook_plug

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GhWebhookPlug

This Plug makes it easy to listen to Github webhook requests in your Elixir and Phoenix apps and trigger actions.

Features:

  • Configurable HTTP endpoint
  • Verifies authenticity using webhook secret
  • Responses are handled for you - just write business logic

Installation

Add gh_webhook_plug to your list of dependencies in mix.exs:

def deps do
  [{:gh_webhook_plug, "~> 0.0.5"}]
end

Usage

Inside a phoenix app, add this line in the Endpoint module:

defmodule MyApp.Endpoint do

  # Add this line above Plug.Parsers plug:
  plug GhWebhookPlug,
    secret: "secret",
    path: "/github_webhook",
    action: {MyApp.GithubWebhook, :handle}

  # Rest of the plugs
end

Now you can write the handler like this:

defmodule MyApp.GithubWebhook do
  def handle(conn, payload) do
    # Handle webhook payload here
    # Return value of this function is ignored
  end
end

Configuration

Add this to your configuration file (config/config.exs):

config :gh_webhook_plug,
  # 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}

These configurations can also be set via options to the plug as shown in the example in the Usage section.

License

MIT

About

An Elixir Plug library that makes it easy to setup Github webhooks. Secret verification comes free.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages