vx-service_connector 0.0.11 → 0.2.0

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.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -1
  3. data/lib/vx/service_connector.rb +0 -2
  4. data/lib/vx/service_connector/gitlab_v6.rb +37 -1
  5. data/lib/vx/service_connector/gitlab_v6/deploy_keys.rb +24 -1
  6. data/lib/vx/service_connector/gitlab_v6/files.rb +13 -3
  7. data/lib/vx/service_connector/gitlab_v6/hooks.rb +40 -4
  8. data/lib/vx/service_connector/gitlab_v6/notices.rb +6 -1
  9. data/lib/vx/service_connector/gitlab_v6/payload.rb +74 -10
  10. data/lib/vx/service_connector/gitlab_v6/repos.rb +72 -1
  11. data/lib/vx/service_connector/gitlab_v6/session.rb +49 -1
  12. data/lib/vx/service_connector/version.rb +1 -1
  13. data/spec/fixtures/gitlab_v6/payload/merge_request.json +1 -1
  14. data/spec/fixtures/gitlab_v6/payload/merged_merge_request.json +20 -0
  15. data/spec/lib/gitlab_payload_spec.rb +1 -1
  16. data/spec/lib/gitlab_spec.rb +1 -1
  17. data/spec/lib/gitlab_v6_payload_spec.rb +11 -3
  18. data/spec/lib/service_connector_spec.rb +0 -5
  19. data/vx-service_connector.gemspec +1 -1
  20. metadata +9 -27
  21. data/lib/vx/service_connector/gitlab_v5.rb +0 -47
  22. data/lib/vx/service_connector/gitlab_v5/deploy_keys.rb +0 -30
  23. data/lib/vx/service_connector/gitlab_v5/files.rb +0 -20
  24. data/lib/vx/service_connector/gitlab_v5/hooks.rb +0 -45
  25. data/lib/vx/service_connector/gitlab_v5/notices.rb +0 -13
  26. data/lib/vx/service_connector/gitlab_v5/payload.rb +0 -120
  27. data/lib/vx/service_connector/gitlab_v5/repos.rb +0 -73
  28. data/lib/vx/service_connector/gitlab_v5/session.rb +0 -58
  29. data/spec/fixtures/gitlab_v5/commits.json +0 -18
  30. data/spec/fixtures/gitlab_v5/deploy_keys.json +0 -14
  31. data/spec/fixtures/gitlab_v5/hooks.json +0 -1
  32. data/spec/fixtures/gitlab_v5/payload/push.json +0 -32
  33. data/spec/fixtures/gitlab_v5/projects.json +0 -1
  34. data/spec/fixtures/gitlab_v5/user_keys.json +0 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a6bb570ebaae300ece69aeaa8af1fff7ad89a596
4
- data.tar.gz: fc9b789a77f95b4ce64fa55b3c2749b230e72291
3
+ metadata.gz: e49f704ce930150ed69a07365ec5e4552969ec58
4
+ data.tar.gz: 63afb325c1a43622b21ee026e5aa757c0bb135db
5
5
  SHA512:
6
- metadata.gz: 9dca5c56992692538e9017f9567ac9d261fc1ef3b784e598f8bbd0261d3b9e2a48fd8a80345c11e3045910b15f54ef4050ffea0f20add623d4b683f40977b4ab
7
- data.tar.gz: c2ccf1066633abf7a69cd05e7753baac3cafb8e5dc71ef74dc5fb9d0a909d98a5beefd1606cb7d27a7cef5aba9cdd6d4be7e54ce17a75769d1c9d6c72654567f
6
+ metadata.gz: bf0888344d76a2bdfbcce6798eeeece39bbc4602345cc4887dc839efd2ae111fb6f8582f5394e9d9fee08e5219095216589b4468fb0a74ea5333f044429047c4
7
+ data.tar.gz: 68777e3db8fc6538e6a84e46b24571e289fc065db1f2e9a78353c2d5c3a4fc504669a307fe51351bf4f56596f54e7b0f6f9e150b13ce99a43a078c0735a46ede
@@ -1,5 +1,5 @@
1
1
  rvm:
2
2
  - "2.0.0"
3
- - "2.1.0"
3
+ - "2.1"
4
4
 
5
5
  script: "rspec spec/ -fp"
@@ -17,8 +17,6 @@ module Vx
17
17
  case name.to_sym
18
18
  when :github
19
19
  Github
20
- when :gitlab_v5
21
- GitlabV5
22
20
  when :gitlab_v6
23
21
  GitlabV6
24
22
  else
@@ -1,6 +1,42 @@
1
1
  module Vx
2
2
  module ServiceConnector
