• Stars
    star
    113
  • Rank 310,115 (Top 7 %)
  • Language
    Ruby
  • License
    MIT License
  • Created over 10 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

πŸ’Ž Ruby gem processing GitHub Webhooks

Gem Version

Github Webhook for Rails

This gem will help you to quickly setup a route in your Rails application which listens to a GitHub webhook

Alternatives

If you want to use this logic outside of Rails, you should consider the following gems (cf #19):

If you are on Rails, please read on!

Installation

Add this line to your application's Gemfile:

gem 'github_webhook', '~> 1.4'

And then execute:

$ bundle install

Configuration

First, configure a route to receive the github webhook POST requests.

# config/routes.rb
resource :github_webhooks, only: :create, defaults: { formats: :json }

Then create a new controller:

# app/controllers/github_webhooks_controller.rb
class GithubWebhooksController < ActionController::API
  include GithubWebhook::Processor

  # Handle push event
  def github_push(payload)
    # TODO: handle push webhook
  end

  # Handle create event
  def github_create(payload)
    # TODO: handle create webhook
  end

  private

  def webhook_secret(payload)
    ENV['GITHUB_WEBHOOK_SECRET']
  end
end

Add as many instance methods as events you want to handle in your controller.

All events are prefixed with github_. So, a push event can be handled by github_push(payload), or a create event can be handled by github_create(payload), etc.

You can read the full list of events GitHub can notify you about.

Adding the Webhook to your git repository:

First, install octokit, then run a rails console.

$ gem install octokit
$ rails console

In the rails console, add the WebHook to GitHub:

require "octokit"
client = Octokit::Client.new(:login => 'ssaunier', :password => 's3cr3t!!!')

repo = "ssaunier/github_webhook"
callback_url = "yourdomain.com/github_webhooks"
webhook_secret = "a_gr34t_s3cr3t"  # Must be set after that in ENV['GITHUB_WEBHOOK_SECRET']

# Create the WebHook
client.subscribe "https://github.com/#{repo}/events/push.json", callback_url, webhook_secret

The secret is set at the webhook creation. Store it in an environment variable, GITHUB_WEBHOOK_SECRET as per the example. It is important to have such a secret, as it will guarantee that your process legit webhooks requests, thus only from GitHub.

You can have an overview of your webhooks at the following URL:

https://github.com/:username/:repo/settings/hooks

Contributing

Specs

This project uses Appraisal to test against multiple versions of Rails.

On Travis, builds are also run on multiple versions of Ruby, each with multiple versions of Rails.

When you run bundle install, it will use the latest version of Rails. You can then run bundle exec rake spec to run the test with that version of Rails.

To run the specs against each version of Rails, use bundle exec appraisal rake spec.

More Repositories

1

round_robin_tournament

πŸ’Ž Ruby gem for Round Robin Tournament scheduling
Ruby
53
star
2

dotfiles

Dot files for my macbook setup (shell = zsh)
Shell
38
star
3

lockyourscreen

Tiny project full of awesome to play a prank on your unlocky coworkers!
HTML
33
star
4

airbnb-clone

JavaScript
30
star
5

ssaunier.github.io

Jekyll repository serving @ssaunier's homepage.
CSS
25
star
6

angular-rails-example

Rails + Angular + Karma with Sprockets (bower / grunt not needed)
Ruby
20
star
7

mergehook

Mark a Pivotal Tracker story as Finished when its Pull Request is merged
Ruby
12
star
8

livestats

A simple solution get a realtime view of your visitors. Cloning ChartBeat and GoSquared simplest features, widget dashboard inspired by Ducksboard.
PHP
11
star
9

jekyll-intro

Hands-on tutorial on how to set your very first Jekyll site
9
star
10

track-outbound-links

Track outbound links clicked in Google Analytics as events
JavaScript
8
star
11

markdown_cache

πŸ’Ž Markdown (GFM) view helper with redis-backed cache
Ruby
7
star
12

node-redis-monitor

Small web app to monitor a redis instance. Graphs command per seconds and memory usage.
JavaScript
7
star
13

trello_webhook

πŸ’Ž Ruby gem processing Trello Webhooks
Ruby
6
star
14

personal-api

Jekyll implementation of @tlongren personal-api
4
star
15

colortimer

Visual color timer to work with the Pomodoro Technique
4
star
16

lab

Quickly hack an algorithm with TDD (Phone interviews!)
Ruby
4
star
17

headsha.re

Drive more traffic to your website throught the links you share on social networks
Ruby
3
star
18

got_fixed

Rails engine to extend your application with a dashboard of your user-reported issues
Ruby
3
star
19

github-french-cities

Where do developer work in France?
Ruby
3
star
20

.js

Sometimes you have to implement the feature yourself
JavaScript
2
star
21

atomic-design-sprint

CSS
2
star
22

github-slideshow

A robot powered training repository πŸ€–
2
star
23

codeacademy

πŸ’Ž Ruby gem to fetch CodeAcademy user achivement badges
Ruby
2
star
24

wagon-uikit

2
star
25

docker-ruby-docsplit

ApacheConf
2
star
26

git-101

Python
2
star
27

contract-generator

Generate LateX contracts for my freelance consulting business from a client.yml file
TeX
2
star
28

terminal-101

HTML
2
star
29

resume

LaTeX resume of SΓ©bastien Saunier, CTO @lewagon
TeX
2
star
30

colissimo

πŸ’Ž Ruby gem to retrieve Colissimo shipping status for a parcel (image only)
Ruby
2
star
31

github-flow

HTML
1
star
32

news

Python
1
star
33

machine

Python
1
star
34

js-test

JavaScript
1
star
35

twitter-api

Python
1
star
36

test-gh

1
star
37

dice-roller

Python
1
star
38

ssaunier

Profile README
1
star
39

lanyon-girls-in-tech

Girls in Tech workshop "Je code, donc je suis" at @LeWagon
CSS
1
star
40

debt

[WIP] Quickly assess the complexity and technical debt of a rails app
Ruby
1
star
41

git-intro

My slides teaching Git & Github at @LeWagonParis
CoffeeScript
1
star
42

landing

HTML
1
star
43

hello-world-actions

1
star
44

pages

pages.xyz front-end application
Vue
1
star