gitlab-akerl 4.0.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 (201) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +20 -0
  3. data/.prospectus +11 -0
  4. data/.travis.yml +8 -0
  5. data/CHANGELOG.md +229 -0
  6. data/CONTRIBUTING.md +195 -0
  7. data/Gemfile +4 -0
  8. data/LICENSE.txt +24 -0
  9. data/README.md +192 -0
  10. data/Rakefile +9 -0
  11. data/bin/console +10 -0
  12. data/bin/setup +6 -0
  13. data/exe/gitlab +7 -0
  14. data/gitlab-akerl.gemspec +31 -0
  15. data/lib/gitlab.rb +45 -0
  16. data/lib/gitlab/api.rb +19 -0
  17. data/lib/gitlab/cli.rb +89 -0
  18. data/lib/gitlab/cli_helpers.rb +241 -0
  19. data/lib/gitlab/client.rb +48 -0
  20. data/lib/gitlab/client/branches.rb +91 -0
  21. data/lib/gitlab/client/build_triggers.rb +51 -0
  22. data/lib/gitlab/client/build_variables.rb +66 -0
  23. data/lib/gitlab/client/builds.rb +106 -0
  24. data/lib/gitlab/client/commits.rb +121 -0
  25. data/lib/gitlab/client/groups.rb +144 -0
  26. data/lib/gitlab/client/issues.rb +113 -0
  27. data/lib/gitlab/client/labels.rb +57 -0
  28. data/lib/gitlab/client/merge_requests.rb +168 -0
  29. data/lib/gitlab/client/milestones.rb +78 -0
  30. data/lib/gitlab/client/namespaces.rb +20 -0
  31. data/lib/gitlab/client/notes.rb +161 -0
  32. data/lib/gitlab/client/pipelines.rb +68 -0
  33. data/lib/gitlab/client/projects.rb +471 -0
  34. data/lib/gitlab/client/repositories.rb +78 -0
  35. data/lib/gitlab/client/repository_files.rb +88 -0
  36. data/lib/gitlab/client/runners.rb +115 -0
  37. data/lib/gitlab/client/services.rb +50 -0
  38. data/lib/gitlab/client/snippets.rb +91 -0
  39. data/lib/gitlab/client/system_hooks.rb +59 -0
  40. data/lib/gitlab/client/tags.rb +96 -0
  41. data/lib/gitlab/client/users.rb +250 -0
  42. data/lib/gitlab/configuration.rb +55 -0
  43. data/lib/gitlab/error.rb +85 -0
  44. data/lib/gitlab/file_response.rb +46 -0
  45. data/lib/gitlab/help.rb +95 -0
  46. data/lib/gitlab/objectified_hash.rb +34 -0
  47. data/lib/gitlab/page_links.rb +33 -0
  48. data/lib/gitlab/paginated_response.rb +97 -0
  49. data/lib/gitlab/request.rb +117 -0
  50. data/lib/gitlab/shell.rb +84 -0
  51. data/lib/gitlab/shell_history.rb +59 -0
  52. data/lib/gitlab/version.rb +3 -0
  53. data/spec/fixtures/branch.json +1 -0
  54. data/spec/fixtures/branch_delete.json +3 -0
  55. data/spec/fixtures/branches.json +1 -0
  56. data/spec/fixtures/build.json +38 -0
  57. data/spec/fixtures/build_artifacts.json +0 -0
  58. data/spec/fixtures/build_cancel.json +24 -0
  59. data/spec/fixtures/build_erase.json +24 -0
  60. data/spec/fixtures/build_retry.json +24 -0
  61. data/spec/fixtures/builds.json +78 -0
  62. data/spec/fixtures/builds_commits.json +64 -0
  63. data/spec/fixtures/compare_merge_request_diff.json +31 -0
  64. data/spec/fixtures/error_already_exists.json +1 -0
  65. data/spec/fixtures/error_project_not_found.json +1 -0
  66. data/spec/fixtures/get_repository_file.json +1 -0
  67. data/spec/fixtures/git_hook.json +1 -0
  68. data/spec/fixtures/group.json +60 -0
  69. data/spec/fixtures/group_create.json +1 -0
  70. data/spec/fixtures/group_create_with_description.json +1 -0
  71. data/spec/fixtures/group_delete.json +1 -0
  72. data/spec/fixtures/group_member.json +1 -0
  73. data/spec/fixtures/group_member_delete.json +1 -0
  74. data/spec/fixtures/group_member_edit.json +1 -0
  75. data/spec/fixtures/group_members.json +1 -0
  76. data/spec/fixtures/group_projects.json +44 -0
  77. data/spec/fixtures/group_search.json +2 -0
  78. data/spec/fixtures/groups.json +2 -0
  79. data/spec/fixtures/issue.json +1 -0
  80. data/spec/fixtures/issues.json +1 -0
  81. data/spec/fixtures/key.json +1 -0
  82. data/spec/fixtures/keys.json +1 -0
  83. data/spec/fixtures/label.json +1 -0
  84. data/spec/fixtures/labels.json +1 -0
  85. data/spec/fixtures/merge_request.json +1 -0
  86. data/spec/fixtures/merge_request_changes.json +1 -0
  87. data/spec/fixtures/merge_request_comment.json +1 -0
  88. data/spec/fixtures/merge_request_comments.json +1 -0
  89. data/spec/fixtures/merge_request_commits.json +1 -0
  90. data/spec/fixtures/merge_requests.json +1 -0
  91. data/spec/fixtures/milestone.json +1 -0
  92. data/spec/fixtures/milestone_issues.json +1 -0
  93. data/spec/fixtures/milestones.json +1 -0
  94. data/spec/fixtures/namespaces.json +1 -0
  95. data/spec/fixtures/note.json +1 -0
  96. data/spec/fixtures/notes.json +1 -0
  97. data/spec/fixtures/pipeline.json +23 -0
  98. data/spec/fixtures/pipeline_cancel.json +23 -0
  99. data/spec/fixtures/pipeline_create.json +23 -0
  100. data/spec/fixtures/pipeline_retry.json +23 -0
  101. data/spec/fixtures/pipelines.json +48 -0
  102. data/spec/fixtures/project.json +1 -0
  103. data/spec/fixtures/project_commit.json +13 -0
  104. data/spec/fixtures/project_commit_comment.json +1 -0
  105. data/spec/fixtures/project_commit_comments.json +1 -0
  106. data/spec/fixtures/project_commit_diff.json +10 -0
  107. data/spec/fixtures/project_commit_status.json +42 -0
  108. data/spec/fixtures/project_commits.json +1 -0
  109. data/spec/fixtures/project_edit.json +21 -0
  110. data/spec/fixtures/project_events.json +1 -0
  111. data/spec/fixtures/project_for_user.json +1 -0
  112. data/spec/fixtures/project_fork.json +50 -0
  113. data/spec/fixtures/project_fork_link.json +1 -0
  114. data/spec/fixtures/project_forked_for_user.json +50 -0
  115. data/spec/fixtures/project_hook.json +1 -0
  116. data/spec/fixtures/project_hooks.json +1 -0
  117. data/spec/fixtures/project_issues.json +1 -0
  118. data/spec/fixtures/project_key.json +6 -0
  119. data/spec/fixtures/project_keys.json +6 -0
  120. data/spec/fixtures/project_runner_enable.json +7 -0
  121. data/spec/fixtures/project_runners.json +16 -0
  122. data/spec/fixtures/project_search.json +1 -0
  123. data/spec/fixtures/project_star.json +44 -0
  124. data/spec/fixtures/project_tag_annotated.json +1 -0
  125. data/spec/fixtures/project_tag_lightweight.json +1 -0
  126. data/spec/fixtures/project_tags.json +1 -0
  127. data/spec/fixtures/project_unstar.json +44 -0
  128. data/spec/fixtures/project_update_commit_status.json +20 -0
  129. data/spec/fixtures/projects.json +1 -0
  130. data/spec/fixtures/raw_file.json +2 -0
  131. data/spec/fixtures/release_create.json +1 -0
  132. data/spec/fixtures/release_update.json +1 -0
  133. data/spec/fixtures/repository_file.json +1 -0
  134. data/spec/fixtures/runner.json +26 -0
  135. data/spec/fixtures/runner_delete.json +7 -0
  136. data/spec/fixtures/runner_edit.json +26 -0
  137. data/spec/fixtures/runners.json +16 -0
  138. data/spec/fixtures/runners_all.json +30 -0
  139. data/spec/fixtures/service.json +1 -0
  140. data/spec/fixtures/session.json +1 -0
  141. data/spec/fixtures/shell_history.json +2 -0
  142. data/spec/fixtures/snippet.json +1 -0
  143. data/spec/fixtures/snippet_content.json +3 -0
  144. data/spec/fixtures/snippets.json +1 -0
  145. data/spec/fixtures/system_hook.json +1 -0
  146. data/spec/fixtures/system_hooks.json +1 -0
  147. data/spec/fixtures/tag.json +1 -0
  148. data/spec/fixtures/tag_create.json +1 -0
  149. data/spec/fixtures/tag_create_with_description.json +1 -0
  150. data/spec/fixtures/tag_delete.json +1 -0
  151. data/spec/fixtures/tags.json +1 -0
  152. data/spec/fixtures/team_member.json +1 -0
  153. data/spec/fixtures/team_members.json +1 -0
  154. data/spec/fixtures/tree.json +1 -0
  155. data/spec/fixtures/trigger.json +7 -0
  156. data/spec/fixtures/triggers.json +16 -0
  157. data/spec/fixtures/user.json +1 -0
  158. data/spec/fixtures/user_block_unblock.json +1 -0
  159. data/spec/fixtures/user_email.json +1 -0
  160. data/spec/fixtures/user_emails.json +1 -0
  161. data/spec/fixtures/user_search.json +1 -0
  162. data/spec/fixtures/users.json +1 -0
  163. data/spec/fixtures/variable.json +4 -0
  164. data/spec/fixtures/variables.json +10 -0
  165. data/spec/gitlab/cli_helpers_spec.rb +57 -0
  166. data/spec/gitlab/cli_spec.rb +110 -0
  167. data/spec/gitlab/client/branches_spec.rb +99 -0
  168. data/spec/gitlab/client/build_triggers_spec.rb +67 -0
  169. data/spec/gitlab/client/build_variables_spec.rb +86 -0
  170. data/spec/gitlab/client/builds_spec.rb +148 -0
  171. data/spec/gitlab/client/client_spec.rb +11 -0
  172. data/spec/gitlab/client/commits_spec.rb +137 -0
  173. data/spec/gitlab/client/groups_spec.rb +197 -0
  174. data/spec/gitlab/client/issues_spec.rb +138 -0
  175. data/spec/gitlab/client/labels_spec.rb +68 -0
  176. data/spec/gitlab/client/merge_requests_spec.rb +177 -0
  177. data/spec/gitlab/client/milestones_spec.rb +82 -0
  178. data/spec/gitlab/client/namespaces_spec.rb +22 -0
  179. data/spec/gitlab/client/notes_spec.rb +205 -0
  180. data/spec/gitlab/client/pipelines_spec.rb +95 -0
  181. data/spec/gitlab/client/projects_spec.rb +603 -0
  182. data/spec/gitlab/client/repositories_spec.rb +109 -0
  183. data/spec/gitlab/client/repository_files_spec.rb +62 -0
  184. data/spec/gitlab/client/runners_spec.rb +185 -0
  185. data/spec/gitlab/client/services_spec.rb +55 -0
  186. data/spec/gitlab/client/snippets_spec.rb +100 -0
  187. data/spec/gitlab/client/system_hooks_spec.rb +69 -0
  188. data/spec/gitlab/client/tags_spec.rb +109 -0
  189. data/spec/gitlab/client/users_spec.rb +418 -0
  190. data/spec/gitlab/error_spec.rb +45 -0
  191. data/spec/gitlab/file_response_spec.rb +33 -0
  192. data/spec/gitlab/help_spec.rb +46 -0
  193. data/spec/gitlab/objectified_hash_spec.rb +48 -0
  194. data/spec/gitlab/page_links_spec.rb +16 -0
  195. data/spec/gitlab/paginated_response_spec.rb +60 -0
  196. data/spec/gitlab/request_spec.rb +73 -0
  197. data/spec/gitlab/shell_history_spec.rb +53 -0
  198. data/spec/gitlab/shell_spec.rb +80 -0
  199. data/spec/gitlab_spec.rb +97 -0
  200. data/spec/spec_helper.rb +74 -0
  201. metadata +476 -0
