vx-service_connector 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/.rspec +3 -0
  4. data/.travis.yml +5 -0
  5. data/Gemfile +8 -0
  6. data/LICENSE.txt +22 -0
  7. data/README.md +29 -0
  8. data/Rakefile +10 -0
  9. data/lib/vx/service_connector.rb +37 -0
  10. data/lib/vx/service_connector/base.rb +27 -0
  11. data/lib/vx/service_connector/github.rb +49 -0
  12. data/lib/vx/service_connector/github/commits.rb +33 -0
  13. data/lib/vx/service_connector/github/deploy_keys.rb +29 -0
  14. data/lib/vx/service_connector/github/files.rb +21 -0
  15. data/lib/vx/service_connector/github/hooks.rb +33 -0
  16. data/lib/vx/service_connector/github/notices.rb +40 -0
  17. data/lib/vx/service_connector/github/payload.rb +124 -0
  18. data/lib/vx/service_connector/github/repos.rb +52 -0
  19. data/lib/vx/service_connector/gitlab_v3.rb +29 -0
  20. data/lib/vx/service_connector/gitlab_v3/deploy_keys.rb +20 -0
  21. data/lib/vx/service_connector/gitlab_v3/repos.rb +28 -0
  22. data/lib/vx/service_connector/model.rb +82 -0
  23. data/lib/vx/service_connector/version.rb +5 -0
  24. data/spec/fixtures/github/add_deploy_key.json +6 -0
  25. data/spec/fixtures/github/commit.json +83 -0
  26. data/spec/fixtures/github/create_hook.json +12 -0
  27. data/spec/fixtures/github/create_status.json +5 -0
  28. data/spec/fixtures/github/deploy_keys.json +8 -0
  29. data/spec/fixtures/github/hooks.json +18 -0
  30. data/spec/fixtures/github/org_repos.json +51 -0
  31. data/spec/fixtures/github/orgs.json +8 -0
  32. data/spec/fixtures/github/payload/closed_pull_request.json +392 -0
  33. data/spec/fixtures/github/payload/foreign_pull_request.json +1 -0
  34. data/spec/fixtures/github/payload/pull_request.json +392 -0
  35. data/spec/fixtures/github/payload/push.json +92 -0
  36. data/spec/fixtures/github/payload/push_tag.json +135 -0
  37. data/spec/fixtures/github/user_repos.json +48 -0
  38. data/spec/fixtures/gitlab_v3/deploy_keys.json +14 -0
  39. data/spec/fixtures/gitlab_v3/projects.json +72 -0
  40. data/spec/lib/github_payload_spec.rb +136 -0
  41. data/spec/lib/github_spec.rb +159 -0
  42. data/spec/lib/gitlab_v3_spec.rb +44 -0
  43. data/spec/lib/model_spec.rb +37 -0
  44. data/spec/lib/service_connector_spec.rb +30 -0
  45. data/spec/spec_helper.rb +14 -0
  46. data/spec/support/create.rb +6 -0
  47. data/spec/support/github_web_mocks.rb +101 -0
  48. data/spec/support/gitlab_v3_mocks.rb +29 -0
  49. data/spec/support/read_fixture.rb +12 -0
  50. data/vx-service_connector.gemspec +28 -0
  51. metadata +203 -0
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+
3
+ describe Vx::ServiceConnector::GitlabV3 do
4
+
5
+ include GitlabV3Mocks
6
+
7
+ let(:endpoint) { 'http://example.com' }
8
+ let(:token) { 'token' }
9
+ let(:repo) { create :repo }
10
+ let(:gitlab) { described_class.new endpoint, token }
11
+ subject { gitlab }
12
+
13
+ context "(repos)" do
14
+ subject { gitlab.repos }
15
+ before { mock_repos }
16
+ it { should have(2).item }
17
+ context "values" do
18
+ subject { gitlab.repos.map(&:values) }
19
+ it { should eq(
20
+ [[4, "diaspora/diaspora-client", true,
21
+ "git@example.com:diaspora/diaspora-client.git",
22
+ "http://example.com/diaspora/diaspora-client",
23
+ "description"],
24
+ [6, "brightbox/puppet", true,
25
+ "git@example.com:brightbox/puppet.git",
26
+ "http://example.com/brightbox/puppet",
27
+ "description"]]
28
+ ) }
29
+ end
30
+ end
31
+
32
+ context "(deploy_keys)" do
33
+ let(:key_name) { 'key_name' }
34
+ let(:public_key) { 'public_key' }
35
+ let(:deploy_keys) { gitlab.deploy_keys(repo) }
36
+
37
+ context "all" do
38
+ subject { deploy_keys.all }
39
+ before { mock_deploy_keys }
40
+ it { should have(2).item }
41
+ end
42
+
43
+ end
44
+ end
@@ -0,0 +1,37 @@
1
+ require 'spec_helper'
2
+
3
+ describe "(models)" do
4
+ context Vx::ServiceConnector::Model::Payload do
5
+ let(:values) {
6
+ [false, nil, 'head', 'base', 'master', 'master:label',
7
+ 'http://example.com', false]
8
+ }
9
+ let(:payload) { described_class.new(*values) }
10
+ subject { payload }
11
+
12
+ it { should be }
13
+ its(:values) { should eq values }
14
+
15
+ context "to_hash" do
16
+ subject { payload.to_hash }
17
+ it { should eq({
18
+ :base => "base",
19
+ :branch => "master",
20
+ :branch_label => "master:label",
21
+ :head => "head",
22
+ :ignore? => false,
23
+ :pull_request? => false,
24
+ :pull_request_number => nil,
25
+ :url => "http://example.com"
26
+ }) }
27
+ end
28
+
29
+ context ".from_hash" do
30
+ let(:params) { payload.to_hash }
31
+ let(:new_payload) { described_class.from_hash params }
32
+ subject { new_payload }
33
+
34
+ its(:values) { should eq payload.values }
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+
3
+ describe Vx::ServiceConnector do
4
+
5
+ context ".payload" do
6
+ subject { described_class.payload type, params }
7
+
8
+ context ":github" do
9
+ let(:type) { :github }
10
+ let(:params) { read_json_fixture("github/payload/push") }
11
+ it { should be }
12
+ it { should be_an_instance_of(Vx::ServiceConnector::Model::Payload) }
13
+ end
14
+ end
15
+
16
+ context "to" do
17
+ subject { described_class.to name }
18
+
19
+ context ":github" do
20
+ let(:name) { :github }
21
+ it { should be }
22
+ end
23
+
24
+ context ":gitlab_v3" do
25
+ let(:name) { :gitlab_v3 }
26
+ it { should be }
27
+ end
28
+ end
29
+
30
+ end
@@ -0,0 +1,14 @@
1
+ require File.expand_path("../../lib/vx/service_connector", __FILE__)
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ Bundler.require
6
+
7
+ require 'rspec/autorun'
8
+ require 'webmock/rspec'
9
+
10
+ Dir[File.expand_path("../..", __FILE__) + "/spec/support/**/*.rb"].each {|f| require f}
11
+
12
+ RSpec.configure do |config|
13
+ config.include ReadFixtureSpecSupport
14
+ end
@@ -0,0 +1,6 @@
1
+ def create(name, params = {})
2
+ case name
3
+ when :repo
4
+ Vx::ServiceConnector::Model::Repo.new(1, 'full/name', false, 'ssh@example.com', 'http://example.com')
5
+ end
6
+ end
@@ -0,0 +1,101 @@
1
+ module GithubWebMocks
2
+
3
+ def mock_get_commit
4
+ mock_get "https://api.github.com/repos/full/name/commits/sha", 'commit'
5
+ end
6
+
7
+ def mock_get_commit_not_found
8
+ stub_request(:get, "https://api.github.com/repos/full/name/commits/sha").
9
+ to_return(:status => 404, :body => "")
10
+ end
11
+
12
+ def mock_create_notice(state)
13
+ mock_post "https://api.github.com/repos/full/name/statuses/sha",
14
+ "{\"description\":\"description\",\"target_url\":\"url\",\"state\":\"#{state}\"}",
15
+ "create_status"
16
+ end
17
+
18
+ def mock_remove_hook
19
+ mock_delete "https://api.github.com/repos/full/name/hooks/1", "{}"
20
+ end
21
+
22
+ def mock_hooks
23
+ mock_get "https://api.github.com/repos/full/name/hooks?per_page=100",
24
+ "hooks"
25
+ end
26
+
27
+ def mock_add_hook
28
+ mock_post "https://api.github.com/repos/full/name/hooks",
29
+ "{\"name\":\"web\",\"config\":{\"url\":\"url\",\"secret\":\"token\",\"content_type\":\"json\"},\"events\":[\"push\",\"pull_request\"],\"active\":true}",
30
+ "create_hook"
31
+ end
32
+
33
+ def mock_deploy_keys
34
+ mock_get "https://api.github.com/repos/full/name/keys?per_page=100", "deploy_keys"
35
+ end
36
+
37
+ def mock_delete_deploy_key
38
+ mock_delete "https://api.github.com/repos/full/name/keys/1", "{}"
39
+ end
40
+
41
+ def mock_add_deploy_key
42
+ mock_post "https://api.github.com/repos/full/name/keys",
43
+ "{\"title\":\"octocat@octomac\",\"key\":\"public key\"}",
44
+ "add_deploy_key"
45
+ end
46
+
47
+ def mock_user_repos
48
+ mock_get "https://api.github.com/user/repos?per_page=100", "user_repos"
49
+ end
50
+
51
+ def mock_org_repos
52
+ mock_get "https://api.github.com/orgs/github/repos?per_page=100", "org_repos"
53
+ end
54
+
55
+ def mock_orgs
56
+ mock_get "https://api.github.com/user/orgs", "orgs"
57
+ end
58
+
59
+ def mock_get_file
60
+ require 'base64'
61
+ require 'json'
62
+
63
+ content = { "content" => Base64.encode64('content') }.to_json
64
+ mock_get "https://api.github.com/repos/full/name/contents/path?ref=sha", nil, content: content
65
+ end
66
+
67
+ def mock_get_file_not_found
68
+ stub_request(:get, "https://api.github.com/repos/full/name/contents/path?ref=sha").
69
+ to_return(:status => 404, :body => "")
70
+ end
71
+
72
+ def mock_post(url, body, fixture)
73
+ stub_request(:post, url).
74
+ with(:body => body,
75
+ :headers => {
76
+ 'Accept'=>'application/vnd.github.beta+json',
77
+ 'Authorization'=>'token token'}).
78
+ to_return(:status => 200, :body => read_fixture("github/#{fixture}.json"), :headers => {})
79
+ end
80
+
81
+ def mock_get(url, fixture, options = {})
82
+ content = options[:content]
83
+ content ||= read_fixture("github/#{fixture}.json")
84
+ content_type = options[:content_type] || 'application/json'
85
+ stub_request(:get, url).
86
+ with(:headers => {
87
+ 'Accept'=>'application/vnd.github.beta+json',
88
+ 'Authorization'=>'token token'}).
89
+ to_return(
90
+ :status => 200,
91
+ :body => content,
92
+ :headers => {'Content-Type'=> content_type})
93
+ end
94
+
95
+ def mock_delete(url, body)
96
+ stub_request(:delete, url).
97
+ with(:body => body,
98
+ :headers => {'Accept'=>'application/vnd.github.beta+json', 'Authorization'=>'token token'}).
99
+ to_return(:status => 200, :body => "")
100
+ end
101
+ end
@@ -0,0 +1,29 @@
1
+ module GitlabV3Mocks
2
+
3
+ def mock_add_deploy_key
4
+ mock_post "http://example.com/api/v3/projects/1/keys", '{}'
5
+ end
6
+
7
+ def mock_deploy_keys
8
+ mock_get "http://example.com/api/v3/projects/1/keys", 'deploy_keys'
9
+ end
10
+
11
+ def mock_repos
12
+ mock_get "http://example.com/api/v3/projects", 'projects'
13
+ end
14
+
15
+ def mock_get(url, fixture)
16
+ stub_request(:get, "#{url}?private_token=token").
17
+ with(:headers => {'Accept'=>'application/json'}).
18
+ to_return(
19
+ :status => 200,
20
+ :body => read_fixture("gitlab_v3/#{fixture}.json"),
21
+ :headers => {'Content-Type' => 'application/json'})
22
+ end
23
+
24
+ def mock_post(url, body)
25
+ stub_request(:post, "#{url}?private_token=token").
26
+ with(:headers => {'Accept'=>'application/json'}, body: body).
27
+ to_return(:status => 200, :body => "{}", :headers => {'Content-Type' => 'application/json'})
28
+ end
29
+ end
@@ -0,0 +1,12 @@
1
+ require 'json'
2
+
3
+ module ReadFixtureSpecSupport
4
+ def read_fixture(name)
5
+ File.read File.expand_path("../../fixtures/#{name}", __FILE__)
6
+ end
7
+
8
+ def read_json_fixture(name)
9
+ JSON.parse read_fixture(name + ".json")
10
+ end
11
+ end
12
+
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'vx/service_connector/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "vx-service_connector"
8
+ spec.version = Vx::ServiceConnector::VERSION
9
+ spec.authors = ["Dmitry Galinsky"]
10
+ spec.email = ["dima.exe@gmail.com"]
11
+ spec.description = %q{ vx-service_connector }
12
+ spec.summary = %q{ vx-service_connector }
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_runtime_dependency 'octokit', '2.2.0'
22
+ spec.add_runtime_dependency 'gitlab', '3.0.0'
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.3"
25
+ spec.add_development_dependency "rake"
26
+ spec.add_development_dependency "rspec"
27
+ spec.add_development_dependency "webmock"
28
+ end
metadata ADDED
@@ -0,0 +1,203 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vx-service_connector
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Dmitry Galinsky
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-01-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: octokit
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 2.2.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 2.2.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: gitlab
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 3.0.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 3.0.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: webmock
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: ' vx-service_connector '
98
+ email:
99
+ - dima.exe@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - .gitignore
105
+ - .rspec
106
+ - .travis.yml
107
+ - Gemfile
108
+ - LICENSE.txt
109
+ - README.md
110
+ - Rakefile
111
+ - lib/vx/service_connector.rb
112
+ - lib/vx/service_connector/base.rb
113
+ - lib/vx/service_connector/github.rb
114
+ - lib/vx/service_connector/github/commits.rb
115
+ - lib/vx/service_connector/github/deploy_keys.rb
116
+ - lib/vx/service_connector/github/files.rb
117
+ - lib/vx/service_connector/github/hooks.rb
118
+ - lib/vx/service_connector/github/notices.rb
119
+ - lib/vx/service_connector/github/payload.rb
120
+ - lib/vx/service_connector/github/repos.rb
121
+ - lib/vx/service_connector/gitlab_v3.rb
122
+ - lib/vx/service_connector/gitlab_v3/deploy_keys.rb
123
+ - lib/vx/service_connector/gitlab_v3/repos.rb
124
+ - lib/vx/service_connector/model.rb
125
+ - lib/vx/service_connector/version.rb
126
+ - spec/fixtures/github/add_deploy_key.json
127
+ - spec/fixtures/github/commit.json
128
+ - spec/fixtures/github/create_hook.json
129
+ - spec/fixtures/github/create_status.json
130
+ - spec/fixtures/github/deploy_keys.json
131
+ - spec/fixtures/github/hooks.json
132
+ - spec/fixtures/github/org_repos.json
133
+ - spec/fixtures/github/orgs.json
134
+ - spec/fixtures/github/payload/closed_pull_request.json
135
+ - spec/fixtures/github/payload/foreign_pull_request.json
136
+ - spec/fixtures/github/payload/pull_request.json
137
+ - spec/fixtures/github/payload/push.json
138
+ - spec/fixtures/github/payload/push_tag.json
139
+ - spec/fixtures/github/user_repos.json
140
+ - spec/fixtures/gitlab_v3/deploy_keys.json
141
+ - spec/fixtures/gitlab_v3/projects.json
142
+ - spec/lib/github_payload_spec.rb
143
+ - spec/lib/github_spec.rb
144
+ - spec/lib/gitlab_v3_spec.rb
145
+ - spec/lib/model_spec.rb
146
+ - spec/lib/service_connector_spec.rb
147
+ - spec/spec_helper.rb
148
+ - spec/support/create.rb
149
+ - spec/support/github_web_mocks.rb
150
+ - spec/support/gitlab_v3_mocks.rb
151
+ - spec/support/read_fixture.rb
152
+ - vx-service_connector.gemspec
153
+ homepage: ''
154
+ licenses:
155
+ - MIT
156
+ metadata: {}
157
+ post_install_message:
158
+ rdoc_options: []
159
+ require_paths:
160
+ - lib
161
+ required_ruby_version: !ruby/object:Gem::Requirement
162
+ requirements:
163
+ - - '>='
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
166
+ required_rubygems_version: !ruby/object:Gem::Requirement
167
+ requirements:
168
+ - - '>='
169
+ - !ruby/object:Gem::Version
170
+ version: '0'
171
+ requirements: []
172
+ rubyforge_project:
173
+ rubygems_version: 2.0.14
174
+ signing_key:
175
+ specification_version: 4
176
+ summary: vx-service_connector
177
+ test_files:
178
+ - spec/fixtures/github/add_deploy_key.json
179
+ - spec/fixtures/github/commit.json
180
+ - spec/fixtures/github/create_hook.json
181
+ - spec/fixtures/github/create_status.json
182
+ - spec/fixtures/github/deploy_keys.json
183
+ - spec/fixtures/github/hooks.json
184
+ - spec/fixtures/github/org_repos.json
185
+ - spec/fixtures/github/orgs.json
186
+ - spec/fixtures/github/payload/closed_pull_request.json
187
+ - spec/fixtures/github/payload/foreign_pull_request.json
188
+ - spec/fixtures/github/payload/pull_request.json
189
+ - spec/fixtures/github/payload/push.json
190
+ - spec/fixtures/github/payload/push_tag.json
191
+ - spec/fixtures/github/user_repos.json
192
+ - spec/fixtures/gitlab_v3/deploy_keys.json
193
+ - spec/fixtures/gitlab_v3/projects.json
194
+ - spec/lib/github_payload_spec.rb
195
+ - spec/lib/github_spec.rb
196
+ - spec/lib/gitlab_v3_spec.rb
197
+ - spec/lib/model_spec.rb
198
+ - spec/lib/service_connector_spec.rb
199
+ - spec/spec_helper.rb
200
+ - spec/support/create.rb
201
+ - spec/support/github_web_mocks.rb
202
+ - spec/support/gitlab_v3_mocks.rb
203
+ - spec/support/read_fixture.rb