vx-service_connector 0.0.5 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/vx/service_connector/base.rb +3 -4
- data/lib/vx/service_connector/github/payload.rb +73 -38
- data/lib/vx/service_connector/github.rb +6 -6
- data/lib/vx/service_connector/{gitlab_v4 → gitlab_v5}/files.rb +1 -1
- data/lib/vx/service_connector/{gitlab_v4 → gitlab_v5}/hooks.rb +1 -1
- data/lib/vx/service_connector/{gitlab_v4 → gitlab_v5}/notices.rb +1 -1
- data/lib/vx/service_connector/gitlab_v5/payload.rb +112 -0
- data/lib/vx/service_connector/{gitlab_v4 → gitlab_v5}/repos.rb +1 -1
- data/lib/vx/service_connector/{gitlab_v4 → gitlab_v5}/session.rb +1 -1
- data/lib/vx/service_connector/gitlab_v5.rb +30 -2
- data/lib/vx/service_connector/model.rb +12 -20
- data/lib/vx/service_connector/version.rb +1 -1
- data/lib/vx/service_connector.rb +0 -19
- data/spec/fixtures/github/payload/foreign_pull_request.json +810 -1
- data/spec/fixtures/github/payload/pull_request.json +0 -1
- data/spec/fixtures/github/payload/push_tag.json +0 -1
- data/spec/fixtures/{gitlab_v4 → gitlab_v5}/commits.json +0 -0
- data/spec/fixtures/{gitlab_v4 → gitlab_v5}/hooks.json +0 -0
- data/spec/fixtures/gitlab_v5/payload/push.json +32 -0
- data/spec/fixtures/{gitlab_v4 → gitlab_v5}/projects.json +0 -0
- data/spec/fixtures/{gitlab_v4 → gitlab_v5}/user_keys.json +0 -0
- data/spec/lib/github_payload_spec.rb +43 -94
- data/spec/lib/github_spec.rb +0 -23
- data/spec/lib/gitlab_v5_payload_spec.rb +33 -0
- data/spec/lib/gitlab_v5_spec.rb +74 -0
- data/spec/lib/model_spec.rb +3 -28
- data/spec/lib/service_connector_spec.rb +0 -35
- data/spec/support/github_web_mocks.rb +2 -2
- data/spec/support/gitlab_v5_web_mocks.rb +41 -2
- metadata +20 -32
- data/lib/vx/service_connector/github/commits.rb +0 -33
- data/lib/vx/service_connector/gitlab_v4/commits.rb +0 -35
- data/lib/vx/service_connector/gitlab_v4/deploy_keys.rb +0 -32
- data/lib/vx/service_connector/gitlab_v4/payload.rb +0 -126
- data/lib/vx/service_connector/gitlab_v4.rb +0 -49
- data/spec/fixtures/gitlab_v4/payload/merge_request1_unchecked.json +0 -47
- data/spec/fixtures/gitlab_v4/payload/merge_request2_can_be_merge.json +0 -47
- data/spec/fixtures/gitlab_v4/payload/push.json +0 -106
- data/spec/lib/gitlab_v4_payload_spec.rb +0 -101
- data/spec/lib/gitlab_v4_spec.rb +0 -141
- data/spec/support/gitlab_v4_web_mocks.rb +0 -73
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 728d36964c4a9f513d0ca3ae5897c4beee46f8de
|
4
|
+
data.tar.gz: 909bc1aa8d6b30e85c0eb652e57e3991d16b5c1b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 915f71759d79a0306ca011f0acd66389c60d4b9925ae9bc2655149d25466c5a3b4e441371c49f55ff8941dabcf7cb60d29d245a396b0062de4fd9b81127555ed
|
7
|
+
data.tar.gz: 27bc9295f4ca3d4f9f0192cd4ebbb0ddf7e821e3254c09193c0ba9367a3fbca0d5b07b37b56ee0ad40ea6038f24e26f672930f80413ba08f68bc4429f5a48d86
|
@@ -1,12 +1,27 @@
|
|
1
|
+
require 'ostruct'
|
2
|
+
|
1
3
|
module Vx
|
2
4
|
module ServiceConnector
|
3
5
|
class Github
|
4
|
-
|
6
|
+
Payload = Struct.new(:session, :params) do
|
5
7
|
|
6
|
-
def
|
7
|
-
|
8
|
+
def build
|
9
|
+
ServiceConnector::Model::Payload.new(
|
10
|
+
!!ignore?,
|
11
|
+
!!pull_request,
|
12
|
+
pull_request_number,
|
13
|
+
branch,
|
14
|
+
branch_label,
|
15
|
+
sha,
|
16
|
+
message,
|
17
|
+
author,
|
18
|
+
author_email,
|
19
|
+
web_url
|
20
|
+
)
|
8
21
|
end
|
9
22
|
|
23
|
+
private
|
24
|
+
|
10
25
|
def pull_request?
|
11
26
|
key? "pull_request"
|
12
27
|
end
|
@@ -21,7 +36,7 @@ module Vx
|
|
21
36
|
end
|
22
37
|
end
|
23
38
|
|
24
|
-
def
|
39
|
+
def sha
|
25
40
|
if pull_request?
|
26
41
|
pull_request["head"]["sha"]
|
27
42
|
else
|
@@ -29,14 +44,6 @@ module Vx
|
|
29
44
|
end
|
30
45
|
end
|
31
46
|
|
32
|
-
def base
|
33
|
-
if pull_request?
|
34
|
-
pull_request["base"]["sha"]
|
35
|
-
else
|
36
|
-
self["before"]
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
47
|
def branch
|
41
48
|
if pull_request?
|
42
49
|
pull_request["head"]["ref"]
|
@@ -53,11 +60,35 @@ module Vx
|
|
53
60
|
end
|
54
61
|
end
|
55
62
|
|
56
|
-
def
|
63
|
+
def web_url
|
64
|
+
if pull_request?
|
65
|
+
pull_request["html_url"]
|
66
|
+
else
|
67
|
+
head_commit["url"]
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def message
|
72
|
+
if pull_request?
|
73
|
+
commit_for_pull_request.message
|
74
|
+
else
|
75
|
+
head_commit["message"]
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def author
|
80
|
+
if pull_request?
|
81
|
+
commit_for_pull_request.author.name
|
82
|
+
else
|
83
|
+
head_commit? && head_commit["author"]["name"]
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def author_email
|
57
88
|
if pull_request?
|
58
|
-
|
89
|
+
commit_for_pull_request.author.email
|
59
90
|
else
|
60
|
-
|
91
|
+
head_commit? && head_commit["author"]["email"]
|
61
92
|
end
|
62
93
|
end
|
63
94
|
|
@@ -85,37 +116,41 @@ module Vx
|
|
85
116
|
if pull_request?
|
86
117
|
closed_pull_request? || !foreign_pull_request?
|
87
118
|
else
|
88
|
-
|
89
|
-
tag?
|
119
|
+
sha == '0000000000000000000000000000000000000000' || tag?
|
90
120
|
end
|
91
121
|
end
|
92
122
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
)
|
123
|
+
|
124
|
+
def commit_for_pull_request
|
125
|
+
@commit_for_pull_request ||=
|
126
|
+
begin
|
127
|
+
data = session.commit pull_request["base"]["repo"]["full_name"], sha
|
128
|
+
data.commit
|
129
|
+
rescue ::Octokit::NotFound => e
|
130
|
+
$stderr.puts "ERROR: #{e.inspect}"
|
131
|
+
OpenStruct.new
|
132
|
+
end
|
104
133
|
end
|
105
134
|
|
106
|
-
|
135
|
+
def head_commit?
|
136
|
+
self["head_commit"]
|
137
|
+
end
|
107
138
|
|
108
|
-
|
109
|
-
|
110
|
-
|
139
|
+
def head_commit
|
140
|
+
self["head_commit"] || {}
|
141
|
+
end
|
111
142
|
|
112
|
-
|
113
|
-
|
114
|
-
|
143
|
+
def pull_request
|
144
|
+
self["pull_request"]
|
145
|
+
end
|
115
146
|
|
116
|
-
|
117
|
-
|
118
|
-
|
147
|
+
def key?(name)
|
148
|
+
params.key? name
|
149
|
+
end
|
150
|
+
|
151
|
+
def [](val)
|
152
|
+
params[val]
|
153
|
+
end
|
119
154
|
|
120
155
|
end
|
121
156
|
|
@@ -11,11 +11,11 @@ module Vx
|
|
11
11
|
include ServiceConnector::Base
|
12
12
|
|
13
13
|
def repos
|
14
|
-
|
14
|
+
Github::Repos.new(session).to_a
|
15
15
|
end
|
16
16
|
|
17
17
|
def organizations
|
18
|
-
|
18
|
+
Github::Repos.new(session).organizations
|
19
19
|
end
|
20
20
|
|
21
21
|
def hooks(repo)
|
@@ -34,8 +34,8 @@ module Vx
|
|
34
34
|
Github::Files.new(session, repo)
|
35
35
|
end
|
36
36
|
|
37
|
-
def
|
38
|
-
Github::
|
37
|
+
def payload(repo, params)
|
38
|
+
Github::Payload.new(session, params).build
|
39
39
|
end
|
40
40
|
|
41
41
|
private
|
@@ -48,6 +48,6 @@ module Vx
|
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
|
-
|
52
|
-
require
|
51
|
+
Dir[File.expand_path("../github/*.rb", __FILE__)].each do |f|
|
52
|
+
require f
|
53
53
|
end
|
@@ -0,0 +1,112 @@
|
|
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
|
+
sha == '0000000000000000000000000000000000000000'
|
83
|
+
end
|
84
|
+
|
85
|
+
def pull_request
|
86
|
+
{}
|
87
|
+
end
|
88
|
+
|
89
|
+
def key?(name)
|
90
|
+
params.key? name
|
91
|
+
end
|
92
|
+
|
93
|
+
def [](val)
|
94
|
+
params[val]
|
95
|
+
end
|
96
|
+
|
97
|
+
def commit_for_payload
|
98
|
+
@commit_for_payload ||=
|
99
|
+
begin
|
100
|
+
commits = session.get("/projects/#{repo.id}/repository/commits", ref_name: sha)
|
101
|
+
commits.first || {}
|
102
|
+
rescue RequestError => e
|
103
|
+
$stderr.puts "ERROR: #{e.inspect}"
|
104
|
+
{}
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
@@ -2,16 +2,44 @@ require 'gitlab'
|
|
2
2
|
|
3
3
|
module Vx
|
4
4
|
module ServiceConnector
|
5
|
-
|
5
|
+
GitlabV5 = Struct.new(:endpoint, :private_token) do
|
6
|
+
|
7
|
+
include ServiceConnector::Base
|
6
8
|
|
7
9
|
def repos
|
8
|
-
@repos ||=
|
10
|
+
@repos ||= GitlabV5::Repos.new(session).to_a
|
11
|
+
end
|
12
|
+
|
13
|
+
def organizations
|
14
|
+
[]
|
15
|
+
end
|
16
|
+
|
17
|
+
def hooks(repo)
|
18
|
+
GitlabV5::Hooks.new(session, repo)
|
9
19
|
end
|
10
20
|
|
11
21
|
def deploy_keys(repo)
|
12
22
|
GitlabV5::DeployKeys.new(session, repo)
|
13
23
|
end
|
14
24
|
|
25
|
+
def notices(repo)
|
26
|
+
GitlabV5::Notices.new(session, repo)
|
27
|
+
end
|
28
|
+
|
29
|
+
def files(repo)
|
30
|
+
GitlabV5::Files.new(session, repo)
|
31
|
+
end
|
32
|
+
|
33
|
+
def payload(repo, params)
|
34
|
+
GitlabV5::Payload.new(session, repo, params).build
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def create_session
|
40
|
+
GitlabV5::Session.new(endpoint, private_token)
|
41
|
+
end
|
42
|
+
|
15
43
|
end
|
16
44
|
end
|
17
45
|
end
|
@@ -12,14 +12,16 @@ module Vx
|
|
12
12
|
)
|
13
13
|
|
14
14
|
Payload = Struct.new(
|
15
|
+
:ignore?,
|
15
16
|
:pull_request?,
|
16
17
|
:pull_request_number,
|
17
|
-
:head,
|
18
|
-
:base,
|
19
18
|
:branch,
|
20
19
|
:branch_label,
|
21
|
-
:
|
22
|
-
:
|
20
|
+
:sha,
|
21
|
+
:message,
|
22
|
+
:author,
|
23
|
+
:author_email,
|
24
|
+
:web_url
|
23
25
|
) do
|
24
26
|
def to_hash ; to_h end
|
25
27
|
|
@@ -34,26 +36,20 @@ module Vx
|
|
34
36
|
end
|
35
37
|
end
|
36
38
|
|
37
|
-
Commit = Struct.new(
|
38
|
-
:sha,
|
39
|
-
:message,
|
40
|
-
:author,
|
41
|
-
:author_email,
|
42
|
-
:http_url
|
43
|
-
)
|
44
|
-
|
45
39
|
extend self
|
46
40
|
|
47
41
|
def test_payload_attributes(params = {})
|
48
42
|
{
|
43
|
+
ignore?: false,
|
49
44
|
pull_request?: false,
|
50
45
|
pull_request_number: nil,
|
51
|
-
head: "HEAD",
|
52
|
-
base: '0000',
|
53
46
|
branch: 'master',
|
54
47
|
branch_label: 'master:label',
|
55
|
-
|
56
|
-
|
48
|
+
sha: "HEAD",
|
49
|
+
message: 'test commit',
|
50
|
+
author: 'User Name',
|
51
|
+
author_email: 'me@example.com',
|
52
|
+
web_url: 'http://example.com',
|
57
53
|
}.merge(params)
|
58
54
|
end
|
59
55
|
|
@@ -61,10 +57,6 @@ module Vx
|
|
61
57
|
Payload.from_hash(test_payload_attributes params)
|
62
58
|
end
|
63
59
|
|
64
|
-
def test_commit
|
65
|
-
Commit.new('sha', 'message', 'author', 'author_email', 'http_url')
|
66
|
-
end
|
67
|
-
|
68
60
|
def test_repo
|
69
61
|
Repo.new(
|
70
62
|
1,
|
data/lib/vx/service_connector.rb
CHANGED
@@ -6,21 +6,15 @@ 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 :GitlabV4, File.expand_path("../service_connector/gitlab_v4", __FILE__)
|
10
9
|
autoload :GitlabV5, File.expand_path("../service_connector/gitlab_v5", __FILE__)
|
11
10
|
autoload :Model, File.expand_path("../service_connector/model", __FILE__)
|
12
11
|
|
13
12
|
extend self
|
14
13
|
|
15
|
-
def github ; Github end
|
16
|
-
def gitlab_v3 ; GitlabV3 end
|
17
|
-
|
18
14
|
def to(name)
|
19
15
|
case name.to_sym
|
20
16
|
when :github
|
21
17
|
Github
|
22
|
-
when :gitlab_v4
|
23
|
-
GitlabV4
|
24
18
|
when :gitlab_v5
|
25
19
|
GitlabV5
|
26
20
|
else
|
@@ -28,18 +22,5 @@ module Vx
|
|
28
22
|
end
|
29
23
|
end
|
30
24
|
|
31
|
-
def payload(name, params)
|
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
|
42
|
-
end
|
43
|
-
|
44
25
|
end
|
45
26
|
end
|