gerry 0.0.3 → 0.0.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 702aaae3f3f3ee526dbf3e7e4cc992abe99b7a31
4
- data.tar.gz: 80dbe7f9b6e0bb8bfb26fa730cec895024dd4b4a
3
+ metadata.gz: b7d5a26248ca8569e79405d01127cc7e15a3e985
4
+ data.tar.gz: 1af2e09f12d470b7effd4ca6349fd926027345a5
5
5
  SHA512:
6
- metadata.gz: c16e1ffe1e8cc8d9096b5ec7d7413c25e273436aa61203355dc86e48283a8e5cfd0388f08fce1657989c055f721068361aff111b123d21b0605cf62d7a3c58b4
7
- data.tar.gz: a721f594ca1c4cc1a09c9854d180b9755e70d48c0d3ae9936308502efb7047def937325fb40c629855e2c87366de9352a9a4bae20a62b7c9f5efa92348fc2ada
6
+ metadata.gz: 1fa7b2004e3ee74dfb975fab016e168919f3e7192e4701d53d766f1b23def124fac756b8eaf4f8693fe2add30726e25b68980a8e96fd0955260e9a90a538ad6d
7
+ data.tar.gz: 2d7c4734217f7197607532c0f0d281cbf151c91496bb02f86222a0e5803130fccfe5aff6b1c16b4749fb156244eb46f40c7c3858ad64a98f5061f0a467e87c7f
@@ -0,0 +1,17 @@
1
+ require 'erb'
2
+
3
+ module Gerry
4
+ class Client
5
+ module Access
6
+ # Get access rights for the specified project
7
+ #
8
+ # @param [VarArgs] projects the project names
9
+ # @return [Hash] the list of access rights
10
+ def access(*projects)
11
+ projects = projects.flatten.map { |name| ERB::Util.url_encode(name) }
12
+ url = "/access/?project=#{projects.join('&project=')}"
13
+ get(url)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -13,9 +13,24 @@ module Gerry
13
13
 
14
14
  # Get all members for a group
15
15
  #
16
+ # @param [Array] options the query parameters
16
17
  # @return [Array] the members
17
- def group_members(group_id)
18
+ def group_members(group_id, options = [])
18
19
  url = "/groups/#{group_id}/members/"
20
+
21
+ if options.empty?
22
+ return get(url)
23
+ end
24
+
25
+ options = map_options(options)
26
+ get("#{url}?#{options}")
27
+ end
28
+
29
+ # Get the directly included groups of a group
30
+ #
31
+ # @return [Array] the included groups
32
+ def included_groups(group_id)
33
+ url = "/groups/#{group_id}/groups/"
19
34
  get(url)
20
35
  end
21
36
 
@@ -7,8 +7,8 @@ module Gerry
7
7
  def projects
8
8
  get('/projects/')
9
9
  end
10
-
11
- # Get the projects that start with the specified prefix
10
+
11
+ # Get the projects that start with the specified prefix
12
12
  # and accessible by the caller.
13
13
  #
14
14
  # @param [String] name the project name.
@@ -16,6 +16,28 @@ module Gerry
16
16
  def find_project(name)
17
17
  get("/projects/#{name}")
18
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
19
41
  end
20
42
  end
21
- end
43
+ end
@@ -27,14 +27,14 @@ module Gerry
27
27
  def put(url, body)
28
28
  if @username && @password
29
29
  auth = { username: @username, password: @password }
