fs-gitlab 4.18.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +270 -0
  3. data/LICENSE.txt +24 -0
  4. data/README.md +260 -0
  5. data/exe/gitlab +11 -0
  6. data/lib/gitlab/api.rb +24 -0
  7. data/lib/gitlab/cli.rb +89 -0
  8. data/lib/gitlab/cli_helpers.rb +243 -0
  9. data/lib/gitlab/client/access_requests.rb +103 -0
  10. data/lib/gitlab/client/application_settings.rb +172 -0
  11. data/lib/gitlab/client/avatar.rb +21 -0
  12. data/lib/gitlab/client/award_emojis.rb +137 -0
  13. data/lib/gitlab/client/boards.rb +146 -0
  14. data/lib/gitlab/client/branches.rb +135 -0
  15. data/lib/gitlab/client/broadcast_messages.rb +75 -0
  16. data/lib/gitlab/client/build_variables.rb +135 -0
  17. data/lib/gitlab/client/builds.rb +108 -0
  18. data/lib/gitlab/client/commits.rb +216 -0
  19. data/lib/gitlab/client/container_registry.rb +85 -0
  20. data/lib/gitlab/client/deployments.rb +34 -0
  21. data/lib/gitlab/client/environments.rb +89 -0
  22. data/lib/gitlab/client/epic_issues.rb +23 -0
  23. data/lib/gitlab/client/epics.rb +73 -0
  24. data/lib/gitlab/client/events.rb +60 -0
  25. data/lib/gitlab/client/features.rb +48 -0
  26. data/lib/gitlab/client/group_badges.rb +88 -0
  27. data/lib/gitlab/client/group_boards.rb +141 -0
  28. data/lib/gitlab/client/group_labels.rb +88 -0
  29. data/lib/gitlab/client/group_milestones.rb +94 -0
  30. data/lib/gitlab/client/groups.rb +358 -0
  31. data/lib/gitlab/client/issue_links.rb +48 -0
  32. data/lib/gitlab/client/issues.rb +231 -0
  33. data/lib/gitlab/client/jobs.rb +250 -0
  34. data/lib/gitlab/client/keys.rb +29 -0
  35. data/lib/gitlab/client/labels.rb +88 -0
  36. data/lib/gitlab/client/lint.rb +19 -0
  37. data/lib/gitlab/client/markdown.rb +23 -0
  38. data/lib/gitlab/client/merge_request_approvals.rb +265 -0
  39. data/lib/gitlab/client/merge_requests.rb +386 -0
  40. data/lib/gitlab/client/milestones.rb +106 -0
  41. data/lib/gitlab/client/namespaces.rb +22 -0
  42. data/lib/gitlab/client/notes.rb +313 -0
  43. data/lib/gitlab/client/packages.rb +95 -0
  44. data/lib/gitlab/client/pipeline_schedules.rb +147 -0
  45. data/lib/gitlab/client/pipeline_triggers.rb +103 -0
  46. data/lib/gitlab/client/pipelines.rb +105 -0
  47. data/lib/gitlab/client/project_badges.rb +85 -0
  48. data/lib/gitlab/client/project_clusters.rb +83 -0
  49. data/lib/gitlab/client/project_release_links.rb +76 -0
  50. data/lib/gitlab/client/project_releases.rb +79 -0
  51. data/lib/gitlab/client/projects.rb +708 -0
  52. data/lib/gitlab/client/protected_tags.rb +59 -0
  53. data/lib/gitlab/client/remote_mirrors.rb +51 -0
  54. data/lib/gitlab/client/repositories.rb +113 -0
  55. data/lib/gitlab/client/repository_files.rb +131 -0
  56. data/lib/gitlab/client/repository_submodules.rb +27 -0
  57. data/lib/gitlab/client/resource_label_events.rb +82 -0
  58. data/lib/gitlab/client/resource_state_events.rb +57 -0
  59. data/lib/gitlab/client/runners.rb +211 -0
  60. data/lib/gitlab/client/search.rb +66 -0
  61. data/lib/gitlab/client/services.rb +53 -0
  62. data/lib/gitlab/client/sidekiq.rb +39 -0
  63. data/lib/gitlab/client/snippets.rb +95 -0
  64. data/lib/gitlab/client/system_hooks.rb +64 -0
  65. data/lib/gitlab/client/tags.rb +97 -0
  66. data/lib/gitlab/client/templates.rb +100 -0
  67. data/lib/gitlab/client/todos.rb +46 -0
  68. data/lib/gitlab/client/user_snippets.rb +114 -0
  69. data/lib/gitlab/client/users.rb +397 -0
  70. data/lib/gitlab/client/versions.rb +18 -0
  71. data/lib/gitlab/client/wikis.rb +79 -0
  72. data/lib/gitlab/client.rb +95 -0
  73. data/lib/gitlab/configuration.rb +57 -0
  74. data/lib/gitlab/error.rb +170 -0
  75. data/lib/gitlab/file_response.rb +48 -0
  76. data/lib/gitlab/help.rb +94 -0
  77. data/lib/gitlab/objectified_hash.rb +51 -0
  78. data/lib/gitlab/page_links.rb +35 -0
  79. data/lib/gitlab/paginated_response.rb +110 -0
  80. data/lib/gitlab/request.rb +109 -0
  81. data/lib/gitlab/shell.rb +83 -0
  82. data/lib/gitlab/shell_history.rb +57 -0
  83. data/lib/gitlab/version.rb +5 -0
  84. data/lib/gitlab.rb +56 -0
  85. metadata +204 -0
