vx-service_connector 0.0.2 → 0.0.3
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.rb +7 -6
- data/lib/vx/service_connector/error.rb +5 -0
- data/lib/vx/service_connector/gitlab_v41.rb +49 -0
- data/lib/vx/service_connector/gitlab_v41/commits.rb +35 -0
- data/lib/vx/service_connector/gitlab_v41/deploy_keys.rb +32 -0
- data/lib/vx/service_connector/gitlab_v41/files.rb +20 -0
- data/lib/vx/service_connector/gitlab_v41/hooks.rb +32 -0
- data/lib/vx/service_connector/gitlab_v41/notices.rb +13 -0
- data/lib/vx/service_connector/gitlab_v41/payload.rb +93 -0
- data/lib/vx/service_connector/gitlab_v41/repos.rb +40 -0
- data/lib/vx/service_connector/gitlab_v41/session.rb +58 -0
- data/lib/vx/service_connector/version.rb +1 -1
- data/spec/fixtures/gitlab_v41/commits.json +18 -0
- data/spec/fixtures/{gitlab_v3 → gitlab_v41}/deploy_keys.json +0 -0
- data/spec/fixtures/gitlab_v41/hooks.json +1 -0
- data/spec/fixtures/gitlab_v41/payload/push.json +106 -0
- data/spec/fixtures/gitlab_v41/projects.json +1 -0
- data/spec/fixtures/gitlab_v41/user_keys.json +1 -0
- data/spec/lib/gitlab_v41_payload_spec.rb +92 -0
- data/spec/lib/gitlab_v41_spec.rb +141 -0
- data/spec/lib/service_connector_spec.rb +2 -2
- data/spec/support/gitlab_v41_web_mocks.rb +73 -0
- metadata +30 -13
- data/lib/vx/service_connector/gitlab_v3.rb +0 -29
- data/lib/vx/service_connector/gitlab_v3/deploy_keys.rb +0 -20
- data/lib/vx/service_connector/gitlab_v3/repos.rb +0 -28
- data/spec/fixtures/gitlab_v3/projects.json +0 -72
- data/spec/lib/gitlab_v3_spec.rb +0 -44
- data/spec/support/gitlab_v3_mocks.rb +0 -29
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bc937a5f342e9a450658d50b50c8b4bb9f46912a
|
4
|
+
data.tar.gz: b2a972208b17bfc6d4c60c8725c6ce49e3a2dbbd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 56bdaf27fdd6d26f450204ed80c8e78011bb525166ea08b166576990c75e39094169c42a7794addab07fed6274c3a39508d54e4d4d3c81b8617f4892c1369c2e
|
7
|
+
data.tar.gz: 01055be7c7e3547e4c1e6cf589a94fdb4575bfc41df56c196df56dd8fbdd3eefa0ac70f62fe61bc626aa12a5ef03aee1af8185ec68ba042552dc3c4573d26e7e
|
data/lib/vx/service_connector.rb
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
require File.expand_path("../service_connector/version", __FILE__)
|
2
|
+
require File.expand_path("../service_connector/error", __FILE__)
|
2
3
|
|
3
4
|
module Vx
|
4
5
|
module ServiceConnector
|
5
6
|
|
6
|
-
autoload :Base,
|
7
|
-
autoload :Github,
|
8
|
-
autoload :
|
9
|
-
autoload :Model,
|
7
|
+
autoload :Base, File.expand_path("../service_connector/base", __FILE__)
|
8
|
+
autoload :Github, File.expand_path("../service_connector/github", __FILE__)
|
9
|
+
autoload :GitlabV41, File.expand_path("../service_connector/gitlab_v41", __FILE__)
|
10
|
+
autoload :Model, File.expand_path("../service_connector/model", __FILE__)
|
10
11
|
|
11
12
|
extend self
|
12
13
|
|
@@ -17,8 +18,8 @@ module Vx
|
|
17
18
|
case name.to_sym
|
18
19
|
when :github
|
19
20
|
Github
|
20
|
-
when :
|
21
|
-
|
21
|
+
when :gitlab_v41
|
22
|
+
GitlabV41
|
22
23
|
else
|
23
24
|
raise ArgumentError, "Serivice for #{name.inspect} is not defined"
|
24
25
|
end
|
@@ -0,0 +1,49 @@
|
|
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
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'base64'
|
2
|
+
|
3
|
+
module Vx
|
4
|
+
module ServiceConnector
|
5
|
+
class GitlabV41
|
6
|
+
Commits = Struct.new(:session, :repo) do
|
7
|
+
|
8
|
+
def get(sha)
|
9
|
+
begin
|
10
|
+
all_commits = session.get "/projects/#{repo.id}/repository/commits", ref_name: sha
|
11
|
+
commits_to_model all_commits
|
12
|
+
rescue RequestError => e
|
13
|
+
$stderr.puts "ERROR: #{e.inspect}"
|
14
|
+
nil
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def commits_to_model(commits)
|
21
|
+
if commit = commits.first
|
22
|
+
Model::Commit.new(
|
23
|
+
commit.id,
|
24
|
+
commit.title,
|
25
|
+
commit.author_name,
|
26
|
+
commit.author_email,
|
27
|
+
nil
|
28
|
+
)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Vx
|
2
|
+
module ServiceConnector
|
3
|
+
class GitlabV41
|
4
|
+
DeployKeys = Struct.new(:session, :repo) do
|
5
|
+
|
6
|
+
def all
|
7
|
+
session.get "/user/keys"
|
8
|
+
end
|
9
|
+
|
10
|
+
def create(key_name, public_key)
|
11
|
+
key_name = compute_key_name(key_name)
|
12
|
+
session.post "/user/keys", title: key_name, key: public_key
|
13
|
+
end
|
14
|
+
|
15
|
+
def destroy(key_name)
|
16
|
+
key_name = compute_key_name(key_name)
|
17
|
+
all.select do |key|
|
18
|
+
key.title == key_name
|
19
|
+
end.map do |key|
|
20
|
+
session.delete "/user/keys/#{key.id}"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
def compute_key_name(orig_name)
|
26
|
+
"(#{repo.full_name}) #{orig_name}"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'base64'
|
2
|
+
|
3
|
+
module Vx
|
4
|
+
module ServiceConnector
|
5
|
+
class GitlabV41
|
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
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Vx
|
2
|
+
module ServiceConnector
|
3
|
+
class GitlabV41
|
4
|
+
Hooks = Struct.new(:session, :repo) do
|
5
|
+
|
6
|
+
def all
|
7
|
+
session.get hooks_url
|
8
|
+
end
|
9
|
+
|
10
|
+
def create(url, token)
|
11
|
+
session.post hooks_url, url: url
|
12
|
+
end
|
13
|
+
|
14
|
+
def destroy(url_mask)
|
15
|
+
all.select do |hook|
|
16
|
+
hook.url =~ /#{Regexp.escape url_mask}/
|
17
|
+
end.map do |hook|
|
18
|
+
session.delete hooks_url, hook_id: hook.id
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def hooks_url
|
25
|
+
"/projects/#{repo.id}/hooks"
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
@@ -0,0 +1,93 @@
|
|
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
|
@@ -0,0 +1,40 @@
|
|
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
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'sawyer'
|
2
|
+
require 'uri'
|
3
|
+
|
4
|
+
module Vx
|
5
|
+
module ServiceConnector
|
6
|
+
class GitlabV41
|
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), 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
|
@@ -0,0 +1,18 @@
|
|
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
|
+
]
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
[{"id":57,"url":"http://example.com/hook","created_at":"2014-01-28T14:04:22Z"}]
|
@@ -0,0 +1,106 @@
|
|
1
|
+
{
|
2
|
+
"before": "e9f2a24318cf0a08dc2d7b987b9d8484e8c89406",
|
3
|
+
"after": "a1dfcca6369dcbd19607c4cc0f932194d8bdf57d",
|
4
|
+
"ref": "refs/heads/master",
|
5
|
+
"user_id": 228,
|
6
|
+
"user_name": "User Name",
|
7
|
+
"repository": {
|
8
|
+
"name": "SQERP",
|
9
|
+
"url": "git@gitlab.example.com:sqerp.git",
|
10
|
+
"description": null,
|
11
|
+
"homepage": "https://gitlab.example.com/sqerp"
|
12
|
+
},
|
13
|
+
"commits": [
|
14
|
+
{
|
15
|
+
"id": "4b65377d80364713293df276d7756ff6253eedcd",
|
16
|
+
"message": "Merge branch '93537_hours_units_in_details' of gitlab.example.com:sqerp",
|
17
|
+
"timestamp": "2014-01-21T08:51:56+04:00",
|
18
|
+
"url": "https://gitlab.example.com/sqerp/commit/4b65377d80364713293df276d7756ff6253eedcd",
|
19
|
+
"author": {
|
20
|
+
"name": "User Name",
|
21
|
+
"email": "me@example.com"
|
22
|
+
}
|
23
|
+
},
|
24
|
+
{
|
25
|
+
"id": "17574ef138f188e5b51a1f036448c92296b674e7",
|
26
|
+
"message": "[97241] activities_controller specs",
|
27
|
+
"timestamp": "2014-01-21T18:26:16+04:00",
|
28
|
+
"url": "https://gitlab.example.com/sqerp/commit/17574ef138f188e5b51a1f036448c92296b674e7",
|
29
|
+
"author": {
|
30
|
+
"name": "User Name",
|
31
|
+
"email": "me@example.com"
|
32
|
+
}
|
33
|
+
},
|
34
|
+
{
|
35
|
+
"id": "ca71c5938c9c796cddf2d5a32c2689669998bb0d",
|
36
|
+
"message": "fixes #84078 Custom roles.",
|
37
|
+
"timestamp": "2014-01-22T11:20:10+04:00",
|
38
|
+
"url": "https://gitlab.example.com/sqerp/commit/ca71c5938c9c796cddf2d5a32c2689669998bb0d",
|
39
|
+
"author": {
|
40
|
+
"name": "Maxim Dorofienko",
|
41
|
+
"email": "dorofienko@gmail.com"
|
42
|
+
}
|
43
|
+
},
|
44
|
+
{
|
45
|
+
"id": "f27d4dca4e7094fbb2206cd61ecbf933d77f0897",
|
46
|
+
"message": "[96071] merge ad_campaing's table",
|
47
|
+
"timestamp": "2014-01-22T12:20:55+04:00",
|
48
|
+
"url": "https://gitlab.example.com/sqerp/commit/f27d4dca4e7094fbb2206cd61ecbf933d77f0897",
|
49
|
+
"author": {
|
50
|
+
"name": "Evgeny Li",
|
51
|
+
"email": "exaspark@gmail.com"
|
52
|
+
}
|
53
|
+
},
|
54
|
+
{
|
55
|
+
"id": "432ead814f28ec1701584b7ffe130eeb8ecd3e1f",
|
56
|
+
"message": "csv exporter fix",
|
57
|
+
"timestamp": "2014-01-23T13:25:38+04:00",
|
58
|
+
"url": "https://gitlab.example.com/sqerp/commit/432ead814f28ec1701584b7ffe130eeb8ecd3e1f",
|
59
|
+
"author": {
|
60
|
+
"name": "Dmitry Koprov",
|
61
|
+
"email": "dmitry.koprov@gmail.com"
|
62
|
+
}
|
63
|
+
},
|
64
|
+
{
|
65
|
+
"id": "780c2e4a26ebf10691d157a64e3d7259f369d48f",
|
66
|
+
"message": "Merge branch '97241_controller_tests' of gitlab.example.com:sqerp",
|
67
|
+
"timestamp": "2014-01-23T14:58:27+04:00",
|
68
|
+
"url": "https://gitlab.example.com/sqerp/commit/780c2e4a26ebf10691d157a64e3d7259f369d48f",
|
69
|
+
"author": {
|
70
|
+
"name": "User Name",
|
71
|
+
"email": "me@example.com"
|
72
|
+
}
|
73
|
+
},
|
74
|
+
{
|
75
|
+
"id": "e63d231b1c3e6286bea9ffbceebd6c12d87e3dc7",
|
76
|
+
"message": "[98386] env fix",
|
77
|
+
"timestamp": "2014-01-28T11:52:48+04:00",
|
78
|
+
"url": "https://gitlab.example.com/sqerp/commit/e63d231b1c3e6286bea9ffbceebd6c12d87e3dc7",
|
79
|
+
"author": {
|
80
|
+
"name": "User Name",
|
81
|
+
"email": "me@example.com"
|
82
|
+
}
|
83
|
+
},
|
84
|
+
{
|
85
|
+
"id": "09d62be9db7e476b01c9773b5e06e5fc6a550d3c",
|
86
|
+
"message": "Merge branch '98386_fix' of gitlab.example.com:sqerp",
|
87
|
+
"timestamp": "2014-01-28T11:54:49+04:00",
|
88
|
+
"url": "https://gitlab.example.com/sqerp/commit/09d62be9db7e476b01c9773b5e06e5fc6a550d3c",
|
89
|
+
"author": {
|
90
|
+
"name": "User Name",
|
91
|
+
"email": "me@example.com"
|
92
|
+
}
|
93
|
+
},
|
94
|
+
{
|
95
|
+
"id": "a1dfcca6369dcbd19607c4cc0f932194d8bdf57d",
|
96
|
+
"message": "Merge branch '96071_merge_ad_campaigns' of gitlab.example.com:sqerp",
|
97
|
+
"timestamp": "2014-01-28T12:10:16+04:00",
|
98
|
+
"url": "https://gitlab.example.com/sqerp/commit/a1dfcca6369dcbd19607c4cc0f932194d8bdf57d",
|
99
|
+
"author": {
|
100
|
+
"name": "User Name",
|
101
|
+
"email": "me@example.com"
|
102
|
+
}
|
103
|
+
}
|
104
|
+
],
|
105
|
+
"total_commits_count": 9
|
106
|
+
}
|
@@ -0,0 +1 @@
|
|
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}]
|
@@ -0,0 +1 @@
|
|
1
|
+
[{"id":589,"title":"(full/name) me@example.com","key":"ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDXnM3fhBisPY223C7poY7J7qsMPHHc1aJ4+rwUqzdGHANNWoP8tCUXXnhWvhy8fxEqImDUWdYMNLQI42MJ8RB7naQjvWJqBU/JUvXRznrGcldPjmdIpb25Jod29wQDmPEYC31S1HoEEgmqVeG1V+ypxeqm8XEy1USjsY/Cbx0cbGUOa560GRV89/8KB4GHzN8R82OUxIzUJotIGIcAvNhYwR+skrsI2/QnDMqty2O5SQU52bgzlotCfSQbeujOT9DU3uP9YeRUcY/Xouqx19Q5TSPNk8rkh5uIHNKQ9LipJlfVU9G+YI0r5oMRlvqEXyR2gUEUwwhzafp8JQ4O/YJ7 me@example.com","created_at":"2013-10-24T12:41:18Z"}]
|
@@ -0,0 +1,92 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Vx::ServiceConnector::GitlabV41::Payload do
|
4
|
+
let(:content) { read_json_fixture("gitlab_v41/payload/push") }
|
5
|
+
let(:payload) { described_class.new content }
|
6
|
+
subject { payload }
|
7
|
+
|
8
|
+
context "push" do
|
9
|
+
let(:url) { "https://gitlab.example.com/sqerp/commit/4b65377d80364713293df276d7756ff6253eedcd" }
|
10
|
+
|
11
|
+
its(:pull_request?) { should be_false }
|
12
|
+
its(:pull_request_number) { should be_nil }
|
13
|
+
its(:head) { should eq 'a1dfcca6369dcbd19607c4cc0f932194d8bdf57d' }
|
14
|
+
its(:base) { should eq 'e9f2a24318cf0a08dc2d7b987b9d8484e8c89406' }
|
15
|
+
its(:branch) { should eq 'master' }
|
16
|
+
its(:branch_label) { should eq 'master' }
|
17
|
+
its(:url) { should eq url }
|
18
|
+
|
19
|
+
its(:pull_request_head_repo_id){ should be_nil }
|
20
|
+
its(:pull_request_base_repo_id){ should be_nil }
|
21
|
+
end
|
22
|
+
|
23
|
+
context "pull_request" do
|
24
|
+
end
|
25
|
+
|
26
|
+
context "tag?" do
|
27
|
+
end
|
28
|
+
|
29
|
+
context "closed_pull_request?" do
|
30
|
+
end
|
31
|
+
|
32
|
+
context "foreign_pull_request?" do
|
33
|
+
end
|
34
|
+
|
35
|
+
=begin
|
36
|
+
context "ignore?" do
|
37
|
+
subject { payload.ignore? }
|
38
|
+
|
39
|
+
context "when pull request" do
|
40
|
+
let(:content) { read_json_fixture("github/payload/foreign_pull_request") }
|
41
|
+
it { should be_false}
|
42
|
+
|
43
|
+
context "and is closed" do
|
44
|
+
before do
|
45
|
+
expect(payload).to receive(:closed_pull_request?) { true }
|
46
|
+
end
|
47
|
+
it { should be_true }
|
48
|
+
end
|
49
|
+
|
50
|
+
context "and same repo" do
|
51
|
+
let(:content) { read_json_fixture("github/payload/pull_request") }
|
52
|
+
it { should be_true }
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
context "when regular commit" do
|
57
|
+
it { should be_false }
|
58
|
+
|
59
|
+
context "and deleted branch" do
|
60
|
+
before do
|
61
|
+
expect(payload).to receive(:head) { '0000000000000000000000000000000000000000' }
|
62
|
+
end
|
63
|
+
it { should be_true }
|
64
|
+
end
|
65
|
+
|
66
|
+
context "and tag created" do
|
67
|
+
before do
|
68
|
+
expect(payload).to receive(:tag?) { true }
|
69
|
+
end
|
70
|
+
it { should be_true }
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
=end
|
75
|
+
|
76
|
+
context "to_model" do
|
77
|
+
subject { payload.to_model }
|
78
|
+
it { should be_instance_of(Vx::ServiceConnector::Model::Payload) }
|
79
|
+
|
80
|
+
its(:values) { should eq(
|
81
|
+
[false,
|
82
|
+
nil,
|
83
|
+
"a1dfcca6369dcbd19607c4cc0f932194d8bdf57d",
|
84
|
+
"e9f2a24318cf0a08dc2d7b987b9d8484e8c89406",
|
85
|
+
"master",
|
86
|
+
"master",
|
87
|
+
"https://gitlab.example.com/sqerp/commit/4b65377d80364713293df276d7756ff6253eedcd",
|
88
|
+
false]
|
89
|
+
) }
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
@@ -0,0 +1,141 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Vx::ServiceConnector::GitlabV41 do
|
4
|
+
|
5
|
+
include GitlabV41WebMocks
|
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 "(notices)" do
|
17
|
+
let(:notices) { gitlab.notices(repo) }
|
18
|
+
|
19
|
+
context "create" do
|
20
|
+
subject { notices.create nil, nil, nil, nil }
|
21
|
+
it { should be :not_available }
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context "(repos)" do
|
26
|
+
subject { gitlab.repos }
|
27
|
+
|
28
|
+
before do
|
29
|
+
mock_repos
|
30
|
+
end
|
31
|
+
|
32
|
+
it { should have(1).item }
|
33
|
+
|
34
|
+
context "values" do
|
35
|
+
subject { gitlab.repos.map(&:values) }
|
36
|
+
it { should eq(
|
37
|
+
[[9, "example.com/sqerp", true, "git@example.com:sqerp.git", "http://example.com:80/sqerp", nil]]
|
38
|
+
) }
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context "(deploy_keys)" do
|
43
|
+
let(:key_name) { 'me@example.com' }
|
44
|
+
let(:public_key) { 'public key' }
|
45
|
+
let(:deploy_keys) { gitlab.deploy_keys(repo) }
|
46
|
+
|
47
|
+
context "all" do
|
48
|
+
subject { deploy_keys.all }
|
49
|
+
before { mock_user_keys }
|
50
|
+
it { should have(1).item }
|
51
|
+
end
|
52
|
+
|
53
|
+
context "create" do
|
54
|
+
subject { deploy_keys.create key_name, public_key }
|
55
|
+
before { mock_add_user_key }
|
56
|
+
it { should be }
|
57
|
+
end
|
58
|
+
|
59
|
+
context "destroy" do
|
60
|
+
subject { deploy_keys.destroy key_name }
|
61
|
+
|
62
|
+
before do
|
63
|
+
mock_user_keys
|
64
|
+
mock_delete_user_key
|
65
|
+
end
|
66
|
+
|
67
|
+
it { should have(1).item }
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
context "(hooks)" do
|
72
|
+
let(:url) { 'url' }
|
73
|
+
let(:token) { 'token' }
|
74
|
+
let(:hooks) { gitlab.hooks(repo) }
|
75
|
+
|
76
|
+
context "all" do
|
77
|
+
subject { hooks.all }
|
78
|
+
before { mock_hooks }
|
79
|
+
it { should have(1).item }
|
80
|
+
end
|
81
|
+
|
82
|
+
context "create" do
|
83
|
+
subject { hooks.create url, token }
|
84
|
+
before { mock_add_hook }
|
85
|
+
it { should be }
|
86
|
+
end
|
87
|
+
|
88
|
+
context "destroy" do
|
89
|
+
let(:mask) { "http://example.com" }
|
90
|
+
subject { hooks.destroy mask }
|
91
|
+
before do
|
92
|
+
mock_hooks
|
93
|
+
mock_remove_hook
|
94
|
+
end
|
95
|
+
it { should have(1).item }
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
context "(files)" do
|
100
|
+
let(:sha) { 'sha' }
|
101
|
+
let(:path) { 'path' }
|
102
|
+
|
103
|
+
context "get" do
|
104
|
+
subject { gitlab.files(repo).get sha, path }
|
105
|
+
|
106
|
+
context "success" do
|
107
|
+
before { mock_get_file }
|
108
|
+
it { should eq 'content' }
|
109
|
+
end
|
110
|
+
|
111
|
+
context "not found" do
|
112
|
+
before { mock_get_file_not_found }
|
113
|
+
it { should be_nil }
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
context "(commits)" do
|
119
|
+
let(:sha) { 'sha' }
|
120
|
+
|
121
|
+
context "get" do
|
122
|
+
subject { gitlab.commits(repo).get sha }
|
123
|
+
|
124
|
+
context "success" do
|
125
|
+
before { mock_get_commit }
|
126
|
+
it { should be }
|
127
|
+
its(:sha) { should eq 'ed899a2f4b50b4370feeea94676502b42383c746' }
|
128
|
+
its(:message) { should eq 'Replace sanitize with escape once' }
|
129
|
+
its(:author) { should eq 'Dmitriy Zaporozhets' }
|
130
|
+
its(:author_email) { should eq 'dzaporozhets@sphereconsultinginc.com' }
|
131
|
+
its(:http_url) { should be_nil }
|
132
|
+
end
|
133
|
+
|
134
|
+
context "not found" do
|
135
|
+
before { mock_get_commit_not_found }
|
136
|
+
it { should be_nil }
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
module GitlabV41WebMocks
|
2
|
+
|
3
|
+
def mock_repos
|
4
|
+
mock_get "projects", 'projects'
|
5
|
+
end
|
6
|
+
|
7
|
+
def mock_user_keys
|
8
|
+
mock_get "user/keys", 'user_keys'
|
9
|
+
end
|
10
|
+
|
11
|
+
def mock_add_user_key
|
12
|
+
mock_post "user/keys", "{\"title\":\"(full/name) me@example.com\",\"key\":\"public key\"}"
|
13
|
+
end
|
14
|
+
|
15
|
+
def mock_delete_user_key
|
16
|
+
mock_delete "user/keys/589", '{}'
|
17
|
+
end
|
18
|
+
|
19
|
+
def mock_add_hook
|
20
|
+
mock_post "projects/1/hooks", "{\"url\":\"url\"}"
|
21
|
+
end
|
22
|
+
|
23
|
+
def mock_remove_hook
|
24
|
+
mock_delete "projects/1/hooks", "{\"hook_id\":57}"
|
25
|
+
end
|
26
|
+
|
27
|
+
def mock_hooks
|
28
|
+
mock_get "projects/1/hooks", 'hooks'
|
29
|
+
end
|
30
|
+
|
31
|
+
def mock_get_file
|
32
|
+
stub_request(:get, "http://example.com/api/v3/projects/1/repository/commits/sha/blob?filepath=path").
|
33
|
+
with(:headers => {'Accept'=>'application/json', 'Content-Type'=>'application/json', 'Private-Token'=>'token'}).
|
34
|
+
to_return(:status => 200, :body => "content")
|
35
|
+
end
|
36
|
+
|
37
|
+
def mock_get_file_not_found
|
38
|
+
stub_request(:get, "http://example.com/api/v3/projects/1/repository/commits/sha/blob?filepath=path").
|
39
|
+
with(:headers => {'Accept'=>'application/json', 'Content-Type'=>'application/json', 'Private-Token'=>'token'}).
|
40
|
+
to_return(:status => 404, :body => "")
|
41
|
+
end
|
42
|
+
|
43
|
+
def mock_get_commit
|
44
|
+
mock_get "projects/1/repository/commits?ref_name=sha", 'commits'
|
45
|
+
end
|
46
|
+
|
47
|
+
def mock_get_commit_not_found
|
48
|
+
stub_request(:get, "http://example.com/api/v3/projects/1/repository/commits?ref_name=sha").
|
49
|
+
with(:headers => {'Accept'=>'application/json', 'Content-Type'=>'application/json', 'Private-Token'=>'token'}).
|
50
|
+
to_return(:status => 404, :body => "")
|
51
|
+
end
|
52
|
+
|
53
|
+
def mock_get(url, fixture)
|
54
|
+
stub_request(:get, "http://example.com/api/v3/#{url}").
|
55
|
+
with(:headers => {'Accept'=>'application/json', 'PRIVATE-TOKEN' => "token"}).
|
56
|
+
to_return(
|
57
|
+
:status => 200,
|
58
|
+
:body => read_fixture("gitlab_v41/#{fixture}.json"),
|
59
|
+
:headers => {'Content-Type' => 'application/json'})
|
60
|
+
end
|
61
|
+
|
62
|
+
def mock_post(url, body)
|
63
|
+
stub_request(:post, "http://example.com/api/v3/#{url}").
|
64
|
+
with(:headers => {'Accept'=>'application/json', }, body: body).
|
65
|
+
to_return(:status => 200, :body => "{}", :headers => {'Content-Type' => 'application/json'})
|
66
|
+
end
|
67
|
+
|
68
|
+
def mock_delete(url, body)
|
69
|
+
stub_request(:delete, "http://example.com/api/v3/#{url}").
|
70
|
+
with(:headers => {'Accept'=>'application/json', }, body: body).
|
71
|
+
to_return(:status => 200, :body => "{}", :headers => {'Content-Type' => 'application/json'})
|
72
|
+
end
|
73
|
+
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.
|
4
|
+
version: 0.0.3
|
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-01-
|
11
|
+
date: 2014-01-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: octokit
|
@@ -110,6 +110,7 @@ files:
|
|
110
110
|
- Rakefile
|
111
111
|
- lib/vx/service_connector.rb
|
112
112
|
- lib/vx/service_connector/base.rb
|
113
|
+
- lib/vx/service_connector/error.rb
|
113
114
|
- lib/vx/service_connector/github.rb
|
114
115
|
- lib/vx/service_connector/github/commits.rb
|
115
116
|
- lib/vx/service_connector/github/deploy_keys.rb
|
@@ -118,9 +119,15 @@ files:
|
|
118
119
|
- lib/vx/service_connector/github/notices.rb
|
119
120
|
- lib/vx/service_connector/github/payload.rb
|
120
121
|
- lib/vx/service_connector/github/repos.rb
|
121
|
-
- lib/vx/service_connector/
|
122
|
-
- lib/vx/service_connector/
|
123
|
-
- lib/vx/service_connector/
|
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
|
124
131
|
- lib/vx/service_connector/model.rb
|
125
132
|
- lib/vx/service_connector/version.rb
|
126
133
|
- spec/fixtures/github/add_deploy_key.json
|
@@ -137,17 +144,22 @@ files:
|
|
137
144
|
- spec/fixtures/github/payload/push.json
|
138
145
|
- spec/fixtures/github/payload/push_tag.json
|
139
146
|
- spec/fixtures/github/user_repos.json
|
140
|
-
- spec/fixtures/
|
141
|
-
- spec/fixtures/
|
147
|
+
- spec/fixtures/gitlab_v41/commits.json
|
148
|
+
- spec/fixtures/gitlab_v41/deploy_keys.json
|
149
|
+
- spec/fixtures/gitlab_v41/hooks.json
|
150
|
+
- spec/fixtures/gitlab_v41/payload/push.json
|
151
|
+
- spec/fixtures/gitlab_v41/projects.json
|
152
|
+
- spec/fixtures/gitlab_v41/user_keys.json
|
142
153
|
- spec/lib/github_payload_spec.rb
|
143
154
|
- spec/lib/github_spec.rb
|
144
|
-
- spec/lib/
|
155
|
+
- spec/lib/gitlab_v41_payload_spec.rb
|
156
|
+
- spec/lib/gitlab_v41_spec.rb
|
145
157
|
- spec/lib/model_spec.rb
|
146
158
|
- spec/lib/service_connector_spec.rb
|
147
159
|
- spec/spec_helper.rb
|
148
160
|
- spec/support/create.rb
|
149
161
|
- spec/support/github_web_mocks.rb
|
150
|
-
- spec/support/
|
162
|
+
- spec/support/gitlab_v41_web_mocks.rb
|
151
163
|
- spec/support/read_fixture.rb
|
152
164
|
- vx-service_connector.gemspec
|
153
165
|
homepage: ''
|
@@ -189,15 +201,20 @@ test_files:
|
|
189
201
|
- spec/fixtures/github/payload/push.json
|
190
202
|
- spec/fixtures/github/payload/push_tag.json
|
191
203
|
- spec/fixtures/github/user_repos.json
|
192
|
-
- spec/fixtures/
|
193
|
-
- spec/fixtures/
|
204
|
+
- spec/fixtures/gitlab_v41/commits.json
|
205
|
+
- spec/fixtures/gitlab_v41/deploy_keys.json
|
206
|
+
- spec/fixtures/gitlab_v41/hooks.json
|
207
|
+
- spec/fixtures/gitlab_v41/payload/push.json
|
208
|
+
- spec/fixtures/gitlab_v41/projects.json
|
209
|
+
- spec/fixtures/gitlab_v41/user_keys.json
|
194
210
|
- spec/lib/github_payload_spec.rb
|
195
211
|
- spec/lib/github_spec.rb
|
196
|
-
- spec/lib/
|
212
|
+
- spec/lib/gitlab_v41_payload_spec.rb
|
213
|
+
- spec/lib/gitlab_v41_spec.rb
|
197
214
|
- spec/lib/model_spec.rb
|
198
215
|
- spec/lib/service_connector_spec.rb
|
199
216
|
- spec/spec_helper.rb
|
200
217
|
- spec/support/create.rb
|
201
218
|
- spec/support/github_web_mocks.rb
|
202
|
-
- spec/support/
|
219
|
+
- spec/support/gitlab_v41_web_mocks.rb
|
203
220
|
- spec/support/read_fixture.rb
|
@@ -1,29 +0,0 @@
|
|
1
|
-
require 'gitlab'
|
2
|
-
|
3
|
-
module Vx
|
4
|
-
module ServiceConnector
|
5
|
-
GitlabV3 = Struct.new(:endpoint, :private_token) do
|
6
|
-
|
7
|
-
include ServiceConnector::Base
|
8
|
-
|
9
|
-
def repos
|
10
|
-
@repos ||= GitlabV3::Repos.new(session).to_a
|
11
|
-
end
|
12
|
-
|
13
|
-
def deploy_keys(repo)
|
14
|
-
GitlabV3::DeployKeys.new(session, repo)
|
15
|
-
end
|
16
|
-
|
17
|
-
private
|
18
|
-
|
19
|
-
def create_session
|
20
|
-
::Gitlab.client(:endpoint => "#{endpoint}/api/v3", private_token: private_token)
|
21
|
-
end
|
22
|
-
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
%w{ repos deploy_keys }.each do |f|
|
28
|
-
require File.expand_path("../gitlab_v3/#{f}", __FILE__)
|
29
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
module Vx
|
2
|
-
module ServiceConnector
|
3
|
-
class GitlabV3
|
4
|
-
DeployKeys = Struct.new(:session, :repo) do
|
5
|
-
|
6
|
-
def all
|
7
|
-
session.deploy_keys(repo.id)
|
8
|
-
end
|
9
|
-
|
10
|
-
def add(key_name, public_key)
|
11
|
-
session.create_deploy_key(repo.id, key_name, public_key)
|
12
|
-
end
|
13
|
-
|
14
|
-
def remove(key_name)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
@@ -1,28 +0,0 @@
|
|
1
|
-
module Vx
|
2
|
-
module ServiceConnector
|
3
|
-
class GitlabV3
|
4
|
-
Repos = Struct.new(:session) do
|
5
|
-
|
6
|
-
def to_a
|
7
|
-
session.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
|
-
repo.path_with_namespace,
|
18
|
-
true,
|
19
|
-
repo.ssh_url_to_repo,
|
20
|
-
repo.web_url,
|
21
|
-
repo.description
|
22
|
-
)
|
23
|
-
end
|
24
|
-
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
@@ -1,72 +0,0 @@
|
|
1
|
-
[
|
2
|
-
{
|
3
|
-
"id": 4,
|
4
|
-
"description": "description",
|
5
|
-
"default_branch": "master",
|
6
|
-
"public": false,
|
7
|
-
"visibility_level": 0,
|
8
|
-
"ssh_url_to_repo": "git@example.com:diaspora/diaspora-client.git",
|
9
|
-
"http_url_to_repo": "http://example.com/diaspora/diaspora-client.git",
|
10
|
-
"web_url": "http://example.com/diaspora/diaspora-client",
|
11
|
-
"owner": {
|
12
|
-
"id": 3,
|
13
|
-
"name": "Diaspora",
|
14
|
-
"created_at": "2013-09-30T13: 46: 02Z"
|
15
|
-
},
|
16
|
-
"name": "Diaspora Client",
|
17
|
-
"name_with_namespace": "Diaspora / Diaspora Client",
|
18
|
-
"path": "diaspora-client",
|
19
|
-
"path_with_namespace": "diaspora/diaspora-client",
|
20
|
-
"issues_enabled": true,
|
21
|
-
"merge_requests_enabled": true,
|
22
|
-
"wall_enabled": false,
|
23
|
-
"wiki_enabled": true,
|
24
|
-
"snippets_enabled": false,
|
25
|
-
"created_at": "2013-09-30T13: 46: 02Z",
|
26
|
-
"last_activity_at": "2013-09-30T13: 46: 02Z",
|
27
|
-
"namespace": {
|
28
|
-
"created_at": "2013-09-30T13: 46: 02Z",
|
29
|
-
"description": "",
|
30
|
-
"id": 3,
|
31
|
-
"name": "Diaspora",
|
32
|
-
"owner_id": 1,
|
33
|
-
"path": "diaspora",
|
34
|
-
"updated_at": "2013-09-30T13: 46: 02Z"
|
35
|
-
}
|
36
|
-
},
|
37
|
-
{
|
38
|
-
"id": 6,
|
39
|
-
"description": "description",
|
40
|
-
"default_branch": "master",
|
41
|
-
"public": false,
|
42
|
-
"visibility_level": 0,
|
43
|
-
"ssh_url_to_repo": "git@example.com:brightbox/puppet.git",
|
44
|
-
"http_url_to_repo": "http://example.com/brightbox/puppet.git",
|
45
|
-
"web_url": "http://example.com/brightbox/puppet",
|
46
|
-
"owner": {
|
47
|
-
"id": 4,
|
48
|
-
"name": "Brightbox",
|
49
|
-
"created_at": "2013-09-30T13:46:02Z"
|
50
|
-
},
|
51
|
-
"name": "Puppet",
|
52
|
-
"name_with_namespace": "Brightbox / Puppet",
|
53
|
-
"path": "puppet",
|
54
|
-
"path_with_namespace": "brightbox/puppet",
|
55
|
-
"issues_enabled": true,
|
56
|
-
"merge_requests_enabled": true,
|
57
|
-
"wall_enabled": false,
|
58
|
-
"wiki_enabled": true,
|
59
|
-
"snippets_enabled": false,
|
60
|
-
"created_at": "2013-09-30T13:46:02Z",
|
61
|
-
"last_activity_at": "2013-09-30T13:46:02Z",
|
62
|
-
"namespace": {
|
63
|
-
"created_at": "2013-09-30T13:46:02Z",
|
64
|
-
"description": "",
|
65
|
-
"id": 4,
|
66
|
-
"name": "Brightbox",
|
67
|
-
"owner_id": 1,
|
68
|
-
"path": "brightbox",
|
69
|
-
"updated_at": "2013-09-30T13:46:02Z"
|
70
|
-
}
|
71
|
-
}
|
72
|
-
]
|
data/spec/lib/gitlab_v3_spec.rb
DELETED
@@ -1,44 +0,0 @@
|
|
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
|
@@ -1,29 +0,0 @@
|
|
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
|