vx-service_connector 0.0.4 → 0.0.5

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 (32) hide show
  1. checksums.yaml +4 -4
  2. data/lib/vx/service_connector.rb +16 -9
  3. data/lib/vx/service_connector/gitlab_v4.rb +49 -0
  4. data/lib/vx/service_connector/{gitlab_v41 → gitlab_v4}/commits.rb +1 -1
  5. data/lib/vx/service_connector/{gitlab_v41 → gitlab_v4}/deploy_keys.rb +1 -1
  6. data/lib/vx/service_connector/{gitlab_v41 → gitlab_v4}/files.rb +1 -1
  7. data/lib/vx/service_connector/{gitlab_v41 → gitlab_v4}/hooks.rb +7 -2
  8. data/lib/vx/service_connector/{gitlab_v41 → gitlab_v4}/notices.rb +1 -1
  9. data/lib/vx/service_connector/gitlab_v4/payload.rb +126 -0
  10. data/lib/vx/service_connector/gitlab_v4/repos.rb +73 -0
  11. data/lib/vx/service_connector/{gitlab_v41 → gitlab_v4}/session.rb +2 -2
  12. data/lib/vx/service_connector/gitlab_v5.rb +21 -0
  13. data/lib/vx/service_connector/gitlab_v5/deploy_keys.rb +26 -0
  14. data/lib/vx/service_connector/version.rb +1 -1
  15. data/spec/fixtures/{gitlab_v41 → gitlab_v4}/commits.json +0 -0
  16. data/spec/fixtures/{gitlab_v41 → gitlab_v4}/hooks.json +0 -0
  17. data/spec/fixtures/gitlab_v4/payload/merge_request1_unchecked.json +47 -0
  18. data/spec/fixtures/gitlab_v4/payload/merge_request2_can_be_merge.json +47 -0
  19. data/spec/fixtures/{gitlab_v41 → gitlab_v4}/payload/push.json +0 -0
  20. data/spec/fixtures/{gitlab_v41 → gitlab_v4}/projects.json +0 -0
  21. data/spec/fixtures/{gitlab_v41 → gitlab_v4}/user_keys.json +0 -0
  22. data/spec/fixtures/gitlab_v5/deploy_keys.json +14 -0
  23. data/spec/lib/{gitlab_v41_payload_spec.rb → gitlab_v4_payload_spec.rb} +11 -2
  24. data/spec/lib/{gitlab_v41_spec.rb → gitlab_v4_spec.rb} +3 -3
  25. data/spec/lib/gitlab_v5_spec.rb +43 -0
  26. data/spec/lib/service_connector_spec.rb +27 -3
  27. data/spec/support/{gitlab_v41_web_mocks.rb → gitlab_v4_web_mocks.rb} +5 -5
  28. data/spec/support/gitlab_v5_web_mocks.rb +34 -0
  29. metadata +38 -26
  30. data/lib/vx/service_connector/gitlab_v41.rb +0 -49
  31. data/lib/vx/service_connector/gitlab_v41/payload.rb +0 -93
  32. data/lib/vx/service_connector/gitlab_v41/repos.rb +0 -40
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b6a64cc8707f0bb609fc5367b39af748569cdcc2
4
- data.tar.gz: 82ff7676058795c32b8bf37ad3c22dee08adf11c
3
+ metadata.gz: 506631ac3d925645c77d80c04a25f9a0ee56b870
4
+ data.tar.gz: 45f29455185ae52784716d02936edad184355a60
5
5
  SHA512:
6
- metadata.gz: b61692d0a884c4464b8238bc5187cb863a981a20570604865d86391255a0fe2fca7ca3b76631f488800ad9244086fc8c657b83d2fd90ab4aff4ded19a01474e1
7
- data.tar.gz: 3401d3e9a432822d480a828ab29fbc78feb29038c85bd11c676fc7a6904c8af934377c34350d088a3966f1159b958267d8fdbf56d0e8d292675f0016223aaaa4
6
+ metadata.gz: df26dd771eaa60bec62f5849bbb8e09ece06e69e79223b5cdcb34153ef78ffc43c4b7e90e0704eddfeeb161173841d1aad2f602a668795c55caa44d0177d0782
7
+ data.tar.gz: 9103c4e08c2293b9274ed3c1c4860958f173e4b1181a0716d6cda0387ee83b6743092134e90ce8c10c5ea73d532d37021cc9a177e3cfbbc3e4fa96e1ff4dfa90
@@ -6,7 +6,8 @@ module Vx
6
6
 
7
7
  autoload :Base, File.expand_path("../service_connector/base", __FILE__)
