hato 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -3
- data/lib/hato/httpd.rb +10 -0
- data/lib/hato/version.rb +1 -1
- data/spec/lib/hato/httpd_spec.rb +19 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 64b8a25d53a8a63fa932e74aaa358d8ac62ba770
|
4
|
+
data.tar.gz: 148d1f0924f999c89e38ae4a510b053b799aff16
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 622fe29841f75850ff8952e0b7cbb5ddc5897764824f486c711811012d4c1db7e7cf43340d0cf83a5ccd0c9aec5b887aa835f90036fa02da46425c22f41f2e5f
|
7
|
+
data.tar.gz: 58ba4e71283ec01a863d96c4183f4aa569206a8124d32c70cf27a85d1f72847edf0cf007775a2ef17be4094d2da00a7b6560b5c85b997a49783563d3d9b7dc93
|
data/README.md
CHANGED
@@ -20,13 +20,13 @@ $ curl -d 'message=test' -d 'tag=test' -d 'api_key=test' http://localhost:9699/n
|
|
20
20
|
|
21
21
|
### WebHook
|
22
22
|
|
23
|
-
Hato supports GitHub/GitHub Enterprise-formatted webhook.
|
23
|
+
Hato supports GitHub/GitHub Enterprise-formatted webhook. Path is expected to be `/webhook/:owner/:repository` like below:
|
24
24
|
|
25
25
|
```
|
26
|
-
$ curl -d 'payload={...}' -d 'api_key=test' http://localhost:9699/webhook
|
26
|
+
$ curl -d 'payload={...}' -d 'api_key=test' http://localhost:9699/webhook/kentaro/hato
|
27
27
|
```
|
28
28
|
|
29
|
-
|
29
|
+
Tag is automatically built from the path. For example, the tag for the path above will be `webhook.kentaro.hato`.
|
30
30
|
|
31
31
|
Consult [the documentation](https://help.github.com/articles/post-receive-hooks) for the details of webhook.
|
32
32
|
|
data/lib/hato/httpd.rb
CHANGED
@@ -50,6 +50,15 @@ module Hato
|
|
50
50
|
end
|
51
51
|
|
52
52
|
post '/webhook/:owner/:repository' do
|
53
|
+
event = request.env['X-GitHub-Event']
|
54
|
+
|
55
|
+
if !event
|
56
|
+
halt 400, JSON.dump(
|
57
|
+
status: :error,
|
58
|
+
message: 'Missing mandatory header: `X-GitHub-Event`',
|
59
|
+
)
|
60
|
+
end
|
61
|
+
|
53
62
|
tag = ['webhook', params[:owner], params[:repository]].join('.')
|
54
63
|
payload = params[:payload]
|
55
64
|
|
@@ -62,6 +71,7 @@ module Hato
|
|
62
71
|
|
63
72
|
settings.observer.update(
|
64
73
|
tag: tag,
|
74
|
+
event: event,
|
65
75
|
payload: payload,
|
66
76
|
logger: logger,
|
67
77
|
)
|
data/lib/hato/version.rb
CHANGED
data/spec/lib/hato/httpd_spec.rb
CHANGED
@@ -63,15 +63,32 @@ describe Hato::Httpd do
|
|
63
63
|
describe 'webhook' do
|
64
64
|
context 'success' do
|
65
65
|
it 'should be success with correct payload' do
|
66
|
-
post '/webhook/kentaro/hato',
|
66
|
+
post '/webhook/kentaro/hato', {
|
67
|
+
payload: {foo: 'bar'},
|
68
|
+
api_key: 'test',
|
69
|
+
}, {
|
70
|
+
'X-GitHub-Event' => 'test',
|
71
|
+
}
|
67
72
|
expect(last_response).to be_ok
|
68
73
|
expect(last_response.body).to eq('{"status":"success","message":"Successfully sent the message you notified to me."}')
|
69
74
|
end
|
70
75
|
end
|
71
76
|
|
72
77
|
context 'error' do
|
78
|
+
it 'should be error when event header is not sent' do
|
79
|
+
post '/webhook/kentaro/hato', {
|
80
|
+
api_key: 'test',
|
81
|
+
}
|
82
|
+
expect(last_response).to be_bad_request
|
83
|
+
expect(last_response.body).to eq('{"status":"error","message":"Missing mandatory header: `X-GitHub-Event`"}')
|
84
|
+
end
|
85
|
+
|
73
86
|
it 'should be error when payload is not passed' do
|
74
|
-
post '/webhook/kentaro/hato',
|
87
|
+
post '/webhook/kentaro/hato', {
|
88
|
+
api_key: 'test',
|
89
|
+
}, {
|
90
|
+
'X-GitHub-Event' => 'test',
|
91
|
+
}
|
75
92
|
expect(last_response).to be_bad_request
|
76
93
|
expect(last_response.body).to eq('{"status":"error","message":"Missing mandatory parameter: `payload`"}')
|
77
94
|
end
|