hato 0.0.5 → 0.0.6

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: 10fe52f50d0d3e9135999a5f4c52a2b7d419266f
4
- data.tar.gz: 82c0ad38232cd128e4e3a834ee1f310fd2f66dcd
3
+ metadata.gz: ce9895dcdaf6ee77a09e2816cee3a20f5034194b
4
+ data.tar.gz: 2bb1f36ebcd0e3f717bb9fdd0be0e4ec8f307edb
5
5
  SHA512:
6
- metadata.gz: b6b226505e06bcea7aa9c77e1e7e4f64d21ad562db087c898667b3e41bc9c4fb0575fdf19326d03e74924606e70853ca3f1ea62e25030366d99c5657a9c50929
7
- data.tar.gz: d9cec8a303fa12785af2c13a62199c30eae69e0792810edd03620870201a1474b4c38a1b1ce7ac89ff765e7cfa4c1ade0bd02b1683bc0efd884d30efb0532dd5
6
+ metadata.gz: 47208c46f29d95adcf2a3ba59d1423d483945e47927f84e341ff10327832f2387763719c2f0d23a55b26c51b7491f54d34f7ce81cb2ccc56f9af05d9cc2ef6e6
7
+ data.tar.gz: 46e5c4c1a57c36a4b6ebb0b25807fba47975e22d54deb712f628a052e2a8e26d1d3106f912c5e07eb92830cea39f8d6e364e3d856be988730e72f3f15bd5945a
data/README.md CHANGED
@@ -10,12 +10,26 @@ Launch Hato with `hato` command:
10
10
  $ hato -c config.rb
11
11
  ```
12
12
 
13
- Then, post your notification message:
13
+ ### Notification
14
+
15
+ Post your notification message:
14
16
 
15
17
  ```
16
18
  $ curl -d 'message=test' -d 'tag=test' -d 'api_key=test' http://localhost:9699/notify
17
19
  ```
18
20
 
21
+ ### WebHook
22
+
23
+ Hato supports GitHub/GitHub Enterprise-formatted webhook.
24
+
25
+ ```
26
+ $ curl -d 'payload={...}' -d 'api_key=test' http://localhost:9699/webhook
27
+ ```
28
+
29
+ The tag is automatically built from payload. For example, the tag for this repository will be `webhook.kentaro.hato`.
30
+
31
+ Consult [the documentation](https://help.github.com/articles/post-receive-hooks) for the details of webhook.
32
+
19
33
  ## Configuration
20
34
 
21
35
  Hato provides DSLs for configuration.
@@ -28,22 +42,30 @@ Hato::Config.define do
28
42
  host '0.0.0.0'
29
43
  port 9699
30
44
 
31
- # test by exact string mathing
45
+ # exact string mathing
32
46
  tag 'test' do
33
- plugin 'Plugin1' do
47
+ plugin 'AwesomePlugin' do
34
48
  key1 'value1'
35
49
  key2 'value2'
36
50
  key3 'value3'
37
51
  end
38
52
  end
39
53
 
40
- # test by regexp matching
54
+ # regexp matching
41
55
  tag /^test2\.([^\.]+)\.([^\.]+)$/ do |matched1, matched2|
42
- plugin 'Plugin2' do
56
+ plugin 'AwesomePlugin' do
43
57
  key1 matched1
44
58
  key2 matched2
45
59
  end
46
60
  end
61
+
62
+ # webhook
63
+ tag /^webhook\.([^\.]+)\.([^\.]+)$/ do |owner, repository|
64
+ plugin 'AwesomePlugin' do
65
+ key1 owner
66
+ key2 repository
67
+ end
68
+ end
47
69
  end
48
70
  ```
49
71
 
