github_webhook 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +5 -0
- data/README.md +5 -1
- data/github_webhook.gemspec +1 -1
- data/lib/github_webhook/processor.rb +14 -2
- data/lib/github_webhook/version.rb +1 -1
- data/spec/github_webhook/processor_spec.rb +10 -3
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1180e1284554cb7a48aabf4eb9337844053516c6
|
4
|
+
data.tar.gz: d955052b93e7897a7712a98cae94d6c6ffaf2ff7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ffb54818c9769f28e8fefa0fda12211b585ab487593fb0a64f0e7fbe4410b79ab545da323f81263998b290b4d9bfa4b156ae3959d04aeca4642ecdbf39514c73
|
7
|
+
data.tar.gz: 102a321a847b70380d8d76ba9e9785926457a80927ee5d050928b02d773d91ad0fceb8213768eff07e63b6393de46b89ca5376d5203ead9e2a33b54ece12899b
|
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
[](https://travis-ci.org/ssaunier/github_webhook)
|
2
|
+
[](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
|
+
```
|
data/github_webhook.gemspec
CHANGED
@@ -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
|
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.
|
13
|
-
|
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
|
@@ -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({ :
|
52
|
-
controller.request.headers['X-Hub-Signature'] = "sha1=
|
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({ :
|
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.
|
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
|
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
|
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
|