github_webhook 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0fbad7d92b15339ae2705eb8fa70f8473ead19de
4
- data.tar.gz: 7651d1752b27aeecb0be2fcbbe1b40c5844ebe23
3
+ metadata.gz: 1180e1284554cb7a48aabf4eb9337844053516c6
4
+ data.tar.gz: d955052b93e7897a7712a98cae94d6c6ffaf2ff7
5
5
  SHA512:
6
- metadata.gz: ff8ad0cc5bca27dea1c2b8422b451d7b569dac12a78994fd0942c074d2f6107935497ea9eed0dfe0aa2552d10a0317820955d1aa73787186a11f9ac755feff6e
7
- data.tar.gz: 3edff72e3d0f132112b3358965c1385d58aada7ce51b4352a85708c892e94197f7cca925b50cebb7cef272f6b5cbf5198a9c6cd37519083408a307ef6aaaa51a
6
+ metadata.gz: ffb54818c9769f28e8fefa0fda12211b585ab487593fb0a64f0e7fbe4410b79ab545da323f81263998b290b4d9bfa4b156ae3959d04aeca4642ecdbf39514c73
7
+ data.tar.gz: 102a321a847b70380d8d76ba9e9785926457a80927ee5d050928b02d773d91ad0fceb8213768eff07e63b6393de46b89ca5376d5203ead9e2a33b54ece12899b
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.1
4
+ - 2.1.0
5
+ - 2.0.0
data/README.md CHANGED
@@ -1,3 +1,7 @@
1
+ [![Build Status](https://travis-ci.org/ssaunier/github_webhook.png)](https://travis-ci.org/ssaunier/github_webhook)
2
+ [![Gem Version](https://badge.fury.io/rb/github_webhook.png)](http://badge.fury.io/rb/github_webhook)
3
+
4
+
1
5
  # GithubWebhook
2
6
 
3
7
  This gem will help you to quickly setup a route in your Rails application which listens
@@ -72,4 +76,4 @@ You can have an overview of your webhooks at the following URL:
72
76
 
73
77
  ```
74
78
  https://github.com/:username/:repo/settings/hooks
75
- ```
79
+ ```
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
8
8
  spec.version = GithubWebhook::VERSION
9
9
  spec.authors = ["Sebastien Saunier"]
10
10
  spec.email = ["seb@saunier.me"]
11
- spec.summary = %q{Rails engine handling Github Webhook}
11
+ spec.summary = %q{Process GitHub Webhooks in your Rails app (Controller mixin)}
12
12
  spec.description = spec.summary
13
13
  spec.homepage = "https://github.com/ssaunier/github_webhook"
14
14
  spec.license = "MIT"
@@ -9,8 +9,16 @@ module GithubWebhook::Processor
9
9
  class UnspecifiedWebhookSecretError < StandardError; end
10
10
 
11
11
  def create
12
- self.send json_body[:action], json_body
13
- head(:ok)
12
+ if self.respond_to? event
13
+ self.send event, json_body
14
+ head(:ok)
15
+ else
16
+ raise NoMethodError.new("GithubWebhooksController##{event} not implemented")
17
+ end
18
+ end
19
+
20
+ def ping(payload)
21
+ puts "[GithubWebhook::Processor] Hook ping received, hook_id: #{payload[:hook_id]}, #{payload[:zen]}"
14
22
  end
15
23
 
16
24
  private
@@ -40,4 +48,8 @@ module GithubWebhook::Processor
40
48
  def signature_header
41
49
  @signature_header ||= request.headers['X-Hub-Signature']
42
50
  end
51
+
52
+ def event
53
+ @event ||= request.headers['X-GitHub-Event'].to_sym
54
+ end
43
55
  end
@@ -1,3 +1,3 @@
1
1
  module GithubWebhook
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -48,18 +48,25 @@ module GithubWebhook
48
48
  end
49
49
 
50
50
  it "calls the #push method in controller" do
51
- controller.request.body = StringIO.new({ :action => "push", :foo => "bar" }.to_json.to_s)
52
- controller.request.headers['X-Hub-Signature'] = "sha1=2bceed8940ebc87562f68ee5028db18685ce5607"
51
+ controller.request.body = StringIO.new({ :foo => "bar" }.to_json.to_s)
52
+ controller.request.headers['X-Hub-Signature'] = "sha1=52b582138706ac0c597c315cfc1a1bf177408a4d"
53
+ controller.request.headers['X-GitHub-Event'] = 'push'
53
54
  controller.send :authenticate_github_request! # Manually as we don't have the before_filter logic in our Mock object
54
55
  controller.create
55
56
  controller.pushed.should eq "bar"
56
57
  end
57
58
 
58
59
  it "raises an error when signature does not match" do
59
- controller.request.body = StringIO.new({ :action => "push", :foo => "bar" }.to_json.to_s)
60
+ controller.request.body = StringIO.new({ :foo => "bar" }.to_json.to_s)
60
61
  controller.request.headers['X-Hub-Signature'] = "sha1=FOOBAR"
62
+ controller.request.headers['X-GitHub-Event'] = 'push'
61
63
  expect { controller_without_secret.send :authenticate_github_request! }.to raise_error
62
64
  end
65
+
66
+ it "raises an error when the github event method is not implemented" do
67
+ controller.request.headers['X-GitHub-Event'] = 'unimplemented_event'
68
+ expect { controller_without_secret.create }.to raise_error
69
+ end
63
70
  end
64
71
  end
65
72
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: github_webhook
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sebastien Saunier
@@ -66,7 +66,7 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '2.14'
69
- description: Rails engine handling Github Webhook
69
+ description: Process GitHub Webhooks in your Rails app (Controller mixin)
70
70
  email:
71
71
  - seb@saunier.me
72
72
  executables: []
@@ -74,6 +74,7 @@ extensions: []
74
74
  extra_rdoc_files: []
75
75
  files:
76
76
  - ".gitignore"
77
+ - ".travis.yml"
77
78
  - Gemfile
78
79
  - Gemfile.lock
79
80
  - LICENSE.txt
@@ -108,7 +109,7 @@ rubyforge_project:
108
109
  rubygems_version: 2.2.2
109
110
  signing_key:
110
111
  specification_version: 4
111
- summary: Rails engine handling Github Webhook
112
+ summary: Process GitHub Webhooks in your Rails app (Controller mixin)
112
113
  test_files:
113
114
  - spec/github_webhook/processor_spec.rb
114
115
  - spec/spec_helper.rb