gitlab 3.5.0 → 3.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +7 -1
  3. data/README.md +17 -0
  4. data/Rakefile +1 -1
  5. data/exe/gitlab +1 -1
  6. data/lib/gitlab.rb +5 -3
  7. data/lib/gitlab/cli.rb +1 -1
  8. data/lib/gitlab/cli_helpers.rb +24 -26
  9. data/lib/gitlab/client.rb +1 -1
  10. data/lib/gitlab/client/branches.rb +2 -5
  11. data/lib/gitlab/client/commits.rb +5 -5
  12. data/lib/gitlab/client/groups.rb +8 -9
  13. data/lib/gitlab/client/issues.rb +7 -7
  14. data/lib/gitlab/client/labels.rb +3 -3
  15. data/lib/gitlab/client/merge_requests.rb +7 -7
  16. data/lib/gitlab/client/milestones.rb +5 -5
  17. data/lib/gitlab/client/namespaces.rb +1 -1
  18. data/lib/gitlab/client/notes.rb +7 -7
  19. data/lib/gitlab/client/projects.rb +22 -21
  20. data/lib/gitlab/client/repositories.rb +7 -7
  21. data/lib/gitlab/client/repository_files.rb +10 -10
  22. data/lib/gitlab/client/snippets.rb +6 -6
  23. data/lib/gitlab/client/system_hooks.rb +1 -1
  24. data/lib/gitlab/client/users.rb +5 -6
  25. data/lib/gitlab/configuration.rb +1 -1
  26. data/lib/gitlab/help.rb +19 -15
  27. data/lib/gitlab/objectified_hash.rb +2 -2
  28. data/lib/gitlab/page_links.rb +33 -0
  29. data/lib/gitlab/paginated_response.rb +97 -0
  30. data/lib/gitlab/request.rb +24 -26
  31. data/lib/gitlab/shell.rb +4 -5
  32. data/lib/gitlab/shell_history.rb +3 -5
  33. data/lib/gitlab/version.rb +1 -1
  34. data/spec/gitlab/cli_helpers_spec.rb +8 -9
  35. data/spec/gitlab/cli_spec.rb +0 -2
  36. data/spec/gitlab/client/branches_spec.rb +2 -2
  37. data/spec/gitlab/client/commits_spec.rb +16 -16
  38. data/spec/gitlab/client/groups_spec.rb +11 -14
  39. data/spec/gitlab/client/issues_spec.rb +9 -9
  40. data/spec/gitlab/client/labels_spec.rb +6 -6
  41. data/spec/gitlab/client/merge_requests_spec.rb +23 -23
  42. data/spec/gitlab/client/milestones_spec.rb +9 -9
  43. data/spec/gitlab/client/namespaces_spec.rb +2 -2
  44. data/spec/gitlab/client/notes_spec.rb +10 -10
  45. data/spec/gitlab/client/projects_spec.rb +29 -28
  46. data/spec/gitlab/client/repositories_spec.rb +7 -7
  47. data/spec/gitlab/client/snippets_spec.rb +7 -7
  48. data/spec/gitlab/client/system_hooks_spec.rb +2 -2
  49. data/spec/gitlab/client/users_spec.rb +20 -21
  50. data/spec/gitlab/help_spec.rb +1 -4
  51. data/spec/gitlab/objectified_hash_spec.rb +2 -2
  52. data/spec/gitlab/page_links_spec.rb +16 -0
  53. data/spec/gitlab/paginated_response_spec.rb +60 -0
  54. data/spec/gitlab/request_spec.rb +12 -13
  55. data/spec/gitlab/shell_history_spec.rb +1 -1
  56. data/spec/gitlab/shell_spec.rb +6 -6
  57. data/spec/spec_helper.rb +12 -12
  58. metadata +8 -2
@@ -1,7 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Gitlab::Help do
4
-
5
4
  describe ".ri_cmd" do
6
5
  context "ri command found" do
7
6
  it "should return the path to RI" do
@@ -13,10 +12,9 @@ describe Gitlab::Help do
13
12
  context "ri command NOT found" do
14
13
  it "should raise" do