3
- class GitlabV6 < GitlabV5
3
+ GitlabV6 = Struct.new(:endpoint, :private_token) do
4
+
5
+ include ServiceConnector::Base
6
+
7
+ def repos
8
+ @repos ||= self.class::Repos.new(session).to_a
9
+ end
10
+
11
+ def organizations
12
+ []
13
+ end
14
+
15
+ def hooks(repo)
16
+ self.class::Hooks.new(session, repo)
17
+ end
18
+
19
+ def deploy_keys(repo)
20
+ self.class::DeployKeys.new(session, repo)
21
+ end
22
+
23
+ def notices(repo)
24
+ self.class::Notices.new(session, repo)
25
+ end
26
+
27
+ def files(repo)
28
+ self.class::Files.new(session, repo)
29
+ end
30
+
31
+ def payload(repo, params)
32
+ self.class::Payload.new(session, repo, params).build
33
+ end
34
+
35
+ private
36
+
37
+ def create_session
38
+ self.class::Session.new(endpoint, private_token)
39
+ end
4
40
  end
5
41
  end
6
42
  end
@@ -1,6 +1,29 @@
1
1
  module Vx
2
2
  module ServiceConnector
3
- class GitlabV6::DeployKeys < GitlabV5::DeployKeys
3
+ class GitlabV6
4
+ DeployKeys = Struct.new(:session, :repo) do
5
+
6
+ def all
7
+ begin
8
+ session.get "/projects/#{repo.id}/keys"
9
+ rescue RequestError
10
+ []
11
+ end
12
+ end
13
+
14
+ def create(key_name, public_key)
15
+ session.post "/projects/#{repo.id}/keys", title: key_name, key: public_key
16
+ end
17
+
18
+ def destroy(key_name)
19
+ all.select do |key|
20
+ key.title == key_name
21
+ end.map do |key|
22
+ session.delete "/projects/#{repo.id}/keys/#{key.id}"
23
+ end
24
+ end
25
+
26
+ end
4
27
  end
5
28
  end
6
29
  end
@@ -1,8 +1,18 @@
1
- require 'base64'
2
-
3
1
  module Vx
4
2
  module ServiceConnector
5
- class GitlabV6::Files < GitlabV5::Files
3
+ class GitlabV6
4
+ Files = Struct.new(:session, :repo) do
5
+
6
+ def get(sha, path)
7
+ begin
8
+ session.get("/projects/#{repo.id}/repository/commits/#{sha}/blob", filepath: path)
9
+ rescue RequestError => e
10
+ $stderr.puts "ERROR: #{e.inspect}"
11
+ nil
12
+ end
13
+ end
14
+
15
+ end
6
16
  end
7
17
  end
8
18
  end
@@ -1,10 +1,46 @@
1
1
  module Vx
2
2
  module ServiceConnector
3
- class GitlabV6::Hooks < GitlabV5::Hooks
4
- private
5
- def hook_url(id)
6
- "#{hooks_url}/#{id}"
3
+
4
+ class GitlabV6
5
+
6
+ Hooks = Struct.new(:session, :repo) do
7
+
8
+ def all
9
+ begin
10
+ session.get hooks_url
11
+ rescue RequestError
12
+ []
13
+ end
7
14
  end
15
+
16
+ def create(url, token)
17
+ session.post(
18
+ hooks_url,
19
+ url: url,
20
+ push_events: true,
21
+ merge_requests_events: true
22
+ )
23
+ end
24
+
25
+ def destroy(url_mask)
26
+ all.select do |hook|
27
+ hook.url =~ /#{Regexp.escape url_mask}/
28
+ end.map do |hook|
29
+ session.delete hook_url(hook.id)
30
+ end
31
+ end
32
+
33
+ private
34
+
35
+ def hooks_url
36
+ "/projects/#{repo.id}/hooks"
37
+ end
38
+
39
+ def hook_url(id)
40
+ "#{hooks_url}/#{id}"
41
+ end
42
+
43
+ end
8
44
  end
9
45
  end
10
46
  end
@@ -1,6 +1,11 @@
1
1
  module Vx
2
2
  module ServiceConnector
3
- class GitlabV6::Notices < GitlabV5::Notices
3
+ class GitlabV6
4
+ Notices = Struct.new(:session, :repo) do
5
+ def create(build_sha, build_status, build_url, description)
6
+ :not_available
7
+ end
8
+ end
4
9
  end
5
10
  end
6
11
  end
@@ -1,8 +1,63 @@
1
1
  module Vx
2
2
  module ServiceConnector
3
- class GitlabV6::Payload < GitlabV5::Payload
3
+ class GitlabV6
4
+
5
+ Payload = Struct.new(:session, :repo, :params) do
6
+
7
+ def build
8
+ ServiceConnector::Model::Payload.new(
9
+ !!ignore?,
10
+ !!pull_request?,
11
+ pull_request_number,
12
+ branch,
13
+ branch_label,
14
+ sha,
15
+ message,
16
+ author,
17
+ author_email,
18
+ web_url
19
+ )
20
+ end
21
+
22
+ private
23
+
24
+ def message
25
+ commit_for_payload["title"]
26
+ end
4
27
 
5
- private
28
+ def author
29
+ commit_for_payload["author_name"]
30
+ end
31
+
32
+ def author_email
33
+ commit_for_payload["author_email"]
34
+ end
35
+
36
+ def branch_label
37
+ branch
38
+ end
39
+
40
+ def foreign_pull_request?
41
+ pull_request_base_repo_id != pull_request_head_repo_id
42
+ end
43
+
44
+ def ignore?
45
+ if pull_request?
46
+ closed_pull_request? || !foreign_pull_request?
47
+ else
48
+ sha == '0000000000000000000000000000000000000000' || tag?
49
+ end
50
+ end
51
+
52
+ def key?(name)
53
+ params.key? name
54
+ end
55
+
56
+ def [](val)
57
+ params[val]
58
+ end
59
+
60
+ #=== V6
6
61
 