8
8
  autoload :Github, File.expand_path("../service_connector/github", __FILE__)
9
- autoload :GitlabV41, File.expand_path("../service_connector/gitlab_v41", __FILE__)
9
+ autoload :GitlabV4, File.expand_path("../service_connector/gitlab_v4", __FILE__)
10
+ autoload :GitlabV5, File.expand_path("../service_connector/gitlab_v5", __FILE__)
10
11
  autoload :Model, File.expand_path("../service_connector/model", __FILE__)
11
12
 
12
13
  extend self
@@ -18,20 +19,26 @@ module Vx
18
19
  case name.to_sym
19
20
  when :github
20
21
  Github
21
- when :gitlab_v41
22
- GitlabV41
22
+ when :gitlab_v4
23
+ GitlabV4
24
+ when :gitlab_v5
25
+ GitlabV5
23
26
  else
24
27
  raise ArgumentError, "Serivice for #{name.inspect} is not defined"
25
28
  end
26
29
  end
27
30
 
28
31
  def payload(name, params)
29
- case name.to_sym
30
- when :github
31
- Github::Payload.new(params).to_model
32
- else
33
- raise ArgumentError, "Payload for #{name.inspect} is not defined"
34
- end
32
+ klass =
33
+ case name.to_sym
34
+ when :github
35
+ Github::Payload
36
+ when :gitlab_v4, :gitlab_v5
37
+ GitlabV4::Payload
38
+ else
39
+ raise ArgumentError, "Payload for #{name.inspect} is not defined"
40
+ end
41
+ klass.new(params).to_model
35
42
  end
36
43
 
37
44
  end
@@ -0,0 +1,49 @@
1
+ require 'gitlab'
2
+
3
+ module Vx
4
+ module ServiceConnector
5
+ GitlabV4 = Struct.new(:endpoint, :private_token) do
6
+
7
+ include ServiceConnector::Base
8
+
9
+ def repos
10
+ @repos ||= GitlabV4::Repos.new(session).to_a
11
+ end
12
+
13
+ def organizations
14
+ []
15
+ end
16
+
17
+ def hooks(repo)
18
+ GitlabV4::Hooks.new(session, repo)
19
+ end
20
+
21
+ def deploy_keys(repo)
22
+ GitlabV4::DeployKeys.new(session, repo)
23
+ end
24
+
25
+ def notices(repo)
26
+ GitlabV4::Notices.new(session, repo)
27
+ end
28
+
29
+ def files(repo)
30
+ GitlabV4::Files.new(session, repo)
31
+ end
32
+
33
+ def commits(repo)
34
+ GitlabV4::Commits.new(session, repo)
35
+ end
36
+
37
+ private
38
+
39
+ def create_session
40
+ GitlabV4::Session.new(endpoint, private_token)
41
+ end
42
+
43
+ end
44
+ end
45
+ end
46
+
47
+ Dir[File.expand_path("../gitlab_v4/*.rb", __FILE__)].each do |f|
48
+ require f
49
+ end
@@ -2,7 +2,7 @@ require 'base64'
2
2
 
3
3
  module Vx
4
4
  module ServiceConnector
5
- class GitlabV41
5
+ class GitlabV4
6
6
  Commits = Struct.new(:session, :repo) do
7
7
 
8
8
  def get(sha)
@@ -1,6 +1,6 @@
1
1
  module Vx
2
2
  module ServiceConnector
3
- class GitlabV41
3
+ class GitlabV4
4
4
  DeployKeys = Struct.new(:session, :repo) do
5
5
 
6
6
  def all
@@ -2,7 +2,7 @@ require 'base64'
2
2
 
3
3
  module Vx
4
4
  module ServiceConnector
5
- class GitlabV41
5
+ class GitlabV4
6
6
  Files = Struct.new(:session, :repo) do
7
7
 
8
8
  def get(sha, path)
@@ -1,6 +1,6 @@
1
1
  module Vx
2
2
  module ServiceConnector
3
- class GitlabV41
3
+ class GitlabV4
4
4
  Hooks = Struct.new(:session, :repo) do
5
5
 
6
6
  def all
@@ -8,7 +8,12 @@ module Vx
8
8
  end
9
9
 
10
10
  def create(url, token)
11
- session.post hooks_url, url: url
11
+ session.post(
12
+ hooks_url,
13
+ url: url,
14
+ push_events: true,
15
+ merge_requests_events: true
16
+ )
12
17
  end
13
18
 
14
19
  def destroy(url_mask)