30
- response = self.class.put("/a#{url}",
31
- body: body.to_json,
30
+ response = self.class.put("/a#{url}",
31
+ body: body.to_json,
32
32
  headers: { 'Content-Type' => 'application/json' },
33
33
  digest_auth: auth
34
34
  )
35
35
  parse(response)
36
36
  else
37
- response = self.class.put(url,
37
+ response = self.class.put(url,
38
38
  body: body.to_json,
39
39
  headers: { 'Content-Type' => 'application/json' }
40
40
  )
@@ -45,14 +45,14 @@ module Gerry
45
45
  def post(url, body)
46
46
  if @username && @password
47
47
  auth = { username: @username, password: @password }
48
- response = self.class.post("/a#{url}",
49
- body: body.to_json,
48
+ response = self.class.post("/a#{url}",
49
+ body: body.to_json,
50
50
  headers: { 'Content-Type' => 'application/json' },
51
51
  digest_auth: auth
52
52
  )
53
53
  parse(response)
54
54
  else
55
- response = self.class.post(url,
55
+ response = self.class.post(url,
56
56
  body: body.to_json,
57
57
  headers: { 'Content-Type' => 'application/json' }
58
58
  )
@@ -65,21 +65,27 @@ module Gerry
65
65
  raise_request_error(response)
66
66
  end
67
67
  if response.body
68
- JSON.parse(remove_magic_prefix(response.body))
68
+ source = remove_magic_prefix(response.body)
69
+ if source.lines.count == 1 && !source.start_with?('{') && !source.start_with?('[')
70
+ # Work around the JSON gem not being able to parse top-level values, see
71
+ # https://github.com/flori/json/issues/206.
72
+ source.gsub!(/^"|"$/, '')
73
+ else
74
+ JSON.parse(source)
75
+ end
69
76
  else
70
77
  nil
71
78
  end
72
79
  end
73
80
 
74
81
  def raise_request_error(response)
75
- body = response.body
76
- raise RequestError.new("There was a request error! Response was: #{body}")
82
+ raise RequestError.new("There was a request error! Response was: #{response.message}")
77
83
  end
78
84
 
79
85
  def remove_magic_prefix(response_body)
80
86
  # We need to strip the magic prefix from the first line of the response, see
81
87
  # https://gerrit-review.googlesource.com/Documentation/rest-api.html#output.
82
- response_body.sub(/^\)\]\}'$/, '')
88
+ response_body.sub(/^\)\]\}'$/, '').strip!
83
89
  end
84
90
  end
85
91
  end
data/lib/gerry/client.rb CHANGED
@@ -5,26 +5,28 @@ module Gerry
5
5
  class Client
6
6
  include HTTParty
7
7
  headers 'Accept' => 'application/json'
8
-
8
+
9
+ require_relative 'client/access'
9
10
  require_relative 'client/accounts'
10
11
  require_relative 'client/changes'
11
12
  require_relative 'client/groups'
12
13
  require_relative 'client/projects'
13
14
  require_relative 'client/request'
14
-
15
+
16
+ include Access
15
17
  include Accounts
16
18
  include Changes
17
19
  include Groups
18
20
  include Projects
19
21
  include Request
20
-
22
+
21
23
  def initialize(url, username = nil, password = nil)
22
24
  self.class.base_uri(url)
23
-
24
- if username && password
25
+
26
+ if username && password
25
27
  @username = username
26
28
  @password = password
27
29
  end
28
30
  end
29
31
  end
30
- end
32
+ end
data/lib/gerry/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Gerry
2
2
 
3
- VERSION = "0.0.3"
3
+ VERSION = "0.0.4"
4
4
 
5
5
  end