7
62
  def pull_request?
8
63
  self["object_kind"] == "merge_request"
@@ -25,13 +80,13 @@ module Vx
25
80
  end
26
81
 
27
82
  def web_url
28
- if pull_request?
83
+ case
84
+ when pull_request?
29
85
  base_url = project_details["web_url"]
30
86
  id = pull_request["iid"]
31
-
32
87
  "#{base_url}/merge_requests/#{id}"
33
-
34
- elsif u = self["repository"] && self["repository"]["homepage"]
88
+ when self["repository"] && self["repository"]["homepage"]
89
+ u = self["repository"]["homepage"]
35
90
  "#{u}/commit/#{sha}"
36
91
  end
37
92
  end
@@ -62,7 +117,7 @@ module Vx
62
117
 
63
118
  def project_details
64
119
  @project_details ||= begin
65
- project = session.get("/projects/#{repo.id}")
120
+ session.get("/projects/#{repo.id}")
66
121
  rescue RequestError => e
67
122
  $stderr.puts "ERROR: #{e.inspect}"
68
123
  nil
@@ -71,8 +126,12 @@ module Vx
71
126
 
72
127
  def commit_sha_for_pull_request
73
128
  @commit_sha ||= begin
74
- branch_details = session.get("/projects/#{repo.id}/repository/branches/#{branch}")
75
- branch_details["commit"]["id"]
129
+ if not ignore?
130
+ branch_details = session.get("/projects/#{repo.id}/repository/branches/#{branch}")
131
+ branch_details["commit"]["id"]
132
+ else
133
+ nil
134
+ end
76
135
  rescue RequestError => e
77
136
  $stderr.puts "ERROR: #{e.inspect}"
78
137
  nil
@@ -90,7 +149,11 @@ module Vx
90
149
  def commit_for_payload
91
150
  @commit_for_payload ||=
92
151
  begin
93
- commit = session.get(commit_uri(repo.id, sha))
152
+ if not ignore?
153
+ session.get(commit_uri(repo.id, sha))
154
+ else
155
+ {}
156
+ end
94
157
  rescue RequestError => e
95
158
  $stderr.puts "ERROR: #{e.inspect}"
96
159
  {}
@@ -100,6 +163,7 @@ module Vx
100
163
  def commit_uri(repo_id, sha)
101
164
  "/projects/#{repo_id}/repository/commits/#{sha}"
102
165
  end
166
+ end
103
167
  end
104
168
  end
105
169
  end
@@ -1,6 +1,77 @@
1
1
  module Vx
2
2
  module ServiceConnector
3
- class GitlabV6::Repos < GitlabV5::Repos
3
+ class GitlabV6
4
+ Repos = Struct.new(:session) do
5
+
6
+ def to_a
7
+ begin
8
+ session.get("/projects", per_page: 30).map do |proj|
9
+ proj_to_model proj
10
+ end
11
+ rescue RequestError
12
+ []
13
+ end
14
+ end
15
+
16
+ private
17
+
18
+ def proj_to_model(repo)
19
+ Model::Repo.new(
20
+ repo.id,
21
+ compute_name_with_namespace(repo),
22
+ compute_is_private(repo),
23
+ compute_ssh_url(repo),
24
+ compute_web_url(repo),
25
+ repo.description
26
+ )
27
+ end
28
+
29
+ def compute_name_with_namespace(repo)
30
+ if repo.path_with_namespace
31
+ # for version 5.x
32
+ repo.path_with_namespace
33
+ else
34
+ # for version 4.x
35
+ hn = session.uri.hostname.to_s.split(".")[-2]
36
+ hm ||= session.uri.hostname
37
+ [hn, repo.name.downcase].join("/").downcase
38
+ end
39
+ end
40
+
41
+ def compute_ssh_url(repo)
42
+ if repo.ssh_url
43
+ # for version 6.x
44
+ repo.ssh_url
45
+ else
46
+ # for version 5.x or 4.x
47
+ name = repo.path_with_namespace || repo.name
48
+ "git@#{session.uri.hostname}:#{name.downcase}.git"
49
+ end
50
+ end
51
+
52
+ def compute_web_url(repo)
53
+ if repo.web_url
54
+ # for version 6.x
55
+ repo.web_url
56
+ else
57
+ # for version 5.x or 4.x
58
+ name = repo.path_with_namespace || repo.name
59
+ "#{session.uri.scheme}://#{session.uri.hostname}:#{session.uri.port}/#{name.downcase}"
60
+ end
61
+ end
62
+
63
+ def compute_is_private(repo)
64
+ case
65
+ # for version before 6.x
66
+ when repo.private != nil
67
+ repo.private
68
+ # for version 6.x
69
+ when repo.public != nil
70
+ !repo.public
71
+ end
72
+ end
73
+
74
+ end
4
75
  end
