git_web_hook_model 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ZWE3YTg0Mjc2ZDZmYTg1ZDY0OWM2NTE3ZWI5NDU0ZWZkMzQyYTMwOQ==
5
+ data.tar.gz: !binary |-
6
+ MDM3ZjU3MDYxMzUxNGIwZTI1ZDg5N2Q2MzM1YjVkODNmMDMwMDcwMg==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ ZTRmZjAxZTRiYjQwNzEyNmMzNzljZTExMDJjMDNjZDUwOTMzYmRiYTM2NjBm
10
+ OTQwNzI0MmI1MGUzMGE1OTUwY2NkZjdiY2NmZTYyNmQxYzA2MDBjOThmZTg3
11
+ YThkYzZhZjc5YTE2NjQyOTA3NWUxNmJjMGEyYjc4OTMwYzRiMjI=
12
+ data.tar.gz: !binary |-
13
+ NTE5YzE3Y2VhZGUxYmIyNzRhZDlhNWFmNjk2NDczNzQxOGZkOTA5ZDRjYzUz
14
+ ZjhiOTVhZmZmYmM4NTUyODczZDI4MzUzZDY2OTFlZGU2N2U4YmJkMjdkZDQ2
15
+ NjcwYTM0NmUyOGFhYTQ0ZDdiYjhlMTc2YWRjMjdjMzY1OGEzNDE=
data/.coveralls.yml ADDED
@@ -0,0 +1,2 @@
1
+ service_name: travis-pro
2
+ repo_token: nHfGiGqBgV8FS4OQIpIpOti8h6H13VzEa
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .ruby-version
4
+ .DS_Store
5
+ .bundle
6
+ .config
7
+ .yardoc
8
+ Gemfile.lock
9
+ InstalledFiles
10
+ _yardoc
11
+ coverage
12
+ doc/
13
+ lib/bundler/man
14
+ pkg
15
+ rdoc
16
+ spec/reports
17
+ test/tmp
18
+ test/version_tmp
19
+ tmp
data/.simplecov ADDED
@@ -0,0 +1,17 @@
1
+ require 'coveralls'
2
+
3
+ SimpleCov.configure do
4
+ minimum_coverage 95
5
+ maximum_coverage_drop 5
6
+
7
+ start('rails') do
8
+ formatter SimpleCov::Formatter::MultiFormatter[
9
+ SimpleCov::Formatter::HTMLFormatter,
10
+ Coveralls::SimpleCov::Formatter
11
+ ]
12
+
13
+ add_group "Long files" do |src_file|
14
+ src_file.lines.count > 100
15
+ end
16
+ end
17
+ end
data/.travis.yml ADDED
@@ -0,0 +1,9 @@
1
+ language: ruby
2
+ script:
3
+ - bundle exec rspec spec/
4
+ rvm:
5
+ - 2.0.0
6
+ - 1.9.3
7
+ notifications:
8
+ email:
9
+ - chuckjhardy@gmail.com
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'coveralls', require: false
4
+
5
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Chuck J hardy
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,184 @@
1
+ # GitWebHookModel
2
+
3
+ Simple, immutable model for github webhooks.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'git_web_hook_model', '~> 0.0.1', group :development
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install git_web_hook_model
18
+
19
+
20
+ ## Usage
21
+
22
+ GitWebHookModel accepts either a hash object or json string returned from [Github's WebHook service](https://help.github.com/articles/post-receive-hooks) and returns an immutable model object.
23
+
24
+ model = GitWebHookModel.for(github_json_response)
25
+ # => #<GitWebHookModel::Hook::Model:0x007fba946a8c08>
26
+
27
+ model.ref
28
+ # => "refs/heads/feature/ci"
29
+
30
+ model.after
31
+ # => "38209a615b72728ef4f3160619c7c63c37b8994c"
32
+
33
+ model.before
34
+ # => "0000000000000000000000000000000000000000"
35
+
36
+ model.created?
37
+ # => true
38
+
39
+ model.deleted?
40
+ # => false
41
+
42
+ model.forced?
43
+ # => true
44
+
45
+ model.compare
46
+ # => "https://github.company.com/organization/otb_www_app/commit/38209a615b72"
47
+
48
+ Commits `Array` of `GitWebHookModel::Hook::Commit`
49
+
50
+ mode.commits
51
+ # => [#<GitWebHookModel::Hook::Commit:0x007fba94714200>]
52
+
53
+ Head Commit `GitWebHookModel::Hook::Commit`
54
+
55
+ mode.head_commit
56
+ # => #<GitWebHookModel::Hook::Commit:0x007fba94714200>
57
+
58
+ Pusher `GitWebHookModel::Hook::Owner`
59
+
60
+ mode.pusher
61
+ # => #<GitWebHookModel::Hook::Owner:0x007fba94714200>
62
+
63
+ Repository `GitWebHookModel::Hook::Repository`
64
+
65
+ model.repository.id
66
+ # => 72
67
+
68
+ model.repository.name
69
+ # => "otb_www_app"
70
+
71
+ model.repository.url
72
+ # => "https://github.company.com/organization/otb_www_app"
73
+
74
+ model.repository.description
75
+ # => "Frontend Application"
76
+
77
+ model.repository.homepage
78
+ # => "www.example.co.uk"
79
+
80
+ model.repository.watchers
81
+ # => 1
82
+
83
+ model.repository.stargazers
84
+ # => 1
85
+
86
+ model.repository.forks
87
+ # => 0
88
+
89
+ model.repository.fork?
90
+ # => false
91
+
92
+ model.repository.size
93
+ # => 54414
94
+
95
+ model.repository.owner
96
+ # => #<GitWebHookModel::Hook::Owner:0x007fba9483d028>
97
+
98
+ model.repository.private?
99
+ # => false
100
+
101
+ model.repository.open_issues
102
+ # => 6
103
+
104
+ model.repository.has_issues?
105
+ # => true
106
+
107
+ model.repository.has_downloads?
108
+ # => true
109
+
110
+ model.repository.has_wiki?
111
+ # => true
112
+
113
+ model.repository.language
114
+ # => "Ruby"
115
+
116
+ model.repository.created_at
117
+ # => 1295946304
118
+
119
+ model.repository.pushed_at
120
+ # => 1383924957
121
+
122
+ model.repository.master_branch
123
+ # => "master"
124
+
125
+ model.repository.organization
126
+ # => "organization"
127
+
128
+ Commit Object `GitWebHookModel::Hook::Commit`
129
+
130
+ obj.id
131
+ # => "38209a615b72728ef4f3160619c7c63c37b8994c"
132
+
133
+ obj.distinct?
134
+ # => true
135
+
136
+ obj.message
137
+ # => "Setup CI"
138
+
139
+ obj.timestamp
140
+ # => 2013-11-08T15:34:33+00:00
141
+
142
+ obj.url
143
+ # => "https://github.company.com/organization/otb_www_app/commit/38209a615b72728ef4f3160619c7c63c37b8994c"
144
+
145
+ obj.author
146
+ # => #<GitWebHookModel::Hook::Owner:0x007fba946f50a8>
147
+
148
+ obj.committer
149
+ # => #<GitWebHookModel::Hook::Owner:0x007fba946f50a8>
150
+
151
+ obj.added
152
+ # => [ "continuus_lenimentus.enc" ]
153
+
154
+ obj.removed
155
+ # => []
156
+
157
+ obj.modified
158
+ # => [ ".simplecov", "Gemfile", "Gemfile.lock", "spec/spec_helper_lite.rb" ]
159
+
160
+ Owner Object `GitWebHookModel::Hook::Owner`
161
+
162
+ obj.name
163
+ # => "Chuck J hardy"
164
+
165
+ obj.email
166
+ # => Some["chuckjhardy@gmail.com"] / None
167
+
168
+ obj.username
169
+ # => Some["charles-hardy"] / None
170
+
171
+ Sometimes fields are returned from Github as `nil`. In these cases the objects return either `Some[value]` or `None`. Have a look at the [Optional Gem](https://github.com/rsslldnphy/optional) for more information.
172
+
173
+ ## Requirements
174
+
175
+ * ruby > 1.9.x
176
+ * id > 0.1.x
177
+
178
+ ## Contributing
179
+
180
+ 1. Fork it
181
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
182
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
183
+ 4. Push to the branch (`git push origin my-new-feature`)
184
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'git_web_hook_model/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "git_web_hook_model"
8
+ spec.version = GitWebHookModel::VERSION
9
+ spec.authors = ["Chuck J hardy"]
10
+ spec.email = ["chuckjhardy@gmail.com"]
11
+ spec.description = %q{Turn a Github WebHook into an object model}
12
+ spec.summary = %q{Turn a Github WebHook into an object model}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
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_dependency "id", "~> 0.1"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.3"
24
+ spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "simplecov", "~> 0.7.1"
26
+ spec.add_development_dependency "rspec", "~> 2.13.0"
27
+ end
@@ -0,0 +1,20 @@
1
+ class GitWebHookModel
2
+ module Hook
3
+ class Commit
4
+ include Id::Model
5
+ include Id::Timestamps
6
+
7
+ field :id
8
+ field :distinct
9
+ field :message
10
+ field :timestamp, type: Time
11
+ field :url
12
+ field :added
13
+ field :removed
14
+ field :modified
15
+
16
+ has_one :author, type: Owner
17
+ has_one :committer, type: Owner
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,21 @@
1
+ class GitWebHookModel
2
+ module Hook
3
+ class Model
4
+ include Id::Model
5
+
6
+ field :ref
7
+ field :after
8
+ field :before
9
+ field :created
10
+ field :deleted
11
+ field :forced
12
+ field :compare
13
+
14
+ has_many :commits
15
+
16
+ has_one :head_commit, type: Commit
17
+ has_one :pusher, type: Owner
18
+ has_one :repository
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,13 @@
1
+ require 'optional'
2
+
3
+ class GitWebHookModel
4
+ module Hook
5
+ class Owner
6
+ include Id::Model
7
+
8
+ field :name
9
+ field :email, optional: true
10
+ field :username, optional: true
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,30 @@
1
+ class GitWebHookModel
2
+ module Hook
3
+ class Repository
4
+ include Id::Model
5
+
6
+ field :id
7
+ field :name
8
+ field :url
9
+ field :description
10
+ field :homepage
11
+ field :watchers
12
+ field :stargazers
13
+ field :forks
14
+ field :fork
15
+ field :size
16
+ field :private
17
+ field :open_issues
18
+ field :has_issues
19
+ field :has_downloads
20
+ field :has_wiki
21
+ field :language
22
+ field :created_at
23
+ field :pushed_at
24
+ field :master_branch
25
+ field :organization
26
+
27
+ has_one :owner
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,23 @@
1
+ require 'json'
2
+
3
+ class GitWebHookModel
4
+ class Parse
5
+ def initialize(response)
6
+ @response = response
7
+ end
8
+
9
+ def as_hash
10
+ hash? ? @response : parsed_response
11
+ end
12
+
13
+ private
14
+
15
+ def hash?
16
+ @response.is_a?(Hash)
17
+ end
18
+
19
+ def parsed_response
20
+ JSON.parse(@response)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,3 @@
1
+ class GitWebHookModel
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,14 @@
1
+ require 'id'
2
+
3
+ require "git_web_hook_model/parse"
4
+ require "git_web_hook_model/hook/owner"
5
+ require "git_web_hook_model/hook/commit"
6
+ require "git_web_hook_model/hook/repository"
7
+ require "git_web_hook_model/hook/model"
8
+ require "git_web_hook_model/version"
9
+
10
+ class GitWebHookModel
11
+ def self.for(response)
12
+ Hook::Model.new(Parse.new(response).as_hash)
13
+ end
14
+ end
@@ -0,0 +1,99 @@
1
+ {
2
+ "ref":"refs/heads/feature/ci",
3
+ "after":"38209a615b72728ef4f3160619c7c63c37b8994c",
4
+ "before":"0000000000000000000000000000000000000000",
5
+ "created":true,
6
+ "deleted":false,
7
+ "forced":true,
8
+ "compare":"https://github.company.com/organisation/otb_www_app/commit/38209a615b72",
9
+ "commits":[
10
+ {
11
+ "id":"38209a615b72728ef4f3160619c7c63c37b8994c",
12
+ "distinct":true,
13
+ "message":"Setup CI",
14
+ "timestamp":"2013-11-08T15:34:33+00:00",
15
+ "url":"https://github.company.com/organisation/otb_www_app/commit/38209a615b72728ef4f3160619c7c63c37b8994c",
16
+ "author":{
17
+ "name":"Chuck J hardy",
18
+ "email":"chuckjhardy@gmail.com",
19
+ "username":"charles-hardy"
20
+ },
21
+ "committer":{
22
+ "name":"Chuck J hardy",
23
+ "email":"chuckjhardy@gmail.com",
24
+ "username":"charles-hardy"
25
+ },
26
+ "added":[
27
+ "continuus_lenimentus.enc"
28
+ ],
29
+ "removed":[
30
+
31
+ ],
32
+ "modified":[
33
+ ".simplecov",
34
+ "Gemfile",
35
+ "Gemfile.lock",
36
+ "spec/spec_helper_lite.rb"
37
+ ]
38
+ }
39
+ ],
40
+ "head_commit":{
41
+ "id":"38209a615b72728ef4f3160619c7c63c37b8994c",
42
+ "distinct":true,
43
+ "message":"Setup CI",
44
+ "timestamp":"2013-11-08T15:34:33+00:00",
45
+ "url":"https://github.company.com/organisation/otb_www_app/commit/38209a615b72728ef4f3160619c7c63c37b8994c",
46
+ "author":{
47
+ "name":"Chuck J hardy",
48
+ "email":"chuckjhardy@gmail.com",
49
+ "username":"charles-hardy"
50
+ },
51
+ "committer":{
52
+ "name":"Chuck J hardy",
53
+ "email":"chuckjhardy@gmail.com",
54
+ "username":"charles-hardy"
55
+ },
56
+ "added":[
57
+ "continuus_lenimentus.enc"
58
+ ],
59
+ "removed":[
60
+
61
+ ],
62
+ "modified":[
63
+ ".simplecov",
64
+ "Gemfile",
65
+ "Gemfile.lock",
66
+ "spec/spec_helper_lite.rb"
67
+ ]
68
+ },
69
+ "repository":{
70
+ "id":72,
71
+ "name":"otb_www_app",
72
+ "url":"https://github.company.com/organisation/otb_www_app",
73
+ "description":"Frontend Application",
74
+ "homepage":"www.example.co.uk",
75
+ "watchers":1,
76
+ "stargazers":1,
77
+ "forks":0,
78
+ "fork":false,
79
+ "size":54414,
80
+ "owner":{
81
+ "name":"company",
82
+ "email":null
83
+ },
84
+ "private":false,
85
+ "open_issues":6,
86
+ "has_issues":true,
87
+ "has_downloads":true,
88
+ "has_wiki":true,
89
+ "language":"Ruby",
90
+ "created_at":1295946304,
91
+ "pushed_at":1383924957,
92
+ "master_branch":"master",
93
+ "organization":"organisation"
94
+ },
95
+ "pusher":{
96
+ "name":"charles-hardy",
97
+ "email":"chuckjhardy@gmail.com"
98
+ }
99
+ }
@@ -0,0 +1,95 @@
1
+ require 'spec_helper'
2
+
3
+ describe GitWebHookModel::Hook::Commit do
4
+ let(:instance) { described_class.new(commit) }
5
+
6
+ let(:response) { File.read('spec/fixtures/hook.json') }
7
+ let(:hash) { GitWebHookModel::Parse.new(response).as_hash }
8
+
9
+ let(:commits) { hash.fetch('commits') }
10
+ let(:commit) { commits.first }
11
+
12
+ describe '#id' do
13
+ subject { instance.id }
14
+
15
+ it 'returns value' do
16
+ expect(subject).to eq("38209a615b72728ef4f3160619c7c63c37b8994c")
17
+ end
18
+ end
19
+
20
+ describe '#distinct?' do
21
+ subject { instance.distinct? }
22
+
23
+ it 'returns true' do
24
+ expect(subject).to be_true
25
+ end
26
+ end
27
+
28
+ describe '#message' do
29
+ subject { instance.message }
30
+
31
+ it 'returns value' do
32
+ expect(subject).to eq('Setup CI')
33
+ end
34
+ end
35
+
36
+ describe '#timestamp' do
37
+ subject { instance.timestamp }
38
+
39
+ it 'returns Time object' do
40
+ expect(subject).to be_an_instance_of(Time)
41
+ end
42
+ end
43
+
44
+ describe '#url' do
45
+ subject { instance.url }
46
+
47
+ let(:url) do
48
+ %Q{https://github.company.com/organisation/otb_www_app/commit/38209a615b72728ef4f3160619c7c63c37b8994c}
49
+ end
50
+
51
+ it 'returns value' do
52
+ expect(subject).to eq(url)
53
+ end
54
+ end
55
+
56
+ describe '#added' do
57
+ subject { instance.added }
58
+
59
+ it 'returns collection' do
60
+ expect(subject).to be_an_instance_of(Array)
61
+ end
62
+ end
63
+
64
+ describe '#removed' do
65
+ subject { instance.removed }
66
+
67
+ it 'returns collection' do
68
+ expect(subject).to be_an_instance_of(Array)
69
+ end
70
+ end
71
+
72
+ describe '#modified' do
73
+ subject { instance.modified }
74
+
75
+ it 'returns collection' do
76
+ expect(subject).to be_an_instance_of(Array)
77
+ end
78
+ end
79
+
80
+ describe '#author' do
81
+ subject { instance.author }
82
+
83
+ it 'returns owner object' do
84
+ expect(subject).to be_an_instance_of(GitWebHookModel::Hook::Owner)
85
+ end
86
+ end
87
+
88
+ describe '#committer' do
89
+ subject { instance.committer }
90
+
91
+ it 'returns owner object' do
92
+ expect(subject).to be_an_instance_of(GitWebHookModel::Hook::Owner)
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,106 @@
1
+ require 'spec_helper'
2
+
3
+ describe GitWebHookModel::Hook::Model do
4
+ let(:instance) { described_class.new(hash) }
5
+
6
+ let(:response) { File.read('spec/fixtures/hook.json') }
7
+ let(:hash) { GitWebHookModel::Parse.new(response).as_hash }
8
+
9
+ describe '#ref' do
10
+ subject { instance.ref }
11
+
12
+ it 'returns value' do
13
+ expect(subject).to eq("refs/heads/feature/ci")
14
+ end
15
+ end
16
+
17
+ describe '#after' do
18
+ subject { instance.after }
19
+
20
+ it 'returns value' do
21
+ expect(subject).to eq("38209a615b72728ef4f3160619c7c63c37b8994c")
22
+ end
23
+ end
24
+
25
+ describe '#before' do
26
+ subject { instance.before }
27
+
28
+ it 'returns value' do
29
+ expect(subject).to eq("0000000000000000000000000000000000000000")
30
+ end
31
+ end
32
+
33
+ describe '#created?' do
34
+ subject { instance.created? }
35
+
36
+ it 'returns true' do
37
+ expect(subject).to be_true
38
+ end
39
+ end
40
+
41
+ describe '#deleted?' do
42
+ subject { instance.deleted? }
43
+
44
+ it 'returns false' do
45
+ expect(subject).to be_false
46
+ end
47
+ end
48
+
49
+ describe '#forced?' do
50
+ subject { instance.forced? }
51
+
52
+ it 'returns true' do
53
+ expect(subject).to be_true
54
+ end
55
+ end
56
+
57
+ describe '#compare' do
58
+ subject { instance.compare }
59
+
60
+ let(:url) do
61
+ %Q{https://github.company.com/organisation/otb_www_app/commit/38209a615b72}
62
+ end
63
+
64
+ it 'returns value' do
65
+ expect(subject).to eq(url)
66
+ end
67
+ end
68
+
69
+ describe '#commits' do
70
+ subject { instance.commits }
71
+
72
+ context 'returns a collection' do
73
+ it 'as an array' do
74
+ expect(subject).to be_an_instance_of(Array)
75
+ end
76
+
77
+ it 'of commit objects' do
78
+ expect(subject.first).to be_an_instance_of(GitWebHookModel::Hook::Commit)
79
+ end
80
+ end
81
+ end
82
+
83
+ describe '#head_commit' do
84
+ subject { instance.head_commit }
85
+
86
+ it 'of commit objects' do
87
+ expect(subject).to be_an_instance_of(GitWebHookModel::Hook::Commit)
88
+ end
89
+ end
90
+
91
+ describe '#pusher' do
92
+ subject { instance.pusher }
93
+
94
+ it 'of owner objects' do
95
+ expect(subject).to be_an_instance_of(GitWebHookModel::Hook::Owner)
96
+ end
97
+ end
98
+
99
+ describe '#repository' do
100
+ subject { instance.repository }
101
+
102
+ it 'of repository objects' do
103
+ expect(subject).to be_an_instance_of(GitWebHookModel::Hook::Repository)
104
+ end
105
+ end
106
+ end
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+
3
+ describe GitWebHookModel::Hook::Owner do
4
+ let(:instance) { described_class.new(owner) }
5
+
6
+ let(:response) { File.read('spec/fixtures/hook.json') }
7
+ let(:hash) { GitWebHookModel::Parse.new(response).as_hash }
8
+
9
+ let(:repository) { hash.fetch('repository') }
10
+ let(:owner) { repository.fetch('owner') }
11
+
12
+ describe '#name' do
13
+ subject { instance.name }
14
+
15
+ it 'returns value' do
16
+ expect(subject).to eq("company")
17
+ end
18
+ end
19
+
20
+ describe '#email' do
21
+ subject { instance.email }
22
+
23
+ it 'returns none' do
24
+ expect(subject).to eq(None)
25
+ end
26
+ end
27
+
28
+ describe '#username' do
29
+ subject { instance.username }
30
+
31
+ it 'returns none' do
32
+ expect(subject).to eq(None)
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,182 @@
1
+ require 'spec_helper'
2
+
3
+ describe GitWebHookModel::Hook::Repository do
4
+ let(:instance) { described_class.new(repository) }
5
+
6
+ let(:response) { File.read('spec/fixtures/hook.json') }
7
+ let(:hash) { GitWebHookModel::Parse.new(response).as_hash }
8
+
9
+ let(:repository) { hash.fetch('repository') }
10
+
11
+ describe '#id' do
12
+ subject { instance.id }
13
+
14
+ it 'returns value' do
15
+ expect(subject).to eq(72)
16
+ end
17
+ end
18
+
19
+ describe '#name' do
20
+ subject { instance.name }
21
+
22
+ it 'returns value' do
23
+ expect(subject).to eq('otb_www_app')
24
+ end
25
+ end
26
+
27
+ describe '#url' do
28
+ subject { instance.url }
29
+
30
+ let(:url) do
31
+ %Q{https://github.company.com/organisation/otb_www_app}
32
+ end
33
+
34
+ it 'returns value' do
35
+ expect(subject).to eq(url)
36
+ end
37
+ end
38
+
39
+ describe '#description' do
40
+ subject { instance.description }
41
+
42
+ it 'returns value' do
43
+ expect(subject).to eq('Frontend Application')
44
+ end
45
+ end
46
+
47
+ describe '#homepage' do
48
+ subject { instance.homepage }
49
+
50
+ it 'returns value' do
51
+ expect(subject).to eq('www.example.co.uk')
52
+ end
53
+ end
54
+
55
+ describe '#watchers' do
56
+ subject { instance.watchers }
57
+
58
+ it 'returns value' do
59
+ expect(subject).to eq(1)
60
+ end
61
+ end
62
+
63
+ describe '#stargazers' do
64
+ subject { instance.stargazers }
65
+
66
+ it 'returns value' do
67
+ expect(subject).to eq(1)
68
+ end
69
+ end
70
+
71
+ describe '#forks' do
72
+ subject { instance.forks }
73
+
74
+ it 'returns value' do
75
+ expect(subject).to eq(0)
76
+ end
77
+ end
78
+
79
+ describe '#fork?' do
80
+ subject { instance.fork? }
81
+
82
+ it 'returns false' do
83
+ expect(subject).to be_false
84
+ end
85
+ end
86
+
87
+ describe '#size' do
88
+ subject { instance.size }
89
+
90
+ it 'returns value' do
91
+ expect(subject).to eq(54414)
92
+ end
93
+ end
94
+
95
+ describe '#private?' do
96
+ subject { instance.private? }
97
+
98
+ it 'returns false' do
99
+ expect(subject).to be_false
100
+ end
101
+ end
102
+
103
+ describe '#open_issues' do
104
+ subject { instance.open_issues }
105
+
106
+ it 'returns value' do
107
+ expect(subject).to eq(6)
108
+ end
109
+ end
110
+
111
+ describe '#has_issues?' do
112
+ subject { instance.has_issues? }
113
+
114
+ it 'returns true' do
115
+ expect(subject).to be_true
116
+ end
117
+ end
118
+
119
+ describe '#has_downloads?' do
120
+ subject { instance.has_downloads? }
121
+
122
+ it 'returns true' do
123
+ expect(subject).to be_true
124
+ end
125
+ end
126
+
127
+ describe '#has_wiki?' do
128
+ subject { instance.has_wiki? }
129
+
130
+ it 'returns true' do
131
+ expect(subject).to be_true
132
+ end
133
+ end
134
+
135
+ describe '#language' do
136
+ subject { instance.language }
137
+
138
+ it 'returns value' do
139
+ expect(subject).to eq('Ruby')
140
+ end
141
+ end
142
+
143
+ describe '#created_at' do
144
+ subject { instance.created_at }
145
+
146
+ it 'returns value' do
147
+ expect(subject).to eq(1295946304)
148
+ end
149
+ end
150
+
151
+ describe '#pushed_at' do
152
+ subject { instance.pushed_at }
153
+
154
+ it 'returns value' do
155
+ expect(subject).to eq(1383924957)
156
+ end
157
+ end
158
+
159
+ describe '#master_branch' do
160
+ subject { instance.master_branch }
161
+
162
+ it 'returns value' do
163
+ expect(subject).to eq('master')
164
+ end
165
+ end
166
+
167
+ describe '#organization' do
168
+ subject { instance.organization }
169
+
170
+ it 'returns value' do
171
+ expect(subject).to eq('organisation')
172
+ end
173
+ end
174
+
175
+ describe '#owner' do
176
+ subject { instance.owner }
177
+
178
+ it 'returns a owner object' do
179
+ expect(subject).to be_an_instance_of(GitWebHookModel::Hook::Owner)
180
+ end
181
+ end
182
+ end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ describe GitWebHookModel::Parse do
4
+ let(:instance) { described_class.new(response) }
5
+ let(:response) { File.read('spec/fixtures/hook.json') }
6
+
7
+ describe '#as_hash' do
8
+ subject { instance.as_hash }
9
+
10
+ it 'returns an instance of hash' do
11
+ expect(subject).to be_an_instance_of(Hash)
12
+ end
13
+
14
+ context 'given a hash' do
15
+ let(:response) { {} }
16
+
17
+ it 'returns original hash' do
18
+ expect(subject).to eq(response)
19
+ end
20
+ end
21
+
22
+ context 'given json' do
23
+ it 'returns parsed json as a hash' do
24
+ expect(subject).to eq(JSON.parse(response))
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,4 @@
1
+ require 'spec_helper'
2
+
3
+ describe GitWebHookModel do
4
+ end
@@ -0,0 +1,19 @@
1
+ require 'simplecov'
2
+ require 'coveralls'
3
+
4
+ Coveralls.wear!
5
+
6
+ ENV["RAILS_ENV"] ||= 'test'
7
+
8
+ require 'rspec/autorun'
9
+ require 'git_web_hook_model'
10
+
11
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
12
+
13
+ RSpec.configure do |config|
14
+ config.order = "random"
15
+ config.filter_run :focus => true
16
+ config.color_enabled = true
17
+ config.run_all_when_everything_filtered = true
18
+ config.treat_symbols_as_metadata_keys_with_true_values = true
19
+ end
metadata ADDED
@@ -0,0 +1,146 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: git_web_hook_model
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Chuck J hardy
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-11-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: id
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '0.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '0.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: simplecov
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 0.7.1
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: 0.7.1
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: 2.13.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: 2.13.0
83
+ description: Turn a Github WebHook into an object model
84
+ email:
85
+ - chuckjhardy@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - .coveralls.yml
91
+ - .gitignore
92
+ - .simplecov
93
+ - .travis.yml
94
+ - Gemfile
95
+ - LICENSE.txt
96
+ - README.md
97
+ - Rakefile
98
+ - git_web_hook_model.gemspec
99
+ - lib/git_web_hook_model.rb
100
+ - lib/git_web_hook_model/hook/commit.rb
101
+ - lib/git_web_hook_model/hook/model.rb
102
+ - lib/git_web_hook_model/hook/owner.rb
103
+ - lib/git_web_hook_model/hook/repository.rb
104
+ - lib/git_web_hook_model/parse.rb
105
+ - lib/git_web_hook_model/version.rb
106
+ - spec/fixtures/hook.json
107
+ - spec/lib/git_web_hook_model/hook/commit_spec.rb
108
+ - spec/lib/git_web_hook_model/hook/model_spec.rb
109
+ - spec/lib/git_web_hook_model/hook/owner_spec.rb
110
+ - spec/lib/git_web_hook_model/hook/repository_spec.rb
111
+ - spec/lib/git_web_hook_model/parse_spec.rb
112
+ - spec/lib/git_web_hook_model_spec.rb
113
+ - spec/spec_helper.rb
114
+ homepage: ''
115
+ licenses:
116
+ - MIT
117
+ metadata: {}
118
+ post_install_message:
119
+ rdoc_options: []
120
+ require_paths:
121
+ - lib
122
+ required_ruby_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ! '>='
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ required_rubygems_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ! '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ requirements: []
133
+ rubyforge_project:
134
+ rubygems_version: 2.1.9
135
+ signing_key:
136
+ specification_version: 4
137
+ summary: Turn a Github WebHook into an object model
138
+ test_files:
139
+ - spec/fixtures/hook.json
140
+ - spec/lib/git_web_hook_model/hook/commit_spec.rb
141
+ - spec/lib/git_web_hook_model/hook/model_spec.rb
142
+ - spec/lib/git_web_hook_model/hook/owner_spec.rb
143
+ - spec/lib/git_web_hook_model/hook/repository_spec.rb
144
+ - spec/lib/git_web_hook_model/parse_spec.rb
145
+ - spec/lib/git_web_hook_model_spec.rb
146
+ - spec/spec_helper.rb