@@ -1,6 +1,6 @@
1
1
  module Vx
2
2
  module ServiceConnector
3
- class GitlabV41
3
+ class GitlabV4
4
4
  Notices = Struct.new(:session, :repo) do
5
5
 
6
6
  def create(build_sha, build_status, build_url, description)
@@ -0,0 +1,126 @@
1
+ module Vx
2
+ module ServiceConnector
3
+ class GitlabV4
4
+ class Payload
5
+
6
+ def initialize(params)
7
+ @params = params || {}
8
+ end
9
+
10
+ def pull_request?
11
+ self["object_kind"] == 'merge_request'
12
+ end
13
+
14
+ def tag?
15
+ false
16
+ end
17
+
18
+ def pull_request_number
19
+ if pull_request?
20
+ pull_request["id"]
21
+ end
22
+ end
23
+
24
+ def head
25
+ if pull_request?
26
+ cid = (pull_request["st_commits"] || []).first
27
+ cid && cid["id"]
28
+ else
29
+ self["after"]
30
+ end
31
+ end
32
+
33
+ def base
34
+ if pull_request?
35
+ cid = (pull_request["st_commits"] || []).first
36
+ cid && cid["parent_ids"] && cid["parent_ids"].first
37
+ else
38
+ self["before"]
39
+ end
40
+ end
41
+
42
+ def branch
43
+ if pull_request?
44
+ pull_request["source_branch"]
45
+ else
46
+ self["ref"].to_s.split("refs/heads/").last
47
+ end
48
+ end
49
+
50
+ def branch_label
51
+ branch
52
+ end
53
+
54
+ def url
55
+ self["commits"] && self["commits"].first && self["commits"].first["url"]
56
+ end
57
+
58
+ def pull_request_head_repo_id
59
+ if pull_request?
60
+ pull_request["target_project_id"]
61
+ end
62
+ end
63
+
64
+ def pull_request_base_repo_id
65
+ if pull_request?
66
+ pull_request["source_project_id"]
67
+ end
68
+ end
69
+
70
+ def closed_pull_request?
71
+ false
72
+ end
73
+
74
+ def foreign_pull_request?
75
+ pull_request_base_repo_id != pull_request_head_repo_id
76
+ end
77
+
78
+ def pull_request_status
79
+ if pull_request?
80
+ pull_request["merge_status"]
81
+ end
82
+ end
83
+
84
+ def ignore_pull_request?
85
+ if pull_request?
86
+ pull_request_status != 'unchecked'
87
+ end
88
+ end
89
+
90
+ def ignore?
91
+ head == '0000000000000000000000000000000000000000' ||
92
+ ignore_pull_request?
93
+ end
94
+
95
+ def to_model
96
+ ServiceConnector::Model::Payload.new(
97
+ !!pull_request?,
98
+ pull_request_number,
99
+ head,
100
+ base,
101
+ branch,
102
+ branch_label,
103
+ url,
104
+ !!ignore?
105
+ )
106
+ end
107
+
108
+ private
109
+
110
+ def pull_request
111
+ self["object_attributes"] || {}
112
+ end
113
+
114
+ def key?(name)
115
+ @params.key? name
116
+ end
117
+
118
+ def [](val)
119
+ @params[val]
120
+ end
121
+
122
+ end
123
+
124
+ end
125
+ end
126
+ end
@@ -0,0 +1,73 @@
1
+ module Vx
2
+ module ServiceConnector
3
+ class GitlabV4
4
+ Repos = Struct.new(:session) do
5
+
6
+ def to_a
7
+ session.get("/projects").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
@@ -3,7 +3,7 @@ require 'uri'
3
3
 
4
4
  module Vx
5
5
  module ServiceConnector
6
- class GitlabV41
6
+ class GitlabV4
7
7
 
8
8
  Session = Struct.new(:endpoint, :private_token) do
9
9
 
@@ -18,7 +18,7 @@ module Vx
18
18
  end
19
19
 
20
20
  def delete(url, options = {})
21
- res = agent.call :delete, request_url(url), options
21
+ res = agent.call :delete, request_url(url), nil, query: options
22
22
  response! res
23
23
  end
24
24
 