5
76
  end
6
77
  end
@@ -3,7 +3,55 @@ require 'uri'
3
3
 
4
4
  module Vx
5
5
  module ServiceConnector
6
- class GitlabV6::Session < GitlabV5::Session
6
+ class GitlabV6
7
+ Session = Struct.new(:endpoint, :private_token) do
8
+
9
+ def get(url, options = {})
10
+ res = agent.call :get, request_url(url), nil, query: options
11
+ response! res
12
+ end
13
+
14
+ def post(url, options = {})
15
+ res = agent.call :post, request_url(url), options, nil
16
+ response! res
17
+ end
18
+
19
+ def delete(url, options = {})
20
+ res = agent.call :delete, request_url(url), nil, query: options
21
+ response! res
22
+ end
23
+
24
+ def uri
25
+ @uri ||= URI(endpoint)
26
+ end
27
+
28
+ private
29
+
30
+ def response!(res)
31
+ if (200..204).include?(res.status)
32
+ res.data
33
+ else
34
+ raise RequestError, res.data.inspect
35
+ end
36
+ end
37
+
38
+ def request_url(url)
39
+ "/api/v3/#{url}"
40
+ end
41
+
42
+ def api_endpoint
43
+ "#{endpoint}/api/v3"
44
+ end
45
+
46
+ def agent
47
+ @agent ||= Sawyer::Agent.new(api_endpoint) do |http|
48
+ http.headers['content-type'] = 'application/json'
49
+ http.headers['accept'] = 'application/json'
50
+ http.headers['PRIVATE-TOKEN'] = private_token
51
+ end
52
+ end
53
+ end
54
+
7
55
  end
8
56
  end
9
57
  end
@@ -1,5 +1,5 @@
1
1
  module Vx
2
2
  module ServiceConnector
3
- VERSION = "0.0.11"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
@@ -13,7 +13,7 @@
13
13
  "milestone_id": null,
14
14
  "state": "opened",
15
15
  "merge_status": "unchecked",
16
- "target_project_id": 2,
16
+ "target_project_id": 3,
17
17
  "iid": 5,
18
18
  "description": "some desc..."
19
19
  }
@@ -0,0 +1,20 @@
1
+ {
2
+ "object_kind": "merge_request",
3
+ "object_attributes": {
4
+ "id": 5,
5
+ "target_branch": "master",
6
+ "source_branch": "some-branch-name",
7
+ "source_project_id": 2,
8
+ "author_id": 1,
9
+ "assignee_id": 1,
10
+ "title": "Uiu",
11
+ "created_at": "2014-04-03T10:04:12.153Z",
12
+ "updated_at": "2014-04-03T10:04:18.012Z",
13
+ "milestone_id": null,
14
+ "state": "merged",
15
+ "merge_status": "can_be_merged",
16
+ "target_project_id": 2,
17
+ "iid": 5,
18
+ "description": "some desc..."
19
+ }
20
+ }
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- [5, 6].each do |version|
3
+ [6].each do |version|
4
4
  gitlab_version = "GitlabV#{version}"
5
5
  describe Vx::ServiceConnector.const_get(gitlab_version)::Payload do
6
6
 
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- [5, 6].each do |version|
3
+ [6].each do |version|
4
4
  klass = Vx::ServiceConnector.const_get("GitlabV#{version}")
5
5
  describe klass do
6
6
  require_relative "../support/gitlab_v#{version}_spec_helpers"
@@ -28,7 +28,7 @@ describe Vx::ServiceConnector::GitlabV6::Payload do
28
28
  its(:author) { should eq 'Dmitriy Zaporozhets' }
29
29
  its(:author_email) { should eq 'dzaporozhets@sphereconsultinginc.com' }
30
30
  its(:web_url) { should eq "http://localhost/example/sqerp/merge_requests/5" }
31
- its(:ignore?) { should be_true }
31
+ its(:ignore?) { should be_false }
32
32
  end
33
33
 
34
34
  context "push tag" do
@@ -46,8 +46,16 @@ describe Vx::ServiceConnector::GitlabV6::Payload do
46
46
  let(:content) { read_json_fixture("gitlab_v6/payload/closed_merge_request") }
47
47
 
48
48
  before do
49
- mock_get_commit 1, 'a7c31647c6449c3d98c4027d97e00b3048ac3bbf'
50
- mock_branch 1, "some-branch-name"
49
+ mock_project 1
50
+ end
51
+
52
+ its(:ignore?) { should be_true }
53
+ end
54
+
55
+ context "merged pull request" do
56
+ let(:content) { read_json_fixture("gitlab_v6/payload/merged_merge_request") }
57
+
58
+ before do
51
59
  mock_project 1
52
60
  end
53
61
 
@@ -10,11 +10,6 @@ describe Vx::ServiceConnector do
10
10
  it { should be_include("Github") }
11
11
  end
12
12
 
13
- context ":gitlab_v5" do
14
- let(:name) { :gitlab_v5 }
15
- it { should be_include("GitlabV5") }
16
- end
17
-
18
13
  context ":gitlab_v6" do
