gitlab 3.3.0 → 3.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +2 -1
  3. data/CHANGELOG.md +157 -0
  4. data/LICENSE.txt +1 -1
  5. data/README.md +16 -10
  6. data/lib/gitlab.rb +1 -1
  7. data/lib/gitlab/api.rb +5 -3
  8. data/lib/gitlab/cli.rb +21 -3
  9. data/lib/gitlab/cli_helpers.rb +46 -79
  10. data/lib/gitlab/client.rb +2 -1
  11. data/lib/gitlab/client/branches.rb +16 -1
  12. data/lib/gitlab/client/groups.rb +1 -0
  13. data/lib/gitlab/client/issues.rb +1 -0
  14. data/lib/gitlab/client/labels.rb +2 -0
  15. data/lib/gitlab/client/merge_requests.rb +12 -10
  16. data/lib/gitlab/client/milestones.rb +15 -0
  17. data/lib/gitlab/client/notes.rb +22 -6
  18. data/lib/gitlab/client/projects.rb +18 -0
  19. data/lib/gitlab/client/repositories.rb +4 -1
  20. data/lib/gitlab/client/repository_files.rb +72 -0
  21. data/lib/gitlab/client/snippets.rb +1 -11
  22. data/lib/gitlab/client/system_hooks.rb +1 -0
  23. data/lib/gitlab/client/users.rb +2 -0
  24. data/lib/gitlab/configuration.rb +3 -1
  25. data/lib/gitlab/error.rb +0 -3
  26. data/lib/gitlab/help.rb +77 -31
  27. data/lib/gitlab/objectified_hash.rb +6 -0
  28. data/lib/gitlab/request.rb +31 -15
  29. data/lib/gitlab/shell.rb +57 -58
  30. data/lib/gitlab/version.rb +1 -1
  31. data/spec/fixtures/branch_delete.json +3 -0
  32. data/spec/fixtures/merge_request_changes.json +1 -0
  33. data/spec/fixtures/milestone_issues.json +1 -0
  34. data/spec/fixtures/project_search.json +1 -0
  35. data/spec/fixtures/repository_file.json +1 -0
  36. data/spec/gitlab/cli_helpers_spec.rb +58 -0
  37. data/spec/gitlab/cli_spec.rb +1 -2
  38. data/spec/gitlab/client/branches_spec.rb +15 -0
  39. data/spec/gitlab/client/merge_requests_spec.rb +20 -12
  40. data/spec/gitlab/client/milestones_spec.rb +16 -0
  41. data/spec/gitlab/client/notes_spec.rb +17 -0
  42. data/spec/gitlab/client/projects_spec.rb +45 -8
  43. data/spec/gitlab/client/repository_files_spec.rb +45 -0
  44. data/spec/gitlab/help_spec.rb +44 -0
  45. data/spec/gitlab/objectified_hash_spec.rb +7 -0
  46. data/spec/gitlab/request_spec.rb +45 -6
  47. data/spec/gitlab/shell_spec.rb +80 -0
  48. data/spec/gitlab_spec.rb +12 -0
  49. metadata +23 -3
@@ -18,6 +18,24 @@ describe Gitlab::Client do
18
18
  end
19
19
  end
20
20
 
21
+ describe ".project_search" do
22
+ before do
23
+ stub_get("/projects/search/Gitlab", "project_search")
24
+ @project_search = Gitlab.project_search("Gitlab")
25
+ end
26
+
27
+ it "should get the correct resource" do
28
+ expect(a_get("/projects/search/Gitlab")).to have_been_made
29
+ end
30
+
31
+ it "should return an array of projects found" do
32
+ expect(@project_search).to be_an Array
33
+ expect(@project_search.first.name).to eq("Gitlab")
34
+ expect(@project_search.first.owner.name).to eq("John Smith")
35
+ end
36
+
37
+ end
38
+
21
39
  describe ".project" do
22
40
  before do
23
41
  stub_get("/projects/3", "project")
@@ -260,17 +278,36 @@ describe Gitlab::Client do
260
278
  end
261
279
 
262
280
  describe ".delete_project_hook" do