@@ -0,0 +1,21 @@
1
+ require 'gitlab'
2
+
3
+ module Vx
4
+ module ServiceConnector
5
+ class GitlabV5 < GitlabV4
6
+
7
+ def repos
8
+ @repos ||= GitlabV4::Repos.new(session).to_a
9
+ end
10
+
11
+ def deploy_keys(repo)
12
+ GitlabV5::DeployKeys.new(session, repo)
13
+ end
14
+
15
+ end
16
+ end
17
+ end
18
+
19
+ Dir[File.expand_path("../gitlab_v5/*.rb", __FILE__)].each do |f|
20
+ require f
21
+ end
@@ -0,0 +1,26 @@
1
+ module Vx
2
+ module ServiceConnector
3
+ class GitlabV5
4
+ DeployKeys = Struct.new(:session, :repo) do
5
+
6
+ def all
7
+ session.get "/projects/#{repo.id}/keys"
8
+ end
9
+
10
+ def create(key_name, public_key)
11
+ session.post "/projects/#{repo.id}/keys", title: key_name, key: public_key
12
+ end
13
+
14
+ def destroy(key_name)
15
+ all.select do |key|
16
+ key.title == key_name
17
+ end.map do |key|
18
+ session.delete "/projects/#{repo.id}/keys/#{key.id}"
19
+ end
20
+ end
21
+
22
+ end
23
+ end
24
+ end
25
+ end
26
+
@@ -1,5 +1,5 @@
1
1
  module Vx
2
2
  module ServiceConnector
3
- VERSION = "0.0.4"
3
+ VERSION = "0.0.5"
4
4
  end
5
5
  end
File without changes
@@ -0,0 +1,47 @@
1
+ {
2
+ "object_kind": "merge_request",
3
+ "object_attributes": {
4
+ "id": 1,
5
+ "target_branch": "master",
6
+ "source_branch": "one",
7
+ "source_project_id": 1,
8
+ "author_id": 1,
9
+ "assignee_id": null,
10
+ "title": "One",
11
+ "created_at": "2014-01-29T16:14:38.113Z",
12
+ "updated_at": "2014-01-29T16:14:45.845Z",
13
+ "st_commits": [
14
+ {
15
+ "id": "d0862adb2c46aecb3db4cb4a50867599e4015cf9",
16
+ "message": "one",
17
+ "parent_ids": [
18
+ "f1f92a4ef47a4257973282718449154938c3684d"
19
+ ],
20
+ "authored_date": "2014-01-29T16:13:20+00:00",
21
+ "author_name": "Dmitry Galinsky",
22
+ "author_email": "dima.exe@gmail.com",
23
+ "committed_date": "2014-01-29T16:13:20+00:00",
24
+ "committer_name": "Dmitry Galinsky",
25
+ "committer_email": "dima.exe@gmail.com"
26
+ }
27
+ ],
28
+ "st_diffs": [
29
+ {
30
+ "diff": "--- a/README\n+++ b/README\n@@ -1 +1,2 @@\n 1\n+2",
31
+ "new_path": "README",
32
+ "old_path": "README",
33
+ "a_mode": null,
34
+ "b_mode": "100644",
35
+ "new_file": false,
36
+ "renamed_file": false,
37
+ "deleted_file": false
38
+ }
39
+ ],
40
+ "milestone_id": null,
41
+ "state": "opened",
42
+ "merge_status": "unchecked",
43
+ "target_project_id": 1,
44
+ "iid": 1,
45
+ "description": "."
46
+ }
47
+ }
@@ -0,0 +1,47 @@
1
+ {
2
+ "object_kind": "merge_request",
3
+ "object_attributes": {
4
+ "id": 1,
5
+ "target_branch": "master",
6
+ "source_branch": "one",
7
+ "source_project_id": 1,
8
+ "author_id": 1,
9
+ "assignee_id": null,
10
+ "title": "One",
11
+ "created_at": "2014-01-29T16:14:38.000Z",
12
+ "updated_at": "2014-01-29T16:14:49.246Z",
13
+ "st_commits": [
14
+ {
15
+ "id": "d0862adb2c46aecb3db4cb4a50867599e4015cf9",
16
+ "message": "one",
17
+ "parent_ids": [
18
+ "f1f92a4ef47a4257973282718449154938c3684d"
19
+ ],
20
+ "authored_date": "2014-01-29T16:13:20+00:00",
21
+ "author_name": "Dmitry Galinsky",
22
+ "author_email": "dima.exe@gmail.com",
23
+ "committed_date": "2014-01-29T16:13:20+00:00",
24
+ "committer_name": "Dmitry Galinsky",
25
+ "committer_email": "dima.exe@gmail.com"
26
+ }
27
+ ],
28
+ "st_diffs": [
29
+ {
30
+ "diff": "--- a/README\n+++ b/README\n@@ -1 +1,2 @@\n 1\n+2",
31
+ "new_path": "README",
32
+ "old_path": "README",
33
+ "a_mode": null,
34
+ "b_mode": "100644",
35
+ "new_file": false,
36
+ "renamed_file": false,
37
+ "deleted_file": false
38
+ }
39
+ ],
40
+ "milestone_id": null,
41
+ "state": "opened",
42
+ "merge_status": "can_be_merged",
43
+ "target_project_id": 1,
44
+ "iid": 1,
45
+ "description": "."
46
+ }
47
+ }
@@ -0,0 +1,14 @@
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,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Vx::ServiceConnector::GitlabV41::Payload do
4
- let(:content) { read_json_fixture("gitlab_v41/payload/push") }
3
+ describe Vx::ServiceConnector::GitlabV4::Payload do
4
+ let(:content) { read_json_fixture("gitlab_v4/payload/push") }
5
5
  let(:payload) { described_class.new content }
