gitlab 3.0.0 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/.travis.yml +1 -0
  4. data/LICENSE.txt +1 -1
  5. data/README.md +28 -3
  6. data/bin/gitlab +7 -0
  7. data/gitlab.gemspec +3 -2
  8. data/lib/gitlab.rb +8 -0
  9. data/lib/gitlab/api.rb +1 -1
  10. data/lib/gitlab/cli.rb +57 -0
  11. data/lib/gitlab/cli_helpers.rb +141 -0
  12. data/lib/gitlab/client.rb +8 -6
  13. data/lib/gitlab/client/branches.rb +79 -0
  14. data/lib/gitlab/client/merge_requests.rb +15 -2
  15. data/lib/gitlab/client/projects.rb +25 -4
  16. data/lib/gitlab/client/repositories.rb +22 -23
  17. data/lib/gitlab/client/system_hooks.rb +58 -0
  18. data/lib/gitlab/client/users.rb +17 -0
  19. data/lib/gitlab/configuration.rb +3 -3
  20. data/lib/gitlab/objectified_hash.rb +8 -2
  21. data/lib/gitlab/request.rb +21 -5
  22. data/lib/gitlab/version.rb +1 -1
  23. data/spec/fixtures/branch.json +1 -0
  24. data/spec/fixtures/{project_branches.json → branches.json} +0 -0
  25. data/spec/fixtures/create_branch.json +1 -0
  26. data/spec/fixtures/merge_request_comments.json +1 -0
  27. data/spec/fixtures/project_commit.json +13 -0
  28. data/spec/fixtures/project_commit_diff.json +10 -0
  29. data/spec/fixtures/{project_branch.json → protect_branch.json} +1 -1
  30. data/spec/fixtures/system_hook.json +1 -0
  31. data/spec/fixtures/system_hook_test.json +1 -0
  32. data/spec/fixtures/system_hooks.json +1 -0
  33. data/spec/fixtures/unprotect_branch.json +1 -0
  34. data/spec/gitlab/cli_spec.rb +80 -0
  35. data/spec/gitlab/client/branches_spec.rb +103 -0
  36. data/spec/gitlab/client/groups_spec.rb +21 -21
  37. data/spec/gitlab/client/issues_spec.rb +26 -26
  38. data/spec/gitlab/client/merge_requests_spec.rb +45 -13
  39. data/spec/gitlab/client/milestones_spec.rb +11 -11
  40. data/spec/gitlab/client/notes_spec.rb +30 -30
  41. data/spec/gitlab/client/projects_spec.rb +93 -59
  42. data/spec/gitlab/client/repositories_spec.rb +28 -25
  43. data/spec/gitlab/client/snippets_spec.rb +16 -16
  44. data/spec/gitlab/client/system_hooks_spec.rb +69 -0
  45. data/spec/gitlab/client/users_spec.rb +60 -24
  46. data/spec/gitlab/objectified_hash_spec.rb +23 -0
  47. data/spec/gitlab/request_spec.rb +48 -0
  48. data/spec/gitlab_spec.rb +16 -7
  49. data/spec/spec_helper.rb +19 -8
  50. metadata +70 -22
@@ -5,6 +5,8 @@ describe Gitlab::Client do
5
5
  it { should respond_to :repo_branches }
6
6
  it { should respond_to :repo_branch }
7
7
  it { should respond_to :repo_commits }
8
+ it { should respond_to :repo_commit }
9
+ it { should respond_to :repo_commit_diff }
8
10
 
9
11
  describe ".tags" do
10
12
  before do
@@ -13,61 +15,62 @@ describe Gitlab::Client do
13
15
  end
14
16
 
15
17
  it "should get the correct resource" do
16
- a_get("/projects/3/repository/tags").should have_been_made
18
+ expect(a_get("/projects/3/repository/tags")).to have_been_made
17
19
  end
18
20
 
19
21
  it "should return an array of repository tags" do
20
- @tags.should be_an Array
21
- @tags.first.name.should == "v2.8.2"
22
+ expect(@tags).to be_an Array
23
+ expect(@tags.first.name).to eq("v2.8.2")
22
24
  end
23
25
  end
24
26
 
25
- describe ".branches" do
27
+ describe ".commits" do
26
28
  before do
27
- stub_get("/projects/3/repository/branches", "project_branches")
28
- @branches = Gitlab.branches(3)
29
+ stub_get("/projects/3/repository/commits", "project_commits").
30
+ with(:query => {:ref_name => "api"})
31
+ @commits = Gitlab.commits(3, :ref_name => "api")
29
32
  end
30
33
 
