gitlab-akerl 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
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,95 @@
1
+ require 'spec_helper'
2
+
3
+ describe Gitlab::Client do
4
+ describe ".pipelines" do
5
+ before do
6
+ stub_get("/projects/3/pipelines", "pipelines")
7
+ @pipelines = Gitlab.pipelines(3)
8
+ end
9
+
10
+ it "should get the correct resource" do
11
+ expect(a_get("/projects/3/pipelines")).to have_been_made
12
+ end
13
+
14
+ it "should return a paginated response of project's pipelines" do
15
+ expect(@pipelines).to be_a Gitlab::PaginatedResponse
16
+ end
17
+ end
18
+
19
+ describe ".pipeline" do
20
+ before do
21
+ stub_get("/projects/3/pipelines/46", "pipeline")
22
+ @pipeline = Gitlab.pipeline(3, 46)
23
+ end
24
+
25
+ it "should get the correct resource" do
26
+ expect(a_get("/projects/3/pipelines/46")).to have_been_made
27
+ end
28
+
29
+ it "should return a single pipeline" do
30
+ expect(@pipeline).to be_a Gitlab::ObjectifiedHash
31
+ end
32
+
33
+ it "should return information about a pipeline" do
34
+ expect(@pipeline.id).to eq(46)
35
+ expect(@pipeline.user.name).to eq("Administrator")
36
+ end
37
+ end
38
+
39
+ describe ".create_pipeline" do
40
+ before do
41
+ stub_post("/projects/3/pipeline?ref=master", "pipeline_create")
42
+ @pipeline_create = Gitlab.create_pipeline(3, 'master')
43
+ end
44
+
45
+ it "should get the correct resource" do
46
+ expect(a_post("/projects/3/pipeline?ref=master")).to have_been_made
47
+ end
48
+
49
+ it "should return a single pipeline" do
50
+ expect(@pipeline_create).to be_a Gitlab::ObjectifiedHash
51
+ end
52
+
53
+ it "should return information about a pipeline" do
54
+ expect(@pipeline_create.user.name).to eq("Administrator")
55
+ end
56
+ end
57
+
58
+ describe ".cancel_pipeline" do
59
+ before do
60
+ stub_post("/projects/3/pipelines/46/cancel", "pipeline_cancel")
61
+ @pipeline_cancel = Gitlab.cancel_pipeline(3, 46)
62
+ end
63
+
64
+ it "should get the correct resource" do
65
+ expect(a_post("/projects/3/pipelines/46/cancel")).to have_been_made
66
+ end
67
+
68
+ it "should return a single pipeline" do
69
+ expect(@pipeline_cancel).to be_a Gitlab::ObjectifiedHash
70
+ end
71
+
72
+ it "should return information about a pipeline" do
73
+ expect(@pipeline_cancel.user.name).to eq("Administrator")
74
+ end
75
+ end
76
+
77
+ describe ".retry_pipeline" do
78
+ before do
79
+ stub_post("/projects/3/pipelines/46/retry", "pipeline_retry")
80
+ @pipeline_retry = Gitlab.retry_pipeline(3, 46)
81
+ end
82
+
83
+ it "should get the correct resource" do
84
+ expect(a_post("/projects/3/pipelines/46/retry")).to have_been_made
85
+ end
86
+
87
+ it "should return a single pipeline" do
88
+ expect(@pipeline_retry).to be_a Gitlab::ObjectifiedHash
89
+ end
90
+
91
+ it "should return information about a pipeline" do
92
+ expect(@pipeline_retry.user.name).to eq("Administrator")
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,603 @@
1
+ require 'spec_helper'
2
+
3
+ describe Gitlab::Client do
4
+ it { should respond_to :search_projects }
5
+
6
+ describe ".projects" do
7
+ before do
8
+ stub_get("/projects", "projects")
9
+ @projects = Gitlab.projects
10
+ end
11
+
12
+ it "should get the correct resource" do
13
+ expect(a_get("/projects")).to have_been_made
14
+ end
15
+
16
+ it "should return a paginated response of projects" do
17
+ expect(@projects).to be_a Gitlab::PaginatedResponse
18
+ expect(@projects.first.name).to eq("Brute")
19
+ expect(@projects.first.owner.name).to eq("John Smith")
20
+ end
21
+ end
22
+
23
+ describe ".project_search" do
24
+ before do
25
+ stub_get("/projects/search/Gitlab", "project_search")
26
+ @project_search = Gitlab.project_search("Gitlab")
27
+ end
28
+
29
+ it "should get the correct resource" do
30
+ expect(a_get("/projects/search/Gitlab")).to have_been_made
31
+ end
32
+
33
+ it "should return a paginated response of projects found" do
34
+ expect(@project_search).to be_a Gitlab::PaginatedResponse
35
+ expect(@project_search.first.name).to eq("Gitlab")
36
+ expect(@project_search.first.owner.name).to eq("John Smith")
37
+ end
38
+ end
39
+
40
+ describe ".project" do
41
+ before do
42
+ stub_get("/projects/3", "project")
43
+ @project = Gitlab.project(3)
44
+ end
45
+
46
+ it "should get the correct resource" do
47
+ expect(a_get("/projects/3")).to have_been_made
48
+ end
49
+
50
+ it "should return information about a project" do
51
+ expect(@project.name).to eq("Gitlab")
52
+ expect(@project.owner.name).to eq("John Smith")
53
+ end
54
+ end
55
+
56
+ describe ".project_events" do
57
+ before do
58
+ stub_get("/projects/2/events", "project_events")
59
+ @events = Gitlab.project_events(2)
60
+ end
61
+
62
+ it "should get the correct resource" do
63
+ expect(a_get("/projects/2/events")).to have_been_made
64
+ end
65
+
66
+ it "should return a paginated response of events" do
67
+ expect(@events).to be_a Gitlab::PaginatedResponse
68
+ expect(@events.size).to eq(2)
69
+ end
70
+
71
+ it "should return the action name of the event" do
72
+ expect(@events.first.action_name).to eq("opened")
73
+ end
74
+ end
75
+
76
+ describe ".create_project" do
77
+ before do
78
+ stub_post("/projects", "project")
79
+ @project = Gitlab.create_project('Gitlab')
80
+ end
81
+
82
+ it "should get the correct resource" do
83
+ expect(a_post("/projects")).to have_been_made
84
+ end
85
+
86
+ it "should return information about a created project" do
87
+ expect(@project.name).to eq("Gitlab")
88
+ expect(@project.owner.name).to eq("John Smith")
89
+ end
90
+ end
91
+
92
+ describe ".create_project for user" do
93
+ before do
94
+ stub_post("/users", "user")
95
+ @owner = Gitlab.create_user("john@example.com", "pass", name: 'John Owner')
96
+ stub_post("/projects/user/#{@owner.id}", "project_for_user")
97
+ @project = Gitlab.create_project('Brute', user_id: @owner.id)
98
+ end
99
+
100
+ it "should return information about a created project" do
101
+ expect(@project.name).to eq("Brute")
102
+ expect(@project.owner.name).to eq("John Owner")
103
+ end
104
+ end
105
+
106
+ describe ".delete_project" do
107
+ before do
108
+ stub_delete("/projects/Gitlab", "project")
109
+ @project = Gitlab.delete_project('Gitlab')
110
+ end
111
+
112
+ it "should get the correct resource" do
113
+ expect(a_delete("/projects/Gitlab")).to have_been_made
114
+ end
115
+
116
+ it "should return information about a deleted project" do
117
+ expect(@project.name).to eq("Gitlab")
118
+ expect(@project.owner.name).to eq("John Smith")
119
+ end
120
+ end
121
+
122
+ describe ".create_fork" do
123
+ context "without sudo option" do
124
+ before do
125
+ stub_post("/projects/fork/3", "project_fork")
126
+ @project = Gitlab.create_fork(3)
127
+ end
128
+
129
+ it "should post to the correct resource" do
130
+ expect(a_post("/projects/fork/3")).to have_been_made
131
+ end
132
+
133
+ it "should return information about the forked project" do
134
+ expect(@project.forked_from_project.id).to eq(3)
135
+ expect(@project.id).to eq(20)
136
+ end
137
+ end
138
+
139
+ context "with the sudo option" do
140
+ before do
141
+ stub_post("/projects/fork/3", "project_forked_for_user")
142
+ @sudoed_username = 'jack.smith'
143
+ @project = Gitlab.create_fork(3, sudo: @sudoed_username)
144
+ end
145
+
146
+ it "should post to the correct resource" do
147
+ expect(a_post("/projects/fork/3")).to have_been_made
148
+ end
149
+
150
+ it "should return information about the forked project" do
151
+ expect(@project.forked_from_project.id).to eq(3)
152
+ expect(@project.id).to eq(20)
153
+ expect(@project.owner.username).to eq(@sudoed_username)
154
+ end
155
+ end
156
+ end
157
+
158
+ describe ".team_members" do
159
+ before do
160
+ stub_get("/projects/3/members", "team_members")
161
+ @team_members = Gitlab.team_members(3)
162
+ end
163
+
164
+ it "should get the correct resource" do
165
+ expect(a_get("/projects/3/members")).to have_been_made
166
+ end
167
+
168
+ it "should return a paginated response of team members" do
169
+ expect(@team_members).to be_a Gitlab::PaginatedResponse
170
+ expect(@team_members.first.name).to eq("John Smith")
171
+ end
172
+ end
173
+
174
+ describe ".team_member" do
175
+ before do
176
+ stub_get("/projects/3/members/1", "team_member")
177
+ @team_member = Gitlab.team_member(3, 1)
178
+ end
179
+
180
+ it "should get the correct resource" do
181
+ expect(a_get("/projects/3/members/1")).to have_been_made
182
+ end
183
+
184
+ it "should return information about a team member" do
185
+ expect(@team_member.name).to eq("John Smith")
186
+ end
187
+ end
188
+
189
+ describe ".add_team_member" do
190
+ before do
191
+ stub_post("/projects/3/members", "team_member")
192
+ @team_member = Gitlab.add_team_member(3, 1, 40)
193
+ end
194
+
195
+ it "should get the correct resource" do
196
+ expect(a_post("/projects/3/members").
197
+ with(body: { user_id: '1', access_level: '40' })).to have_been_made
198
+ end
199
+
200
+ it "should return information about an added team member" do
201
+ expect(@team_member.name).to eq("John Smith")
202
+ end
203
+ end
204
+
205
+ describe ".edit_team_member" do
206
+ before do
207
+ stub_put("/projects/3/members/1", "team_member")
208
+ @team_member = Gitlab.edit_team_member(3, 1, 40)
209
+ end
210
+
211
+ it "should get the correct resource" do
212
+ expect(a_put("/projects/3/members/1").
213
+ with(body: { access_level: '40' })).to have_been_made
214
+ end
215
+
216
+ it "should return information about an edited team member" do
217
+ expect(@team_member.name).to eq("John Smith")
218
+ end
219
+ end
220
+
221
+ describe ".remove_team_member" do
222
+ before do
223
+ stub_delete("/projects/3/members/1", "team_member")
224
+ @team_member = Gitlab.remove_team_member(3, 1)
225
+ end
226
+
227
+ it "should get the correct resource" do
228
+ expect(a_delete("/projects/3/members/1")).to have_been_made
229
+ end
230
+
231
+ it "should return information about a removed team member" do
232
+ expect(@team_member.name).to eq("John Smith")
233
+ end
234
+ end
235
+
236
+ describe ".project_hooks" do
237
+ before do
238
+ stub_get("/projects/1/hooks", "project_hooks")
239
+ @hooks = Gitlab.project_hooks(1)
240
+ end
241
+
242
+ it "should get the correct resource" do
243
+ expect(a_get("/projects/1/hooks")).to have_been_made
244
+ end
245
+
246
+ it "should return a paginated response of hooks" do
247
+ expect(@hooks).to be_a Gitlab::PaginatedResponse
248
+ expect(@hooks.first.url).to eq("https://api.example.net/v1/webhooks/ci")
249
+ end
250
+ end
251
+
252
+ describe ".project_hook" do
253
+ before do
254
+ stub_get("/projects/1/hooks/1", "project_hook")
255
+ @hook = Gitlab.project_hook(1, 1)
256
+ end
257
+
258
+ it "should get the correct resource" do
259
+ expect(a_get("/projects/1/hooks/1")).to have_been_made
260
+ end
261
+
262
+ it "should return information about a hook" do
263
+ expect(@hook.url).to eq("https://api.example.net/v1/webhooks/ci")
264
+ end
265
+ end
266
+
267
+ describe ".add_project_hook" do
268
+ context "without specified events" do
269
+ before do
270
+ stub_post("/projects/1/hooks", "project_hook")
271
+ @hook = Gitlab.add_project_hook(1, "https://api.example.net/v1/webhooks/ci")
272
+ end
273
+
274
+ it "should get the correct resource" do
275
+ body = { url: "https://api.example.net/v1/webhooks/ci" }
276
+ expect(a_post("/projects/1/hooks").with(body: body)).to have_been_made
277
+ end
278
+
279
+ it "should return information about an added hook" do
280
+ expect(@hook.url).to eq("https://api.example.net/v1/webhooks/ci")
281
+ end
282
+ end
283
+
284
+ context "with specified events" do
285
+ before do
286
+ stub_post("/projects/1/hooks", "project_hook")
287
+ @hook = Gitlab.add_project_hook(1, "https://api.example.net/v1/webhooks/ci", push_events: true, merge_requests_events: true)
288
+ end
289
+
290
+ it "should get the correct resource" do
291
+ body = { url: "https://api.example.net/v1/webhooks/ci", push_events: "true", merge_requests_events: "true" }
292
+ expect(a_post("/projects/1/hooks").with(body: body)).to have_been_made
293
+ end
294
+
295
+ it "should return information about an added hook" do
296
+ expect(@hook.url).to eq("https://api.example.net/v1/webhooks/ci")
297
+ end
298
+ end
299
+ end
300
+
301
+ describe ".edit_project_hook" do
302
+ before do
303
+ stub_put("/projects/1/hooks/1", "project_hook")
304
+ @hook = Gitlab.edit_project_hook(1, 1, "https://api.example.net/v1/webhooks/ci")
305
+ end
306
+
307
+ it "should get the correct resource" do
308
+ body = { url: "https://api.example.net/v1/webhooks/ci" }
309
+ expect(a_put("/projects/1/hooks/1").with(body: body)).to have_been_made
310
+ end
311
+
312
+ it "should return information about an edited hook" do
313
+ expect(@hook.url).to eq("https://api.example.net/v1/webhooks/ci")
314
+ end
315
+ end
316
+
317
+ describe ".edit_project" do
318
+ before do
319
+ stub_put("/projects/3", "project_edit").with(query: { name: "Gitlab-edit" })
320
+ @edited_project = Gitlab.edit_project(3, name: "Gitlab-edit")
321
+ end
322
+
323
+ it "should get the correct resource" do
324
+ expect(a_put("/projects/3").with(query: { name: "Gitlab-edit" })).to have_been_made
325
+ end
326
+
327
+ it "should return information about an edited project" do
328
+ expect(@edited_project.name).to eq("Gitlab-edit")
329
+ end
330
+ end
331
+
332
+ describe ".delete_project_hook" do
333
+ context "when empty response" do
334
+ before do
335
+ stub_request(:delete, "#{Gitlab.endpoint}/projects/1/hooks/1").
336
+ with(headers: { 'PRIVATE-TOKEN' => Gitlab.private_token }).
337
+ to_return(body: '')
338
+ @hook = Gitlab.delete_project_hook(1, 1)
339
+ end
340
+
341
+ it "should get the correct resource" do
342
+ expect(a_delete("/projects/1/hooks/1")).to have_been_made
343
+ end
344
+
345
+ it "should return false" do
346
+ expect(@hook).to be(false)
347
+ end
348
+ end
349
+
350
+ context "when JSON response" do
351
+ before do
352
+ stub_delete("/projects/1/hooks/1", "project_hook")
353
+ @hook = Gitlab.delete_project_hook(1, 1)
354
+ end
355
+
356
+ it "should get the correct resource" do
357
+ expect(a_delete("/projects/1/hooks/1")).to have_been_made
358
+ end
359
+
360
+ it "should return information about a deleted hook" do
361
+ expect(@hook.url).to eq("https://api.example.net/v1/webhooks/ci")
362
+ end
363
+ end
364
+ end
365
+
366
+ describe ".git_hook" do
367
+ before do
368
+ stub_get("/projects/1/git_hook", "git_hook")
369
+ @git_hook = Gitlab.git_hook(1)
370
+ end
371
+
372
+ it "should get the correct resource" do
373
+ expect(a_get("/projects/1/git_hook")).to have_been_made
374
+ end
375
+
376
+ it "should return information about a git hook" do
377
+ expect(@git_hook.commit_message_regex).to eq("\\b[A-Z]{3}-[0-9]+\\b")
378
+ end
379
+ end
380
+
381
+ describe ".add_git_hook" do
382
+ before do
383
+ stub_post("/projects/1/git_hook", "git_hook")
384
+ @git_hook = Gitlab.add_git_hook(1, { deny_delete_tag: false, commit_message_regex: "\\b[A-Z]{3}-[0-9]+\\b" })
385
+ end
386
+
387
+ it "should get the correct resource" do
388
+ expect(a_post("/projects/1/git_hook")).to have_been_made
389
+ end
390
+
391
+ it "should return information about an added git hook" do
392
+ expect(@git_hook.commit_message_regex).to eq("\\b[A-Z]{3}-[0-9]+\\b")
393
+ end
394
+ end
395
+
396
+ describe ".edit_git_hook" do
397
+ before do
398
+ stub_put("/projects/1/git_hook", "git_hook")
399
+ @git_hook = Gitlab.edit_git_hook(1, { deny_delete_tag: false, commit_message_regex: "\\b[A-Z]{3}-[0-9]+\\b" })
400
+ end
401
+
402
+ it "should get the correct resource" do
403
+ expect(a_put("/projects/1/git_hook")).to have_been_made
404
+ end
405
+
406
+ it "should return information about an edited git hook" do
407
+ expect(@git_hook.commit_message_regex).to eq("\\b[A-Z]{3}-[0-9]+\\b")
408
+ end
409
+ end
410
+
411
+ describe ".delete_git_hook" do
412
+ context "when empty response" do
413
+ before do
414
+ stub_request(:delete, "#{Gitlab.endpoint}/projects/1/git_hook").
415
+ with(headers: { 'PRIVATE-TOKEN' => Gitlab.private_token }).
416
+ to_return(body: '')
417
+ @git_hook = Gitlab.delete_git_hook(1)
418
+ end
419
+
420
+ it "should get the correct resource" do
421
+ expect(a_delete("/projects/1/git_hook")).to have_been_made
422
+ end
423
+
424
+ it "should return false" do
425
+ expect(@git_hook).to be(false)
426
+ end
427
+ end
428
+
429
+ context "when JSON response" do
430
+ before do
431
+ stub_delete("/projects/1/git_hook", "git_hook")
432
+ @git_hook = Gitlab.delete_git_hook(1)
433
+ end
434
+
435
+ it "should get the correct resource" do
436
+ expect(a_delete("/projects/1/git_hook")).to have_been_made
437
+ end
438
+
439
+ it "should return information about a deleted git hook" do
440
+ expect(@git_hook.commit_message_regex).to eq("\\b[A-Z]{3}-[0-9]+\\b")
441
+ end
442
+ end
443
+ end
444
+
445
+ describe ".make_forked_from" do
446
+ before do
447
+ stub_post("/projects/42/fork/24", "project_fork_link")
448
+ @forked_project_link = Gitlab.make_forked_from(42, 24)
449
+ end
450
+
451
+ it "should get the correct resource" do
452
+ expect(a_post("/projects/42/fork/24")).to have_been_made
453
+ end
454
+
455
+ it "should return information about a forked project" do
456
+ expect(@forked_project_link.forked_from_project_id).to eq(24)
457
+ expect(@forked_project_link.forked_to_project_id).to eq(42)
458
+ end
459
+ end
460
+
461
+ describe ".remove_forked" do
462
+ before do
463
+ stub_delete("/projects/42/fork", "project_fork_link")
464
+ @forked_project_link = Gitlab.remove_forked(42)
465
+ end
466
+
467
+ it "should be sent to correct resource" do
468
+ expect(a_delete("/projects/42/fork")).to have_been_made
469
+ end
470
+
471
+ it "should return information about an unforked project" do
472
+ expect(@forked_project_link.forked_to_project_id).to eq(42)
473
+ end
474
+ end
475
+
476
+ describe ".deploy_keys" do
477
+ before do
478
+ stub_get("/projects/42/keys", "project_keys")
479
+ @deploy_keys = Gitlab.deploy_keys(42)
480
+ end
481
+
482
+ it "should get the correct resource" do
483
+ expect(a_get("/projects/42/keys")).to have_been_made
484
+ end
485
+
486
+ it "should return project deploy keys" do
487
+ expect(@deploy_keys).to be_a Gitlab::PaginatedResponse
488
+ expect(@deploy_keys.first.id).to eq 2
489
+ expect(@deploy_keys.first.title).to eq "Key Title"
490
+ expect(@deploy_keys.first.key).to match(/ssh-rsa/)
491
+ end
492
+ end
493
+
494
+ describe ".deploy_key" do
495
+ before do
496
+ stub_get("/projects/42/keys/2", "project_key")
497
+ @deploy_key = Gitlab.deploy_key(42, 2)
498
+ end
499
+
500
+ it "should get the correct resource" do
501
+ expect(a_get("/projects/42/keys/2")).to have_been_made
502
+ end
503
+
504
+ it "should return project deploy key" do
505
+ expect(@deploy_key.id).to eq 2
506
+ expect(@deploy_key.title).to eq "Key Title"
507
+ expect(@deploy_key.key).to match(/ssh-rsa/)
508
+ end
509
+ end
510
+
511
+ describe ".delete_deploy_key" do
512
+ before do
513
+ stub_delete("/projects/42/keys/2", "project_key")
514
+ @deploy_key = Gitlab.delete_deploy_key(42, 2)
515
+ end
516
+
517
+ it "should get the correct resource" do
518
+ expect(a_delete("/projects/42/keys/2")).to have_been_made
519
+ end
520
+
521
+ it "should return information about a deleted key" do
522
+ expect(@deploy_key.id).to eq(2)
523
+ end
524
+ end
525
+
526
+ describe ".enable_deploy_key" do
527
+ before do
528
+ stub_post("/projects/42/deploy_keys/2/enable", "project_key")
529
+ @deploy_key = Gitlab.enable_deploy_key(42, 2)
530
+ end
531
+
532
+ it "should get the correct resource" do
533
+ expect(a_post("/projects/42/deploy_keys/2/enable").
534
+ with(body: { id: '42', key_id: '2' })).to have_been_made
535
+ end
536
+
537
+ it "should return information about an enabled key" do
538
+ expect(@deploy_key.id).to eq(2)
539
+ end
540
+ end
541
+
542
+ describe ".disable_deploy_key" do
543
+ before do
544
+ stub_post("/projects/42/deploy_keys/2/disable", "project_key")
545
+ @deploy_key = Gitlab.disable_deploy_key(42, 2)
546
+ end
547
+
548
+ it "should get the correct resource" do
549
+ expect(a_post("/projects/42/deploy_keys/2/disable").
550
+ with(body: { id: '42', key_id: '2' })).to have_been_made
551
+ end
552
+
553
+ it "should return information about a disabled key" do
554
+ expect(@deploy_key.id).to eq(2)
555
+ end
556
+ end
557
+
558
+ describe ".share_project_with_group" do
559
+ before do
560
+ stub_post("/projects/3/share", "group")
561
+ @group = Gitlab.share_project_with_group(3, 10, 40)
562
+ end
563
+
564
+ it "should get the correct resource" do
565
+ expect(a_post("/projects/3/share").
566
+ with(body: { group_id: '10', group_access: '40' })).to have_been_made
567
+ end
568
+
569
+ it "should return information about an added group" do
570
+ expect(@group.id).to eq(10)
571
+ end
572
+ end
573
+
574
+ describe ".star_project" do
575
+ before do
576
+ stub_post("/projects/3/star", "project_star")
577
+ @starred_project = Gitlab.star_project(3)
578
+ end
579
+
580
+ it "should get the correct resource" do
581
+ expect(a_post("/projects/3/star")).to have_been_made
582
+ end
583
+
584
+ it "should return information about the starred project" do
585
+ expect(@starred_project.id).to eq(3)
586
+ end
587
+ end
588
+
589
+ describe ".unstar_project" do
590
+ before do
591
+ stub_delete("/projects/3/star", "project_unstar")
592
+ @unstarred_project = Gitlab.unstar_project(3)
593
+ end
594
+
595
+ it "should get the correct resource" do
596
+ expect(a_delete("/projects/3/star")).to have_been_made
597
+ end
598
+
599
+ it "should return information about the unstarred project" do
600
+ expect(@unstarred_project.id).to eq(3)
601
+ end
602
+ end
603
+ end