6
6
  subject { payload }
7
7
 
@@ -21,6 +21,15 @@ describe Vx::ServiceConnector::GitlabV41::Payload do
21
21
  end
22
22
 
23
23
  context "pull_request" do
24
+ let(:content) { read_json_fixture("gitlab_v4/payload/merge_request1_unchecked") }
25
+
26
+ its(:pull_request?) { should be_true }
27
+ its(:pull_request_number) { should eq 1 }
28
+ its(:ignore?) { should be_false }
29
+ its(:head) { should eq 'd0862adb2c46aecb3db4cb4a50867599e4015cf9' }
30
+ its(:base) { should eq 'f1f92a4ef47a4257973282718449154938c3684d' }
31
+ its(:branch) { should eq 'one' }
32
+ its(:url) { should be_nil }
24
33
  end
25
34
 
26
35
  context "tag?" do
@@ -1,8 +1,8 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Vx::ServiceConnector::GitlabV41 do
3
+ describe Vx::ServiceConnector::GitlabV4 do
4
4
 
5
- include GitlabV41WebMocks
5
+ include GitlabV4WebMocks
6
6
 
7
7
  let(:endpoint) { 'http://example.com' }
8
8
  let(:token) { 'token' }
@@ -34,7 +34,7 @@ describe Vx::ServiceConnector::GitlabV41 do
34
34
  context "values" do
35
35
  subject { gitlab.repos.map(&:values) }
36
36
  it { should eq(
37
- [[9, "example.com/sqerp", true, "git@example.com:sqerp.git", "http://example.com:80/sqerp", nil]]
37
+ [[9, "example/sqerp", true, "git@example.com:sqerp.git", "http://example.com:80/sqerp", nil]]
38
38
  ) }
39
39
  end
40
40
  end
@@ -0,0 +1,43 @@
1
+ require 'spec_helper'
2
+
3
+ describe Vx::ServiceConnector::GitlabV5 do
4
+
5
+ include GitlabV5WebMocks
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
+
12
+ subject { gitlab }
13
+
14
+ it { should be }
15
+
16
+ context "(deploy_keys)" do
17
+ let(:key_name) { 'me@example.com' }
18
+ let(:public_key) { 'public key' }
19
+ let(:deploy_keys) { gitlab.deploy_keys(repo) }
20
+
21
+ context "all" do
22
+ subject { deploy_keys.all }
23
+ before { mock_deploy_keys }
24
+ it { should have(2).items }
25
+ end
26
+
27
+ context "create" do
28
+ subject { deploy_keys.create key_name, public_key }
29
+ before { mock_add_deploy_key }
30
+ it { should be }
31
+ end
32
+
33
+ context "destroy" do
34
+ subject { deploy_keys.destroy key_name }
35
+ before do
36
+ mock_deploy_keys
37
+ mock_delete_deploy_key
38
+ end
39
+
40
+ it { should have(1).item }
41
+ end
42
+ end
43
+ end
@@ -14,15 +14,39 @@ describe Vx::ServiceConnector do
14
14
  end
15
15
 
16
16
  context "to" do
17
- subject { described_class.to name }
17
+ subject { described_class.to(name).to_s }
18
18
 
19
19
  context ":github" do
20
20
  let(:name) { :github }
21
+ it { should be_include("Github") }
22
+ end
23
+
24
+ context ":gitlab_v4" do
25
+ let(:name) { :gitlab_v4 }
26
+ it { should be_include("GitlabV4") }
27
+ end
28
+
29
+ context ":gitlab_v5" do
30
+ let(:name) { :gitlab_v5 }
31
+ it { should be_include("GitlabV5") }
32
+ end
33
+ end
34
+
35
+ context "payload" do
36
+ subject { described_class.payload(name, {}) }
37
+
38
+ context ":github" do
39
+ let(:name) { :github }
40
+ it { should be }
41
+ end
42
+
43
+ context ":gitlab_v4" do
44
+ let(:name) { :gitlab_v4 }
21
45
  it { should be }
