gitlab 3.4.0 → 3.5.0

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.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +30 -2
  3. data/README.md +22 -0
  4. data/bin/console +10 -0
  5. data/bin/setup +6 -0
  6. data/{bin → exe}/gitlab +0 -0
  7. data/gitlab.gemspec +4 -1
  8. data/lib/gitlab.rb +1 -1
  9. data/lib/gitlab/cli.rb +20 -2
  10. data/lib/gitlab/cli_helpers.rb +74 -15
  11. data/lib/gitlab/client.rb +2 -0
  12. data/lib/gitlab/client/commits.rb +121 -0
  13. data/lib/gitlab/client/groups.rb +25 -2
  14. data/lib/gitlab/client/issues.rb +7 -0
  15. data/lib/gitlab/client/milestones.rb +6 -0
  16. data/lib/gitlab/client/namespaces.rb +19 -0
  17. data/lib/gitlab/client/notes.rb +12 -0
  18. data/lib/gitlab/client/projects.rb +30 -0
  19. data/lib/gitlab/client/repositories.rb +0 -75
  20. data/lib/gitlab/client/repository_files.rb +16 -0
  21. data/lib/gitlab/client/snippets.rb +15 -0
  22. data/lib/gitlab/client/users.rb +54 -5
  23. data/lib/gitlab/configuration.rb +14 -0
  24. data/lib/gitlab/error.rb +3 -0
  25. data/lib/gitlab/request.rb +13 -2
  26. data/lib/gitlab/shell.rb +1 -2
  27. data/lib/gitlab/version.rb +1 -1
  28. data/spec/fixtures/branch_delete.json +0 -0
  29. data/spec/fixtures/get_repository_file.json +1 -0
  30. data/spec/fixtures/group_create_with_description.json +1 -0
  31. data/spec/fixtures/group_search.json +2 -0
  32. data/spec/fixtures/namespaces.json +1 -0
  33. data/spec/fixtures/project_commit_status.json +42 -0
  34. data/spec/fixtures/project_edit.json +21 -0
  35. data/spec/fixtures/project_fork.json +50 -0
  36. data/spec/fixtures/project_forked_for_user.json +50 -0
  37. data/spec/fixtures/project_update_commit_status.json +20 -0
  38. data/spec/fixtures/snippet_content.json +3 -0
  39. data/spec/fixtures/user.json +1 -1
  40. data/spec/fixtures/user_block_unblock.json +1 -0
  41. data/spec/fixtures/users.json +1 -1
  42. data/spec/gitlab/cli_helpers_spec.rb +6 -6
  43. data/spec/gitlab/cli_spec.rb +16 -0
  44. data/spec/gitlab/client/commits_spec.rb +137 -0
  45. data/spec/gitlab/client/groups_spec.rb +51 -13
  46. data/spec/gitlab/client/namespaces_spec.rb +22 -0
  47. data/spec/gitlab/client/projects_spec.rb +51 -0
  48. data/spec/gitlab/client/repositories_spec.rb +0 -88
  49. data/spec/gitlab/client/repository_files_spec.rb +17 -0
  50. data/spec/gitlab/client/snippets_spec.rb +15 -0
  51. data/spec/gitlab/client/users_spec.rb +73 -0
  52. data/spec/gitlab/help_spec.rb +1 -1
  53. data/spec/gitlab/request_spec.rb +16 -3
  54. data/spec/gitlab/shell_spec.rb +2 -2
  55. metadata +51 -6
@@ -21,19 +21,40 @@ describe Gitlab::Client do
21
21
  end
22
22
 
23
23
  describe ".create_group" do