@@ -0,0 +1,708 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Gitlab::Client
4
+ # Defines methods related to projects.
5
+ # @see https://docs.gitlab.com/ce/api/projects.html
6
+ module Projects
7
+ # Gets a list of projects owned by the authenticated user.
8
+ #
9
+ # @example
10
+ # Gitlab.projects
11
+ #
12
+ # @param [Hash] options A customizable set of options.
13
+ # @option options [Integer] :page The page number.
14
+ # @option options [Integer] :per_page The number of results per page.
15
+ # (Any provided options will be passed to Gitlab. See {https://docs.gitlab.com/ce/api/projects.html#list-all-projects Gitlab docs} for all valid options)
16
+ #
17
+ # @return [Array<Gitlab::ObjectifiedHash>]
18
+ def projects(options = {})
19
+ get('/projects', query: options)
20
+ end
21
+
22
+ # Search for projects by name.
23
+ #
24
+ # @example
25
+ # Gitlab.project_search('gitlab')
26
+ # Gitlab.project_search('gitlab', { order_by: 'last_activity_at' })
27
+ # Gitlab.search_projects('gitlab', { order_by: 'name', sort: 'asc' })
28
+ #
29
+ # @param [Hash] options A customizable set of options.
30
+ # @option options [String] :per_page Number of projects to return per page
31
+ # @option options [String] :page The page to retrieve
32
+ # @option options [String] :order_by Return requests ordered by id, name, created_at or last_activity_at fields
33
+ # @option options [String] :sort Return requests sorted in asc or desc order
34
+ # @return [Array<Gitlab::ObjectifiedHash>]
35
+ def project_search(query, options = {})
36
+ get('/projects', query: options.merge(search: query))
37
+ end
38
+ alias search_projects project_search
39
+
40
+ # Gets information about a project.
41
+ #
42
+ # @example
43
+ # Gitlab.project(3)
44
+ # Gitlab.project('gitlab')
45
+ #
46
+ # @param [Integer, String] id The ID or path of a project.
47
+ # @param options [string] :license Include project license data
48
+ # @param options [string] :statistics Include project statistics.
49
+ # @param options [string] :with_custom_attributes Include custom attributes in response. (admins only)
50
+ # @return [Gitlab::ObjectifiedHash]
51
+ def project(id, options = {})
52
+ get("/projects/#{url_encode id}", query: options)
53
+ end
54
+
55
+ # Creates a new project.
56
+ #
57
+ # @example
58
+ # Gitlab.create_project('gitlab')
59
+ # Gitlab.create_project('viking', { description: 'Awesome project' })
60
+ # Gitlab.create_project('Red', { wall_enabled: false })
61
+ #
62
+ # @param [String] name The name of a project.
63
+ # @param [Hash] options A customizable set of options.
64
+ # @option options [String] :description The description of a project.
65
+ # @option options [String] :default_branch The default branch of a project.
66
+ # @option options [String] :path Repository name for new project. (Default is lowercase name with dashes)
67
+ # @option options [String] :namespace_id The namespace in which to create a project.
68
+ # @option options [Boolean] :wiki_enabled The wiki integration for a project (0 = false, 1 = true).
69
+ # @option options [Boolean] :wall_enabled The wall functionality for a project (0 = false, 1 = true).
70
+ # @option options [Boolean] :issues_enabled The issues integration for a project (0 = false, 1 = true).
71
+ # @option options [Boolean] :snippets_enabled The snippets integration for a project (0 = false, 1 = true).
72
+ # @option options [Boolean] :merge_requests_enabled The merge requests functionality for a project (0 = false, 1 = true).
73
+ # @option options [String] :visibility The setting for making a project public ('private', 'internal', 'public').
74
+ # @option options [Integer] :user_id The user/owner id of a project.
75
+ # @return [Gitlab::ObjectifiedHash] Information about created project.
76
+ def create_project(name, options = {})
77
+ url = options[:user_id] ? "/projects/user/#{options[:user_id]}" : '/projects'
78
+ post(url, body: { name: name }.merge(options))
79
+ end
80
+
81
+ # Deletes a project.
82
+ #
83
+ # @example
84
+ # Gitlab.delete_project(4)
85
+ #
86
+ # @param [Integer, String] id The ID or path of a project.
87
+ # @return [Gitlab::ObjectifiedHash] Information about deleted project.
88
+ def delete_project(id)
89
+ delete("/projects/#{url_encode id}")
90
+ end
91
+
92
+ # Gets a list of project team members.
93
+ #
94
+ # @example
95
+ # Gitlab.team_members(42)
96
+ # Gitlab.team_members('gitlab')
97
+ #
98
+ # @param [Integer, String] project The ID or path of a project.
99
+ # @param [Hash] options A customizable set of options.
100
+ # @option options [String] :query The search query.
101
+ # @option options [Integer] :page The page number.
102
+ # @option options [Integer] :per_page The number of results per page.
103
+ # @return [Array<Gitlab::ObjectifiedHash>]
104
+ def team_members(project, options = {})
105
+ get("/projects/#{url_encode project}/members", query: options)
106
+ end
107
+
108
+ # Gets a list of all project team members including inherited members.
109
+ #
110
+ # @example
111
+ # Gitlab.all_members(42)
112
+ # Gitlab.all_members('gitlab')
113
+ #
114
+ # @param [Integer, String] project The ID or path of a project.
115
+ # @param [Hash] options A customizable set of options.
116
+ # @option options [String] :query The search query.
117
+ # @option options [Integer] :page The page number.
118
+ # @option options [Integer] :per_page The number of results per page.
119
+ # @return [Array<Gitlab::ObjectifiedHash>]
120
+ def all_members(project, options = {})
121
+ get("/projects/#{url_encode project}/members/all", query: options)
122
+ end
123
+
124
+ # Gets a project team member.
125
+ #
126
+ # @example
127
+ # Gitlab.team_member('gitlab', 2)
128
+ #
129
+ # @param [Integer, String] project The ID or path of a project.
130
+ # @param [Integer] id The ID of a project team member.
131
+ # @return [Gitlab::ObjectifiedHash]
132
+ def team_member(project, id)
133
+ get("/projects/#{url_encode project}/members/#{id}")
134
+ end
135
+
136
+ # Adds a user to project team.
137
+ #
138
+ # @example
139
+ # Gitlab.add_team_member('gitlab', 2, 40)
140
+ # Gitlab.add_team_member('gitlab', 2, 40, { expires_at: "2018-12-31"})
141
+ #
142
+ # @param [Integer, String] project The ID or path of a project.
143
+ # @param [Integer] id The ID of a user.
144
+ # @param [Integer] access_level The access level to project.
145
+ # @param [Hash] options A customizable set of options.
146
+ # @option options [String] :expires_at A date string in the format YEAR-MONTH-DAY.
147
+ # @return [Gitlab::ObjectifiedHash] Information about added team member.
148
+ def add_team_member(project, id, access_level, options = {})
149
+ body = { user_id: id, access_level: access_level }.merge(options)
150
+ post("/projects/#{url_encode project}/members", body: body)
151
+ end
152
+
153
+ # Updates a team member's project access level.
154
+ #
155
+ # @example
156
+ # Gitlab.edit_team_member('gitlab', 3, 20)
157
+ # Gitlab.edit_team_member('gitlab', 3, 20, { expires_at: "2018-12-31"})
158
+ #
159
+ # @param [Integer, String] project The ID or path of a project.
160
+ # @param [Integer] id The ID of a user.
161
+ # @param [Integer] access_level The access level to project.
162
+ # @param [Hash] options A customizable set of options.
163
+ # @option options [String] :expires_at A date string in the format YEAR-MONTH-DAY.
164
+ # @return [Array<Gitlab::ObjectifiedHash>] Information about updated team member.
165
+ def edit_team_member(project, id, access_level, options = {})
166
+ body = { access_level: access_level }.merge(options)
167
+ put("/projects/#{url_encode project}/members/#{id}", body: body)
168
+ end
169
+
170
+ # Removes a user from project team.
171
+ #
172
+ # @example
173
+ # Gitlab.remove_team_member('gitlab', 2)
174
+ #
175
+ # @param [Integer, String] project The ID or path of a project.
176
+ # @param [Integer] id The ID of a user.
177
+ # @param [Hash] options A customizable set of options.
178
+ # @return [Gitlab::ObjectifiedHash] Information about removed team member.
179
+ def remove_team_member(project, id)
180
+ delete("/projects/#{url_encode project}/members/#{id}")
181
+ end
182
+
183
+ # Gets a list of project hooks.
184
+ #
185
+ # @example
186
+ # Gitlab.project_hooks(42)
187
+ # Gitlab.project_hooks('gitlab')
188
+ #
189
+ # @param [Integer, String] project The ID or path of a project.
190
+ # @param [Hash] options A customizable set of options.
191
+ # @option options [Integer] :page The page number.
192
+ # @option options [Integer] :per_page The number of results per page.
193
+ # @return [Array<Gitlab::ObjectifiedHash>]
194
+ def project_hooks(project, options = {})
195
+ get("/projects/#{url_encode project}/hooks", query: options)
196
+ end
197
+
198
+ # Gets a project hook.
199
+ #
200
+ # @example
201
+ # Gitlab.project_hook(42, 5)
202
+ # Gitlab.project_hook('gitlab', 5)
203
+ #
204
+ # @param [Integer, String] project The ID or path of a project.
205
+ # @param [Integer] id The ID of a hook.
206
+ # @return [Gitlab::ObjectifiedHash]
207
+ def project_hook(project, id)
208
+ get("/projects/#{url_encode project}/hooks/#{id}")
209
+ end
210
+
211
+ # Adds a new hook to the project.
212
+ #
213
+ # @example
214
+ # Gitlab.add_project_hook(42, 'https://api.example.net/v1/webhooks/ci')
215
+ #
216
+ # @param [Integer, String] project The ID or path of a project.
217
+ # @param [String] url The hook URL.
218
+ # @param [Hash] options A customizable set of options.
219
+ # @param option [Boolean] :push_events Trigger hook on push events (0 = false, 1 = true)
220
+ # @param option [Boolean] :issues_events Trigger hook on issues events (0 = false, 1 = true)
221
+ # @param option [Boolean] :merge_requests_events Trigger hook on merge_requests events (0 = false, 1 = true)
222
+ # @param option [Boolean] :tag_push_events Trigger hook on push_tag events (0 = false, 1 = true)
223
+ # @return [Gitlab::ObjectifiedHash] Information about added hook.
224
+ def add_project_hook(project, url, options = {})
225
+ body = { url: url }.merge(options)
226
+ post("/projects/#{url_encode project}/hooks", body: body)
227
+ end
228
+
229
+ # Updates a project hook URL.
230
+ #
231
+ # @example
232
+ # Gitlab.edit_project_hook(42, 1, 'https://api.example.net/v1/webhooks/ci')
233
+ #
234
+ # @param [Integer, String] project The ID or path of a project.
235
+ # @param [Integer] id The ID of the hook.
236
+ # @param [String] url The hook URL.
237
+ # @param [Hash] options A customizable set of options.
238
+ # @param option [Boolean] :push_events Trigger hook on push events (0 = false, 1 = true)
239
+ # @param option [Boolean] :issues_events Trigger hook on issues events (0 = false, 1 = true)
240
+ # @param option [Boolean] :merge_requests_events Trigger hook on merge_requests events (0 = false, 1 = true)
241
+ # @param option [Boolean] :tag_push_events Trigger hook on push_tag events (0 = false, 1 = true)
242
+ # @return [Gitlab::ObjectifiedHash] Information about updated hook.
243
+ def edit_project_hook(project, id, url, options = {})
244
+ body = { url: url }.merge(options)
245
+ put("/projects/#{url_encode project}/hooks/#{id}", body: body)
246
+ end
247
+
248
+ # Deletes a hook from project.
249
+ #
250
+ # @example
251
+ # Gitlab.delete_project_hook('gitlab', 4)
252
+ #
253
+ # @param [Integer, String] project The ID or path of a project.
254
+ # @param [String] id The ID of the hook.
255
+ # @return [Gitlab::ObjectifiedHash] Information about deleted hook.
256
+ def delete_project_hook(project, id)
257
+ delete("/projects/#{url_encode project}/hooks/#{id}")
258
+ end
259
+
260
+ # Gets a project push rule.
261
+ # @see https://docs.gitlab.com/ee/api/projects.html#show-project-push-rules
262
+ #
263
+ # @example
264
+ # Gitlab.push_rule(42)
265
+ #
266
+ # @param [Integer] id The ID of a project.
267
+ # @return [Gitlab::ObjectifiedHash]
268
+ def push_rule(id)
269
+ get("/projects/#{url_encode id}/push_rule")
270
+ end
271
+
272
+ # Adds a project push rule.
273
+ # @see https://docs.gitlab.com/ee/api/projects.html#add-project-push-rule
274
+ #
275
+ # @example
276
+ # Gitlab.add_push_rule(42, { deny_delete_tag: false, commit_message_regex: '\\b[A-Z]{3}-[0-9]+\\b' })
277
+ #
278
+ # @param [Integer] id The ID of a project.
279
+ # @param [Hash] options A customizable set of options.
280
+ # @param option [Boolean] :deny_delete_tag Do not allow users to remove git tags with git push (0 = false, 1 = true)
281
+ # @param option [String] :commit_message_regex Commit message regex
282
+ # @return [Gitlab::ObjectifiedHash] Information about added push rule.
283
+ def add_push_rule(id, options = {})
284
+ post("/projects/#{url_encode id}/push_rule", body: options)
285
+ end
286
+
287
+ # Updates a project push rule.
288
+ # @see https://docs.gitlab.com/ee/api/projects.html#edit-project-push-rule
289
+ #
290
+ # @example
291
+ # Gitlab.edit_push_rule(42, { deny_delete_tag: false, commit_message_regex: '\\b[A-Z]{3}-[0-9]+\\b' })
292
+ #
293
+ # @param [Integer] id The ID of a project.
294
+ # @param [Hash] options A customizable set of options.
295
+ # @param option [Boolean] :deny_delete_tag Do not allow users to remove git tags with git push (0 = false, 1 = true)
296
+ # @param option [String] :commit_message_regex Commit message regex
297
+ # @return [Gitlab::ObjectifiedHash] Information about updated push rule.
298
+ def edit_push_rule(id, options = {})
299
+ put("/projects/#{url_encode id}/push_rule", body: options)
300
+ end
301
+
302
+ # Deletes a push rule from a project.
303
+ # @see https://docs.gitlab.com/ee/api/projects.html#delete-project-push-rule
304
+ #
305
+ # @example
306
+ # Gitlab.delete_push_rule(42)
307
+ #
308
+ # @param [Integer] id The ID of a project.
309
+ # @return [Gitlab::ObjectifiedHash] Information about deleted push rule.
310
+ def delete_push_rule(id)
311
+ delete("/projects/#{url_encode id}/push_rule")
312
+ end
313
+
314
+ # Mark this project as forked from the other
315
+ #
316
+ # @example
317
+ # Gitlab.make_forked(42, 24)
318
+ #
319
+ # @param [Integer, String] project The ID or path of a project.
320
+ # @param [Integer] id The ID of the project it is forked from.
321
+ # @return [Gitlab::ObjectifiedHash] Information about the forked project.
322
+ def make_forked_from(project, id)
323
+ post("/projects/#{url_encode project}/fork/#{id}")
324
+ end
325
+
326
+ # Remove a forked_from relationship for a project.
327
+ #
328
+ # @example
329
+ # Gitlab.remove_forked(42)
330
+ #
331
+ # @param [Integer, String] project The ID or path of a project.
332
+ # @param [Integer] project The ID of the project it is forked from
333
+ # @return [Gitlab::ObjectifiedHash] Information about the forked project.
334
+ def remove_forked(project)
335
+ delete("/projects/#{url_encode project}/fork")
336
+ end
337
+
338
+ # Gets a project deploy keys.
339
+ #
340
+ # @example
341
+ # Gitlab.deploy_keys(42)
342
+ #
343
+ # @param [Integer, String] project The ID or path of a project.
344
+ # @param [Hash] options A customizable set of options.
345
+ # @option options [Integer] :page The page number.
346
+ # @option options [Integer] :per_page The number of results per page.
347
+ # @return [Array<Gitlab::ObjectifiedHash>]
348
+ def deploy_keys(project, options = {})
349
+ get("/projects/#{url_encode project}/deploy_keys", query: options)
350
+ end
351
+
352
+ # Gets a single project deploy key.
353
+ #
354
+ # @example
355
+ # Gitlab.deploy_key(42, 1)
356
+ #
357
+ # @param [Integer, String] project The ID or path of a project.
358
+ # @param [Integer] id The ID of a deploy key.
359
+ # @return [Gitlab::ObjectifiedHash]
360
+ def deploy_key(project, id)
361
+ get("/projects/#{url_encode project}/deploy_keys/#{id}")
362
+ end
363
+
364
+ # Creates a new deploy key.
365
+ #
366
+ # @example
367
+ # Gitlab.create_deploy_key(42, 'My Key', 'Key contents', can_push: true)
368
+ #
369
+ # @param [Integer, String] project The ID or path of a project.
370
+ # @param [String] title The title of a deploy key.
371
+ # @param [String] key The content of a deploy key.
372
+ # @param [Hash] options A customizable set of options.
373
+ # @return [Gitlab::ObjectifiedHash] Information about created deploy key.
374
+ def create_deploy_key(project, title, key, options = {})
375
+ post("/projects/#{url_encode project}/deploy_keys", body: { title: title, key: key }.merge(options))
376
+ end
377
+
378
+ # Enables a deploy key at the project.
379
+ #
380
+ # @example
381
+ # Gitlab.enable_deploy_key(42, 66)
382
+ #
383
+ # @param [Integer, String] project The ID or path of a project.
384
+ # @param [Integer] key The ID of a deploy key.
385
+ # @return [Gitlab::ObjectifiedHash] Information about the enabled deploy key.
386
+ def enable_deploy_key(project, key)
387
+ post("/projects/#{url_encode project}/deploy_keys/#{key}/enable", body: { id: project, key_id: key })
388
+ end
389
+
390
+ # Disables a deploy key at the project.
391
+ #
392
+ # @example
393
+ # Gitlab.disable_deploy_key(42, 66)
394
+ #
395
+ # @param [Integer, String] project The ID or path of a project.
396
+ # @param [Integer] key The ID of a deploy key.
397
+ # @return [Gitlab::ObjectifiedHash] Information about the disabled deploy key.
398
+ def disable_deploy_key(project, key)
399
+ post("/projects/#{url_encode project}/deploy_keys/#{key}/disable", body: { id: project, key_id: key })
400
+ end
401
+
402
+ # Updates an existing deploy key.
403
+ #
404
+ # @example
405
+ # Gitlab.edit_deploy_key(42, 66, 'New key name', can_push: false)
406
+ #
407
+ # @param [Integer, String] project The ID or path of a project.
408
+ # @param [Integer] id The ID of a deploy key.
409
+ # @param [String] title The title of a deploy key.
410
+ # @param [Hash] options A customizable set of options.
411
+ # @return [Gitlab::ObjectifiedHash] Information about created deploy key.
412
+ def edit_deploy_key(project, id, title, options = {})
413
+ put("/projects/#{url_encode project}/deploy_keys/#{id}", body: { title: title }.merge(options))
414
+ end
415
+
416
+ # Deletes a deploy key from project.
417
+ #
418
+ # @example
419
+ # Gitlab.delete_deploy_key(42, 1)
420
+ #
421
+ # @param [Integer, String] project The ID or path of a project.
422
+ # @param [Integer] id The ID of a deploy key.
423
+ # @return [Gitlab::ObjectifiedHash] Information about deleted deploy key.
424
+ def delete_deploy_key(project, id)
425
+ delete("/projects/#{url_encode project}/deploy_keys/#{id}")
426
+ end
427
+
428
+ # Forks a project into the user namespace.
429
+ #
430
+ # @example
431
+ # Gitlab.create_fork(42)
432
+ # Gitlab.create_fork(42, { sudo: 'another_username' })
433
+ #
434
+ # @param [Integer, String] project The ID or path of a project.
435
+ # @param [Hash] options A customizable set of options.
436
+ # @option options [String] :sudo The username the project will be forked for
437
+ # @return [Gitlab::ObjectifiedHash] Information about the forked project.
438
+ def create_fork(id, options = {})
439
+ post("/projects/#{url_encode id}/fork", body: options)
440
+ end
441
+
442
+ # Get a list of all visible projects across GitLab for the authenticated user.
443
+ # When accessed without authentication, only public projects are returned.
444
+ #
445
+ # Note: This feature was introduced in GitLab 10.1
446
+ #
447
+ # @example
448
+ # Gitlab.project_forks(42)
449
+ #
450
+ # @param [Hash] options A customizable set of options.
451
+ # @option options [Integer] :page The page number.
452
+ # @option options [Integer] :per_page The number of results per page.
453
+ # @option options [String] :order_by Return requests ordered by id, name, created_at or last_activity_at fields
454
+ # @option options [String] :sort Return requests sorted in asc or desc order
455
+ # @return [Array<Gitlab::ObjectifiedHash>]
456
+ def project_forks(id, options = {})
457
+ get("/projects/#{url_encode id}/forks", query: options)
458
+ end
459
+
460
+ # Updates an existing project.
461
+ #
462
+ # @example
463
+ # Gitlab.edit_project(42)
464
+ # Gitlab.edit_project(42, { name: 'Project Name' })
465
+ # Gitlab.edit_project('project-name', { name: 'New Project Name', path: 'new-project-patth' })
466
+ #
467
+ # @param [Integer, String] project The ID or path of a project.
468
+ # @param [Hash] options A customizable set of options
469
+ # @option options [String] :name The name of a project
470
+ # @option options [String] :path The project's repository name, also used in Gitlab's URLs
471
+ # @option options [String] :description The description to show in Gitlab
472
+ # (Any provided options will be passed to Gitlab. See {https://docs.gitlab.com/ce/api/projects.html#edit-project Gitlab docs} for all valid options)
473
+ #
474
+ # @return [Gitlab::ObjectifiedHash] Information about the edited project.
475
+ def edit_project(id, options = {})
476
+ put("/projects/#{url_encode id}", body: options)
477
+ end
478
+
479
+ # Share project with group.
480
+ #
481
+ # @example
482
+ # Gitlab.share_project_with_group('gitlab', 2, 40)
483
+ #
484
+ # @param [Integer, String] project The ID or path of a project.
485
+ # @param [Integer] id The ID of a group.
486
+ # @param [Integer] group_access The access level to project.
487
+ def share_project_with_group(project, id, group_access)
488
+ post("/projects/#{url_encode project}/share", body: { group_id: id, group_access: group_access })
489
+ end
490
+
491
+ # Unshare project with group.
492
+ #
493
+ # @example
494
+ # Gitlab.unshare_project_with_group('gitlab', 2)
495
+ #
496
+ # @param [Integer, String] project The ID or path of a project.
497
+ # @param [Integer] id The ID of a group.
498
+ # @return [void] This API call returns an empty response body.
499
+ def unshare_project_with_group(project, id)
500
+ delete("/projects/#{url_encode project}/share/#{id}")
501
+ end
502
+
503
+ # Transfer a project to a new namespace.
504
+ #
505
+ # @example
506
+ # Gitlab.transfer_project(42, 'yolo')
507
+ #
508
+ # @param [Integer, String] project The ID or path of a project
509
+ # @param [Integer, String] namespace The ID or path of the namespace to transfer to project to
510
+ # @return [Gitlab::ObjectifiedHash] Information about transfered project.
511
+ def transfer_project(project, namespace)
512
+ put("/projects/#{url_encode project}/transfer", body: { namespace: namespace })
513
+ end
514
+
515
+ # Stars a project.
516
+ # @see https://docs.gitlab.com/ce/api/projects.html#star-a-project
517
+ #
518
+ # @example
519
+ # Gitlab.star_project(42)
520
+ # Gitlab.star_project('gitlab-org/gitlab-ce')
521
+ #
522
+ # @param [Integer, String] id The ID or path of a project.
523
+ # @return [Gitlab::ObjectifiedHash] Information about starred project.
524
+ def star_project(id)
525
+ post("/projects/#{url_encode id}/star")
526
+ end
527
+
528
+ # Unstars a project.
529
+ # @see https://docs.gitlab.com/ce/api/projects.html#unstar-a-project
530
+ #
531
+ # @example
532
+ # Gitlab.unstar_project(42)
533
+ # Gitlab.unstar_project('gitlab-org/gitlab-ce')
534
+ #
535
+ # @param [Integer, String] id The ID or path of a project.
536
+ # @return [Gitlab::ObjectifiedHash] Information about unstarred project.
537
+ def unstar_project(id)
538
+ delete("/projects/#{url_encode id}/star")
539
+ end
540
+
541
+ # Get a list of visible projects that the given user has starred.
542
+ # @see https://docs.gitlab.com/ee/api/projects.html#list-projects-starred-by-a-user
543
+ #
544
+ # @example
545
+ # Gitlab.user_starred_projects(1)
546
+ # Gitlab.user_starred_projects(1, { order_by: 'last_activity_at' })
547
+ # Gitlab.user_starred_projects('username', { order_by: 'name', sort: 'asc' })
548
+ #
549
+ # @param [Integer, String] user_id The ID or username of the user.
550
+ # @param [Hash] options A customizable set of options.
551
+ # @option options [String] :per_page Number of projects to return per page
552
+ # @option options [String] :page The page to retrieve
553
+ # @option options [String] :order_by Return projects ordered by id, name, path, created_at, updated_at, or last_activity_at fields.
554
+ # @option options [String] :sort Return projects sorted in asc or desc order.
555
+ # @return [Array<Gitlab::ObjectifiedHash>]
556
+ def user_starred_projects(user_id, options = {})
557
+ get("/users/#{url_encode user_id}/starred_projects", query: options)
558
+ end
559
+
560
+ # Get a list of visible projects for the given user.
561
+ # @see https://docs.gitlab.com/ee/api/projects.html#list-user-projects
562
+ #
563
+ # @example
564
+ # Gitlab.user_projects(1)
565
+ # Gitlab.user_projects(1, { order_by: 'last_activity_at' })
566
+ # Gitlab.user_projects('username', { order_by: 'name', sort: 'asc' })
567
+ #
568
+ # @param [Integer, String] user_id The ID or username of the user.
569
+ # @param [Hash] options A customizable set of options.
570
+ # @option options [String] :per_page Number of projects to return per page
571
+ # @option options [String] :page The page to retrieve
572
+ # @option options [String] :order_by Return projects ordered by id, name, path, created_at, updated_at, or last_activity_at fields.
573
+ # @option options [String] :sort Return projects sorted in asc or desc order.
574
+ # @return [Array<Gitlab::ObjectifiedHash>]
575
+ def user_projects(user_id, options = {})
576
+ get("/users/#{url_encode user_id}/projects", query: options)
577
+ end
578
+
579
+ # Uploads a file to the specified project to be used in an issue or
580
+ # merge request description, or a comment.
581
+ # @see https://docs.gitlab.com/ee/api/projects.html#upload-a-file
582
+ #
583
+ # @example
584
+ # Gitlab.upload_file(1, '/full/path/to/avatar.jpg')
585
+ #
586
+ # @param [Integer, String] id The ID or path of a project.
587
+ # @param [String] file_fullpath The fullpath of the file you are interested to upload.
588
+ # @return [Gitlab::ObjectifiedHash]
589
+ def upload_file(id, file_fullpath)
590
+ post("/projects/#{url_encode id}/uploads", body: { file: File.open(file_fullpath, 'r') })
591
+ end
592
+
593
+ # Get all project templates of a particular type
594
+ # @see https://docs.gitlab.com/ce/api/project_templates.html
595
+ #
596
+ # @example
597
+ # Gitlab.project_templates(1, 'dockerfiles')
598
+ # Gitlab.project_templates(1, 'licenses')
599
+ #
600
+ # @param [Integer, String] id The ID or URL-encoded path of the project.
601
+ # @param [String] type The type (dockerfiles|gitignores|gitlab_ci_ymls|licenses) of the template
602
+ # @return [Array<Gitlab::ObjectifiedHash>]
603
+ def project_templates(project, type)
604
+ get("/projects/#{url_encode project}/templates/#{type}")
605
+ end
606
+
607
+ # Get one project template of a particular type
608
+ # @see https://docs.gitlab.com/ce/api/project_templates.html
609
+ #
610
+ # @example
611
+ # Gitlab.project_template(1, 'dockerfiles', 'dockey')
612
+ # Gitlab.project_template(1, 'licenses', 'gpl', { project: 'some project', fullname: 'Holder Holding' })
613
+ #
614
+ # @param [Integer, String] project The ID or URL-encoded path of the project.
615
+ # @param [String] type The type (dockerfiles|gitignores|gitlab_ci_ymls|licenses) of the template
616
+ # @param [String] key The key of the template, as obtained from the collection endpoint
617
+ # @param [Hash] options A customizable set of options.
618
+ # @option options [String] project(optional) The project name to use when expanding placeholders in the template. Only affects licenses
619
+ # @option options [String] fullname(optional) The full name of the copyright holder to use when expanding placeholders in the template. Only affects licenses
620
+ # @return [Gitlab::ObjectifiedHash]
621
+ def project_template(project, type, key, options = {})
622
+ get("/projects/#{url_encode project}/templates/#{type}/#{key}", query: options)
623
+ end
624
+
625
+ # Archives a project.
626
+ #
627
+ # @example
628
+ # Gitlab.archive_project(4)
629
+ #
630
+ # @param [Integer, String] id The ID or path of a project.
631
+ # @return [Gitlab::ObjectifiedHash] Information about archived project.
632
+ def archive_project(id)
633
+ post("/projects/#{url_encode id}/archive")
634
+ end
635
+
636
+ # Unarchives a project.
637
+ #
638
+ # @example
639
+ # Gitlab.unarchive_project(4)
640
+ #
641
+ # @param [Integer, String] id The ID or path of a project.
642
+ # @return [Gitlab::ObjectifiedHash] Information about unarchived project.
643
+ def unarchive_project(id)
644
+ post("/projects/#{url_encode id}/unarchive")
645
+ end
646
+
647
+ # Gets project custom_attributes.
648
+ #
649
+ # @example
650
+ # Gitlab.project_custom_attributes(2)
651
+ #
652
+ # @param [Integer] project_id The ID of a project.
653
+ # @return [Gitlab::ObjectifiedHash]
654
+ def project_custom_attributes(project_id)
655
+ get("/projects/#{project_id}/custom_attributes")
656
+ end
657
+
658
+ # Gets single project custom_attribute.
659
+ #
660
+ # @example
661
+ # Gitlab.project_custom_attribute(key, 2)
662
+ #
663
+ # @param [String] key The custom_attributes key
664
+ # @param [Integer] project_id The ID of a project.
665
+ # @return [Gitlab::ObjectifiedHash]
666
+ def project_custom_attribute(key, project_id)
667
+ get("/projects/#{project_id}/custom_attributes/#{key}")
668
+ end
669
+
670
+ # Creates a new custom_attribute
671
+ #
672
+ # @example
673
+ # Gitlab.add_custom_attribute('some_new_key', 'some_new_value', 2)
674
+ #
675
+ # @param [String] key The custom_attributes key
676
+ # @param [String] value The custom_attributes value
677
+ # @param [Integer] project_id The ID of a project.
678
+ # @return [Gitlab::ObjectifiedHash]
679
+ def add_project_custom_attribute(key, value, project_id)
680
+ url = "/projects/#{project_id}/custom_attributes/#{key}"
681
+ put(url, body: { value: value })
682
+ end
683
+
684
+ # Delete custom_attribute
685
+ # Will delete a custom_attribute
686
+ #
687
+ # @example
688
+ # Gitlab.delete_project_custom_attribute('somekey', 2)
689
+ #
690
+ # @param [String] key The custom_attribute key to delete
691
+ # @param [Integer] project_id The ID of a project.
692
+ # @return [Boolean]
693
+ def delete_project_custom_attribute(key, project_id = nil)
694
+ delete("/projects/#{project_id}/custom_attributes/#{key}")
695
+ end
696
+
697
+ # List project deploy tokens
698
+ #
699
+ # @example
700
+ # Gitlab.project_deploy_tokens(42)
701
+ #
702
+ # @param [Integer, String] id The ID or path of a project.
703
+ # @option options [Boolean] :active Limit by active status. Optional.
704
+ def project_deploy_tokens(project, options = {})
705
+ get("/projects/#{url_encode project}/deploy_tokens", query: options)
706
+ end
707
+ end
708
+ end