22
46
  end
23
47
 
24
- context ":gitlab_v41" do
25
- let(:name) { :gitlab_v41 }
48
+ context ":gitlab_v5" do
49
+ let(:name) { :gitlab_v5 }
26
50
  it { should be }
27
51
  end
28
52
  end
@@ -1,4 +1,4 @@
1
- module GitlabV41WebMocks
1
+ module GitlabV4WebMocks
2
2
 
3
3
  def mock_repos
4
4
  mock_get "projects", 'projects'
@@ -13,15 +13,15 @@ module GitlabV41WebMocks
13
13
  end
14
14
 
15
15
  def mock_delete_user_key
16
- mock_delete "user/keys/589", '{}'
16
+ mock_delete "user/keys/589", nil
17
17
  end
18
18
 
19
19
  def mock_add_hook
20
- mock_post "projects/1/hooks", "{\"url\":\"url\"}"
20
+ mock_post "projects/1/hooks", "{\"url\":\"url\",\"push_events\":true,\"merge_requests_events\":true}"
21
21
  end
22
22
 
23
23
  def mock_remove_hook
24
- mock_delete "projects/1/hooks", "{\"hook_id\":57}"
24
+ mock_delete "projects/1/hooks?hook_id=57", ""
25
25
  end
26
26
 
27
27
  def mock_hooks
@@ -55,7 +55,7 @@ module GitlabV41WebMocks
55
55
  with(:headers => {'Accept'=>'application/json', 'PRIVATE-TOKEN' => "token"}).
56
56
  to_return(
57
57
  :status => 200,
58
- :body => read_fixture("gitlab_v41/#{fixture}.json"),
58
+ :body => read_fixture("gitlab_v4/#{fixture}.json"),
59
59
  :headers => {'Content-Type' => 'application/json'})
60
60
  end
61
61
 
@@ -0,0 +1,34 @@
1
+ module GitlabV5WebMocks
2
+ def mock_deploy_keys
3
+ mock_get "projects/1/keys", "deploy_keys"
4
+ end
5
+
6
+ def mock_add_deploy_key
7
+ mock_post "projects/1/keys", "{\"title\":\"me@example.com\",\"key\":\"public key\"}"
8
+ end
9
+
10
+ def mock_delete_deploy_key
11
+ mock_delete "projects/1/keys/3", nil
12
+ end
13
+
14
+ def mock_get(url, fixture)
15
+ stub_request(:get, "http://example.com/api/v3/#{url}").
16
+ with(:headers => {'Accept'=>'application/json', 'PRIVATE-TOKEN' => "token"}).
17
+ to_return(
18
+ :status => 200,
19
+ :body => read_fixture("gitlab_v5/#{fixture}.json"),
20
+ :headers => {'Content-Type' => 'application/json'})
21
+ end
22
+
23
+ def mock_post(url, body)
24
+ stub_request(:post, "http://example.com/api/v3/#{url}").
25
+ with(:headers => {'Accept'=>'application/json', }, body: body).
26
+ to_return(:status => 200, :body => "{}", :headers => {'Content-Type' => 'application/json'})
27
+ end
28
+
29
+ def mock_delete(url, body)
30
+ stub_request(:delete, "http://example.com/api/v3/#{url}").
31
+ with(:headers => {'Accept'=>'application/json', }, body: body).
32
+ to_return(:status => 200, :body => "{}", :headers => {'Content-Type' => 'application/json'})
33
+ end
34
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vx-service_connector
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitry Galinsky
@@ -119,15 +119,17 @@ files:
119
119
  - lib/vx/service_connector/github/notices.rb
120
120
  - lib/vx/service_connector/github/payload.rb
121
121
  - lib/vx/service_connector/github/repos.rb