24
- before do
25
- stub_post("/groups", "group_create")
26
- @group = Gitlab.create_group('GitLab-Group', 'gitlab-path')
27
- end
28
-
29
- it "should get the correct resource" do
30
- expect(a_post("/groups").
31
- with(:body => {:path => 'gitlab-path', :name => 'GitLab-Group'})).to have_been_made
32
- end
33
-
34
- it "should return information about a created group" do
35
- expect(@group.name).to eq("Gitlab-Group")
36
- expect(@group.path).to eq("gitlab-group")
24
+ context "without description" do
25
+ before do
26
+ stub_post("/groups", "group_create")
27
+ @group = Gitlab.create_group('GitLab-Group', 'gitlab-path')
28
+ end
29
+
30
+ it "should get the correct resource" do
31
+ expect(a_post("/groups").
32
+ with(:body => {:path => 'gitlab-path', :name => 'GitLab-Group'})).to have_been_made
33
+ end
34
+
35
+ it "should return information about a created group" do
36
+ expect(@group.name).to eq("Gitlab-Group")
37
+ expect(@group.path).to eq("gitlab-group")
38
+ end
39
+ end
40
+
41
+ context "with description" do
42
+ before do
43
+ stub_post("/groups", "group_create_with_description")
44
+ @group = Gitlab.create_group('GitLab-Group', 'gitlab-path', :description => 'gitlab group description')
45
+ end
46
+
47
+ it "should get the correct resource" do
48
+ expect(a_post("/groups").
49
+ with(:body => {:path => 'gitlab-path', :name => 'GitLab-Group',
50
+ :description => 'gitlab group description'})).to have_been_made
51
+ end
52
+
53
+ it "should return information about a created group" do
54
+ expect(@group.name).to eq("Gitlab-Group")
55
+ expect(@group.path).to eq("gitlab-group")
56
+ expect(@group.description).to eq("gitlab group description")
57
+ end
37
58
  end
38
59
  end
39
60
 
@@ -108,4 +129,21 @@ describe Gitlab::Client do
108
129
  end
109
130
 
110
131
 
132
+ describe ".group_search" do
133
+ before do
134
+ stub_get("/groups?search=Group", "group_search")
135
+ @groups = Gitlab.group_search('Group')
136
+ end
137
+
138
+ it "should get the correct resource" do
139
+ expect(a_get("/groups?search=Group")).to have_been_made
140
+ end
141
+
142
+ it "should return an array of groups found" do
143
+ expect(@groups.first.id).to eq(5)
144
+ expect(@groups.last.id).to eq(8)
145
+ end
146
+ end
147
+
148
+
111
149
  end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ describe Gitlab::Client do
4
+ it { should respond_to :namespaces }
5
+
6
+ describe ".namespaces" do
7
+ before do
8
+ stub_get("/namespaces", "namespaces")
9
+ @namespaces = Gitlab.namespaces
10
+ end
11
+
12
+ it "should get the correct resource" do
13
+ expect(a_get("/namespaces")).to have_been_made
14
+ end
15
+
16
+ it "should return an array of namespaces" do
17
+ expect(@namespaces).to be_an Array
18
+ expect(@namespaces.first.path).to eq("john")
19
+ expect(@namespaces.first.kind).to eq("user")
20
+ end
21
+ end
22
+ end
@@ -118,6 +118,42 @@ describe Gitlab::Client do
118
118
  end
119
119
  end
120
120
 
121
+ describe ".create_fork" do
122
+ context "without sudo option" do
123
+ before do
124
+ stub_post("/projects/fork/3", "project_fork")
125
+ @project = Gitlab.create_fork(3)
126
+ end
127
+
128
+ it "should post to the correct resource" do
129
+ expect(a_post("/projects/fork/3")).to have_been_made
130
+ end
131
+
132
+ it "should return information about the forked project" do
133
+ expect(@project.forked_from_project.id).to eq(3)
134
+ expect(@project.id).to eq(20)
135
+ end
136
+ end
137
+
138
+ context "with the sudo option" do
139
+ before do
140
+ stub_post("/projects/fork/3", "project_forked_for_user")
141
+ @sudoed_username = 'jack.smith'
142
+ @project = Gitlab.create_fork(3, {sudo: @sudoed_username})
143
+ end
144
+
145
+ it "should post to the correct resource" do
146
+ expect(a_post("/projects/fork/3")).to have_been_made
147
+ end
148
+
149
+ it "should return information about the forked project" do
150
+ expect(@project.forked_from_project.id).to eq(3)
151
+ expect(@project.id).to eq(20)
152
+ expect(@project.owner.username).to eq(@sudoed_username)
153
+ end
154
+ end
155
+ end
156
+
121
157
  describe ".team_members" do
122
158
  before do
123
159
  stub_get("/projects/3/members", "team_members")