@@ -54,6 +76,7 @@ There have already been some plugins:
54
76
  * [Hato::Plugin::Ikachan](https://github.com/kentaro/hato-plugin-ikachan)
55
77
  * [Hato::Plugin::Mail](https://github.com/kentaro/hato-plugin-mail)
56
78
  * [Hato::Plugin::Hipchat](https://github.com/banyan/hato-plugin-hipchat)
79
+ * [Hato::Plugin::Twitter](https://github.com/kentaro/hato-plugin-twitter)
57
80
 
58
81
  You can easily extend Hato by creating your own plugins. See the source for detail. It's really easy.
59
82
 
data/hato.gemspec CHANGED
@@ -30,5 +30,6 @@ Gem::Specification.new do |spec|
30
30
  spec.add_development_dependency "rspec"
31
31
  spec.add_development_dependency "pry"
32
32
  spec.add_development_dependency "rack-test"
33
+ spec.add_development_dependency "response_code_matchers"
33
34
  end
34
35
 
data/lib/hato/httpd.rb CHANGED
@@ -36,7 +36,7 @@ module Hato
36
36
  'Hato https://github.com/kentaro/hato'
37
37
  end
38
38
 
39
- post "/notify" do
39
+ post '/notify' do
40
40
  settings.observer.update(
41
41
  tag: params[:tag],
42
42
  message: params[:message],
@@ -48,6 +48,40 @@ module Hato
48
48
  message: 'Successfully sent the message you notified to me.',
49
49
  )
50
50
  end
51
+
52
+ post '/webhook' do
53
+ payload = params[:payload]
54
+
55
+ if !payload
56
+ halt 400, JSON.dump(
57
+ status: :error,
58
+ message: 'Missing mandatory parameter: `payload`',
59
+ )
60
+ end
61
+
62
+ owner = payload['repository'] && payload['repository']['owner'] && payload['repository']['owner']['name']
63
+ repository = payload['repository'] && payload['repository']['name']
64
+
65
+ if owner && repository
66
+ tag = ['webhook', owner, repository].join('.')
67
+ else
68
+ halt 400, JSON.dump(
69
+ status: :error,
70
+ message: 'Invalid JSON message: both `repository.owner.name` and `repository.name` are required',
71
+ )
72
+ end
73
+
74
+ settings.observer.update(
75
+ tag: tag,
76
+ payload: payload,
77
+ logger: logger,
78
+ )
79
+
80
+ JSON.dump(
81
+ status: :success,
82
+ message: 'Successfully sent the message you notified to me.',
83
+ )
84
+ end
51
85
  end
52
86
  end
53
87
  end
data/lib/hato/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Hato
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -6,18 +6,23 @@ require 'rack/test'
6
6
  describe Hato::Httpd do
7
7
  include Rack::Test::Methods
8
8
 
9
- def app
9
+ let(:config) {
10
10
  config = Hato::Config.load(
11
11
  File.expand_path('../../../assets/config/test.rb', __FILE__)
12
12
  )
13
- observer = Hato::Observer.new(config)
14
- Hato::Httpd::App.set(:observer, observer)
15
- Hato::Httpd::App.set(:api_key, config.api_key)
16
- Hato::Httpd::App.new
13
+ }
14
+
15
+ def app
16
+ @_app ||= -> {
17
+ observer = Hato::Observer.new(config)
18
+ Hato::Httpd::App.set(:observer, observer)
19
+ Hato::Httpd::App.set(:api_key, config.api_key)
20
+ Hato::Httpd::App.new
21
+ }.call
17
22
  end
18
23
 
19
24
  describe 'index' do
20
- it do
25
+ it 'should return response' do
21
26
  get '/'
22
27
  expect(last_response).to be_ok
23
28
  expect(last_response.body).to eq('Hato https://github.com/kentaro/hato')
@@ -25,16 +30,73 @@ describe Hato::Httpd do
25
30
  end
26
31
 
27
32
  describe 'notify' do
28
- it 'success' do
29
- post '/notify', {message: 'test', tag: 'test', api_key: 'test'}
30
- expect(last_response).to be_ok
31
- expect(last_response.body).to eq('{"status":"success","message":"Successfully sent the message you notified to me."}')
33
+ context 'success' do
34
+ context 'when api_key is set' do
35
+ it 'should be success with correct api_key' do
36
+ post '/notify', {message: 'test', tag: 'test', api_key: 'test'}
37
+ expect(last_response).to be_ok
38
+ expect(last_response.body).to eq('{"status":"success","message":"Successfully sent the message you notified to me."}')
39
+ end
40
+ end
41
+
42
+ context 'when api_key is not set' do
43
+ before { app.settings.api_key = nil }
44
+ after { app.settings.api_key = config.api_key }
45
+
46
+ it 'should be success without api_key' do
47
+ post '/notify', {message: 'test', tag: 'test'}
48
+ expect(last_response).to be_ok
49
+ expect(last_response.body).to eq('{"status":"success","message":"Successfully sent the message you notified to me."}')
50
+ end
51
+ end
32
52
  end
33
53
 
34
- it 'error' do
35
- post '/notify', {message: 'test', tag: 'test', api_key: 'wrong_key'}
36
- expect(last_response).to be_forbidden
37
- expect(last_response.body).to eq('{"status":"error","message":"API key is wrong. Confirm your API key setting of server/client."}')
54
+ context 'error' do
55
+ it 'should be error when api_key is wrong' do
56
+ post '/notify', {message: 'test', tag: 'test', api_key: 'wrong_key'}
57
+ expect(last_response).to be_forbidden
58
+ expect(last_response.body).to eq('{"status":"error","message":"API key is wrong. Confirm your API key setting of server/client."}')
59
+ end
60
+ end
61
+ end
62
+
63
+ describe 'webhook' do
64
+ context 'success' do
65
+ let(:payload) {
66
+ {
67
+ repository: {
68
+ name: 'hato',
69
+ owner: {
70
+ name: 'kentaro',
71
+ },
72
+ }
73
+ }
74
+ }
75
+ it 'should be success with correct payload' do
76
+ post '/webhook', payload: payload, api_key: 'test'
77
+ expect(last_response).to be_ok
78
+ expect(last_response.body).to eq('{"status":"success","message":"Successfully sent the message you notified to me."}')
79
+ end
80
+ end
81
+
82
+ context 'error' do
83
+ it 'should be error when payload is not passed' do
84
+ post '/webhook', api_key: 'test'
85
+ expect(last_response).to be_bad_request
86
+ expect(last_response.body).to eq('{"status":"error","message":"Missing mandatory parameter: `payload`"}')
87
+ end
88
+
89
+ it 'should be error when repository.name is not passed' do
90
+ post '/webhook', api_key: 'test', payload: {repository: {owner: {name: 'kentaro'}}}
91
+ expect(last_response).to be_bad_request
92
+ expect(last_response.body).to eq('{"status":"error","message":"Invalid JSON message: both `repository.owner.name` and `repository.name` are required"}')
93
+ end
94
+
95
+ it 'should be error when repository.owner.name is not passed' do
96
+ post '/webhook', api_key: 'test', payload: {repository: {name: 'hato'}}
97
+ expect(last_response).to be_bad_request
98
+ expect(last_response.body).to eq('{"status":"error","message":"Invalid JSON message: both `repository.owner.name` and `repository.name` are required"}')
99
+ end
38
100
  end
39
101
  end
40
102
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hato
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kentaro Kuribayashi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-24 00:00:00.000000000 Z
11
+ date: 2013-11-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sinatra
@@ -122,6 +122,20 @@ dependencies:
122
122
  - - '>='
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: response_code_matchers
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - '>='
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
125
139
  description: A Notification Management Tools
126
140
  email:
127
141
  - kentarok@gmail.com