263
- before do
264
- stub_delete("/projects/1/hooks/1", "project_hook")
265
- @hook = Gitlab.delete_project_hook(1, 1)
266
- end
281
+ context "when empty response" do
282
+ before do
283
+ stub_request(:delete, "#{Gitlab.endpoint}/projects/1/hooks/1").
284
+ with(:headers => {'PRIVATE-TOKEN' => Gitlab.private_token}).
285
+ to_return(:body => '')
286
+ @hook = Gitlab.delete_project_hook(1, 1)
287
+ end
267
288
 
268
- it "should get the correct resource" do
269
- expect(a_delete("/projects/1/hooks/1")).to have_been_made
289
+ it "should get the correct resource" do
290
+ expect(a_delete("/projects/1/hooks/1")).to have_been_made
291
+ end
292
+
293
+ it "should return false" do
294
+ expect(@hook).to be(false)
295
+ end
270
296
  end
271
297
 
272
- it "should return information about a deleted hook" do
273
- expect(@hook.url).to eq("https://api.example.net/v1/webhooks/ci")
298
+ context "when JSON response" do
299
+ before do
300
+ stub_delete("/projects/1/hooks/1", "project_hook")
301
+ @hook = Gitlab.delete_project_hook(1, 1)
302
+ end
303
+
304
+ it "should get the correct resource" do
305
+ expect(a_delete("/projects/1/hooks/1")).to have_been_made
306
+ end
307
+
308
+ it "should return information about a deleted hook" do
309
+ expect(@hook.url).to eq("https://api.example.net/v1/webhooks/ci")
310
+ end
274
311
  end
275
312
  end
276
313
 
@@ -0,0 +1,45 @@
1
+ require "spec_helper"
2
+
3
+ describe Gitlab::Client do
4
+ describe ".create_file" do
5
+ let!(:request_stub) { stub_post("/projects/3/repository/files", "repository_file") }
6
+ let!(:file) { Gitlab.create_file(3, "path", "branch", "content", "commit message") }
7
+
8
+ it "should create the correct resource" do
9
+ expect(request_stub).to have_been_made
10
+ end
11
+
12
+ it "should return information about the new file" do
13
+ expect(file.file_path).to eq "path"
14
+ expect(file.branch_name).to eq "branch"
15
+ end
16
+ end
17
+
18
+ describe ".edit_file" do
19
+ let!(:request_stub) { stub_put("/projects/3/repository/files", "repository_file") }
20
+ let!(:file) { Gitlab.edit_file(3, "path", "branch", "content", "commit message") }
21
+
22
+ it "should create the correct resource" do
23
+ expect(request_stub).to have_been_made
24
+ end
25
+
26
+ it "should return information about the new file" do
27
+ expect(file.file_path).to eq "path"
28
+ expect(file.branch_name).to eq "branch"
29
+ end
30
+ end
31
+
32
+ describe ".remove_file" do
33
+ let!(:request_stub) { stub_delete("/projects/3/repository/files", "repository_file") }
34
+ let!(:file) { Gitlab.remove_file(3, "path", "branch", "commit message") }
35
+
36
+ it "should create the correct resource" do
37
+ expect(request_stub).to have_been_made
38
+ end
39
+
40
+ it "should return information about the new file" do
41
+ expect(file.file_path).to eq "path"
42
+ expect(file.branch_name).to eq "branch"
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+
3
+ describe Gitlab::Help do
4
+
5
+ describe ".ri_cmd" do
6
+ context "ri command found" do
7
+ it "should return the path to RI" do
8
+ allow(Gitlab::Help).to receive(:`).with(/which ri/).and_return('/usr/bin/ri')
9
+ expect(Gitlab::Help.ri_cmd).to eq('/usr/bin/ri')
10
+ end
11
+ end
12
+
13
+ context "ri command NOT found" do
14
+ it "should raise" do
15
+ allow(Gitlab::Help).to receive(:`).with(/which ri/).and_return('')
16
+ expect{Gitlab::Help.ri_cmd}.to raise_error
17
+ end
18
+ end
19
+
20
+ end
21
+
22
+ describe ".change_help_output!" do
23
+ before do
24
+ @cmd = "create_branch"
25
+ @help_output = "Gitlab.#{@cmd}(4, 'new-branch', 'master')"
26
+ end
27
+ it "should return a String of modified output" do
28
+ Gitlab::Help.change_help_output! @cmd, @help_output
29
+ expect(@help_output).to eq("Gitlab.create_branch 4 'new-branch' 'master'")
30
+ end
31
+ end
32
+
33
+ describe ".namespace" do
34
+ before do
35
+ @cmd = 'create_tag'
36
+ @namespace = Gitlab::Help.namespace @cmd
37
+ end
38
+ it "should return the full namespace for a command" do
39
+ expect(@namespace).to be_a String
40
+ expect(@namespace).to eq("Gitlab::Client::Repositories.#{@cmd}")
41
+ end
42
+ end
43
+
44
+ end
@@ -21,6 +21,13 @@ describe Gitlab::ObjectifiedHash do
21
21
  end
