octoks 0.0.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 +7 -0
- data/.gitignore +17 -0
- data/.travis.yml +6 -0
- data/Gemfile +7 -0
- data/LICENSE.txt +22 -0
- data/README.md +53 -0
- data/Rakefile +8 -0
- data/examples/app.ru +11 -0
- data/lib/octoks/event.rb +11 -0
- data/lib/octoks/receiver.rb +46 -0
- data/lib/octoks/version.rb +3 -0
- data/lib/octoks.rb +6 -0
- data/octoks.gemspec +23 -0
- data/test/octoks/test_event.rb +14 -0
- data/test/octoks/test_receiver.rb +32 -0
- metadata +88 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2a2b87c14b4b155235a4e61aa0e27f6cc82b3215
|
4
|
+
data.tar.gz: f88291da568e3ccd08fdf77ed22872866f5aa380
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9769aed0186f5569ad1bebad9336879888e8b6b071a49a5bc8f06097237da2d1669e48ee09d4785d853288179cb3513d9b2c4fb700c3226fd54f1ff4df3240a0
|
7
|
+
data.tar.gz: 26bf41998a82245f854a7f5bf1fee236bfe2f478b78bc2353b081afcf02f99488b8ff09a71390dbbf90b025939cf000d1530d157c8c0dfc6dd77216934ef7a54
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 hisaichi5518
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# Octoks
|
2
|
+
|
3
|
+
Octoks is Github Hooks Receiver. inspired by `GitHub::Hooks::Receiver`
|
4
|
+
|
5
|
+
https://github.com/Songmu/Github-Hooks-Receiver
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'octoks'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install octoks
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
# this file name is `config.ru`
|
25
|
+
require 'octoks'
|
26
|
+
|
27
|
+
receiver = Octoks::Receiver.new
|
28
|
+
receiver.on :push do |event|
|
29
|
+
# event is Octoks::Event object
|
30
|
+
p event.name
|
31
|
+
p event.payload
|
32
|
+
end
|
33
|
+
|
34
|
+
run receiver
|
35
|
+
```
|
36
|
+
|
37
|
+
And `rackup`
|
38
|
+
|
39
|
+
```sh
|
40
|
+
# run receiver
|
41
|
+
rackup config.ru
|
42
|
+
```
|
43
|
+
|
44
|
+
You can check the following hook name.
|
45
|
+
https://developer.github.com/v3/activity/events/types/
|
46
|
+
|
47
|
+
## Contributing
|
48
|
+
|
49
|
+
1. Fork it ( http://github.com/hisaichi5518/octoks/fork )
|
50
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
51
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
52
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
53
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/examples/app.ru
ADDED
data/lib/octoks/event.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'rack'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module Octoks
|
5
|
+
class Receiver
|
6
|
+
attr_accessor :hooks
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@hooks = {}
|
10
|
+
end
|
11
|
+
|
12
|
+
def on(name, &cb)
|
13
|
+
@hooks[name] ||= []
|
14
|
+
@hooks[name].push(cb)
|
15
|
+
end
|
16
|
+
|
17
|
+
def emit(event)
|
18
|
+
hooks[event.name] ||= []
|
19
|
+
hooks[event.name].each do |hook|
|
20
|
+
hook.call(event)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def call(env)
|
25
|
+
req = Rack::Request.new(env)
|
26
|
+
failed = [400, [], ["BAD REQUEST"]]
|
27
|
+
|
28
|
+
if !req.post? or req.params['payload'].nil? or req.env["HTTP_X_GITHUB_EVENT"].nil?
|
29
|
+
return failed
|
30
|
+
end
|
31
|
+
|
32
|
+
begin
|
33
|
+
payload = JSON.parse(req.params['payload'])
|
34
|
+
rescue
|
35
|
+
return failed
|
36
|
+
end
|
37
|
+
|
38
|
+
event_name = req.env["HTTP_X_GITHUB_EVENT"]
|
39
|
+
event = Octoks::Event.new(event_name.to_sym, payload)
|
40
|
+
|
41
|
+
emit(event)
|
42
|
+
|
43
|
+
[200, [], ["OK"]]
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/lib/octoks.rb
ADDED
data/octoks.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'octoks/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "octoks"
|
8
|
+
spec.version = Octoks::VERSION
|
9
|
+
spec.authors = ["hisaichi5518"]
|
10
|
+
spec.email = ["hisaichi5518@gmail.com"]
|
11
|
+
spec.summary = %q{github hooks receiver.}
|
12
|
+
spec.description = %q{github hooks receiver.}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require 'octoks'
|
3
|
+
|
4
|
+
class TestEvent < MiniTest::Unit::TestCase
|
5
|
+
def test_name
|
6
|
+
event = Octoks::Event.new(:name, {"test" => "test"})
|
7
|
+
assert_equal event.name, :name
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_payload
|
11
|
+
event = Octoks::Event.new(:name, {"test" => "test"})
|
12
|
+
assert_equal event.payload, {"test" => "test"}
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require 'octoks'
|
3
|
+
|
4
|
+
class TestReceiver < MiniTest::Unit::TestCase
|
5
|
+
def test_on
|
6
|
+
receiver = Octoks::Receiver.new
|
7
|
+
receiver.on :push do |event|
|
8
|
+
end
|
9
|
+
receiver.on :push do |event|
|
10
|
+
end
|
11
|
+
|
12
|
+
assert_equal receiver.hooks[:push].size, 2
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_emit
|
16
|
+
receiver = Octoks::Receiver.new
|
17
|
+
receiver.on :push do |event|
|
18
|
+
event.payload["count"] = 1
|
19
|
+
end
|
20
|
+
receiver.on :push do |event|
|
21
|
+
event.payload["count"] += 1
|
22
|
+
end
|
23
|
+
|
24
|
+
event = Octoks::Event.new(:push, {"test" => "test"})
|
25
|
+
receiver.emit(event)
|
26
|
+
assert_equal event.payload["count"], 2
|
27
|
+
|
28
|
+
event = Octoks::Event.new(:test, {"test" => "test"})
|
29
|
+
receiver.emit(event)
|
30
|
+
assert_equal receiver.hooks[:test].size, 0
|
31
|
+
end
|
32
|
+
end
|
metadata
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: octoks
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- hisaichi5518
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-04-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.5'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: github hooks receiver.
|
42
|
+
email:
|
43
|
+
- hisaichi5518@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- ".travis.yml"
|
50
|
+
- Gemfile
|
51
|
+
- LICENSE.txt
|
52
|
+
- README.md
|
53
|
+
- Rakefile
|
54
|
+
- examples/app.ru
|
55
|
+
- lib/octoks.rb
|
56
|
+
- lib/octoks/event.rb
|
57
|
+
- lib/octoks/receiver.rb
|
58
|
+
- lib/octoks/version.rb
|
59
|
+
- octoks.gemspec
|
60
|
+
- test/octoks/test_event.rb
|
61
|
+
- test/octoks/test_receiver.rb
|
62
|
+
homepage: ''
|
63
|
+
licenses:
|
64
|
+
- MIT
|
65
|
+
metadata: {}
|
66
|
+
post_install_message:
|
67
|
+
rdoc_options: []
|
68
|
+
require_paths:
|
69
|
+
- lib
|
70
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
requirements: []
|
81
|
+
rubyforge_project:
|
82
|
+
rubygems_version: 2.2.0
|
83
|
+
signing_key:
|
84
|
+
specification_version: 4
|
85
|
+
summary: github hooks receiver.
|
86
|
+
test_files:
|
87
|
+
- test/octoks/test_event.rb
|
88
|
+
- test/octoks/test_receiver.rb
|