audc-gerry 0.1.6 → 0.1.8
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/README.md +62 -62
- data/Rakefile +7 -7
- data/lib/gerry/api/access.rb +17 -17
- data/lib/gerry/api/accounts.rb +38 -38
- data/lib/gerry/api/branches.rb +45 -45
- data/lib/gerry/api/changes.rb +38 -38
- data/lib/gerry/api/groups.rb +72 -72
- data/lib/gerry/api/projects.rb +73 -73
- data/lib/gerry/api/request.rb +86 -86
- data/lib/gerry/client.rb +58 -58
- data/lib/gerry/version.rb +5 -5
- data/lib/gerry.rb +11 -11
- data/spec/access_spec.rb +15 -15
- data/spec/accounts_spec.rb +35 -35
- data/spec/branches_spec.rb +36 -36
- data/spec/changes_spec.rb +55 -55
- data/spec/fixtures/README.md.json +2 -2
- data/spec/fixtures/access_rights.json +250 -250
- data/spec/fixtures/account_groups.json +32 -32
- data/spec/fixtures/branch_access.json +50 -50
- data/spec/fixtures/capabilities.json +7 -7
- data/spec/fixtures/changes.json +30 -30
- data/spec/fixtures/changes_batch_0.json +18 -18
- data/spec/fixtures/changes_batch_1.json +18 -18
- data/spec/fixtures/changes_batch_2.json +17 -17
- data/spec/fixtures/group_members.json +14 -14
- data/spec/fixtures/groups.json +68 -68
- data/spec/fixtures/open_changes.json +16 -16
- data/spec/fixtures/project_branch.json +6 -6
- data/spec/fixtures/project_branches.json +21 -21
- data/spec/fixtures/project_head.json +2 -2
- data/spec/fixtures/projects.json +9 -9
- data/spec/fixtures/query_capabilities.json +4 -4
- data/spec/groups_spec.rb +92 -92
- data/spec/projects_spec.rb +90 -90
- data/spec/request_spec.rb +46 -46
- data/spec/spec_helper.rb +49 -49
- metadata +52 -54
data/lib/gerry/api/projects.rb
CHANGED
|
@@ -1,73 +1,73 @@
|
|
|
1
|
-
module Gerry
|
|
2
|
-
module Api
|
|
3
|
-
module Projects
|
|
4
|
-
# Get the projects accessible by the caller.
|
|
5
|
-
#
|
|
6
|
-
# @return [Hash] the projects.
|
|
7
|
-
def projects
|
|
8
|
-
get('/projects/')
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
# Get the projects that start with the specified prefix
|
|
12
|
-
# and accessible by the caller.
|
|
13
|
-
#
|
|
14
|
-
# @param [String] name the project name.
|
|
15
|
-
# @return [Hash] the projects.
|
|
16
|
-
def find_project(name)
|
|
17
|
-
get("/projects/#{name}")
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
# Get the symbolic HEAD ref for the specified project.
|
|
21
|
-
#
|
|
22
|
-
# @param [String] project the project name.
|
|
23
|
-
# @return [String] the current ref to which HEAD points to.
|
|
24
|
-
def get_head(project)
|
|
25
|
-
get("/projects/#{project}/HEAD")
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
# Set the symbolic HEAD ref for the specified project to
|
|
29
|
-
# point to the specified branch.
|
|
30
|
-
#
|
|
31
|
-
# @param [String] project the project name.
|
|
32
|
-
# @param [String] branch the branch to point to.
|
|
33
|
-
# @return [String] the new ref to which HEAD points to.
|
|
34
|
-
def set_head(project, branch)
|
|
35
|
-
url = "/projects/#{project}/HEAD"
|
|
36
|
-
body = {
|
|
37
|
-
ref: 'refs/heads/' + branch
|
|
38
|
-
}
|
|
39
|
-
put(url, body)
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
##
|
|
43
|
-
# lists the access rights for signle project
|
|
44
|
-
def project_access(project)
|
|
45
|
-
get("/projects/#{project}/access")
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
def create_project_access(project, permissions)
|
|
49
|
-
access = {
|
|
50
|
-
'add' => permissions
|
|
51
|
-
}
|
|
52
|
-
post("/projects/#{project}/access", access)
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
def remove_project_access(project, permissions)
|
|
56
|
-
access = {
|
|
57
|
-
'remove' => permissions
|
|
58
|
-
}
|
|
59
|
-
post("/projects/#{project}/access", access)
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
##
|
|
63
|
-
# Retrieves a commit of a project.
|
|
64
|
-
def project_commit(project, commit_id)
|
|
65
|
-
get("/projects/#{project}/commits/#{commit_id}")
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
def project_file(project, commit_id, file_id)
|
|
69
|
-
get("/projects/#{project}/commits/#{commit_id}/files/#{file_id}/content")
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
end
|
|
73
|
-
end
|
|
1
|
+
module Gerry
|
|
2
|
+
module Api
|
|
3
|
+
module Projects
|
|
4
|
+
# Get the projects accessible by the caller.
|
|
5
|
+
#
|
|
6
|
+
# @return [Hash] the projects.
|
|
7
|
+
def projects
|
|
8
|
+
get('/projects/')
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
# Get the projects that start with the specified prefix
|
|
12
|
+
# and accessible by the caller.
|
|
13
|
+
#
|
|
14
|
+
# @param [String] name the project name.
|
|
15
|
+
# @return [Hash] the projects.
|
|
16
|
+
def find_project(name)
|
|
17
|
+
get("/projects/#{name}")
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# Get the symbolic HEAD ref for the specified project.
|
|
21
|
+
#
|
|
22
|
+
# @param [String] project the project name.
|
|
23
|
+
# @return [String] the current ref to which HEAD points to.
|
|
24
|
+
def get_head(project)
|
|
25
|
+
get("/projects/#{project}/HEAD")
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# Set the symbolic HEAD ref for the specified project to
|
|
29
|
+
# point to the specified branch.
|
|
30
|
+
#
|
|
31
|
+
# @param [String] project the project name.
|
|
32
|
+
# @param [String] branch the branch to point to.
|
|
33
|
+
# @return [String] the new ref to which HEAD points to.
|
|
34
|
+
def set_head(project, branch)
|
|
35
|
+
url = "/projects/#{project}/HEAD"
|
|
36
|
+
body = {
|
|
37
|
+
ref: 'refs/heads/' + branch
|
|
38
|
+
}
|
|
39
|
+
put(url, body)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
##
|
|
43
|
+
# lists the access rights for signle project
|
|
44
|
+
def project_access(project)
|
|
45
|
+
get("/projects/#{project}/access")
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def create_project_access(project, permissions)
|
|
49
|
+
access = {
|
|
50
|
+
'add' => permissions
|
|
51
|
+
}
|
|
52
|
+
post("/projects/#{project}/access", access)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def remove_project_access(project, permissions)
|
|
56
|
+
access = {
|
|
57
|
+
'remove' => permissions
|
|
58
|
+
}
|
|
59
|
+
post("/projects/#{project}/access", access)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
##
|
|
63
|
+
# Retrieves a commit of a project.
|
|
64
|
+
def project_commit(project, commit_id)
|
|
65
|
+
get("/projects/#{project}/commits/#{commit_id}")
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def project_file(project, commit_id, file_id)
|
|
69
|
+
get("/projects/#{project}/commits/#{commit_id}/files/#{file_id}/content")
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
data/lib/gerry/api/request.rb
CHANGED
|
@@ -1,86 +1,86 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Gerry
|
|
4
|
-
module Api
|
|
5
|
-
module Request # :nodoc:
|
|
6
|
-
class RequestError < StandardError
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
# Get the mapped options.
|
|
10
|
-
#
|
|
11
|
-
# @param [Array] or [Hash] options the query parameters.
|
|
12
|
-
# @return [String] the mapped options.
|
|
13
|
-
def map_options(options)
|
|
14
|
-
if options.is_a?(Array)
|
|
15
|
-
options.map { |v| "#{v}" }.join('&')
|
|
16
|
-
elsif options.is_a?(Hash)
|
|
17
|
-
options.map { |k,v| "#{k}=#{v.join(',')}" }.join('&')
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def options(body = nil, is_json = true)
|
|
22
|
-
return {} unless body
|
|
23
|
-
default_options = {
|
|
24
|
-
headers: {
|
|
25
|
-
'Content-Type' => is_json ? 'application/json' : 'text/plain'
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
default_options[:body] = is_json ? body.to_json : body
|
|
29
|
-
default_options
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
def get(url)
|
|
33
|
-
response = self.class.get(auth_url(url))
|
|
34
|
-
parse(response)
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
def auth_url(url)
|
|
38
|
-
self.class.default_options[:basic_auth] ? "/a#{url}" : url
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
def put(url, body = nil, is_json = true)
|
|
42
|
-
response = self.class.put(auth_url(url), options(body, is_json))
|
|
43
|
-
parse(response)
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
def post(url, body, is_json = true)
|
|
47
|
-
response = self.class.post(auth_url(url), options(body, is_json))
|
|
48
|
-
parse(response)
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
def delete(url)
|
|
52
|
-
response = self.class.delete(auth_url(url))
|
|
53
|
-
parse(response)
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
private
|
|
57
|
-
|
|
58
|
-
def parse(response)
|
|
59
|
-
unless /2[0-9][0-9]/.match(response.code.to_s)
|
|
60
|
-
raise_request_error(response)
|
|
61
|
-
end
|
|
62
|
-
return nil if !response.body || response.body.size.zero?
|
|
63
|
-
|
|
64
|
-
source = remove_magic_prefix(response.body)
|
|
65
|
-
if source.lines.count == 1 && !source.start_with?('{') && !source.start_with?('[')
|
|
66
|
-
# Work around the JSON gem not being able to parse top-level values, see
|
|
67
|
-
# https://github.com/flori/json/issues/206.
|
|
68
|
-
source.gsub!(/^"|"$/, '')
|
|
69
|
-
else
|
|
70
|
-
JSON.parse(source)
|
|
71
|
-
end
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
def raise_request_error(response)
|
|
75
|
-
raise RequestError.new("There was a request error! Response was: #{response.message}")
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
def remove_magic_prefix(response_body)
|
|
79
|
-
# We need to strip the magic prefix from the first line of the response, see
|
|
80
|
-
# https://gerrit-review.googlesource.com/Documentation/rest-api.html#output.
|
|
81
|
-
# magic prefix: )]}
|
|
82
|
-
response_body[4..-1].strip!
|
|
83
|
-
end
|
|
84
|
-
end
|
|
85
|
-
end
|
|
86
|
-
end
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Gerry
|
|
4
|
+
module Api
|
|
5
|
+
module Request # :nodoc:
|
|
6
|
+
class RequestError < StandardError
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
# Get the mapped options.
|
|
10
|
+
#
|
|
11
|
+
# @param [Array] or [Hash] options the query parameters.
|
|
12
|
+
# @return [String] the mapped options.
|
|
13
|
+
def map_options(options)
|
|
14
|
+
if options.is_a?(Array)
|
|
15
|
+
options.map { |v| "#{v}" }.join('&')
|
|
16
|
+
elsif options.is_a?(Hash)
|
|
17
|
+
options.map { |k,v| "#{k}=#{v.join(',')}" }.join('&')
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def options(body = nil, is_json = true)
|
|
22
|
+
return {} unless body
|
|
23
|
+
default_options = {
|
|
24
|
+
headers: {
|
|
25
|
+
'Content-Type' => is_json ? 'application/json' : 'text/plain'
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
default_options[:body] = is_json ? body.to_json : body
|
|
29
|
+
default_options
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def get(url)
|
|
33
|
+
response = self.class.get(auth_url(url))
|
|
34
|
+
parse(response)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def auth_url(url)
|
|
38
|
+
self.class.default_options[:basic_auth] ? "/a#{url}" : url
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def put(url, body = nil, is_json = true)
|
|
42
|
+
response = self.class.put(auth_url(url), options(body, is_json))
|
|
43
|
+
parse(response)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def post(url, body, is_json = true)
|
|
47
|
+
response = self.class.post(auth_url(url), options(body, is_json))
|
|
48
|
+
parse(response)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def delete(url)
|
|
52
|
+
response = self.class.delete(auth_url(url))
|
|
53
|
+
parse(response)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
private
|
|
57
|
+
|
|
58
|
+
def parse(response)
|
|
59
|
+
unless /2[0-9][0-9]/.match(response.code.to_s)
|
|
60
|
+
raise_request_error(response)
|
|
61
|
+
end
|
|
62
|
+
return nil if !response.body || response.body.size.zero?
|
|
63
|
+
|
|
64
|
+
source = remove_magic_prefix(response.body)
|
|
65
|
+
if source.lines.count == 1 && !source.start_with?('{') && !source.start_with?('[')
|
|
66
|
+
# Work around the JSON gem not being able to parse top-level values, see
|
|
67
|
+
# https://github.com/flori/json/issues/206.
|
|
68
|
+
source.gsub!(/^"|"$/, '')
|
|
69
|
+
else
|
|
70
|
+
JSON.parse(source)
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def raise_request_error(response)
|
|
75
|
+
raise RequestError.new("There was a request error! Response was: #{response.message}. Body: #{response.body}")
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def remove_magic_prefix(response_body)
|
|
79
|
+
# We need to strip the magic prefix from the first line of the response, see
|
|
80
|
+
# https://gerrit-review.googlesource.com/Documentation/rest-api.html#output.
|
|
81
|
+
# magic prefix: )]}
|
|
82
|
+
response_body[4..-1].strip!
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
end
|
data/lib/gerry/client.rb
CHANGED
|
@@ -1,58 +1,58 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'httparty'
|
|
4
|
-
require 'json'
|
|
5
|
-
|
|
6
|
-
require_relative 'api/access'
|
|
7
|
-
require_relative 'api/accounts'
|
|
8
|
-
require_relative 'api/changes'
|
|
9
|
-
require_relative 'api/groups'
|
|
10
|
-
require_relative 'api/projects'
|
|
11
|
-
require_relative 'api/request'
|
|
12
|
-
require_relative 'api/branches'
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
module Gerry
|
|
16
|
-
##
|
|
17
|
-
# Client for gerrit request api
|
|
18
|
-
#
|
|
19
|
-
# - for anonymout user
|
|
20
|
-
# client = Gerry::Client.new('http://gerrit.example.com')
|
|
21
|
-
# - for user/password
|
|
22
|
-
# client = Gerry::Client.new('http://gerrit.example.com', 'username', 'password')
|
|
23
|
-
#
|
|
24
|
-
#
|
|
25
|
-
|
|
26
|
-
class Client
|
|
27
|
-
include HTTParty
|
|
28
|
-
headers 'Accept' => 'application/json'
|
|
29
|
-
|
|
30
|
-
include Api::Access
|
|
31
|
-
include Api::Accounts
|
|
32
|
-
include Api::Changes
|
|
33
|
-
include Api::Groups
|
|
34
|
-
include Api::Projects
|
|
35
|
-
include Api::Branches
|
|
36
|
-
include Api::Request
|
|
37
|
-
|
|
38
|
-
def set_auth_type(auth_type)
|
|
39
|
-
warn 'set_auth_type is deprecated. digest auth is no longer supported'
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
def initialize(url, username = nil, password = nil)
|
|
43
|
-
self.class.base_uri(url)
|
|
44
|
-
|
|
45
|
-
if username && password
|
|
46
|
-
@username = username
|
|
47
|
-
@password = password
|
|
48
|
-
else
|
|
49
|
-
require 'netrc'
|
|
50
|
-
@username, @password = Netrc.read[URI.parse(url).host]
|
|
51
|
-
end
|
|
52
|
-
if @username && @password
|
|
53
|
-
self.class.basic_auth(@username, @password)
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
end
|
|
58
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'httparty'
|
|
4
|
+
require 'json'
|
|
5
|
+
|
|
6
|
+
require_relative 'api/access'
|
|
7
|
+
require_relative 'api/accounts'
|
|
8
|
+
require_relative 'api/changes'
|
|
9
|
+
require_relative 'api/groups'
|
|
10
|
+
require_relative 'api/projects'
|
|
11
|
+
require_relative 'api/request'
|
|
12
|
+
require_relative 'api/branches'
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
module Gerry
|
|
16
|
+
##
|
|
17
|
+
# Client for gerrit request api
|
|
18
|
+
#
|
|
19
|
+
# - for anonymout user
|
|
20
|
+
# client = Gerry::Client.new('http://gerrit.example.com')
|
|
21
|
+
# - for user/password
|
|
22
|
+
# client = Gerry::Client.new('http://gerrit.example.com', 'username', 'password')
|
|
23
|
+
#
|
|
24
|
+
#
|
|
25
|
+
|
|
26
|
+
class Client
|
|
27
|
+
include HTTParty
|
|
28
|
+
headers 'Accept' => 'application/json'
|
|
29
|
+
|
|
30
|
+
include Api::Access
|
|
31
|
+
include Api::Accounts
|
|
32
|
+
include Api::Changes
|
|
33
|
+
include Api::Groups
|
|
34
|
+
include Api::Projects
|
|
35
|
+
include Api::Branches
|
|
36
|
+
include Api::Request
|
|
37
|
+
|
|
38
|
+
def set_auth_type(auth_type)
|
|
39
|
+
warn 'set_auth_type is deprecated. digest auth is no longer supported'
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def initialize(url, username = nil, password = nil)
|
|
43
|
+
self.class.base_uri(url)
|
|
44
|
+
|
|
45
|
+
if username && password
|
|
46
|
+
@username = username
|
|
47
|
+
@password = password
|
|
48
|
+
else
|
|
49
|
+
require 'netrc'
|
|
50
|
+
@username, @password = Netrc.read[URI.parse(url).host]
|
|
51
|
+
end
|
|
52
|
+
if @username && @password
|
|
53
|
+
self.class.basic_auth(@username, @password)
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
data/lib/gerry/version.rb
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
module Gerry
|
|
2
|
-
|
|
3
|
-
VERSION = "0.1.
|
|
4
|
-
|
|
5
|
-
end
|
|
1
|
+
module Gerry
|
|
2
|
+
|
|
3
|
+
VERSION = "0.1.8"
|
|
4
|
+
|
|
5
|
+
end
|
data/lib/gerry.rb
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
require_relative 'gerry/client'
|
|
2
|
-
|
|
3
|
-
module Gerry
|
|
4
|
-
class << self
|
|
5
|
-
# Alias for Gerry::Client.new
|
|
6
|
-
#
|
|
7
|
-
# @return [Gerry::Client]
|
|
8
|
-
def new(url, username = nil, password = nil)
|
|
9
|
-
Gerry::Client.new(url, username, password)
|
|
10
|
-
end
|
|
11
|
-
end
|
|
1
|
+
require_relative 'gerry/client'
|
|
2
|
+
|
|
3
|
+
module Gerry
|
|
4
|
+
class << self
|
|
5
|
+
# Alias for Gerry::Client.new
|
|
6
|
+
#
|
|
7
|
+
# @return [Gerry::Client]
|
|
8
|
+
def new(url, username = nil, password = nil)
|
|
9
|
+
Gerry::Client.new(url, username, password)
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
12
|
end
|
data/spec/access_spec.rb
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
describe '.list_access_rights' do
|
|
4
|
-
it 'lists the access rights for projects' do
|
|
5
|
-
projects = ['All-Projects', 'MyProject']
|
|
6
|
-
stub = stub_get("/access/?project=#{projects.join('&project=')}", 'access_rights.json')
|
|
7
|
-
|
|
8
|
-
client = MockGerry.new
|
|
9
|
-
access_rights = client.access(projects)
|
|
10
|
-
expect(stub).to have_been_requested
|
|
11
|
-
|
|
12
|
-
expect(access_rights['All-Projects']['revision']).to eq('edd453d18e08640e67a8c9a150cec998ed0ac9aa')
|
|
13
|
-
expect(access_rights['MyProject']['revision']).to eq('61157ed63e14d261b6dca40650472a9b0bd88474')
|
|
14
|
-
end
|
|
15
|
-
end
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe '.list_access_rights' do
|
|
4
|
+
it 'lists the access rights for projects' do
|
|
5
|
+
projects = ['All-Projects', 'MyProject']
|
|
6
|
+
stub = stub_get("/access/?project=#{projects.join('&project=')}", 'access_rights.json')
|
|
7
|
+
|
|
8
|
+
client = MockGerry.new
|
|
9
|
+
access_rights = client.access(projects)
|
|
10
|
+
expect(stub).to have_been_requested
|
|
11
|
+
|
|
12
|
+
expect(access_rights['All-Projects']['revision']).to eq('edd453d18e08640e67a8c9a150cec998ed0ac9aa')
|
|
13
|
+
expect(access_rights['MyProject']['revision']).to eq('61157ed63e14d261b6dca40650472a9b0bd88474')
|
|
14
|
+
end
|
|
15
|
+
end
|
data/spec/accounts_spec.rb
CHANGED
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
describe '.account_capabilities' do
|
|
4
|
-
it 'should fetch all account capabilities' do
|
|
5
|
-
stub = stub_get('/accounts/self/capabilities', 'capabilities.json')
|
|
6
|
-
|
|
7
|
-
client = MockGerry.new
|
|
8
|
-
capabilities = client.account_capabilities
|
|
9
|
-
|
|
10
|
-
expect(capabilities['queryLimit']['min']).to eq(0)
|
|
11
|
-
expect(capabilities['queryLimit']['max']).to eq(500)
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
it 'should fetch some account capabilities' do
|
|
15
|
-
stub = stub_get('/accounts/self/capabilities?q=createAccount&q=createGroup', 'query_capabilities.json')
|
|
16
|
-
|
|
17
|
-
client = MockGerry.new
|
|
18
|
-
capabilities = client.account_capabilities(['q=createAccount', 'q=createGroup'])
|
|
19
|
-
expect(stub).to have_been_requested
|
|
20
|
-
|
|
21
|
-
expect(capabilities['createAccount']).to eq(true)
|
|
22
|
-
expect(capabilities['createGroup']).to eq(true)
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
describe '.groups_for_account' do
|
|
27
|
-
it "fetches all groups for which the account is a member" do
|
|
28
|
-
user = "jane.roe@example.com"
|
|
29
|
-
|
|
30
|
-
stub = stub_get("/accounts/#{user}/groups/", "account_groups.json")
|
|
31
|
-
|
|
32
|
-
client = MockGerry.new
|
|
33
|
-
new_group = client.groups_for_account(user)
|
|
34
|
-
expect(stub).to have_been_requested
|
|
35
|
-
end
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe '.account_capabilities' do
|
|
4
|
+
it 'should fetch all account capabilities' do
|
|
5
|
+
stub = stub_get('/accounts/self/capabilities', 'capabilities.json')
|
|
6
|
+
|
|
7
|
+
client = MockGerry.new
|
|
8
|
+
capabilities = client.account_capabilities
|
|
9
|
+
|
|
10
|
+
expect(capabilities['queryLimit']['min']).to eq(0)
|
|
11
|
+
expect(capabilities['queryLimit']['max']).to eq(500)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
it 'should fetch some account capabilities' do
|
|
15
|
+
stub = stub_get('/accounts/self/capabilities?q=createAccount&q=createGroup', 'query_capabilities.json')
|
|
16
|
+
|
|
17
|
+
client = MockGerry.new
|
|
18
|
+
capabilities = client.account_capabilities(['q=createAccount', 'q=createGroup'])
|
|
19
|
+
expect(stub).to have_been_requested
|
|
20
|
+
|
|
21
|
+
expect(capabilities['createAccount']).to eq(true)
|
|
22
|
+
expect(capabilities['createGroup']).to eq(true)
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
describe '.groups_for_account' do
|
|
27
|
+
it "fetches all groups for which the account is a member" do
|
|
28
|
+
user = "jane.roe@example.com"
|
|
29
|
+
|
|
30
|
+
stub = stub_get("/accounts/#{user}/groups/", "account_groups.json")
|
|
31
|
+
|
|
32
|
+
client = MockGerry.new
|
|
33
|
+
new_group = client.groups_for_account(user)
|
|
34
|
+
expect(stub).to have_been_requested
|
|
35
|
+
end
|
|
36
36
|
end
|
data/spec/branches_spec.rb
CHANGED
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
describe 'branches' do
|
|
4
|
-
before(:all) do
|
|
5
|
-
@client = MockGerry.new
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
it 'fetchs all branches' do
|
|
9
|
-
stub = stub_get('/projects/foo/branches', 'project_branches.json')
|
|
10
|
-
|
|
11
|
-
groups = @client.branches('foo')
|
|
12
|
-
expect(stub).to have_been_requested
|
|
13
|
-
|
|
14
|
-
expect(groups.size).to eq(3)
|
|
15
|
-
expect(groups.first.fetch('ref')).to eq('master')
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
it 'create branch' do
|
|
19
|
-
body = {
|
|
20
|
-
ref: 'master'
|
|
21
|
-
}
|
|
22
|
-
response = %Q<)]}'
|
|
23
|
-
{
|
|
24
|
-
"ref": "/refs/heads/stable",
|
|
25
|
-
"revision": "b43",
|
|
26
|
-
"can_delete": true
|
|
27
|
-
}
|
|
28
|
-
>
|
|
29
|
-
stub = stub_put('/projects/foo/branches/stable', body, response)
|
|
30
|
-
branch = @client.create_branch('foo', 'master', 'stable')
|
|
31
|
-
|
|
32
|
-
expect(stub).to have_been_requested
|
|
33
|
-
|
|
34
|
-
expect(branch.fetch('ref')).to eql('/refs/heads/stable')
|
|
35
|
-
end
|
|
36
|
-
end
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe 'branches' do
|
|
4
|
+
before(:all) do
|
|
5
|
+
@client = MockGerry.new
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
it 'fetchs all branches' do
|
|
9
|
+
stub = stub_get('/projects/foo/branches', 'project_branches.json')
|
|
10
|
+
|
|
11
|
+
groups = @client.branches('foo')
|
|
12
|
+
expect(stub).to have_been_requested
|
|
13
|
+
|
|
14
|
+
expect(groups.size).to eq(3)
|
|
15
|
+
expect(groups.first.fetch('ref')).to eq('master')
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it 'create branch' do
|
|
19
|
+
body = {
|
|
20
|
+
ref: 'master'
|
|
21
|
+
}
|
|
22
|
+
response = %Q<)]}'
|
|
23
|
+
{
|
|
24
|
+
"ref": "/refs/heads/stable",
|
|
25
|
+
"revision": "b43",
|
|
26
|
+
"can_delete": true
|
|
27
|
+
}
|
|
28
|
+
>
|
|
29
|
+
stub = stub_put('/projects/foo/branches/stable', body, response)
|
|
30
|
+
branch = @client.create_branch('foo', 'master', 'stable')
|
|
31
|
+
|
|
32
|
+
expect(stub).to have_been_requested
|
|
33
|
+
|
|
34
|
+
expect(branch.fetch('ref')).to eql('/refs/heads/stable')
|
|
35
|
+
end
|
|
36
|
+
end
|