22
22
  end
23
23
 
24
+ describe "#inspect" do
25
+ it "should return a formatted string" do
26
+ pretty_string = "#<#{@oh.class.name}:#{@oh.object_id} {hash: #{@hash.to_s}}"
27
+ expect(@oh.inspect).to eq(pretty_string)
28
+ end
29
+ end
30
+
24
31
  describe "#respond_to" do
25
32
  it "should return true for methods this object responds to through method_missing as sym" do
26
33
  expect(@oh.respond_to?(:a)).to be_truthy
@@ -5,6 +5,12 @@ describe Gitlab::Request do
5
5
  it { should respond_to :post }
6
6
  it { should respond_to :put }
7
7
  it { should respond_to :delete }
8
+ before do
9
+ @request = Gitlab::Request.new
10
+ @obj_h = Gitlab::ObjectifiedHash.new({user: ['not set'],
11
+ password: ['too short'],
12
+ embed_entity: { foo: ['bar'], sna: ['fu'] }})
13
+ end
8
14
 
9
15
  describe ".default_options" do
10
16
  it "should have default values" do
@@ -27,23 +33,56 @@ describe Gitlab::Request do
27
33
  describe "#set_request_defaults" do
28
34
  context "when endpoint is not set" do
29
35
  it "should raise Error::MissingCredentials" do
36
+ @request.endpoint = nil
30
37
  expect {
31
- Gitlab::Request.new.set_request_defaults(nil, 1234000)
38
+ @request.set_request_defaults
32
39
  }.to raise_error(Gitlab::Error::MissingCredentials, 'Please set an endpoint to API')
33
40
  end
34
41
  end
35
42
 
36
43
  context "when endpoint is set" do
37
- it "should set instance variable 'endpoint'" do
38
- request = Gitlab::Request.new
39
- request.set_request_defaults('http://rabbit-hole.example.org', 1234000)
40
- expect(request.instance_variable_get(:@endpoint)).to eq("http://rabbit-hole.example.org")
44
+ before(:each) do
45
+ @request.endpoint = 'http://rabbit-hole.example.org'
41
46
  end
42
47
 
43
48
  it "should set default_params" do
44
- Gitlab::Request.new.set_request_defaults('http://rabbit-hole.example.org', 1234000, 'sudoer')
49
+ @request.set_request_defaults('sudoer')
45
50
  expect(Gitlab::Request.default_params).to eq({:sudo => 'sudoer'})
46
51
  end
47
52
  end
48
53
  end