31
34
  it "should get the correct resource" do
32
- a_get("/projects/3/repository/branches").should have_been_made
35
+ expect(a_get("/projects/3/repository/commits").
36
+ with(:query => {:ref_name => "api"})).to have_been_made
33
37
  end
34
38
 
35
- it "should return an array of repository branches" do
36
- @branches.should be_an Array
37
- @branches.first.name.should == "api"
39
+ it "should return an array of repository commits" do
40
+ expect(@commits).to be_an Array
41
+ expect(@commits.first.id).to eq("f7dd067490fe57505f7226c3b54d3127d2f7fd46")
38
42
  end
39
43
  end
40
44
 
41
- describe ".branch" do
45
+ describe ".commit" do
42
46
  before do
43
- stub_get("/projects/3/repository/branches/api", "project_branch")
44
- @branch = Gitlab.branch(3, "api")
47
+ stub_get("/projects/3/repository/commits/6104942438c14ec7bd21c6cd5bd995272b3faff6", "project_commit")
48
+ @commit = Gitlab.commit(3, '6104942438c14ec7bd21c6cd5bd995272b3faff6')
45
49
  end
46
50
 
47
51
  it "should get the correct resource" do
48
- a_get("/projects/3/repository/branches/api").should have_been_made
52
+ expect(a_get("/projects/3/repository/commits/6104942438c14ec7bd21c6cd5bd995272b3faff6"))
53
+ .to have_been_made
49
54
  end
50
55
 
51
- it "should return information about a repository branch" do
52
- @branch.name.should == "api"
56
+ it "should return a repository commit" do
57
+ expect(@commit.id).to eq("6104942438c14ec7bd21c6cd5bd995272b3faff6")
53
58
  end
54
59
  end
55
60
 
56
- describe ".commits" do
61
+ describe ".commit_diff" do
57
62
  before do
58
- stub_get("/projects/3/repository/commits", "project_commits").
59
- with(:query => {:ref_name => "api"})
60
- @commits = Gitlab.commits(3, :ref_name => "api")
63
+ stub_get("/projects/3/repository/commits/6104942438c14ec7bd21c6cd5bd995272b3faff6/diff", "project_commit_diff")
64
+ @diff = Gitlab.commit_diff(3, '6104942438c14ec7bd21c6cd5bd995272b3faff6')
61
65
  end
62
66
 
63
67
  it "should get the correct resource" do
64
- a_get("/projects/3/repository/commits").
65
- with(:query => {:ref_name => "api"}).should have_been_made
68
+ expect(a_get("/projects/3/repository/commits/6104942438c14ec7bd21c6cd5bd995272b3faff6/diff"))
69
+ .to have_been_made
66
70
  end
67
71
 
68
- it "should return an array of repository commits" do
69
- @commits.should be_an Array
70
- @commits.first.id.should == "f7dd067490fe57505f7226c3b54d3127d2f7fd46"
72
+ it "should return a diff of a commit" do
73
+ expect(@diff.new_path).to eq("doc/update/5.4-to-6.0.md")
71
74
  end
72
75
  end
73
76
  end
@@ -8,12 +8,12 @@ describe Gitlab::Client do
8
8
  end
9
9
 
10
10
  it "should get the correct resource" do
11
- a_get("/projects/3/snippets").should have_been_made
11
+ expect(a_get("/projects/3/snippets")).to have_been_made
12
12
  end
13
13
 
14
14
  it "should return an array of project's snippets" do
15
- @snippets.should be_an Array
16
- @snippets.first.file_name.should == "mailer_test.rb"
15
+ expect(@snippets).to be_an Array
16
+ expect(@snippets.first.file_name).to eq("mailer_test.rb")
17
17
  end
18
18
  end
19
19
 
@@ -24,12 +24,12 @@ describe Gitlab::Client do
24
24
  end
25
25
 
26
26
  it "should get the correct resource" do
27
- a_get("/projects/3/snippets/1").should have_been_made
27
+ expect(a_get("/projects/3/snippets/1")).to have_been_made
28
28
  end
29
29
 
30
30
  it "should return information about a snippet" do
31
- @snippet.file_name.should == "mailer_test.rb"
32
- @snippet.author.name.should == "John Smith"
31
+ expect(@snippet.file_name).to eq("mailer_test.rb")
32
+ expect(@snippet.author.name).to eq("John Smith")
33
33
  end
34
34
  end
35
35
 
@@ -41,12 +41,12 @@ describe Gitlab::Client do
41
41
 
42
42
  it "should get the correct resource" do
43
43
  body = {:title => 'API', :file_name => 'api.rb', :code => 'code'}
