gerry 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +12 -7
- data/lib/gerry/client.rb +5 -0
- data/lib/gerry/client/changes.rb +2 -2
- data/lib/gerry/client/request.rb +18 -8
- data/lib/gerry/version.rb +2 -2
- data/spec/request_spec.rb +22 -2
- metadata +4 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7acb8ce23cd5d62c8c798fd0ec2c0894d7c3261b
|
4
|
+
data.tar.gz: 48ce2f02ba42cf6054eac0e43bbf1369db8349bb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fa5fbdc2557111413f6d49025b3e260d004eaead164998fdcf56ee65ead061d0dad52058b86a75759a0971c01ecb60b79a0f1de4a2f6183cff13c6c053bb48b3
|
7
|
+
data.tar.gz: 6a6362df52ea5469b09a6c8e1b64989f20b36c7f7025488f908ff64917d19fff979a9d294c641c7891ea97a39e843346cc4228ec3b1caeb045b4ef2231a6f1c4
|
data/README.md
CHANGED
@@ -39,10 +39,19 @@ client.changes(['q=is:open'])
|
|
39
39
|
=> [{"project"=>"awesome", "branch"=>"master", "id"=>"Ibfedd978...."}]
|
40
40
|
```
|
41
41
|
|
42
|
+
### Authentication type
|
43
|
+
Gerrit uses digest authentication by default. This can be changed by
|
44
|
+
configuring `auth.gitBasicAuth = true`. If the gerrit server uses
|
45
|
+
basic authentication, you need to specify it:
|
46
|
+
```ruby
|
47
|
+
client = Gerry.new('https://review', 'user', 'p455w0rd')
|
48
|
+
client.set_auth_type(:basic_auth)
|
49
|
+
```
|
50
|
+
|
42
51
|
## Licence
|
43
52
|
The MIT Licence
|
44
53
|
|
45
|
-
Copyright (c) Fabian Mettler, Andrew Erickson, Travis Truman, Sebastian Schuberth
|
54
|
+
Copyright (c) Fabian Mettler, Andrew Erickson, Travis Truman, Sebastian Schuberth, Orgad Shaneh
|
46
55
|
|
47
56
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
48
57
|
|
@@ -51,10 +60,6 @@ The above copyright notice and this permission notice shall be included in all c
|
|
51
60
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
52
61
|
|
53
62
|
## References
|
54
|
-
|
55
|
-
|
56
|
-
[gerrit]: http://code.google.com/p/gerrit/
|
57
|
-
|
58
|
-
[https://gerrit-review.googlesource.com/Documentation/rest-api.html][apidocumentation]
|
63
|
+
https://www.gerritcodereview.com/
|
59
64
|
|
60
|
-
|
65
|
+
https://gerrit-review.googlesource.com/Documentation/rest-api.html
|
data/lib/gerry/client.rb
CHANGED
@@ -20,8 +20,13 @@ module Gerry
|
|
20
20
|
include Projects
|
21
21
|
include Request
|
22
22
|
|
23
|
+
def set_auth_type(auth_type)
|
24
|
+
@auth_type = auth_type
|
25
|
+
end
|
26
|
+
|
23
27
|
def initialize(url, username = nil, password = nil)
|
24
28
|
self.class.base_uri(url)
|
29
|
+
@auth_type = :digest_auth
|
25
30
|
|
26
31
|
if username && password
|
27
32
|
@username = username
|
data/lib/gerry/client/changes.rb
CHANGED
@@ -16,7 +16,7 @@ module Gerry
|
|
16
16
|
end
|
17
17
|
|
18
18
|
response = get(url)
|
19
|
-
return response
|
19
|
+
return response if response.empty? || !response.last.delete('_more_changes')
|
20
20
|
|
21
21
|
# Get the original start parameter, if any, else start from 0.
|
22
22
|
query = URI.parse(url).query
|
@@ -30,7 +30,7 @@ module Gerry
|
|
30
30
|
url = endpoint + '?' + map_options(query)
|
31
31
|
|
32
32
|
response.concat(get(url))
|
33
|
-
return response
|
33
|
+
return response if response.empty? || !response.last.delete('_more_changes')
|
34
34
|
end
|
35
35
|
end
|
36
36
|
end
|
data/lib/gerry/client/request.rb
CHANGED
@@ -13,27 +13,23 @@ module Gerry
|
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
-
private
|
17
|
-
class RequestError < StandardError
|
18
|
-
end
|
19
|
-
|
20
16
|
def get(url)
|
21
17
|
response = if @username && @password
|
22
18
|
auth = { username: @username, password: @password }
|
23
|
-
self.class.get("/a#{url}",
|
19
|
+
self.class.get("/a#{url}", @auth_type => auth)
|
24
20
|
else
|
25
21
|
self.class.get(url)
|
26
22
|
end
|
27
23
|
parse(response)
|
28
24
|
end
|
29
25
|
|
30
|
-
def put(url, body)
|
26
|
+
def put(url, body = nil)
|
31
27
|
if @username && @password
|
32
28
|
auth = { username: @username, password: @password }
|
33
29
|
response = self.class.put("/a#{url}",
|
34
30
|
body: body.to_json,
|
35
31
|
headers: { 'Content-Type' => 'application/json' },
|
36
|
-
|
32
|
+
@auth_type => auth
|
37
33
|
)
|
38
34
|
parse(response)
|
39
35
|
else
|
@@ -51,7 +47,7 @@ module Gerry
|
|
51
47
|
response = self.class.post("/a#{url}",
|
52
48
|
body: body.to_json,
|
53
49
|
headers: { 'Content-Type' => 'application/json' },
|
54
|
-
|
50
|
+
@auth_type => auth
|
55
51
|
)
|
56
52
|
parse(response)
|
57
53
|
else
|
@@ -63,6 +59,20 @@ module Gerry
|
|
63
59
|
end
|
64
60
|
end
|
65
61
|
|
62
|
+
def delete(url)
|
63
|
+
response = if @username && @password
|
64
|
+
auth = { username: @username, password: @password }
|
65
|
+
self.class.delete("/a#{url}", @auth_type => auth)
|
66
|
+
else
|
67
|
+
self.class.delete(url)
|
68
|
+
end
|
69
|
+
parse(response)
|
70
|
+
end
|
71
|
+
|
72
|
+
private
|
73
|
+
class RequestError < StandardError
|
74
|
+
end
|
75
|
+
|
66
76
|
def parse(response)
|
67
77
|
unless /2[0-9][0-9]/.match(response.code.to_s)
|
68
78
|
raise_request_error(response)
|
data/lib/gerry/version.rb
CHANGED
data/spec/request_spec.rb
CHANGED
@@ -20,7 +20,7 @@ describe '.get' do
|
|
20
20
|
expect(stub).to have_been_requested
|
21
21
|
end
|
22
22
|
|
23
|
-
it 'should request projects as user' do
|
23
|
+
it 'should request projects as user with digest auth' do
|
24
24
|
username = 'gerry'
|
25
25
|
password = 'whoop'
|
26
26
|
|
@@ -39,4 +39,24 @@ describe '.get' do
|
|
39
39
|
expect(projects['awesome']['description']).to eq('Awesome project')
|
40
40
|
expect(projects['clean']['description']).to eq('Clean code!')
|
41
41
|
end
|
42
|
-
|
42
|
+
|
43
|
+
it 'should request projects as user with basic auth' do
|
44
|
+
username = 'gerry'
|
45
|
+
password = 'whoop'
|
46
|
+
|
47
|
+
body = get_fixture('projects.json')
|
48
|
+
|
49
|
+
stub = stub_request(:get, "http://#{username}:#{password}@localhost/a/projects/").
|
50
|
+
with(:headers => {'Accept'=>'application/json'}).
|
51
|
+
to_return(:status => 200, :body => body, :headers => {})
|
52
|
+
|
53
|
+
client = Gerry.new(MockGerry::URL, 'gerry', 'whoop')
|
54
|
+
client.set_auth_type(:basic_auth)
|
55
|
+
projects = client.projects
|
56
|
+
|
57
|
+
expect(stub).to have_been_requested
|
58
|
+
|
59
|
+
expect(projects['awesome']['description']).to eq('Awesome project')
|
60
|
+
expect(projects['clean']['description']).to eq('Clean code!')
|
61
|
+
end
|
62
|
+
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.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fabian Mettler
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date:
|
14
|
+
date: 2017-06-21 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: httparty
|
@@ -125,8 +125,7 @@ dependencies:
|
|
125
125
|
- - ">="
|
126
126
|
- !ruby/object:Gem::Version
|
127
127
|
version: '0'
|
128
|
-
description:
|
129
|
-
Simple Ruby wrapper for the Gerrit Code Review REST-API.
|
128
|
+
description: " Simple Ruby wrapper for the Gerrit Code Review REST-API.\n"
|
130
129
|
email: trumant@gmail.com
|
131
130
|
executables: []
|
132
131
|
extensions: []
|
@@ -182,7 +181,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
182
181
|
version: '0'
|
183
182
|
requirements: []
|
184
183
|
rubyforge_project:
|
185
|
-
rubygems_version: 2.
|
184
|
+
rubygems_version: 2.5.1
|
186
185
|
signing_key:
|
187
186
|
specification_version: 4
|
188
187
|
summary: Simple Ruby wrapper for the Gerrit Code Review REST-API.
|