54
+
55
+ describe "#set_authorization_header" do
56
+ it "should raise MissingCredentials when auth_token and private_token are not set" do
57
+ expect {
58
+ @request.send(:set_authorization_header, {})
59
+ }.to raise_error(Gitlab::Error::MissingCredentials)
60
+ end
61
+
62
+ it "should set the correct header when given a private_token" do
63
+ @request.private_token = 'ys9BtunN3rDKbaJCYXaN'
64
+ expect(@request.send(:set_authorization_header, {})).to eq({"PRIVATE-TOKEN"=>'ys9BtunN3rDKbaJCYXaN'})
65
+ end
66
+
67
+ it "should set the correct header when setting an auth_token via the private_token config option" do
68
+ @request.private_token = '3225e2804d31fea13fc41fc83bffef00cfaedc463118646b154acc6f94747603'
69
+ expect(@request.send(:set_authorization_header, {})).to eq({"Authorization"=>"Bearer 3225e2804d31fea13fc41fc83bffef00cfaedc463118646b154acc6f94747603"})
70
+ end
71
+ end
72
+
73
+ describe "#handle_error" do
74
+ context "when passed an ObjectifiedHash" do
75
+ it "should return a joined string of error messages sorted by key" do
76
+ expect(@request.send(:handle_error, @obj_h)).to eq("'embed_entity' (foo: bar) (sna: fu), 'password' too short, 'user' not set")
77
+ end
78
+ end
79
+
80
+ context "when passed a String" do
81
+ it "should return the String untouched" do
82
+ error = 'this is an error string'
83
+ expect(@request.send(:handle_error, error)).to eq('this is an error string')
84
+ end
85
+ end
86
+ end
87
+
49
88
  end
@@ -0,0 +1,80 @@
1
+ require 'spec_helper'
2
+
3
+ describe Gitlab::Shell do
4
+ before do
5
+ Gitlab::Shell.setup
6
+ end
7
+
8
+ describe ".execute" do
9
+ context "invalid command" do
10
+ it "should raise" do
11
+ expect{Gitlab::Shell.execute 'foobar', []}.to raise_error(RuntimeError)
12
+ end
13
+ end
14
+ end
15
+
16
+ describe ".history" do
17
+ before do
18
+ @history = Gitlab::Shell.history
19
+ end
20
+
21
+ it "should return a Gitlab::Shell::History instance" do
22
+ expect(@history).to be_a Gitlab::Shell::History
23
+ end
24
+ it "should respond to :save" do
25
+ expect(@history).to respond_to :save
26
+ end
27
+ it "should respond to :load" do
28
+ expect(@history).to respond_to :load
29
+ end
30
+ it "should respond to :<<" do
31
+ expect(@history).to respond_to :<<
32
+ end
33
+ end
34
+
35
+ describe ".setup" do
36
+ it "should set the Readline completion_proc" do
37
+ completion = Readline.completion_proc
38
+ expect(completion).to be_truthy
39
+ expect(completion).to be_a Proc
40
+ end
41
+ it "should set the Readline completion_append_character" do
42
+ completion_character = Readline.completion_append_character
43
+ expect(completion_character).to eq(' ')
44
+ end
45
+ end
46
+
47
+ describe ".completion" do
48
+ before do
49
+ @comp = Gitlab::Shell.completion
50
+ end
51
+ it "should return a Proc object" do
52
+ expect(@comp).to be_a Proc
53
+ end
54
+ context "called with an argument" do
55
+ it "should return an Array of matching commands" do
56
+ completed_cmds = @comp.call 'group'
57
+ expect(completed_cmds).to be_a Array
58
+ expect(completed_cmds.sort).to eq(['group', 'group_members', 'groups'])
59
+ end
60
+ end
61
+ end
62
+
63
+ describe ".parse_input" do
64
+ context "with arguments" do
65
+ it "should set command & arguements" do
66
+ Gitlab::Shell.parse_input('create_branch 1 "api" "master"')
67
+ expect(Gitlab::Shell.command).to eq('create_branch')
68
+ expect(Gitlab::Shell.arguments).to eq(['1', 'api', 'master'])
69
+ end
70
+ end
71
+
72
+ context "without arguments" do
73
+ it 'should set command & empty arguments' do
74
+ Gitlab::Shell.parse_input('exit')
75
+ expect(Gitlab::Shell.command).to eq('exit')
76
+ expect(Gitlab::Shell.arguments).to be_empty
77
+ end
78
+ end
79
+ end
80
+ end
@@ -16,6 +16,11 @@ describe Gitlab do
16
16
  expect(client1.private_token).to eq('001')
17
17
  expect(client2.private_token).to eq('002')
18
18
  end