@@ -277,6 +313,21 @@ describe Gitlab::Client do
277
313
  end
278
314
  end
279
315
 
316
+ describe ".edit_project" do
317
+ before do
318
+ stub_put("/projects/3", "project_edit").with(:query => { :name => "Gitlab-edit" })
319
+ @edited_project = Gitlab.edit_project(3, :name => "Gitlab-edit")
320
+ end
321
+
322
+ it "should get the correct resource" do
323
+ expect(a_put("/projects/3").with(:query => { :name => "Gitlab-edit" })).to have_been_made
324
+ end
325
+
326
+ it "should return information about an edited project" do
327
+ expect(@edited_project.name).to eq("Gitlab-edit")
328
+ end
329
+ end
330
+
280
331
  describe ".delete_project_hook" do
281
332
  context "when empty response" do
282
333
  before do
@@ -5,11 +5,6 @@ describe Gitlab::Client do
5
5
  it { should respond_to :repo_create_tag }
6
6
  it { should respond_to :repo_branches }
7
7
  it { should respond_to :repo_branch }
8
- it { should respond_to :repo_commits }
9
- it { should respond_to :repo_commit }
10
- it { should respond_to :repo_commit_diff }
11
- it { should respond_to :repo_commit_comments }
12
- it { should respond_to :repo_create_commit_comment }
13
8
  it { should respond_to :repo_tree }
14
9
  it { should respond_to :repo_compare}
15
10
 
@@ -94,89 +89,6 @@ describe Gitlab::Client do
94
89
  end
95
90
  end
96
91
 
97
- describe ".commits" do
98
- before do
99
- stub_get("/projects/3/repository/commits", "project_commits").
100
- with(:query => {:ref_name => "api"})
101
- @commits = Gitlab.commits(3, :ref_name => "api")
102
- end
103
-
104
- it "should get the correct resource" do
105
- expect(a_get("/projects/3/repository/commits").
106
- with(:query => {:ref_name => "api"})).to have_been_made
107
- end
108
-
109
- it "should return an array of repository commits" do
110
- expect(@commits).to be_an Array
111
- expect(@commits.first.id).to eq("f7dd067490fe57505f7226c3b54d3127d2f7fd46")
112
- end
113
- end
114
-
115
- describe ".commit" do
116
- before do
117
- stub_get("/projects/3/repository/commits/6104942438c14ec7bd21c6cd5bd995272b3faff6", "project_commit")
118
- @commit = Gitlab.commit(3, '6104942438c14ec7bd21c6cd5bd995272b3faff6')
119
- end
120
-
121
- it "should get the correct resource" do
122
- expect(a_get("/projects/3/repository/commits/6104942438c14ec7bd21c6cd5bd995272b3faff6"))
123
- .to have_been_made
124
- end
125
-
126
- it "should return a repository commit" do
127
- expect(@commit.id).to eq("6104942438c14ec7bd21c6cd5bd995272b3faff6")
128
- end
129
- end
130
-
131
- describe ".commit_diff" do
132
- before do
133
- stub_get("/projects/3/repository/commits/6104942438c14ec7bd21c6cd5bd995272b3faff6/diff", "project_commit_diff")
134
- @diff = Gitlab.commit_diff(3, '6104942438c14ec7bd21c6cd5bd995272b3faff6')
135
- end
136
-
137
- it "should get the correct resource" do
138
- expect(a_get("/projects/3/repository/commits/6104942438c14ec7bd21c6cd5bd995272b3faff6/diff"))
139
- .to have_been_made
140
- end
141
-
142
- it "should return a diff of a commit" do
143
- expect(@diff.new_path).to eq("doc/update/5.4-to-6.0.md")
144
- end
145
- end
146
-
147
- describe ".commit_comments" do
148
- before do
149
- stub_get("/projects/3/repository/commits/6104942438c14ec7bd21c6cd5bd995272b3faff6/comments", "project_commit_comments")
150
- @commit_comments = Gitlab.commit_comments(3, '6104942438c14ec7bd21c6cd5bd995272b3faff6')
151
- end
152
-
153
- it "should get the correct resource" do
154
- expect(a_get("/projects/3/repository/commits/6104942438c14ec7bd21c6cd5bd995272b3faff6/comments"))
155
- .to have_been_made
156
- end
157
-
158
- it "should return commit's comments" do
159
- expect(@commit_comments).to be_an Array
160
- expect(@commit_comments.length).to eq(2)
161
- expect(@commit_comments[0].note).to eq("this is the 1st comment on commit 6104942438c14ec7bd21c6cd5bd995272b3faff6")
162
- expect(@commit_comments[0].author.id).to eq(11)
163
- expect(@commit_comments[1].note).to eq("another discussion point on commit 6104942438c14ec7bd21c6cd5bd995272b3faff6")
164
- expect(@commit_comments[1].author.id).to eq(12)
165
- end
166
- end
167
-
168
- describe ".create_commit_comment" do
169
- before do
170
- stub_post("/projects/3/repository/commits/6104942438c14ec7bd21c6cd5bd995272b3faff6/comments", "project_commit_comment")
171
- @merge_request = Gitlab.create_commit_comment(3, '6104942438c14ec7bd21c6cd5bd995272b3faff6', 'Nice code!')
172
- end
173
-
174
- it "should return information about the newly created comment" do
175
- expect(@merge_request.note).to eq('Nice code!')
176
- expect(@merge_request.author.id).to eq(1)
177
- end
178
- end
179
-
180
92
  describe ".compare" do