15
14
  allow(Gitlab::Help).to receive(:`).with(/which ri/).and_return('')
16
- expect{Gitlab::Help.ri_cmd}.to raise_error RuntimeError
15
+ expect { Gitlab::Help.ri_cmd }.to raise_error RuntimeError
17
16
  end
18
17
  end
19
-
20
18
  end
21
19
 
22
20
  describe ".change_help_output!" do
@@ -40,5 +38,4 @@ describe Gitlab::Help do
40
38
  expect(@namespace).to eq("Gitlab::Client::Repositories.#{@cmd}")
41
39
  end
42
40
  end
43
-
44
41
  end
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  describe Gitlab::ObjectifiedHash do
4
4
  before do
5
- @hash = {a: 1, b: 2, 'string' => 'string', symbol: :symbol}
5
+ @hash = { a: 1, b: 2, 'string' => 'string', symbol: :symbol }
6
6
  @oh = Gitlab::ObjectifiedHash.new @hash
7
7
  end
8
8
 
@@ -23,7 +23,7 @@ describe Gitlab::ObjectifiedHash do
23
23
 
24
24
  describe "#inspect" do
25
25
  it "should return a formatted string" do
26
- pretty_string = "#<#{@oh.class.name}:#{@oh.object_id} {hash: #{@hash.to_s}}"
26
+ pretty_string = "#<#{@oh.class.name}:#{@oh.object_id} {hash: #{@hash}}"
27
27
  expect(@oh.inspect).to eq(pretty_string)
28
28
  end
29
29
  end
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+
3
+ describe Gitlab::PageLinks do
4
+ before do
5
+ @page_links = Gitlab::PageLinks.new('Link' => "<http://example.com/api/v3/projects?page=1&per_page=5>; rel=\"first\", <http://example.com/api/v3/projects?page=20&per_page=5>; rel=\"last\", <http://example.com/api/v3/projects?page=7&per_page=5>; rel=\"prev\", <http://example.com/api/v3/projects?page=9&per_page=5>; rel=\"next\"")
6
+ end
7
+
8
+ context '.extract_links' do
9
+ it 'should extract link header appropriately' do
10
+ expect(@page_links.last).to eql 'http://example.com/api/v3/projects?page=20&per_page=5'
11
+ expect(@page_links.first).to eql 'http://example.com/api/v3/projects?page=1&per_page=5'
12
+ expect(@page_links.next).to eql 'http://example.com/api/v3/projects?page=9&per_page=5'
13
+ expect(@page_links.prev).to eql 'http://example.com/api/v3/projects?page=7&per_page=5'
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,60 @@
1
+ require 'spec_helper'
2
+
3
+ describe Gitlab::PaginatedResponse do
4
+ before do
5
+ array = [1, 2, 3, 4]
6
+ @paginated_response = Gitlab::PaginatedResponse.new array
7
+ end
8
+
9
+ it "should respond to *_page and has_*_page methods" do
10
+ expect(@paginated_response).to respond_to :first_page
11
+ expect(@paginated_response).to respond_to :last_page
12
+ expect(@paginated_response).to respond_to :next_page
13
+ expect(@paginated_response).to respond_to :prev_page
14
+ expect(@paginated_response).to respond_to :has_first_page?
15
+ expect(@paginated_response).to respond_to :has_last_page?
16
+ expect(@paginated_response).to respond_to :has_next_page?
17
+ expect(@paginated_response).to respond_to :has_prev_page?
18
+ end
19
+
20
+ context '.parse_headers!' do
21
+ it "should parse headers" do
22
+ @paginated_response.parse_headers!('Link' => "<http://example.com/api/v3/projects?page=1&per_page=5>; rel=\"first\", <http://example.com/api/v3/projects?page=20&per_page=5>; rel=\"last\"")
23
+ client = @paginated_response.client = double('client')
24
+ first_page_response = double('first_page_response')
25
+ last_page_response = double('last_page_response')
26
+ allow(client).to receive(:endpoint).and_return("http://example.com/api/v3")
27
+ allow(client).to receive(:get).with("/projects?page=1&per_page=5").and_return(first_page_response)
28
+ allow(client).to receive(:get).with("/projects?page=20&per_page=5").and_return(last_page_response)
29
+ expect(@paginated_response.has_first_page?).to be true
30
+ expect(@paginated_response.has_last_page?).to be true
31
+ expect(@paginated_response.has_next_page?).to be false
32
+ expect(@paginated_response.has_prev_page?).to be false
33
+ expect(@paginated_response.first_page).to be first_page_response
34
+ expect(@paginated_response.last_page).to be last_page_response
35
+ expect(@paginated_response.next_page).to be_nil
36
+ expect(@paginated_response.prev_page).to be_nil
37
+ end
38
+ end
39
+
40
+ context '.each_page' do
41
+ it "should iterate pages" do
42
+ next_page = double('next_page')
43
+ allow(@paginated_response).to receive(:has_next_page?).and_return(true)
44
+ allow(@paginated_response).to receive(:next_page).and_return(next_page)
45
+ allow(next_page).to receive(:has_next_page?).and_return(false)
46
+ expect { |b| @paginated_response.each_page(&b) }.to yield_successive_args(@paginated_response, next_page)
47
+ end
48
+ end
49
+
50
+ context '.auto_paginate' do
51
+ it "should returns an array if block is not given" do
52
+ next_page = double('next_page')
53
+ allow(@paginated_response).to receive(:has_next_page?).and_return(true)
54
+ allow(@paginated_response).to receive(:next_page).and_return(next_page)
55
+ allow(next_page).to receive(:has_next_page?).and_return(false)
56
+ allow(next_page).to receive(:to_ary).and_return([5, 6, 7, 8])
57
+ expect(@paginated_response.auto_paginate).to contain_exactly(1, 2, 3, 4, 5, 6, 7, 8)
58
+ end
59
+ end
60
+ end
@@ -15,14 +15,14 @@ describe Gitlab::Request do
15
15
  expect(default_options).to be_a Hash
16
16
  expect(default_options[:parser]).to be_a Proc
17
17
  expect(default_options[:format]).to eq(:json)
18
- expect(default_options[:headers]).to eq({'Accept' => 'application/json'})
18
+ expect(default_options[:headers]).to eq('Accept' => 'application/json')
19
19
  expect(default_options[:default_params]).to be_nil
20
20
  end
21
21
  end
22
22
 
23
23
  describe ".parse" do
24
24
  it "should return ObjectifiedHash" do
25
- body = JSON.unparse({a: 1, b: 2})
25
+ body = JSON.unparse(a: 1, b: 2)
26
26
  expect(Gitlab::Request.parse(body)).to be_an Gitlab::ObjectifiedHash
27
27
  expect(Gitlab::Request.parse("true")).to be true
28
28
  expect(Gitlab::Request.parse("false")).to be false
@@ -35,9 +35,9 @@ describe Gitlab::Request do
35
35
  context "when endpoint is not set" do
36
36
  it "should raise Error::MissingCredentials" do
37
37
  @request.endpoint = nil
38
- expect {
38
+ expect do
39
39
  @request.set_request_defaults
40
- }.to raise_error(Gitlab::Error::MissingCredentials, 'Please set an endpoint to API')
40
+ end.to raise_error(Gitlab::Error::MissingCredentials, 'Please set an endpoint to API')
41
41
  end
42
42
  end
43
43
 
@@ -48,35 +48,35 @@ describe Gitlab::Request do
48
48
 
49
49
  it "should set default_params" do
50
50
  @request.set_request_defaults('sudoer')
51
- expect(Gitlab::Request.default_params).to eq({:sudo => 'sudoer'})
51
+ expect(Gitlab::Request.default_params).to eq(sudo: 'sudoer')
52
52
  end
53
53
  end
54
54
  end
55
55
 
56
56
  describe "#set_authorization_header" do
57
57
  it "should raise MissingCredentials when auth_token and private_token are not set" do
58
- expect {
58
+ expect do
59
59
  @request.send(:set_authorization_header, {})
60
- }.to raise_error(Gitlab::Error::MissingCredentials)
60
+ end.to raise_error(Gitlab::Error::MissingCredentials)
61
61
  end
62
62
 
63
63
  it "should set the correct header when given a private_token" do
64
64
  @request.private_token = 'ys9BtunN3rDKbaJCYXaN'
65
- expect(@request.send(:set_authorization_header, {})).to eq({"PRIVATE-TOKEN"=>'ys9BtunN3rDKbaJCYXaN'})
65
+ expect(@request.send(:set_authorization_header, {})).to eq("PRIVATE-TOKEN" => 'ys9BtunN3rDKbaJCYXaN')
66
66
  end
67
67
 
68
68
  it "should set the correct header when setting an auth_token via the private_token config option" do
69
69
  @request.private_token = '3225e2804d31fea13fc41fc83bffef00cfaedc463118646b154acc6f94747603'
70
- expect(@request.send(:set_authorization_header, {})).to eq({"Authorization"=>"Bearer 3225e2804d31fea13fc41fc83bffef00cfaedc463118646b154acc6f94747603"})
70
+ expect(@request.send(:set_authorization_header, {})).to eq("Authorization" => "Bearer 3225e2804d31fea13fc41fc83bffef00cfaedc463118646b154acc6f94747603")
71
71
  end
72
72
  end
73
73
 
74
74
  describe "#handle_error" do
75
75
  before do
76
76
  @array = Array.new(['First message.', 'Second message.'])
77
- @obj_h = Gitlab::ObjectifiedHash.new({user: ['not set'],
78
- password: ['too short'],
79
- embed_entity: { foo: ['bar'], sna: ['fu'] }})
77
+ @obj_h = Gitlab::ObjectifiedHash.new(user: ['not set'],
78
+ password: ['too short'],
79
+ embed_entity: { foo: ['bar'], sna: ['fu'] })
80
80
  end
81
81
  context "when passed an ObjectifiedHash" do
82
82
  it "should return a joined string of error messages sorted by key" do
@@ -97,5 +97,4 @@ describe Gitlab::Request do
97
97
  end
98
98
  end
99
99
  end
100
-
101
100
  end
@@ -8,7 +8,7 @@ describe Gitlab::Shell::History do
8
8
  @history = Gitlab::Shell::History.new(file_path: @file.path)
9
9
  end
10
10
 
11
- after do @file.close(true) end
11
+ after { @file.close(true) }
12
12
 
13
13
  it 'saves the lines' do
14
14
  @history << 'party on, dudes'
@@ -8,7 +8,7 @@ describe Gitlab::Shell do
8
8
  describe ".execute" do
9
9
  context "invalid command" do
10
10
  it "should raise" do
11
- expect{Gitlab::Shell.execute 'foobar', []}.to raise_error(RuntimeError)
11
+ expect { Gitlab::Shell.execute 'foobar', [] }.to raise_error(RuntimeError)
12
12
  end
13
13
  end
14
14
  end
@@ -55,7 +55,7 @@ describe Gitlab::Shell do
55
55
  it "should return an Array of matching commands" do
56
56
  completed_cmds = @comp.call 'group'
57
57
  expect(completed_cmds).to be_a Array
58
- expect(completed_cmds.sort).to eq(['group', 'group_members', 'group_search', 'groups'])
58
+ expect(completed_cmds.sort).to eq(%w(group group_members group_search groups))
59
59
  end
60
60
  end
61
61
  end
@@ -63,15 +63,15 @@ describe Gitlab::Shell do
63
63
  describe ".parse_input" do
64
64
  context "with arguments" do
65
65
  it "should set command & arguments" do
66
- Gitlab::Shell.parse_input('create_branch 1 "api" "master"')
66
+ Gitlab::Shell.parse_input('create_branch 1 "api" "master"')
67
67
  expect(Gitlab::Shell.command).to eq('create_branch')
68
- expect(Gitlab::Shell.arguments).to eq(['1', 'api', 'master'])
68
+ expect(Gitlab::Shell.arguments).to eq(%w(1 api master))
69
69
  end
70
70
  end
71
-
71
+
72
72
  context "without arguments" do
73
73
  it 'should set command & empty arguments' do
74
- Gitlab::Shell.parse_input('exit')
74
+ Gitlab::Shell.parse_input('exit')
75
75
  expect(Gitlab::Shell.command).to eq('exit')
76
76
  expect(Gitlab::Shell.arguments).to be_empty
77
77
  end
@@ -28,47 +28,47 @@ end
28
28
  # GET
29
29
  def stub_get(path, fixture)
30
30
  stub_request(:get, "#{Gitlab.endpoint}#{path}").
31
- with(:headers => {'PRIVATE-TOKEN' => Gitlab.private_token}).
32
- to_return(:body => load_fixture(fixture))
31
+ with(headers: { 'PRIVATE-TOKEN' => Gitlab.private_token }).
32
+ to_return(body: load_fixture(fixture))
33
33
  end
34
34
 
35
35
  def a_get(path)
36
36
  a_request(:get, "#{Gitlab.endpoint}#{path}").
37
- with(:headers => {'PRIVATE-TOKEN' => Gitlab.private_token})
37
+ with(headers: { 'PRIVATE-TOKEN' => Gitlab.private_token })
38
38
  end
39
39
 
40
40
  # POST
41
41
  def stub_post(path, fixture, status_code=200)
42
42
  stub_request(:post, "#{Gitlab.endpoint}#{path}").
43
- with(:headers => {'PRIVATE-TOKEN' => Gitlab.private_token}).
44
- to_return(:body => load_fixture(fixture), :status => status_code)
43
+ with(headers: { 'PRIVATE-TOKEN' => Gitlab.private_token }).
44
+ to_return(body: load_fixture(fixture), status: status_code)
45
45
  end
46
46
 
47
47
  def a_post(path)
48
48
  a_request(:post, "#{Gitlab.endpoint}#{path}").
49
- with(:headers => {'PRIVATE-TOKEN' => Gitlab.private_token})
49
+ with(headers: { 'PRIVATE-TOKEN' => Gitlab.private_token })
50
50
  end
51
51
 
52
52
  # PUT
53
53
  def stub_put(path, fixture)
54
54
  stub_request(:put, "#{Gitlab.endpoint}#{path}").
55
- with(:headers => {'PRIVATE-TOKEN' => Gitlab.private_token}).
56
- to_return(:body => load_fixture(fixture))
55
+ with(headers: { 'PRIVATE-TOKEN' => Gitlab.private_token }).
56
+ to_return(body: load_fixture(fixture))
57
57
  end
58
58
 
59
59
  def a_put(path)
60
60
  a_request(:put, "#{Gitlab.endpoint}#{path}").
61
- with(:headers => {'PRIVATE-TOKEN' => Gitlab.private_token})
61
+ with(headers: { 'PRIVATE-TOKEN' => Gitlab.private_token })
62
62
  end
63
63
 
64
64
  # DELETE
65
65
  def stub_delete(path, fixture)
66
66
  stub_request(:delete, "#{Gitlab.endpoint}#{path}").
67
- with(:headers => {'PRIVATE-TOKEN' => Gitlab.private_token}).
68
- to_return(:body => load_fixture(fixture))
67
+ with(headers: { 'PRIVATE-TOKEN' => Gitlab.private_token }).
68
+ to_return(body: load_fixture(fixture))
69
69
  end
70
70
 
71
71
  def a_delete(path)
72
72
  a_request(:delete, "#{Gitlab.endpoint}#{path}").
73
- with(:headers => {'PRIVATE-TOKEN' => Gitlab.private_token})
73
+ with(headers: { 'PRIVATE-TOKEN' => Gitlab.private_token })
74
74
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitlab
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.5.0
4
+ version: 3.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nihad Abbasov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-11-26 00:00:00.000000000 Z
11
+ date: 2015-12-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -138,6 +138,8 @@ files:
138
138
  - lib/gitlab/error.rb
139
139
  - lib/gitlab/help.rb
140
140
  - lib/gitlab/objectified_hash.rb
141
+ - lib/gitlab/page_links.rb
142
+ - lib/gitlab/paginated_response.rb
141
143
  - lib/gitlab/request.rb
142
144
  - lib/gitlab/shell.rb
143
145
  - lib/gitlab/shell_history.rb
@@ -231,6 +233,8 @@ files:
231
233
  - spec/gitlab/client/users_spec.rb
232
234
  - spec/gitlab/help_spec.rb
233
235
  - spec/gitlab/objectified_hash_spec.rb
236
+ - spec/gitlab/page_links_spec.rb
237
+ - spec/gitlab/paginated_response_spec.rb
234
238
  - spec/gitlab/request_spec.rb
235
239
  - spec/gitlab/shell_history_spec.rb
236
240
  - spec/gitlab/shell_spec.rb
@@ -350,6 +354,8 @@ test_files:
350
354
  - spec/gitlab/client/users_spec.rb
351
355
  - spec/gitlab/help_spec.rb
352
356
  - spec/gitlab/objectified_hash_spec.rb
357
+ - spec/gitlab/page_links_spec.rb
358
+ - spec/gitlab/paginated_response_spec.rb
353
359
  - spec/gitlab/request_spec.rb
354
360
  - spec/gitlab/shell_history_spec.rb
355
361
  - spec/gitlab/shell_spec.rb