19
+
20
+ it "should set private_token to the auth_token when provided" do
21
+ client = Gitlab.client(endpoint: 'https://api2.example.com', auth_token: '3225e2804d31fea13fc41fc83bffef00cfaedc463118646b154acc6f94747603')
22
+ expect(client.private_token).to eq('3225e2804d31fea13fc41fc83bffef00cfaedc463118646b154acc6f94747603')
23
+ end
19
24
  end
20
25
 
21
26
  describe ".actions" do
@@ -41,6 +46,13 @@ describe Gitlab do
41
46
  end
42
47
  end
43
48
 
49
+ describe ".auth_token=" do
50
+ it "should set auth_token", focus: true do
51
+ Gitlab.auth_token = 'auth_secret'
52
+ expect(Gitlab.private_token).to eq('auth_secret')
53
+ end
54
+ end
55
+
44
56
  describe ".sudo=" do
45
57
  it "should set sudo" do
46
58
  Gitlab.sudo = 'user'
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.3.0
4
+ version: 3.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nihad Abbasov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-22 00:00:00.000000000 Z
11
+ date: 2015-04-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -90,6 +90,7 @@ extra_rdoc_files: []
90
90
  files:
91
91
  - ".gitignore"
92
92
  - ".travis.yml"
93
+ - CHANGELOG.md
93
94
  - CONTRIBUTING.md
94
95
  - Gemfile
95
96
  - LICENSE.txt
@@ -111,6 +112,7 @@ files:
111
112
  - lib/gitlab/client/notes.rb
112
113
  - lib/gitlab/client/projects.rb
113
114
  - lib/gitlab/client/repositories.rb
115
+ - lib/gitlab/client/repository_files.rb
114
116
  - lib/gitlab/client/snippets.rb
115
117
  - lib/gitlab/client/system_hooks.rb
116
118
  - lib/gitlab/client/users.rb
@@ -123,6 +125,7 @@ files:
123
125
  - lib/gitlab/shell_history.rb
124
126
  - lib/gitlab/version.rb
125
127
  - spec/fixtures/branch.json
128
+ - spec/fixtures/branch_delete.json
126
129
  - spec/fixtures/branches.json
127
130
  - spec/fixtures/compare_merge_request_diff.json
128
131
  - spec/fixtures/error_already_exists.json
@@ -139,10 +142,12 @@ files:
139
142
  - spec/fixtures/label.json
140
143
  - spec/fixtures/labels.json
141
144
  - spec/fixtures/merge_request.json
145
+ - spec/fixtures/merge_request_changes.json
142
146
  - spec/fixtures/merge_request_comment.json
143
147
  - spec/fixtures/merge_request_comments.json
144
148
  - spec/fixtures/merge_requests.json
145
149
  - spec/fixtures/milestone.json
150
+ - spec/fixtures/milestone_issues.json
146
151
  - spec/fixtures/milestones.json
147
152
  - spec/fixtures/note.json
148
153
  - spec/fixtures/notes.json
@@ -160,11 +165,13 @@ files:
160
165
  - spec/fixtures/project_issues.json
161
166
  - spec/fixtures/project_key.json
162
167
  - spec/fixtures/project_keys.json
168
+ - spec/fixtures/project_search.json
163
169
  - spec/fixtures/project_tag_annotated.json
164
170
  - spec/fixtures/project_tag_lightweight.json
165
171
  - spec/fixtures/project_tags.json
166
172
  - spec/fixtures/projects.json
167
173
  - spec/fixtures/raw_file.json
174
+ - spec/fixtures/repository_file.json
168
175
  - spec/fixtures/session.json
169
176
  - spec/fixtures/shell_history.json
170
177
  - spec/fixtures/snippet.json
@@ -176,6 +183,7 @@ files:
176
183
  - spec/fixtures/tree.json
177
184
  - spec/fixtures/user.json
178
185
  - spec/fixtures/users.json
186
+ - spec/gitlab/cli_helpers_spec.rb
179
187
  - spec/gitlab/cli_spec.rb
180
188
  - spec/gitlab/client/branches_spec.rb
181
189
  - spec/gitlab/client/groups_spec.rb
@@ -186,12 +194,15 @@ files:
186
194
  - spec/gitlab/client/notes_spec.rb
187
195
  - spec/gitlab/client/projects_spec.rb
188
196
  - spec/gitlab/client/repositories_spec.rb