122
- - lib/vx/service_connector/gitlab_v41.rb
123
- - lib/vx/service_connector/gitlab_v41/commits.rb
124
- - lib/vx/service_connector/gitlab_v41/deploy_keys.rb
125
- - lib/vx/service_connector/gitlab_v41/files.rb
126
- - lib/vx/service_connector/gitlab_v41/hooks.rb
127
- - lib/vx/service_connector/gitlab_v41/notices.rb
128
- - lib/vx/service_connector/gitlab_v41/payload.rb
129
- - lib/vx/service_connector/gitlab_v41/repos.rb
130
- - lib/vx/service_connector/gitlab_v41/session.rb
122
+ - lib/vx/service_connector/gitlab_v4.rb
123
+ - lib/vx/service_connector/gitlab_v4/commits.rb
124
+ - lib/vx/service_connector/gitlab_v4/deploy_keys.rb
125
+ - lib/vx/service_connector/gitlab_v4/files.rb
126
+ - lib/vx/service_connector/gitlab_v4/hooks.rb
127
+ - lib/vx/service_connector/gitlab_v4/notices.rb
128
+ - lib/vx/service_connector/gitlab_v4/payload.rb
129
+ - lib/vx/service_connector/gitlab_v4/repos.rb
130
+ - lib/vx/service_connector/gitlab_v4/session.rb
131
+ - lib/vx/service_connector/gitlab_v5.rb
132
+ - lib/vx/service_connector/gitlab_v5/deploy_keys.rb
131
133
  - lib/vx/service_connector/model.rb
132
134
  - lib/vx/service_connector/version.rb
133
135
  - spec/fixtures/github/add_deploy_key.json
@@ -144,21 +146,26 @@ files:
144
146
  - spec/fixtures/github/payload/push.json
145
147
  - spec/fixtures/github/payload/push_tag.json
146
148
  - spec/fixtures/github/user_repos.json
147
- - spec/fixtures/gitlab_v41/commits.json
148
- - spec/fixtures/gitlab_v41/hooks.json
149
- - spec/fixtures/gitlab_v41/payload/push.json
150
- - spec/fixtures/gitlab_v41/projects.json
151
- - spec/fixtures/gitlab_v41/user_keys.json
149
+ - spec/fixtures/gitlab_v4/commits.json
150
+ - spec/fixtures/gitlab_v4/hooks.json
151
+ - spec/fixtures/gitlab_v4/payload/merge_request1_unchecked.json
152
+ - spec/fixtures/gitlab_v4/payload/merge_request2_can_be_merge.json
153
+ - spec/fixtures/gitlab_v4/payload/push.json
154
+ - spec/fixtures/gitlab_v4/projects.json
155
+ - spec/fixtures/gitlab_v4/user_keys.json
156
+ - spec/fixtures/gitlab_v5/deploy_keys.json
152
157
  - spec/lib/github_payload_spec.rb
153
158
  - spec/lib/github_spec.rb
154
- - spec/lib/gitlab_v41_payload_spec.rb
155
- - spec/lib/gitlab_v41_spec.rb
159
+ - spec/lib/gitlab_v4_payload_spec.rb
160
+ - spec/lib/gitlab_v4_spec.rb
161
+ - spec/lib/gitlab_v5_spec.rb
156
162
  - spec/lib/model_spec.rb
157
163
  - spec/lib/service_connector_spec.rb
158
164
  - spec/spec_helper.rb
159
165
  - spec/support/create.rb
160
166
  - spec/support/github_web_mocks.rb
161
- - spec/support/gitlab_v41_web_mocks.rb
167
+ - spec/support/gitlab_v4_web_mocks.rb
168
+ - spec/support/gitlab_v5_web_mocks.rb
162
169
  - spec/support/read_fixture.rb
163
170
  - vx-service_connector.gemspec
164
171
  homepage: ''
@@ -200,19 +207,24 @@ test_files:
200
207
  - spec/fixtures/github/payload/push.json
201
208
  - spec/fixtures/github/payload/push_tag.json
202
209
  - spec/fixtures/github/user_repos.json
203
- - spec/fixtures/gitlab_v41/commits.json
204
- - spec/fixtures/gitlab_v41/hooks.json
205
- - spec/fixtures/gitlab_v41/payload/push.json
206
- - spec/fixtures/gitlab_v41/projects.json
207
- - spec/fixtures/gitlab_v41/user_keys.json
210
+ - spec/fixtures/gitlab_v4/commits.json
211
+ - spec/fixtures/gitlab_v4/hooks.json
212
+ - spec/fixtures/gitlab_v4/payload/merge_request1_unchecked.json
213
+ - spec/fixtures/gitlab_v4/payload/merge_request2_can_be_merge.json
214
+ - spec/fixtures/gitlab_v4/payload/push.json
215
+ - spec/fixtures/gitlab_v4/projects.json
216
+ - spec/fixtures/gitlab_v4/user_keys.json
217
+ - spec/fixtures/gitlab_v5/deploy_keys.json
208
218
  - spec/lib/github_payload_spec.rb
209
219
  - spec/lib/github_spec.rb
