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