19
14
  let(:name) { :gitlab_v6 }
20
15
  it { should be_include("GitlabV6") }
@@ -24,6 +24,6 @@ Gem::Specification.new do |spec|
24
24
 
25
25
  spec.add_development_dependency "bundler", "~> 1.3"
26
26
  spec.add_development_dependency "rake"
27
- spec.add_development_dependency "rspec"
27
+ spec.add_development_dependency "rspec", '2.14.0'
28
28
  spec.add_development_dependency "webmock"
29
29
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vx-service_connector
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitry Galinsky
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-13 00:00:00.000000000 Z
11
+ date: 2014-06-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: octokit
@@ -84,16 +84,16 @@ dependencies:
84
84
  name: rspec
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - '>='
87
+ - - '='
88
88
  - !ruby/object:Gem::Version
89
- version: '0'
89
+ version: 2.14.0
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - '>='
94
+ - - '='
95
95
  - !ruby/object:Gem::Version
96
- version: '0'
96
+ version: 2.14.0
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: webmock
99
99
  requirement: !ruby/object:Gem::Requirement
@@ -132,14 +132,6 @@ files:
132
132
  - lib/vx/service_connector/github/notices.rb
133
133
  - lib/vx/service_connector/github/payload.rb
134
134
  - lib/vx/service_connector/github/repos.rb
135
- - lib/vx/service_connector/gitlab_v5.rb
136
- - lib/vx/service_connector/gitlab_v5/deploy_keys.rb
137
- - lib/vx/service_connector/gitlab_v5/files.rb
138
- - lib/vx/service_connector/gitlab_v5/hooks.rb
139
- - lib/vx/service_connector/gitlab_v5/notices.rb
140
- - lib/vx/service_connector/gitlab_v5/payload.rb
141
- - lib/vx/service_connector/gitlab_v5/repos.rb
142
- - lib/vx/service_connector/gitlab_v5/session.rb
143
135
  - lib/vx/service_connector/gitlab_v6.rb
144
136
  - lib/vx/service_connector/gitlab_v6/deploy_keys.rb
145
137
  - lib/vx/service_connector/gitlab_v6/files.rb
@@ -165,12 +157,6 @@ files:
165
157
  - spec/fixtures/github/payload/push.json
166
158
  - spec/fixtures/github/payload/push_tag.json
167
159
  - spec/fixtures/github/user_repos.json
168
- - spec/fixtures/gitlab_v5/commits.json
169
- - spec/fixtures/gitlab_v5/deploy_keys.json
170
- - spec/fixtures/gitlab_v5/hooks.json
171
- - spec/fixtures/gitlab_v5/payload/push.json
172
- - spec/fixtures/gitlab_v5/projects.json
173
- - spec/fixtures/gitlab_v5/user_keys.json
174
160
  - spec/fixtures/gitlab_v6/branch.json
175
161
  - spec/fixtures/gitlab_v6/commit.json
176
162
  - spec/fixtures/gitlab_v6/commits.json
@@ -178,6 +164,7 @@ files:
178
164
  - spec/fixtures/gitlab_v6/hooks.json
179
165
  - spec/fixtures/gitlab_v6/payload/closed_merge_request.json
180
166
  - spec/fixtures/gitlab_v6/payload/merge_request.json
167
+ - spec/fixtures/gitlab_v6/payload/merged_merge_request.json
181
168
  - spec/fixtures/gitlab_v6/payload/push.json
182
169
  - spec/fixtures/gitlab_v6/payload/push_tag.json
183
170
  - spec/fixtures/gitlab_v6/project.json
@@ -219,7 +206,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
219
206
  version: '0'
220
207
  requirements: []
221
208
  rubyforge_project:
222
- rubygems_version: 2.0.14
209
+ rubygems_version: 2.2.2
223
210
  signing_key:
224
211
  specification_version: 4
225
212
  summary: vx-service_connector
@@ -238,12 +225,6 @@ test_files:
238
225
  - spec/fixtures/github/payload/push.json
239
226
  - spec/fixtures/github/payload/push_tag.json
240
227
  - spec/fixtures/github/user_repos.json
241
- - spec/fixtures/gitlab_v5/commits.json
242
- - spec/fixtures/gitlab_v5/deploy_keys.json
243
- - spec/fixtures/gitlab_v5/hooks.json
244
- - spec/fixtures/gitlab_v5/payload/push.json
245
- - spec/fixtures/gitlab_v5/projects.json
246
- - spec/fixtures/gitlab_v5/user_keys.json
247
228
  - spec/fixtures/gitlab_v6/branch.json
248
229
  - spec/fixtures/gitlab_v6/commit.json
249
230
  - spec/fixtures/gitlab_v6/commits.json
@@ -251,6 +232,7 @@ test_files:
251
232
  - spec/fixtures/gitlab_v6/hooks.json
252
233
  - spec/fixtures/gitlab_v6/payload/closed_merge_request.json
253
234
  - spec/fixtures/gitlab_v6/payload/merge_request.json