197
+ - spec/gitlab/client/repository_files_spec.rb
189
198
  - spec/gitlab/client/snippets_spec.rb
190
199
  - spec/gitlab/client/system_hooks_spec.rb
191
200
  - spec/gitlab/client/users_spec.rb
201
+ - spec/gitlab/help_spec.rb
192
202
  - spec/gitlab/objectified_hash_spec.rb
193
203
  - spec/gitlab/request_spec.rb
194
204
  - spec/gitlab/shell_history_spec.rb
205
+ - spec/gitlab/shell_spec.rb
195
206
  - spec/gitlab_spec.rb
196
207
  - spec/spec_helper.rb
197
208
  homepage: https://github.com/narkoz/gitlab
@@ -213,12 +224,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
213
224
  version: '0'
214
225
  requirements: []
215
226
  rubyforge_project:
216
- rubygems_version: 2.3.0
227
+ rubygems_version: 2.4.5
217
228
  signing_key:
218
229
  specification_version: 4
219
230
  summary: A Ruby wrapper and CLI for the GitLab API
220
231
  test_files:
221
232
  - spec/fixtures/branch.json
233
+ - spec/fixtures/branch_delete.json
222
234
  - spec/fixtures/branches.json
223
235
  - spec/fixtures/compare_merge_request_diff.json
224
236
  - spec/fixtures/error_already_exists.json
@@ -235,10 +247,12 @@ test_files:
235
247
  - spec/fixtures/label.json
236
248
  - spec/fixtures/labels.json
237
249
  - spec/fixtures/merge_request.json
250
+ - spec/fixtures/merge_request_changes.json
238
251
  - spec/fixtures/merge_request_comment.json
239
252
  - spec/fixtures/merge_request_comments.json
240
253
  - spec/fixtures/merge_requests.json
241
254
  - spec/fixtures/milestone.json
255
+ - spec/fixtures/milestone_issues.json
242
256
  - spec/fixtures/milestones.json
243
257
  - spec/fixtures/note.json
244
258
  - spec/fixtures/notes.json
@@ -256,11 +270,13 @@ test_files:
256
270
  - spec/fixtures/project_issues.json
257
271
  - spec/fixtures/project_key.json
258
272
  - spec/fixtures/project_keys.json
273
+ - spec/fixtures/project_search.json
259
274
  - spec/fixtures/project_tag_annotated.json
260
275
  - spec/fixtures/project_tag_lightweight.json
261
276
  - spec/fixtures/project_tags.json
262
277
  - spec/fixtures/projects.json
263
278
  - spec/fixtures/raw_file.json
279
+ - spec/fixtures/repository_file.json
264
280
  - spec/fixtures/session.json
265
281
  - spec/fixtures/shell_history.json
266
282
  - spec/fixtures/snippet.json
@@ -272,6 +288,7 @@ test_files:
272
288
  - spec/fixtures/tree.json
273
289
  - spec/fixtures/user.json
274
290
  - spec/fixtures/users.json
291
+ - spec/gitlab/cli_helpers_spec.rb
275
292
  - spec/gitlab/cli_spec.rb
276
293
  - spec/gitlab/client/branches_spec.rb
277
294
  - spec/gitlab/client/groups_spec.rb
@@ -282,11 +299,14 @@ test_files:
282
299
  - spec/gitlab/client/notes_spec.rb
283
300
  - spec/gitlab/client/projects_spec.rb
284
301
  - spec/gitlab/client/repositories_spec.rb
302
+ - spec/gitlab/client/repository_files_spec.rb
285
303
  - spec/gitlab/client/snippets_spec.rb
286
304
  - spec/gitlab/client/system_hooks_spec.rb
287
305
  - spec/gitlab/client/users_spec.rb
306
+ - spec/gitlab/help_spec.rb
288
307
  - spec/gitlab/objectified_hash_spec.rb
289
308
  - spec/gitlab/request_spec.rb
290
309
  - spec/gitlab/shell_history_spec.rb
310
+ - spec/gitlab/shell_spec.rb
291
311
  - spec/gitlab_spec.rb
292
312
  - spec/spec_helper.rb