181
93
  before do
182
94
  stub_get("/projects/3/repository/compare", "compare_merge_request_diff").
@@ -1,6 +1,23 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe Gitlab::Client do
4
+ describe ".get_file" do
5
+ before do
6
+ stub_get("/projects/3/repository/files?file_path=README.md&ref=master", "get_repository_file")
7
+ @file = Gitlab.get_file(3, 'README.md', 'master')
8
+ end
9
+
10
+ it "should create the correct resource" do
11
+ expect(a_get("/projects/3/repository/files?file_path=README.md&ref=master")).to have_been_made
12
+ end
13
+
14
+ it "should return the base64 encoded file" do
15
+ expect(@file.file_path).to eq "README.md"
16
+ expect(@file.ref).to eq "master"
17
+ expect(@file.content).to eq "VGhpcyBpcyBhICpSRUFETUUqIQ==\n"
18
+ end
19
+ end
20
+
4
21
  describe ".create_file" do
5
22
  let!(:request_stub) { stub_post("/projects/3/repository/files", "repository_file") }
6
23
  let!(:file) { Gitlab.create_file(3, "path", "branch", "content", "commit message") }
@@ -82,4 +82,19 @@ describe Gitlab::Client do
82
82
  expect(@snippet.author.name).to eq("John Smith")
83
83
  end
84
84
  end
85
+
86
+ describe ".snippet_content" do
87
+ before do
88
+ stub_get("/projects/3/snippets/1/raw", "snippet_content")
89
+ @snippet_content = Gitlab.snippet_content(3, 1)
90
+ end
91
+
92
+ it "should get the correct resource" do
93
+ expect(a_get("/projects/3/snippets/1/raw")).to have_been_made
94
+ end
95
+
96
+ it "should return raw content of a snippet" do
97
+ expect(@snippet_content).to eq("#!/usr/bin/env ruby\n\nputs \"Cool snippet!\"\n")
98
+ end
99
+ end
85
100
  end
@@ -76,6 +76,33 @@ describe Gitlab::Client do
76
76
  end
77
77
  end
78
78
 
79
+ describe ".create_user_with_userame" do
80
+ context "when successful request" do
81
+ before do
82
+ stub_post("/users", "user")
83
+ @user = Gitlab.create_user("email", "pass", "username")
84
+ end
85
+
86
+ it "should get the correct resource" do
87
+ body = {:email => "email", :password => "pass", :username => "username"}
88
+ expect(a_post("/users").with(:body => body)).to have_been_made
89
+ end
90
+
91
+ it "should return information about a created user" do
92
+ expect(@user.email).to eq("john@example.com")
93
+ end
94
+ end
95
+
96
+ context "when bad request" do
97
+ it "should throw an exception" do
98
+ stub_post("/users", "error_already_exists", 409)
99
+ expect {
100
+ Gitlab.create_user("email", "pass", "username")
101
+ }.to raise_error(Gitlab::Error::Conflict, "Server responded with code 409, message: 409 Already exists. Request URI: #{Gitlab.endpoint}/users")
102
+ end
103
+ end
104
+ end
105
+
79
106
  describe ".edit_user" do