44
- a_post("/projects/3/snippets").with(:body => body).should have_been_made
44
+ expect(a_post("/projects/3/snippets").with(:body => body)).to have_been_made
45
45
  end
46
46
 
47
47
  it "should return information about a new snippet" do
48
- @snippet.file_name.should == "mailer_test.rb"
49
- @snippet.author.name.should == "John Smith"
48
+ expect(@snippet.file_name).to eq("mailer_test.rb")
49
+ expect(@snippet.author.name).to eq("John Smith")
50
50
  end
51
51
  end
52
52
 
@@ -57,13 +57,13 @@ describe Gitlab::Client do
57
57
  end
58
58
 
59
59
  it "should get the correct resource" do
60
- a_put("/projects/3/snippets/1").
61
- with(:body => {:file_name => 'mailer_test.rb'}).should have_been_made
60
+ expect(a_put("/projects/3/snippets/1").
61
+ with(:body => {:file_name => 'mailer_test.rb'})).to have_been_made
62
62
  end
63
63
 
64
64
  it "should return information about an edited snippet" do
65
- @snippet.file_name.should == "mailer_test.rb"
66
- @snippet.author.name.should == "John Smith"
65
+ expect(@snippet.file_name).to eq("mailer_test.rb")
66
+ expect(@snippet.author.name).to eq("John Smith")
67
67
  end
68
68
  end
69
69
 
@@ -74,12 +74,12 @@ describe Gitlab::Client do
74
74
  end
75
75
 
76
76
  it "should get the correct resource" do
77
- a_delete("/projects/3/snippets/1").should have_been_made
77
+ expect(a_delete("/projects/3/snippets/1")).to have_been_made
78
78
  end
79
79
 
80
80
  it "should return information about a deleted snippet" do
81
- @snippet.file_name.should == "mailer_test.rb"
82
- @snippet.author.name.should == "John Smith"
81
+ expect(@snippet.file_name).to eq("mailer_test.rb")
82
+ expect(@snippet.author.name).to eq("John Smith")
83
83
  end
84
84
  end
85
85
  end
@@ -0,0 +1,69 @@
1
+ require 'spec_helper'
2
+
3
+ describe Gitlab::Client do
4
+ it { should respond_to :system_hooks }
5
+ it { should respond_to :add_system_hook }
6
+ it { should respond_to :system_hook }
7
+ it { should respond_to :delete_system_hook }
8
+
9
+ describe ".hooks" do
10
+ before do
11
+ stub_get("/hooks", "system_hooks")
12
+ @hooks = Gitlab.hooks
13
+ end
14
+
15
+ it "should get the correct resource" do
16
+ expect(a_get("/hooks")).to have_been_made
17
+ end
18
+
19
+ it "should return an array of system hooks" do
20
+ expect(@hooks).to be_an Array
21
+ expect(@hooks.first.url).to eq("http://example.com/hook")
22
+ end
23
+ end
24
+
25
+ describe ".add_hook" do
26
+ before do
27
+ stub_post("/hooks", "system_hook")
28
+ @hook = Gitlab.add_hook("http://example.com/hook")
29
+ end
30
+
31
+ it "should get the correct resource" do
32
+ expect(a_post("/hooks")).to have_been_made
33
+ end
34
+
35
+ it "should return information about a added system hook" do
36
+ expect(@hook.url).to eq("http://example.com/hook")
37
+ end
38
+ end
39
+
40
+ describe ".hook" do
41
+ before do
42
+ stub_get("/hooks/3", "system_hook_test")
43
+ @hook = Gitlab.hook(3)
44
+ end
45
+ it "should get the correct resource" do
46
+ expect(a_get("/hooks/3")).to have_been_made
47
+ end
48
+
49
+ it "should return information about a added system hook" do
50
+ expect(@hook.event_name).to eq("project_create")
51
+ expect(@hook.project_id).to eq(1)
52
+ end
53
+ end
54
+
55
+ describe ".delete_hook" do
56
+ before do
57
+ stub_delete("/hooks/3", "system_hook")
58
+ @hook = Gitlab.delete_hook(3)
59
+ end
60
+
61
+ it "should get the correct resource" do
62
+ expect(a_delete("/hooks/3")).to have_been_made
63
+ end
64
+
65
+ it "should return information about a deleted system hook" do
66
+ expect(@hook.url).to eq("http://example.com/hook")
67
+ end
68
+ end
69
+ end
@@ -8,12 +8,12 @@ describe Gitlab::Client do
8
8
  end
9
9
 
10
10
  it "should get the correct resource" do