@@ -0,0 +1,110 @@
1
+ require 'spec_helper'
2
+ require 'json'
3
+
4
+ describe Gitlab::CLI do
5
+ describe ".run" do
6
+ context "when command is version" do
7
+ it "should show gem version" do
8
+ output = capture_output { Gitlab::CLI.run('-v') }
9
+ expect(output).to eq("Gitlab Ruby Gem #{Gitlab::VERSION}\n")
10
+ end
11
+ end
12
+
13
+ context "when command is info" do
14
+ it "should show environment info" do
15
+ output = capture_output { Gitlab::CLI.run('info') }
16
+ expect(output).to include("Gitlab endpoint is")
17
+ expect(output).to include("Gitlab private token is")
18
+ expect(output).to include("Ruby Version is")
19
+ expect(output).to include("Gitlab Ruby Gem")
20
+ end
21
+ end
22
+
23
+ context "when command is help" do
24
+ it "should show available actions" do
25
+ output = capture_output { Gitlab::CLI.run('help') }
26
+ expect(output).to include('Help Topics')
27
+ expect(output).to include('MergeRequests')
28
+ end
29
+ end
30
+
31
+ context "when command is user" do
32
+ before do
33
+ stub_get("/user", "user")
34
+ @output = capture_output { Gitlab::CLI.run('user') }
35
+ end
36
+
37
+ it "should show executed command" do
38
+ expect(@output).to include('Gitlab.user')
39
+ end
40
+
41
+ it "should show user data" do
42
+ expect(@output).to include('name')
43
+ expect(@output).to include('John Smith')
44
+ end
45
+ end
46
+
47
+ context "when command is users" do
48
+ before do
49
+ stub_get("/users", "users")
50
+ @output = capture_output { Gitlab::CLI.run('users') }
51
+ end
52
+
53
+ it "should show executed command" do
54
+ expect(@output).to include('Gitlab.users')
55
+ end
56
+
57
+ it "should show users data" do
58
+ expect(@output).to include('name')
59
+ expect(@output).to include('John Smith')
60
+ expect(@output).to include('Jack Smith')
61
+ end
62
+ end
63
+ end
64
+
65
+ describe ".start" do
66
+ context "when command with excluded fields" do
67
+ before do
68
+ stub_get("/user", "user")
69
+ args = ['user', '--except=id,email,name']
70
+ @output = capture_output { Gitlab::CLI.start(args) }
71
+ end
72
+
73
+ it "should show user data with excluded fields" do
74
+ expect(@output).to_not include('John Smith')
75
+ expect(@output).to include('bio')
76
+ expect(@output).to include('created_at')
77
+ end
78
+ end
79
+
80
+ context "when command with json output" do
81
+ before do
82
+ stub_get("/user", "user")
83
+ args = ['user', '--json']
84
+ @output = capture_output { Gitlab::CLI.start(args) }
85
+ end
86
+
87
+ it "should render output as json" do
88
+ expect(JSON.parse(@output)['result']).to eq(JSON.parse(File.read(File.dirname(__FILE__) + '/../fixtures/user.json')))
89
+ expect(JSON.parse(@output)['cmd']).to eq('Gitlab.user')
90
+ end
91
+ end
92
+
93
+ context "when command with required fields" do
94
+ before do
95
+ stub_get("/user", "user")
96
+ args = ['user', '--only=id,email,name']
97
+ @output = capture_output { Gitlab::CLI.start(args) }
98
+ end
99
+
100
+ it "should show user data with required fields" do
101
+ expect(@output).to include('id')
102
+ expect(@output).to include('name')
103
+ expect(@output).to include('email')
104
+ expect(@output).to include('John Smith')
105
+ expect(@output).to_not include('bio')
106
+ expect(@output).to_not include('created_at')
107
+ end
108
+ end
109
+ end
110
+ end
@@ -0,0 +1,99 @@
1
+ require 'spec_helper'
2
+
3
+ describe Gitlab::Client do
4
+ it { should respond_to :repo_branches }
5
+ it { should respond_to :repo_branch }
6
+ it { should respond_to :repo_protect_branch }
7
+ it { should respond_to :repo_unprotect_branch }
8
+
9
+ describe ".branches" do
10
+ before do
11
+ stub_get("/projects/3/repository/branches", "branches")
12
+ @branches = Gitlab.branches(3)
13
+ end
14
+
15
+ it "should get the correct resource" do
16
+ expect(a_get("/projects/3/repository/branches")).to have_been_made
17
+ end
18
+
19
+ it "should return a paginated response of repository branches" do
20
+ expect(@branches).to be_a Gitlab::PaginatedResponse
21
+ expect(@branches.first.name).to eq("api")
22
+ end
23
+ end
24
+
25
+ describe ".branch" do
26
+ before do
27
+ stub_get("/projects/3/repository/branches/api", "branch")
28
+ @branch = Gitlab.branch(3, "api")
29
+ end
30
+
31
+ it "should get the correct resource" do
32
+ expect(a_get("/projects/3/repository/branches/api")).to have_been_made
33
+ end
34
+
35
+ it "should return information about a repository branch" do
36
+ expect(@branch.name).to eq("api")
37
+ end
38
+ end
39
+
40
+ describe ".protect_branch" do
41
+ before do
42
+ stub_put("/projects/3/repository/branches/api/protect", "branch")
43
+ @branch = Gitlab.protect_branch(3, "api")
44
+ end
45
+
46
+ it "should get the correct resource" do
47
+ expect(a_put("/projects/3/repository/branches/api/protect")).to have_been_made
48
+ end
49
+
50
+ it "should return information about a protected repository branch" do
51
+ expect(@branch.name).to eq("api")
52
+ end
53
+ end
54
+
55
+ describe ".unprotect_branch" do
56
+ before do
57
+ stub_put("/projects/3/repository/branches/api/unprotect", "branch")
58
+ @branch = Gitlab.unprotect_branch(3, "api")
59
+ end
60
+
61
+ it "should get the correct resource" do
62
+ expect(a_put("/projects/3/repository/branches/api/unprotect")).to have_been_made
63
+ end
64
+
65
+ it "should return information about an unprotected repository branch" do
66
+ expect(@branch.name).to eq("api")
67
+ end
68
+ end
69
+
70
+ describe ".create_branch" do
71
+ before do
72
+ stub_post("/projects/3/repository/branches", "branch")
73
+ @branch = Gitlab.create_branch(3, "api", "master")
74
+ end
75
+
76
+ it "should get the correct resource" do
77
+ expect(a_post("/projects/3/repository/branches")).to have_been_made
78
+ end
79
+
80
+ it "should return information about a new repository branch" do
81
+ expect(@branch.name).to eq("api")
82
+ end
83
+ end
84
+
85
+ describe ".delete_branch" do
86
+ before do
87
+ stub_delete("/projects/3/repository/branches/api", "branch_delete")
88
+ @branch = Gitlab.delete_branch(3, "api")
89
+ end
90
+
91
+ it "should get the correct resource" do
92
+ expect(a_delete("/projects/3/repository/branches/api")).to have_been_made
93
+ end
94
+
95
+ it "should return information about the deleted repository branch" do
96
+ expect(@branch.branch_name).to eq("api")
97
+ end
98
+ end
99
+ end
@@ -0,0 +1,67 @@
1
+ require 'spec_helper'
2
+
3
+ describe Gitlab::Client do
4
+ describe ".triggers" do
5
+ before do
6
+ stub_get("/projects/3/triggers", "triggers")
7
+ @triggers = Gitlab.triggers(3)
8
+ end
9
+
10
+ it "should get the correct resource" do
11
+ expect(a_get("/projects/3/triggers")).to have_been_made
12
+ end
13
+
14
+ it "should return an array of project's triggers" do
15
+ expect(@triggers).to be_a Gitlab::PaginatedResponse
16
+ expect(@triggers.first.token).to eq("fbdb730c2fbdb095a0862dbd8ab88b")
17
+ end
18
+ end
19
+
20
+ describe ".trigger" do
21
+ before do
22
+ stub_get("/projects/3/triggers/7b9148c158980bbd9bcea92c17522d", "trigger")
23
+ @trigger = Gitlab.trigger(3, "7b9148c158980bbd9bcea92c17522d")
24
+ end
25
+
26
+ it "should get the correct resource" do
27
+ expect(a_get("/projects/3/triggers/7b9148c158980bbd9bcea92c17522d")).to have_been_made
28
+ end
29
+
30
+ it "should return information about a trigger" do
31
+ expect(@trigger.created_at).to eq("2015-12-23T16:25:56.760Z")
32
+ expect(@trigger.token).to eq("7b9148c158980bbd9bcea92c17522d")
33
+ end
34
+ end
35
+
36
+ describe ".create_trigger" do
37
+ before do
38
+ stub_post("/projects/3/triggers", "trigger")
39
+ @trigger = Gitlab.create_trigger(3)
40
+ end
41
+
42
+ it "should get the correct resource" do
43
+ expect(a_post("/projects/3/triggers")).to have_been_made
44
+ end
45
+
46
+ it "should return information about a new trigger" do
47
+ expect(@trigger.created_at).to eq("2015-12-23T16:25:56.760Z")
48
+ expect(@trigger.token).to eq("7b9148c158980bbd9bcea92c17522d")
49
+ end
50
+ end
51
+
52
+ describe ".remove_trigger" do
53
+ before do
54
+ stub_delete("/projects/3/triggers/7b9148c158980bbd9bcea92c17522d", "trigger")
55
+ @trigger = Gitlab.remove_trigger(3, "7b9148c158980bbd9bcea92c17522d")
56
+ end
57
+
58
+ it "should get the correct resource" do
59
+ expect(a_delete("/projects/3/triggers/7b9148c158980bbd9bcea92c17522d")).to have_been_made
60
+ end
61
+
62
+ it "should return information about a deleted trigger" do
63
+ expect(@trigger.created_at).to eq("2015-12-23T16:25:56.760Z")
64
+ expect(@trigger.token).to eq("7b9148c158980bbd9bcea92c17522d")
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,86 @@
1
+ require 'spec_helper'
2
+
3
+ describe Gitlab::Client do
4
+ describe ".variables" do
5
+ before do
6
+ stub_get("/projects/3/variables", "variables")
7
+ @variables = Gitlab.variables(3)
8
+ end
9
+
10
+ it "should get the correct resource" do
11
+ expect(a_get("/projects/3/variables")).to have_been_made
12
+ end
13
+
14
+ it "should return an array of project's variables" do
15
+ expect(@variables).to be_a Gitlab::PaginatedResponse
16
+ expect(@variables.first.key).to eq("TEST_VARIABLE_1")
17
+ expect(@variables.first.value).to eq("TEST_1")
18
+ end
19
+ end
20
+
21
+ describe ".variable" do
22
+ before do
23
+ stub_get("/projects/3/variables/VARIABLE", "variable")
24
+ @variable = Gitlab.variable(3, "VARIABLE")
25
+ end
26
+
27
+ it "should get the correct resource" do
28
+ expect(a_get("/projects/3/variables/VARIABLE")).to have_been_made
29
+ end
30
+
31
+ it "should return information about a variable" do
32
+ expect(@variable.key).to eq("VARIABLE")
33
+ expect(@variable.value).to eq("the value")
34
+ end
35
+ end
36
+
37
+ describe ".create_variable" do
38
+ before do
39
+ stub_post("/projects/3/variables", "variable")
40
+ @variable = Gitlab.create_variable(3, "NEW_VARIABLE", "new value")
41
+ end
42
+
43
+ it "should get the correct resource" do
44
+ body = { key: "NEW_VARIABLE", value: "new value" }
45
+ expect(a_post("/projects/3/variables").with(body: body)).to have_been_made
46
+ end
47
+
48
+ it "should return information about a new variable" do
49
+ expect(@variable.key).to eq("VARIABLE")
50
+ expect(@variable.value).to eq("the value")
51
+ end
52
+ end
53
+
54
+ describe ".update_variable" do
55
+ before do
56
+ stub_put("/projects/3/variables/UPD_VARIABLE", "variable")
57
+ @variable = Gitlab.update_variable(3, "UPD_VARIABLE", "updated value")
58
+ end
59
+
60
+ it "should put the correct resource" do
61
+ body = { value: "updated value" }
62
+ expect(a_put("/projects/3/variables/UPD_VARIABLE").with(body: body)).to have_been_made
63
+ end
64
+
65
+ it "should return information about an updated variable" do
66
+ expect(@variable.key).to eq("VARIABLE")
67
+ expect(@variable.value).to eq("the value")
68
+ end
69
+ end
70
+
71
+ describe ".remove_variable" do
72
+ before do
73
+ stub_delete("/projects/3/variables/DEL_VARIABLE", "variable")
74
+ @variable = Gitlab.remove_variable(3, "DEL_VARIABLE")
75
+ end
76
+
77
+ it "should get the correct resource" do
78
+ expect(a_delete("/projects/3/variables/DEL_VARIABLE")).to have_been_made
79
+ end
80
+
81
+ it "should return information about a deleted variable" do
82
+ expect(@variable.key).to eq("VARIABLE")
83
+ expect(@variable.value).to eq("the value")
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,148 @@
1
+ require 'spec_helper'
2
+
3
+ describe Gitlab::Client do
4
+ describe ".builds" do
5
+ before do
6
+ stub_get("/projects/3/builds", "builds")
7
+ @builds = Gitlab.builds(3)
8
+ end
9
+
10
+ it "should get the correct resource" do
11
+ expect(a_get("/projects/3/builds")).to have_been_made
12
+ end
13
+
14
+ it "should return a paginated response of project's builds" do
15
+ expect(@builds).to be_a Gitlab::PaginatedResponse
16
+ end
17
+ end
18
+
19
+ describe ".build" do
20
+ before do
21
+ stub_get("/projects/3/builds/8", "build")
22
+ @build = Gitlab.build(3, 8)
23
+ end
24
+
25
+ it "should get the correct resource" do
26
+ expect(a_get("/projects/3/builds/8")).to have_been_made
27
+ end
28
+
29
+ it "should return a single build" do
30
+ expect(@build).to be_a Gitlab::ObjectifiedHash
31
+ end
32
+
33
+ it "should return information about a build" do
34
+ expect(@build.id).to eq(8)
35
+ expect(@build.user.name).to eq("John Smith")
36
+ end
37
+ end
38
+
39
+ describe ".build_artifacts" do
40
+ context "when successful request" do
41
+ before do
42
+ fixture = load_fixture('build_artifacts')
43
+ fixture.set_encoding(Encoding::ASCII_8BIT)
44
+ stub_request(:get, "#{Gitlab.endpoint}/projects/3/builds/8/artifacts").
45
+ with(headers: { 'PRIVATE-TOKEN' => Gitlab.private_token }).
46
+ to_return(body: fixture.read, headers: { 'Content-Disposition' => "attachment; filename=artifacts.zip" })
47
+ @build_artifacts = Gitlab.build_artifacts(3, 8)
48
+ end
49
+
50
+ it "should get the correct resource" do
51
+ expect(a_get("/projects/3/builds/8/artifacts")).to have_been_made
52
+ end
53
+
54
+ it "should return a FileResponse" do
55
+ expect(@build_artifacts).to be_a Gitlab::FileResponse
56
+ end
57
+
58
+ it "should return a file with filename" do
59
+ expect(@build_artifacts.filename).to eq "artifacts.zip"
60
+ end
61
+ end
62
+
63
+ context "when bad request" do
64
+ it "should throw an exception" do
65
+ stub_get("/projects/3/builds/8/artifacts", "error_project_not_found", 404)
66
+ expect{ Gitlab.build_artifacts(3, 8) }.to raise_error(Gitlab::Error::NotFound, "Server responded with code 404, message: 404 Project Not Found. Request URI: #{Gitlab.endpoint}/projects/3/builds/8/artifacts")
67
+ end
68
+ end
69
+ end
70
+
71
+ describe ".builds_commits" do
72
+ before do
73
+ stub_get("/projects/3/repository/commits/0ff3ae198f8601a285adcf5c0fff204ee6fba5fd/builds", "builds_commits")
74
+ @builds_commits = Gitlab.commit_builds(3, "0ff3ae198f8601a285adcf5c0fff204ee6fba5fd")
75
+ end
76
+
77
+ it "should get the correct resource" do
78
+ expect(a_get("/projects/3/repository/commits/0ff3ae198f8601a285adcf5c0fff204ee6fba5fd/builds")).to have_been_made
79
+ end
80
+
81
+ it "should return a paginated response of commit builds" do
82
+ expect(@builds_commits).to be_a Gitlab::PaginatedResponse
83
+ end
84
+
85
+ it "should return information about the builds" do
86
+ expect(@builds_commits.count).to eq(2)
87
+ end
88
+ end
89
+
90
+
91
+
92
+ describe ".build_cancel" do
93
+ before do
94
+ stub_post("/projects/3/builds/8/cancel", "build_cancel")
95
+ @build_cancel = Gitlab.build_cancel(3, 8)
96
+ end
97
+
98
+ it "should get the correct resource" do
99
+ expect(a_post("/projects/3/builds/8/cancel")).to have_been_made
100
+ end
101
+
102
+ it "should return a single build" do
103
+ expect(@build_cancel).to be_a Gitlab::ObjectifiedHash
104
+ end
105
+
106
+ it "should return information about a build" do
107
+ expect(@build_cancel.commit.author_name).to eq("John Smith")
108
+ end
109
+ end
110
+
111
+ describe ".build_retry" do
112
+ before do
113
+ stub_post("/projects/3/builds/69/retry", "build_retry")
114
+ @build_retry = Gitlab.build_retry(3, 69)
115
+ end
116
+
117
+ it "should get the correct resource" do
118
+ expect(a_post("/projects/3/builds/69/retry")).to have_been_made
119
+ end
120
+
121
+ it "should return a single build" do
122
+ expect(@build_retry).to be_a Gitlab::ObjectifiedHash
123
+ end
124
+
125
+ it "should return information about a build" do
126
+ expect(@build_retry.commit.author_name).to eq("John Smith")
127
+ end
128
+ end
129
+
130
+ describe ".build_erase" do
131
+ before do
132
+ stub_post("/projects/3/builds/69/erase", "build_erase")
133
+ @build_retry = Gitlab.build_erase(3, 69)
134
+ end
135
+
136
+ it "should get the correct resource" do
137
+ expect(a_post("/projects/3/builds/69/erase")).to have_been_made
138
+ end
139
+
140
+ it "should return a single build" do
141
+ expect(@build_retry).to be_a Gitlab::ObjectifiedHash
142
+ end
143
+
144
+ it "should return information about a build" do
145
+ expect(@build_retry.commit.author_name).to eq("John Smith")
146
+ end
147
+ end
148
+ end