80
107
  before do
81
108
  @options = { :name => "Roberto" }
@@ -88,6 +115,51 @@ describe Gitlab::Client do
88
115
  end
89
116
  end
90
117
 
118
+ describe ".delete_user" do
119
+ before do
120
+ stub_delete("/users/1", "user")
121
+ @user = Gitlab.delete_user(1)
122
+ end
123
+
124
+ it "should get the correct resource" do
125
+ expect(a_delete("/users/1")).to have_been_made
126
+ end
127
+
128
+ it "should return information about a deleted user" do
129
+ expect(@user.email).to eq("john@example.com")
130
+ end
131
+ end
132
+
133
+ describe ".block_user" do
134
+ before do
135
+ stub_put("/users/1/block", "user_block_unblock")
136
+ @result = Gitlab.block_user(1)
137
+ end
138
+
139
+ it "should get the correct resource" do
140
+ expect(a_put("/users/1/block")).to have_been_made
141
+ end
142
+
143
+ it "should return boolean" do
144
+ expect(@result).to eq(true)
145
+ end
146
+ end
147
+
148
+ describe ".unblock_user" do
149
+ before do
150
+ stub_put("/users/1/unblock", "user_block_unblock")
151
+ @result = Gitlab.unblock_user(1)
152
+ end
153
+
154
+ it "should get the correct resource" do
155
+ expect(a_put("/users/1/unblock")).to have_been_made
156
+ end
157
+
158
+ it "should return boolean" do
159
+ expect(@result).to eq(true)
160
+ end
161
+ end
162
+
91
163
  describe ".session" do
92
164
  after do
93
165
  Gitlab.endpoint = 'https://api.example.com'
@@ -189,4 +261,5 @@ describe Gitlab::Client do
189
261
  expect(@key.title).to eq("narkoz@helium")
190
262
  end
191
263
  end
264
+
192
265
  end
@@ -13,7 +13,7 @@ describe Gitlab::Help do
13
13
  context "ri command NOT found" do
14
14
  it "should raise" do
15
15
  allow(Gitlab::Help).to receive(:`).with(/which ri/).and_return('')
16
- expect{Gitlab::Help.ri_cmd}.to raise_error
16
+ expect{Gitlab::Help.ri_cmd}.to raise_error RuntimeError
17
17
  end
18
18
  end
19
19
 
@@ -7,9 +7,6 @@ describe Gitlab::Request do
7
7
  it { should respond_to :delete }
8
8
  before do
9
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
10
  end
14
11
 
15
12
  describe ".default_options" do
@@ -27,6 +24,10 @@ describe Gitlab::Request do
27
24
  it "should return ObjectifiedHash" do
28
25
  body = JSON.unparse({a: 1, b: 2})
29
26
  expect(Gitlab::Request.parse(body)).to be_an Gitlab::ObjectifiedHash
27
+ expect(Gitlab::Request.parse("true")).to be true
28
+ expect(Gitlab::Request.parse("false")).to be false
29
+
30
+ expect { Gitlab::Request.parse("string") }.to raise_error(Gitlab::Error::Parsing)
30
31
  end
31
32
  end
32
33
 
@@ -71,12 +72,24 @@ describe Gitlab::Request do
71
72
  end
72
73
 
73
74
  describe "#handle_error" do
75
+ before do
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'] }})
80
+ end
74
81
  context "when passed an ObjectifiedHash" do
75
82
  it "should return a joined string of error messages sorted by key" do
76
83
  expect(@request.send(:handle_error, @obj_h)).to eq("'embed_entity' (foo: bar) (sna: fu), 'password' too short, 'user' not set")
77
84
  end
78
85
  end
79
86
 
87
+ context "when passed an Array" do
88
+ it "should return a joined string of messages" do
89
+ expect(@request.send(:handle_error, @array)).to eq("First message. Second message.")
90
+ end
91
+ end
92
+
80
93
  context "when passed a String" do
81
94
  it "should return the String untouched" do
82
95
  error = 'this is an error string'