@@ -0,0 +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
@@ -0,0 +1,250 @@
1
+ )]}'
2
+ {
3
+ "All-Projects": {
4
+ "revision": "edd453d18e08640e67a8c9a150cec998ed0ac9aa",
5
+ "local": {
6
+ "GLOBAL_CAPABILITIES": {
7
+ "permissions": {
8
+ "priority": {
9
+ "rules": {
10
+ "15bfcd8a6de1a69c50b30cedcdcc951c15703152": {
11
+ "action": "BATCH"
12
+ }
13
+ }
14
+ },
15
+ "streamEvents": {
16
+ "rules": {
17
+ "15bfcd8a6de1a69c50b30cedcdcc951c15703152": {
18
+ "action": "ALLOW"
19
+ }
20
+ }
21
+ },
22
+ "administrateServer": {
23
+ "rules": {
24
+ "53a4f647a89ea57992571187d8025f830625192a": {
25
+ "action": "ALLOW"
26
+ }
27
+ }
28
+ }
29
+ }
30
+ },
31
+ "refs/meta/config": {
32
+ "permissions": {
33
+ "submit": {
34
+ "rules": {
35
+ "53a4f647a89ea57992571187d8025f830625192a": {
36
+ "action": "ALLOW"
37
+ },
38
+ "global:Project-Owners": {
39
+ "action": "ALLOW"
40
+ }
41
+ }
42
+ },
43
+ "label-Code-Review": {
44
+ "label": "Code-Review",
45
+ "rules": {
46
+ "53a4f647a89ea57992571187d8025f830625192a": {
47
+ "action": "ALLOW",
48
+ "min": -2,
49
+ "max": 2
50
+ },
51
+ "global:Project-Owners": {
52
+ "action": "ALLOW",
53
+ "min": -2,
54
+ "max": 2
55
+ }
56
+ }
57
+ },
58
+ "read": {
59
+ "exclusive": true,
60
+ "rules": {
61
+ "53a4f647a89ea57992571187d8025f830625192a": {
62
+ "action": "ALLOW"
63
+ },
64
+ "global:Project-Owners": {
65
+ "action": "ALLOW"
66
+ }
67
+ }
68
+ },
69
+ "push": {
70
+ "rules": {
71
+ "53a4f647a89ea57992571187d8025f830625192a": {
72
+ "action": "ALLOW"
73
+ },
74
+ "global:Project-Owners": {
75
+ "action": "ALLOW"
76
+ }
77
+ }
78
+ }
79
+ }
80
+ },
81
+ "refs/for/refs/*": {
82
+ "permissions": {
83
+ "pushMerge": {
84
+ "rules": {
85
+ "global:Registered-Users": {
86
+ "action": "ALLOW"
87
+ }
88
+ }
89
+ },
90
+ "push": {
91
+ "rules": {
92
+ "global:Registered-Users": {
93
+ "action": "ALLOW"
94
+ }
95
+ }
96
+ }
97
+ }
98
+ },
99
+ "refs/tags/*": {
100
+ "permissions": {
101
+ "pushSignedTag": {
102
+ "rules": {
103
+ "53a4f647a89ea57992571187d8025f830625192a": {
104
+ "action": "ALLOW"
105
+ },
106
+ "global:Project-Owners": {
107
+ "action": "ALLOW"
108
+ }
109
+ }
110
+ },
111
+ "pushTag": {
112
+ "rules": {
113
+ "53a4f647a89ea57992571187d8025f830625192a": {
114
+ "action": "ALLOW"
115
+ },
116
+ "global:Project-Owners": {
117
+ "action": "ALLOW"
118
+ }
119
+ }
120
+ }
121
+ }
122
+ },
123
+ "refs/heads/*": {
124
+ "permissions": {
125
+ "forgeCommitter": {
126
+ "rules": {
127
+ "53a4f647a89ea57992571187d8025f830625192a": {
128
+ "action": "ALLOW"
129
+ },
130
+ "global:Project-Owners": {
131
+ "action": "ALLOW"
132
+ }
133
+ }
134
+ },
135
+ "forgeAuthor": {
136
+ "rules": {
137
+ "global:Registered-Users": {
138
+ "action": "ALLOW"
139
+ }
140
+ }
141
+ },
142
+ "submit": {
143
+ "rules": {
144
+ "53a4f647a89ea57992571187d8025f830625192a": {
145
+ "action": "ALLOW"
146
+ },
147
+ "global:Project-Owners": {
148
+ "action": "ALLOW"
149
+ }
150
+ }
151
+ },
152
+ "editTopicName": {
153
+ "rules": {
154
+ "53a4f647a89ea57992571187d8025f830625192a": {
155
+ "action": "ALLOW",
156
+ "force": true
157
+ },
158
+ "global:Project-Owners": {
159
+ "action": "ALLOW",
160
+ "force": true
161
+ }
162
+ }
163
+ },
164
+ "label-Code-Review": {
165
+ "label": "Code-Review",
166
+ "rules": {
167
+ "global:Registered-Users": {
168
+ "action": "ALLOW",
169
+ "min": -1,
170
+ "max": 1
171
+ },
172
+ "53a4f647a89ea57992571187d8025f830625192a": {
173
+ "action": "ALLOW",
174
+ "min": -2,
175
+ "max": 2
176
+ },
177
+ "global:Project-Owners": {
178
+ "action": "ALLOW",
179
+ "min": -2,
180
+ "max": 2
181
+ }
182
+ }
183
+ },
184
+ "create": {
185
+ "rules": {
186
+ "53a4f647a89ea57992571187d8025f830625192a": {
187
+ "action": "ALLOW"
188
+ },
189
+ "global:Project-Owners": {
190
+ "action": "ALLOW"
191
+ }
192
+ }
193
+ },
194
+ "push": {
195
+ "rules": {
196
+ "53a4f647a89ea57992571187d8025f830625192a": {
197
+ "action": "ALLOW"
198
+ },
199
+ "global:Project-Owners": {
200
+ "action": "ALLOW"
201
+ }
202
+ }
203
+ }
204
+ }
205
+ },
206
+ "refs/*": {
207
+ "permissions": {
208
+ "read": {
209
+ "rules": {
210
+ "global:Anonymous-Users": {
211
+ "action": "ALLOW"
212
+ },
213
+ "53a4f647a89ea57992571187d8025f830625192a": {
214
+ "action": "ALLOW"
215
+ }
216
+ }
217
+ }
218
+ }
219
+ }
220
+ },
221
+ "is_owner": true,
222
+ "owner_of": [
223
+ "GLOBAL_CAPABILITIES",
224
+ "refs/meta/config",
225
+ "refs/for/refs/*",
226
+ "refs/tags/*",
227
+ "refs/heads/*",
228
+ "refs/*"
229
+ ],
230
+ "can_upload": true,
231
+ "can_add": true,
232
+ "config_visible": true
233
+ },
234
+ "MyProject": {
235
+ "revision": "61157ed63e14d261b6dca40650472a9b0bd88474",
236
+ "inherits_from": {
237
+ "id": "All-Projects",
238
+ "name": "All-Projects",
239
+ "description": "Access inherited by all other projects."
240
+ },
241
+ "local": {},
242
+ "is_owner": true,
243
+ "owner_of": [
244
+ "refs/*"
245
+ ],
246
+ "can_upload": true,
247
+ "can_add": true,
248
+ "config_visible": true
249
+ }
250
+ }
@@ -0,0 +1,2 @@
1
+ )]}'
2
+ "refs/heads/stable"
@@ -1,9 +1,9 @@
1
1
  )]}'