11
- a_get("/users").should have_been_made
11
+ expect(a_get("/users")).to have_been_made
12
12
  end
13
13
 
14
14
  it "should return an array of users" do
15
- @users.should be_an Array
16
- @users.first.email.should == "john@example.com"
15
+ expect(@users).to be_an Array
16
+ expect(@users.first.email).to eq("john@example.com")
17
17
  end
18
18
  end
19
19
 
@@ -25,11 +25,11 @@ describe Gitlab::Client do
25
25
  end
26
26
 
27
27
  it "should get the correct resource" do
28
- a_get("/users/1").should have_been_made
28
+ expect(a_get("/users/1")).to have_been_made
29
29
  end
30
30
 
31
31
  it "should return information about a user" do
32
- @user.email.should == "john@example.com"
32
+ expect(@user.email).to eq("john@example.com")
33
33
  end
34
34
  end
35
35
 
@@ -40,11 +40,11 @@ describe Gitlab::Client do
40
40
  end
41
41
 
42
42
  it "should get the correct resource" do
43
- a_get("/user").should have_been_made
43
+ expect(a_get("/user")).to have_been_made
44
44
  end
45
45
 
46
46
  it "should return information about an authorized user" do
47
- @user.email.should == "john@example.com"
47
+ expect(@user.email).to eq("john@example.com")
48
48
  end
49
49
  end
50
50
  end
@@ -58,11 +58,11 @@ describe Gitlab::Client do
58
58
 
59
59
  it "should get the correct resource" do
60
60
  body = {:email => "email", :password => "pass", :name => "email"}
61
- a_post("/users").with(:body => body).should have_been_made
61
+ expect(a_post("/users").with(:body => body)).to have_been_made
62
62
  end
63
63
 
64
64
  it "should return information about a created user" do
65
- @user.email.should == "john@example.com"
65
+ expect(@user.email).to eq("john@example.com")
66
66
  end
67
67
  end
68
68
 
@@ -76,19 +76,55 @@ describe Gitlab::Client do
76
76
  end
77
77
  end
78
78
 
79
+ describe ".edit_user" do
80
+ before do
81
+ @options = { :name => "Roberto" }
82
+ stub_put("/users/1", "user").with(:body => @options)
83
+ @user = Gitlab.edit_user(1, @options)
84
+ end
85
+
86
+ it "should get the correct resource" do
87
+ expect(a_put("/users/1").with(:body => @options)).to have_been_made
88
+ end
89
+ end
90
+
79
91
  describe ".session" do
92
+ after do
93
+ Gitlab.endpoint = 'https://api.example.com'
94
+ Gitlab.private_token = 'secret'
95
+ end
96
+
80
97
  before do
81
- stub_post("/session", "session")
98
+ stub_request(:post, "#{Gitlab.endpoint}/session").
99
+ to_return(:body => load_fixture('session'), :status => 200)
82
100
  @session = Gitlab.session("email", "pass")
83
101
  end
84
102
 
85
- it "should get the correct resource" do
86
- a_post("/session").should have_been_made
103
+ context "when endpoint is not set" do
104
+ it "should raise Error::MissingCredentials" do
105
+ Gitlab.endpoint = nil
106
+ expect {
107
+ Gitlab.session("email", "pass")
108
+ }.to raise_error(Gitlab::Error::MissingCredentials, 'Please set an endpoint to API')
109
+ end
110
+ end
111
+
112
+ context "when private_token is not set" do
113
+ it "should not raise Error::MissingCredentials" do
114
+ Gitlab.private_token = nil
115
+ expect { Gitlab.session("email", "pass") }.to_not raise_error
116
+ end
87
117
  end
88
118
 
89
- it "should return information about a created session" do
90
- @session.email.should == "john@example.com"
91
- @session.private_token.should == "qEsq1pt6HJPaNciie3MG"
119
+ context "when endpoint is set" do
120
+ it "should get the correct resource" do
121
+ expect(a_request(:post, "#{Gitlab.endpoint}/session")).to have_been_made
122
+ end
123
+
124
+ it "should return information about a created session" do
125
+ expect(@session.email).to eq("john@example.com")
126
+ expect(@session.private_token).to eq("qEsq1pt6HJPaNciie3MG")
127
+ end
92
128
  end
93
129
  end
94
130
 
@@ -99,12 +135,12 @@ describe Gitlab::Client do
99
135
  end
100
136
 
101
137
  it "should get the correct resource" do
102
- a_get("/user/keys").should have_been_made
138
+ expect(a_get("/user/keys")).to have_been_made
103
139
  end
104
140
 
105
141
  it "should return an array of SSH keys" do
