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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 202679221627cc28218e8f0fb405f4961eaaea3d
4
- data.tar.gz: e54790c53ba76c24dbfbb90bd6721090fcfcf96d
3
+ metadata.gz: 64b8a25d53a8a63fa932e74aaa358d8ac62ba770
4
+ data.tar.gz: 148d1f0924f999c89e38ae4a510b053b799aff16
5
5
  SHA512:
6
- metadata.gz: c7915729dc929ede55d761e1308a78fbd08a713294b6e5297571f4a2d27d4c32f95e3a0b9c9b25ee07e09bf1cfcf11ed2dfeaa0e10f061083333df716a0a18f0
7
- data.tar.gz: f1793d36de2b22e9e20d3332ff902922dab820a262d6463ad8326d1abc0ec110b6d4e6fac0da62de0dfb59cd5078bf08e77fd6d8dbe02d0ab9d121251c1f2bad
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
- The tag is automatically built from payload. For example, the tag for this repository will be `webhook.kentaro.hato`.
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
@@ -1,3 +1,3 @@
1
1
  module Hato
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
@@ -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', payload: {foo: 'bar'}, api_key: 'test'
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', api_key: 'test'
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hato
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kentaro Kuribayashi