2
2
  {
3
3
  "awesome": {
4
- "description": "Awesome project"
4
+ "description": "Awesome project"
5
5
  },
6
6
  "clean": {
7
- "description": "Clean code!"
7
+ "description": "Clean code!"
8
8
  }
9
9
  }
@@ -1,26 +1,54 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe '.projects' do
3
+ describe '.projects' do
4
4
  it 'should fetch all projects' do
5
- stub = stub_get('/projects/', 'projects.json')
6
-
5
+ stub = stub_get('/projects/', 'projects.json')
6
+
7
7
  client = MockGerry.new
8
8
  projects = client.projects
9
-
9
+
10
10
  expect(stub).to have_been_requested
11
-
11
+
12
12
  expect(projects['awesome']['description']).to eq('Awesome project')
13
13
  expect(projects['clean']['description']).to eq('Clean code!')
14
14
  end
15
-
15
+
16
16
  it 'should fetch a project' do
17
- stub = stub_get('/projects/awesome', 'projects.json')
18
-
17
+ stub = stub_get('/projects/awesome', 'projects.json')
18
+
19
19
  client = MockGerry.new
20
20
  projects = client.find_project('awesome')
21
-
21
+
22
22
  expect(stub).to have_been_requested
23
-
23
+
24
24
  expect(projects['awesome']['description']).to eq('Awesome project')