235
+ - spec/fixtures/gitlab_v6/payload/merged_merge_request.json
254
236
  - spec/fixtures/gitlab_v6/payload/push.json
255
237
  - spec/fixtures/gitlab_v6/payload/push_tag.json
256
238
  - spec/fixtures/gitlab_v6/project.json
@@ -1,47 +0,0 @@
1
- module Vx
2
- module ServiceConnector
3
- GitlabV5 = Struct.new(:endpoint, :private_token) do
4
-
5
- include ServiceConnector::Base
6
-
7
- def repos
8
- @repos ||= self.class::Repos.new(session).to_a
9
- end
10
-
11
- def organizations
12
- []
13
- end
14
-
15
- def hooks(repo)
16
- self.class::Hooks.new(session, repo)
17
- end
18
-
19
- def deploy_keys(repo)
20
- self.class::DeployKeys.new(session, repo)
21
- end
22
-
23
- def notices(repo)
24
- self.class::Notices.new(session, repo)
25
- end
26
-
27
- def files(repo)
28
- self.class::Files.new(session, repo)
29
- end
30
-
31
- def payload(repo, params)
32
- self.class::Payload.new(session, repo, params).build
33
- end
34
-
35
- private
36
-
37
- def create_session
38
- self.class::Session.new(endpoint, private_token)
39
- end
40
-
41
- end
42
- end
43
- end
44
-
45
- Dir[File.expand_path("../gitlab_v5/*.rb", __FILE__)].each do |f|
46
- require f
47
- end
@@ -1,30 +0,0 @@
1
- module Vx
2
- module ServiceConnector
3
- class GitlabV5
4
- DeployKeys = Struct.new(:session, :repo) do
5
-
6
- def all
7
- begin
8
- session.get "/projects/#{repo.id}/keys"
9
- rescue RequestError
10
- []
11
- end
12
- end
13
-
14
- def create(key_name, public_key)
15
- session.post "/projects/#{repo.id}/keys", title: key_name, key: public_key
16
- end
17
-
18
- def destroy(key_name)
19
- all.select do |key|
20
- key.title == key_name
21
- end.map do |key|
22
- session.delete "/projects/#{repo.id}/keys/#{key.id}"
23
- end
24
- end
25
-
26
- end
27
- end
28
- end
29
- end
30
-
@@ -1,20 +0,0 @@
1
- require 'base64'
2
-
3
- module Vx
4
- module ServiceConnector
5
- class GitlabV5
6
- Files = Struct.new(:session, :repo) do
7
-
8
- def get(sha, path)
9
- begin
10
- session.get("/projects/#{repo.id}/repository/commits/#{sha}/blob", filepath: path)
11
- rescue RequestError => e
12
- $stderr.puts "ERROR: #{e.inspect}"
13
- nil
14
- end
15
- end
16
-
17
- end
18
- end
19
- end
20
- end
@@ -1,45 +0,0 @@
1
- module Vx
2
- module ServiceConnector
3
- class GitlabV5
4
- Hooks = Struct.new(:session, :repo) do
5
-
6
- def all
7
- begin
8
- session.get hooks_url
9
- rescue RequestError
10
- []
11
- end
12
- end
13
-
14
- def create(url, token)
15
- session.post(
16
- hooks_url,
17
- url: url,
18
- push_events: true,
19
- merge_requests_events: true
20
- )
21
- end
22
-
23
- def destroy(url_mask)
24
- all.select do |hook|
25
- hook.url =~ /#{Regexp.escape url_mask}/
26
- end.map do |hook|
27
- session.delete hook_url(hook.id)
28
- end
29
- end
30
-
31
- private
32
-
33
- def hooks_url
34
- "/projects/#{repo.id}/hooks"
35
- end
36
-
37
- def hook_url(id)
38
- "#{hooks_url}?hook_id=#{id}"
39
- end
40
-
41
- end
42
- end
43
- end
44
- end
45
-
@@ -1,13 +0,0 @@
1
- module Vx
2
- module ServiceConnector
3
- class GitlabV5
4
- Notices = Struct.new(:session, :repo) do
5
-
6
- def create(build_sha, build_status, build_url, description)
7
- :not_available
8
- end
9
-
10
- end
11
- end
12
- end
13
- end
@@ -1,120 +0,0 @@
1
- module Vx
2
- module ServiceConnector
3
- class GitlabV5
4
- Payload = Struct.new(:session, :repo, :params) do
5
-
6
- def build
7
- ServiceConnector::Model::Payload.new(
8
- !!ignore?,
9
- !!pull_request?,
10
- pull_request_number,
11
- branch,
12
- branch_label,
13
- sha,
14
- message,
15
- author,
16
- author_email,
17
- web_url
18
- )
19
- end
20
-
21
- private
22
-
23
- def message
24
- commit_for_payload["title"]
25
- end
26
-
27
- def author
28
- commit_for_payload["author_name"]
29
- end
30
-
31
- def author_email
32
- commit_for_payload["author_email"]
33
- end
34
-
35
- def pull_request?
36
- false
37
- end
38
-
39
- def tag?
40
- false
41
- end
42
-
43
- def pull_request_number
44
- nil
45
- end
46
-
47
- def sha
48
- self["after"]
49
- end
50
-
51
- def branch
52
- self["ref"].to_s.split("refs/heads/").last
53
- end
54
-
55
- def branch_label
56
- branch
57
- end
58
-
59
- def web_url
60
- if u = self["repository"] && self["repository"]["homepage"]
61
- "#{u}/commit/#{sha}"
62
- end
63
- end
64
-
65
- def pull_request_head_repo_id
66
- nil
67
- end
68
-
69
- def pull_request_base_repo_id
70
- nil
71
- end
72
-
73
- def closed_pull_request?
74
- false
75
- end
76
-
77
- def foreign_pull_request?
78
- pull_request_base_repo_id != pull_request_head_repo_id
79
- end
80
-
81
- def ignore?
82
- if pull_request?
83
- closed_pull_request? || !foreign_pull_request?
84
- else
85
- sha == '0000000000000000000000000000000000000000' || tag?
86
- end
87
- end
88
-
89
- def pull_request
90
- {}
91
- end
92
-
93
- def key?(name)
94
- params.key? name
95
- end
96
-
97
- def [](val)
98
- params[val]
99
- end
100
-
101
- def commit_for_payload
102
- @commit_for_payload ||=
103
- begin
104
- commits = session.get(commit_uri(repo.id, sha))
105
- commits.first || {}
106
- rescue RequestError => e
107
- $stderr.puts "ERROR: #{e.inspect}"
108
- {}
109
- end
110
- end
111
-
112
- def commit_uri(repo_id, sha)
113
- "/projects/#{repo_id}/repository/commits?ref_name=#{sha}"
114
- end
115
-
116
- end
117
-
118
- end
119
- end
120
- end
@@ -1,73 +0,0 @@
1
- module Vx
2
- module ServiceConnector
3
- class GitlabV5
4
- Repos = Struct.new(:session) do
5
-
6
- def to_a
7
- session.get("/projects", per_page: 30).map do |proj|
8
- proj_to_model proj
9
- end
10
- end
11
-
12
- private
13
-
14
- def proj_to_model(repo)
15
- Model::Repo.new(
16
- repo.id,
17
- compute_name_with_namespace(repo),
18
- compute_is_private(repo),
19
- compute_ssh_url(repo),
20
- compute_web_url(repo),
21
- repo.description
22
- )
23
- end
24
-
25
- def compute_name_with_namespace(repo)
26
- if repo.path_with_namespace
27
- # for version 5.x
28
- repo.path_with_namespace
29
- else
30
- # for version 4.x
31
- hn = session.uri.hostname.to_s.split(".")[-2]
32
- hm ||= session.uri.hostname
33
- [hn, repo.name.downcase].join("/").downcase
34
- end
35
- end
36
-
37
- def compute_ssh_url(repo)
38
- if repo.ssh_url
39
- # for version 6.x
40
- repo.ssh_url
41
- else
42
- # for version 5.x or 4.x
43
- name = repo.path_with_namespace || repo.name
44
- "git@#{session.uri.hostname}:#{name.downcase}.git"
45
- end
46
- end
47
-
48
- def compute_web_url(repo)
49
- if repo.web_url
50
- # for version 6.x
51
- repo.web_url
52
- else
53
- # for version 5.x or 4.x
54
- name = repo.path_with_namespace || repo.name
55
- "#{session.uri.scheme}://#{session.uri.hostname}:#{session.uri.port}/#{name.downcase}"
56
- end
57
- end
58
-
59
- def compute_is_private(repo)
60
- case
61
- # for version before 6.x
62
- when repo.private != nil
63
- repo.private
64
- # for version 6.x
65
- when repo.public != nil
66
- !repo.public
67
- end
68
- end
69
-
70
- end
71
- end
72
- end
73
- end
@@ -1,58 +0,0 @@
1
- require 'sawyer'
2
- require 'uri'
3
-
4
- module Vx
5
- module ServiceConnector
6
- class GitlabV5
7
-
8
- Session = Struct.new(:endpoint, :private_token) do
9
-
10
- def get(url, options = {})
11
- res = agent.call :get, request_url(url), nil, query: options
12
- response! res
13
- end
14
-
15
- def post(url, options = {})
16
- res = agent.call :post, request_url(url), options, nil
17
- response! res
18
- end
19
-
20
- def delete(url, options = {})
21
- res = agent.call :delete, request_url(url), nil, query: options
22
- response! res
23
- end
24
-
25
- def uri
26
- @uri ||= URI(endpoint)
27
- end
28
-
29
- private
30
-
31
- def response!(res)
32
- if (200..204).include?(res.status)
33
- res.data
34
- else
35
- raise RequestError, res.data
36
- end
37
- end
38
-
39
- def request_url(url)
40
- "/api/v3/#{url}"
41
- end
42
-
43
- def api_endpoint
44
- "#{endpoint}/api/v3"
45
- end
46
-
47
- def agent
48
- @agent ||= Sawyer::Agent.new(api_endpoint) do |http|
49
- http.headers['content-type'] = 'application/json'
50
- http.headers['accept'] = 'application/json'
51
- http.headers['PRIVATE-TOKEN'] = private_token
52
- end
53
- end
54
- end
55
-
56
- end
57
- end
58
- end
@@ -1,18 +0,0 @@
1
- [
2
- {
3
- "id": "ed899a2f4b50b4370feeea94676502b42383c746",
4
- "short_id": "ed899a2f4b5",
5
- "title": "Replace sanitize with escape once",
6
- "author_name": "Dmitriy Zaporozhets",
7
- "author_email": "dzaporozhets@sphereconsultinginc.com",
8
- "created_at": "2012-09-20T11:50:22+03:00"
9
- },
10
- {
11
- "id": "6104942438c14ec7bd21c6cd5bd995272b3faff6",
12
- "short_id": "6104942438c",
13
- "title": "Sanitize for network graph",
14
- "author_name": "randx",
15
- "author_email": "dmitriy.zaporozhets@gmail.com",
16
- "created_at": "2012-09-20T09:06:12+03:00"
17
- }
18
- ]
@@ -1,14 +0,0 @@
1
- [
2
- {
3
- "id": 1,
4
- "title" : "Public key",
5
- "key": "ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt4 596k6YjzGGphH2TUxwKzxcKDKKezwkpfnxPkSMkuEspGRt/aZZ9wa++Oi7Qkr8prgHc4 soW6NUlfDzpvZK2H5E7eQaSeP3SAwGmQKUFHCddNaP0L+hM7zhFNzjFvpaMgJw0=",
6
- "created_at":"2013-10-02T10:12:29Z"
7
- },
8
- {
9
- "id": 3,
10
- "title" : "me@example.com",
11
- "key": "ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt4 596k6YjzGGphH2TUxwKzxcKDKKezwkpfnxPkSMkuEspGRt/aZZ9wa++Oi7Qkr8prgHc4 soW6NUlfDzpvZK2H5E7eQaSeP3SAwGmQKUFHCddNaP0L+hM7zhFNzjFvpaMgJw0=",
12
- "created_at":"2013-10-02T11:12:29Z"
13
- }
14
- ]
@@ -1 +0,0 @@
1
- [{"id":57,"url":"http://example.com/hook","created_at":"2014-01-28T14:04:22Z"}]
@@ -1,32 +0,0 @@
1
- {
2
- "before": "0000000000000000000000000000000000000000",
3
- "after": "decc3915e29d7ae1786bb981b2ea3702afae592a",
4
- "ref": "refs/heads/testing",
5
- "user_id": 13,
6
- "user_name": "Dmitry",
7
- "repository": {
8
- "name": "event_generator",
9
- "url": "git@git.dev.gorod-skidok.com:serverist2/event_generator.git",
10
- "description": null,
11
- "homepage": "http://git.dev.gorod-skidok.com/serverist2/event_generator"
12
- },
13
- "commits": null,
14
- "total_commits_count": 0,
15
- "_service": "gitlab",
16
- "token": "cb170b9c-8274-43e6-80c8-f1a744ac43b4",
17
- "repo_callback": {
18
- "before": "0000000000000000000000000000000000000000",
19
- "after": "decc3915e29d7ae1786bb981b2ea3702afae592a",
20
- "ref": "refs/heads/testing",
21
- "user_id": 13,
22
- "user_name": "Dmitry",
23
- "repository": {
24
- "name": "event_generator",
25
- "url": "git@git.dev.gorod-skidok.com:serverist2/event_generator.git",
26
- "description": null,
27
- "homepage": "http://git.dev.gorod-skidok.com/serverist2/event_generator"
28
- },
29
- "commits": null,
30
- "total_commits_count": 0
31
- }
32
- }
@@ -1 +0,0 @@
1
- [{"id":9,"name":"SQERP","description":null,"default_branch":"master","owner":{"id":14,"username":null,"email":"me@example.com","name":"MyName","blocked":true,"created_at":"2012-06-21T07:47:41Z"},"private":true,"issues_enabled":true,"merge_requests_enabled":true,"wall_enabled":true,"wiki_enabled":true,"created_at":"2012-06-21T08:02:09Z","namespace":null}]
@@ -1 +0,0 @@
1
- [{"id":589,"title":"me@example.com for full/name","key":"ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDXnM3fhBisPY223C7poY7J7qsMPHHc1aJ4+rwUqzdGHANNWoP8tCUXXnhWvhy8fxEqImDUWdYMNLQI42MJ8RB7naQjvWJqBU/JUvXRznrGcldPjmdIpb25Jod29wQDmPEYC31S1HoEEgmqVeG1V+ypxeqm8XEy1USjsY/Cbx0cbGUOa560GRV89/8KB4GHzN8R82OUxIzUJotIGIcAvNhYwR+skrsI2/QnDMqty2O5SQU52bgzlotCfSQbeujOT9DU3uP9YeRUcY/Xouqx19Q5TSPNk8rkh5uIHNKQ9LipJlfVU9G+YI0r5oMRlvqEXyR2gUEUwwhzafp8JQ4O/YJ7 me@example.com","created_at":"2013-10-24T12:41:18Z"}]