106
- @keys.should be_an Array
107
- @keys.first.title.should == "narkoz@helium"
142
+ expect(@keys).to be_an Array
143
+ expect(@keys.first.title).to eq("narkoz@helium")
108
144
  end
109
145
  end
110
146
 
@@ -115,11 +151,11 @@ describe Gitlab::Client do
115
151
  end
116
152
 
117
153
  it "should get the correct resource" do
118
- a_get("/user/keys/1").should have_been_made
154
+ expect(a_get("/user/keys/1")).to have_been_made
119
155
  end
120
156
 
121
157
  it "should return information about an SSH key" do
122
- @key.title.should == "narkoz@helium"
158
+ expect(@key.title).to eq("narkoz@helium")
123
159
  end
124
160
  end
125
161
 
@@ -131,11 +167,11 @@ describe Gitlab::Client do
131
167
 
132
168
  it "should get the correct resource" do
133
169
  body = {:title => "title", :key => "body"}
134
- a_post("/user/keys").with(:body => body).should have_been_made
170
+ expect(a_post("/user/keys").with(:body => body)).to have_been_made
135
171
  end
136
172
 
137
173
  it "should return information about a created SSH key" do
138
- @key.title.should == "narkoz@helium"
174
+ expect(@key.title).to eq("narkoz@helium")
139
175
  end
140
176
  end
141
177
 
@@ -146,11 +182,11 @@ describe Gitlab::Client do
146
182
  end
147
183
 
148
184
  it "should get the correct resource" do
149
- a_delete("/user/keys/1").should have_been_made
185
+ expect(a_delete("/user/keys/1")).to have_been_made
150
186
  end
151
187
 
152
188
  it "should return information about a deleted SSH key" do
153
- @key.title.should == "narkoz@helium"
189
+ expect(@key.title).to eq("narkoz@helium")
154
190
  end
155
191
  end
156
192
  end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe Gitlab::ObjectifiedHash do
4
+ before do
5
+ @hash = {a: 1, b: 2}
6
+ @oh = Gitlab::ObjectifiedHash.new @hash
7
+ end
8
+
9
+ it "should objectify hash" do
10
+ expect(@oh.a).to eq(@hash[:a])
11
+ expect(@oh.b).to eq(@hash[:b])
12
+ end
13
+
14
+ describe "#to_hash" do
15
+ it "should return an original hash" do
16
+ expect(@oh.to_hash).to eq(@hash)
17
+ end
18
+
19
+ it "should have an alias #to_h" do
20
+ expect(@oh.respond_to?(:to_h)).to be_true
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,48 @@
1
+ require 'spec_helper'
2
+
3
+ describe Gitlab::Request do
4
+ it { should respond_to :get }
5
+ it { should respond_to :post }
6
+ it { should respond_to :put }
7
+ it { should respond_to :delete }
8
+
9
+ describe ".default_options" do
10
+ it "should have default values" do
11
+ default_options = Gitlab::Request.default_options
12
+ expect(default_options).to be_a Hash
13
+ expect(default_options[:parser]).to be_a Proc
14
+ expect(default_options[:format]).to eq(:json)
15
+ expect(default_options[:headers]).to eq({'Accept' => 'application/json'})
16
+ expect(default_options[:default_params]).to be_nil
17
+ end
18
+ end
19
+
20
+ describe ".parse" do
21
+ it "should return ObjectifiedHash" do
22
+ body = JSON.unparse({a: 1, b: 2})
23
+ expect(Gitlab::Request.parse(body)).to be_an Gitlab::ObjectifiedHash
24
+ end
25
+ end
26
+
27
+ describe "#set_request_defaults" do
28
+ context "when endpoint is not set" do
29
+ it "should raise Error::MissingCredentials" do
30
+ expect {
31
+ Gitlab::Request.new.set_request_defaults(nil, 1234000)
32
+ }.to raise_error(Gitlab::Error::MissingCredentials, 'Please set an endpoint to API')
33
+ end
34
+ end
35
+
36
+ context "when endpoint is set" do
37
+ it "should set base_uri" do
38
+ Gitlab::Request.new.set_request_defaults('http://rabbit-hole.example.org', 1234000)
39
+ expect(Gitlab::Request.base_uri).to eq("http://rabbit-hole.example.org")
40
+ end
41
+
42
+ it "should set default_params" do
43
+ Gitlab::Request.new.set_request_defaults('http://rabbit-hole.example.org', 1234000, 'sudoer')
44
+ expect(Gitlab::Request.default_params).to eq({:sudo => 'sudoer'})
45
+ end
46
+ end
47
+ end
48
+ end