25
25
  end
26
- end
26
+
27
+ it 'should resolve the symbolic HEAD ref of a project' do
28
+ project = 'awesome'
29
+ stub = stub_get("/projects/#{project}/HEAD", 'project_head.json')
30
+
31
+ client = MockGerry.new
32
+ branch = client.get_head(project)
33
+
34
+ expect(stub).to have_been_requested
35
+
36
+ expect(branch).to eq('refs/heads/stable')
37
+ end
38
+
39
+ it 'should define the symbolic HEAD ref of a project' do
40
+ project = 'awesome'
41
+ branch = 'stable'
42
+ input = {
43
+ ref: 'refs/heads/' + branch
44
+ }
45
+ stub = stub_put("/projects/#{project}/HEAD", input.to_json, get_fixture('project_head.json'))
46
+
47
+ client = MockGerry.new
48
+ new_branch = client.set_head(project, branch)
49
+
50
+ expect(stub).to have_been_requested
51
+
52
+ expect(new_branch).to eq('refs/heads/' + branch)
53
+ end
54
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gerry
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fabian Mettler
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2015-06-12 00:00:00.000000000 Z
13
+ date: 2015-08-03 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: httparty
@@ -135,20 +135,24 @@ files:
135
135
  - Rakefile
136
136
  - lib/gerry.rb
137
137
  - lib/gerry/client.rb
138
+ - lib/gerry/client/access.rb
138
139
  - lib/gerry/client/accounts.rb
139
140
  - lib/gerry/client/changes.rb
140
141
  - lib/gerry/client/groups.rb
141
142
  - lib/gerry/client/projects.rb
142
143
  - lib/gerry/client/request.rb
143
144
  - lib/gerry/version.rb
145
+ - spec/access_spec.rb
144
146
  - spec/accounts_spec.rb
145
147
  - spec/changes_spec.rb
148
+ - spec/fixtures/access_rights.json
146
149
  - spec/fixtures/account_groups.json
147
150
  - spec/fixtures/capabilities.json
148
151
  - spec/fixtures/changes.json
149
152
  - spec/fixtures/group_members.json
150
153
  - spec/fixtures/groups.json
151
154
  - spec/fixtures/open_changes.json
155
+ - spec/fixtures/project_head.json
152
156
  - spec/fixtures/projects.json
153
157
  - spec/fixtures/query_capabilities.json
154
158
  - spec/groups_spec.rb
@@ -179,14 +183,17 @@ signing_key:
179
183
  specification_version: 4
180
184
  summary: Simple Ruby wrapper for the Gerrit Code Review REST-API.
181
185
  test_files:
186
+ - spec/access_spec.rb
182
187
  - spec/accounts_spec.rb
183
188
  - spec/changes_spec.rb
189
+ - spec/fixtures/access_rights.json
184
190
  - spec/fixtures/account_groups.json
185
191
  - spec/fixtures/capabilities.json
186
192
  - spec/fixtures/changes.json
187
193
  - spec/fixtures/group_members.json
188
194
  - spec/fixtures/groups.json
189
195
  - spec/fixtures/open_changes.json
196
+ - spec/fixtures/project_head.json
190
197
  - spec/fixtures/projects.json
191
198
  - spec/fixtures/query_capabilities.json
192
199
  - spec/groups_spec.rb