210
- - spec/lib/gitlab_v41_payload_spec.rb
211
- - spec/lib/gitlab_v41_spec.rb
220
+ - spec/lib/gitlab_v4_payload_spec.rb
221
+ - spec/lib/gitlab_v4_spec.rb
222
+ - spec/lib/gitlab_v5_spec.rb
212
223
  - spec/lib/model_spec.rb
213
224
  - spec/lib/service_connector_spec.rb
214
225
  - spec/spec_helper.rb
215
226
  - spec/support/create.rb
216
227
  - spec/support/github_web_mocks.rb
217
- - spec/support/gitlab_v41_web_mocks.rb
228
+ - spec/support/gitlab_v4_web_mocks.rb
229
+ - spec/support/gitlab_v5_web_mocks.rb
218
230
  - spec/support/read_fixture.rb
@@ -1,49 +0,0 @@
1
- require 'gitlab'
2
-
3
- module Vx
4
- module ServiceConnector
5
- GitlabV41 = Struct.new(:endpoint, :private_token) do
6
-
7
- include ServiceConnector::Base
8
-
9
- def repos
10
- @repos ||= GitlabV41::Repos.new(session).to_a
11
- end
12
-
13
- def organizations
14
- []
15
- end
16
-
17
- def hooks(repo)
18
- GitlabV41::Hooks.new(session, repo)
19
- end
20
-
21
- def deploy_keys(repo)
22
- GitlabV41::DeployKeys.new(session, repo)
23
- end
24
-
25
- def notices(repo)
26
- GitlabV41::Notices.new(session, repo)
27
- end
28
-
29
- def files(repo)
30
- GitlabV41::Files.new(session, repo)
31
- end
32
-
33
- def commits(repo)
34
- GitlabV41::Commits.new(session, repo)
35
- end
36
-
37
- private
38
-
39
- def create_session
40
- GitlabV41::Session.new(endpoint, private_token)
41
- end
42
-
43
- end
44
- end
45
- end
46
-
47
- Dir[File.expand_path("../gitlab_v41/*.rb", __FILE__)].each do |f|
48
- require f
49
- end
@@ -1,93 +0,0 @@
1
- module Vx
2
- module ServiceConnector
3
- class GitlabV41
4
- class Payload
5
-
6
- def initialize(params)
7
- @params = params || {}
8
- end
9
-
10
- def pull_request?
11
- false
12
- end
13
-
14
- def tag?
15
- false
16
- end
17
-
18
- def pull_request_number
19
- nil
20
- end
21
-
22
- def head
23
- self["after"]
24
- end
25
-
26
- def base
27
- self["before"]
28
- end
29
-
30
- def branch
31
- self["ref"].to_s.split("refs/heads/").last
32
- end
33
-
34
- def branch_label
35
- branch
36
- end
37
-
38
- def url
39
- self["commits"] && self["commits"].first && self["commits"].first["url"]
40
- end
41
-
42
- def pull_request_head_repo_id
43
- nil
44
- end
45
-
46
- def pull_request_base_repo_id
47
- nil
48
- end
49
-
50
- def closed_pull_request?
51
- false
52
- end
53
-
54
- def foreign_pull_request?
55
- false
56
- end
57
-
58
- def ignore?
59
- head == '0000000000000000000000000000000000000000'
60
- end
61
-
62
- def to_model
63
- ServiceConnector::Model::Payload.new(
64
- !!pull_request,
65
- pull_request_number,
66
- head,
67
- base,
68
- branch,
69
- branch_label,
70
- url,
71
- !!ignore?
72
- )
73
- end
74
-
75
- private
76
-
77
- def pull_request
78
- self["pull_request"]
79
- end
80
-
81
- def key?(name)
82
- @params.key? name
83
- end
84
-
85
- def [](val)
86
- @params[val]
87
- end
88
-
89
- end
90
-
91
- end
92
- end
93
- end
@@ -1,40 +0,0 @@
1
- module Vx
2
- module ServiceConnector
3
- class GitlabV41
4
- Repos = Struct.new(:session) do
5
-
6
- def to_a
7
- session.get("/projects").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
- repo.private,
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
- [session.uri.hostname, repo.name.downcase].join("/")
27
- end
28
-
29
- def compute_ssh_url(repo)
30
- "git@#{session.uri.hostname}:#{repo.name.downcase}.git"
31
- end
32
-
33
- def compute_web_url(repo)
34
- "#{session.uri.scheme}://#{session.uri.hostname}:#{session.uri.port}/#{repo.name.downcase}"
35
- end
36
-
37
- end
38
- end
39
- end
40
- end