gitlab 4.5.0 → 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 (96) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +0 -267
  3. data/LICENSE.txt +1 -1
  4. data/README.md +40 -30
  5. data/exe/gitlab +5 -1
  6. data/lib/gitlab/api.rb +7 -3
  7. data/lib/gitlab/cli.rb +13 -9
  8. data/lib/gitlab/cli_helpers.rb +49 -45
  9. data/lib/gitlab/client/access_requests.rb +10 -1
  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 +5 -3
  13. data/lib/gitlab/client/boards.rb +62 -4
  14. data/lib/gitlab/client/branches.rb +47 -8
  15. data/lib/gitlab/client/broadcast_messages.rb +75 -0
  16. data/lib/gitlab/client/build_variables.rb +19 -12
  17. data/lib/gitlab/client/builds.rb +13 -11
  18. data/lib/gitlab/client/commits.rb +73 -21
  19. data/lib/gitlab/client/container_registry.rb +85 -0
  20. data/lib/gitlab/client/deployments.rb +3 -1
  21. data/lib/gitlab/client/environments.rb +5 -3
  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 +6 -4
  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 +7 -6
  30. data/lib/gitlab/client/groups.rb +326 -12
  31. data/lib/gitlab/client/issue_links.rb +48 -0
  32. data/lib/gitlab/client/issues.rb +47 -13
  33. data/lib/gitlab/client/jobs.rb +96 -8
  34. data/lib/gitlab/client/keys.rb +13 -0
  35. data/lib/gitlab/client/labels.rb +6 -4
  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 +164 -9
  39. data/lib/gitlab/client/merge_requests.rb +148 -11
  40. data/lib/gitlab/client/merge_trains.rb +55 -0
  41. data/lib/gitlab/client/milestones.rb +19 -5
  42. data/lib/gitlab/client/namespaces.rb +4 -2
  43. data/lib/gitlab/client/notes.rb +38 -9
  44. data/lib/gitlab/client/packages.rb +95 -0
  45. data/lib/gitlab/client/pipeline_schedules.rb +36 -10
  46. data/lib/gitlab/client/pipeline_triggers.rb +10 -8
  47. data/lib/gitlab/client/pipelines.rb +65 -3
  48. data/lib/gitlab/client/project_badges.rb +85 -0
  49. data/lib/gitlab/client/project_clusters.rb +83 -0
  50. data/lib/gitlab/client/project_exports.rb +54 -0
  51. data/lib/gitlab/client/project_release_links.rb +76 -0
  52. data/lib/gitlab/client/project_releases.rb +90 -0
  53. data/lib/gitlab/client/projects.rb +307 -26
  54. data/lib/gitlab/client/protected_tags.rb +59 -0
  55. data/lib/gitlab/client/remote_mirrors.rb +51 -0
  56. data/lib/gitlab/client/repositories.rb +77 -6
  57. data/lib/gitlab/client/repository_files.rb +21 -3
  58. data/lib/gitlab/client/repository_submodules.rb +27 -0
  59. data/lib/gitlab/client/resource_label_events.rb +82 -0
  60. data/lib/gitlab/client/resource_state_events.rb +57 -0
  61. data/lib/gitlab/client/runners.rb +170 -18
  62. data/lib/gitlab/client/search.rb +66 -0
  63. data/lib/gitlab/client/services.rb +4 -1
  64. data/lib/gitlab/client/sidekiq.rb +2 -0
  65. data/lib/gitlab/client/snippets.rb +5 -3
  66. data/lib/gitlab/client/system_hooks.rb +9 -7
  67. data/lib/gitlab/client/tags.rb +10 -9
  68. data/lib/gitlab/client/templates.rb +100 -0
  69. data/lib/gitlab/client/todos.rb +7 -5
  70. data/lib/gitlab/client/user_snippets.rb +114 -0
  71. data/lib/gitlab/client/users.rb +302 -31
  72. data/lib/gitlab/client/versions.rb +18 -0
  73. data/lib/gitlab/client/wikis.rb +79 -0
  74. data/lib/gitlab/client.rb +48 -9
  75. data/lib/gitlab/configuration.rb +9 -6
  76. data/lib/gitlab/error.rb +73 -3
  77. data/lib/gitlab/file_response.rb +4 -2
  78. data/lib/gitlab/headers/page_links.rb +37 -0
  79. data/lib/gitlab/headers/total.rb +29 -0
  80. data/lib/gitlab/help.rb +16 -16
  81. data/lib/gitlab/objectified_hash.rb +27 -10
  82. data/lib/gitlab/paginated_response.rb +43 -25
  83. data/lib/gitlab/request.rb +51 -37
  84. data/lib/gitlab/shell.rb +6 -4
  85. data/lib/gitlab/shell_history.rb +11 -13
  86. data/lib/gitlab/version.rb +3 -1
  87. data/lib/gitlab.rb +23 -9
  88. metadata +59 -45
  89. data/.gitignore +0 -22
  90. data/CONTRIBUTING.md +0 -195
  91. data/Gemfile +0 -4
  92. data/Rakefile +0 -17
  93. data/bin/console +0 -10
  94. data/bin/setup +0 -6
  95. data/gitlab.gemspec +0 -33
  96. data/lib/gitlab/page_links.rb +0 -33
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Gitlab::Client
2
4
  # Defines methods related to users.
3
5
  # @see https://docs.gitlab.com/ce/api/users.html
@@ -12,8 +14,8 @@ class Gitlab::Client
12
14
  # @option options [Integer] :page The page number.
13
15
  # @option options [Integer] :per_page The number of results per page.
14
16
  # @return [Array<Gitlab::ObjectifiedHash>]
15
- def users(options={})
16
- get("/users", query: options)
17
+ def users(options = {})
18
+ get('/users', query: options)
17
19
  end
18
20
 
19
21
  # Gets information about a user.
@@ -25,8 +27,8 @@ class Gitlab::Client
25
27
  #
26
28
  # @param [Integer] id The ID of a user.
27
29
  # @return [Gitlab::ObjectifiedHash]
28
- def user(id=nil)
29
- id.to_i.zero? ? get("/user") : get("/users/#{id}")
30
+ def user(id = nil)
31
+ id.to_i.zero? ? get('/user') : get("/users/#{id}")
30
32
  end
31
33
 
32
34
  # Creates a new user.
@@ -35,11 +37,11 @@ class Gitlab::Client
35
37
  # @example
36
38
  # Gitlab.create_user('joe@foo.org', 'secret', 'joe', { name: 'Joe Smith' })
37
39
  # or
38
- # Gitlab.create_user('joe@foo.org', 'secret')
40
+ # Gitlab.create_user('joe@foo.org', 'secret', 'joe')
39
41
  #
40
- # @param [String] email The email of a user.
41
- # @param [String] password The password of a user.
42
- # @param [String] username The username of a user.
42
+ # @param [String] email(required) The email of a user.
43
+ # @param [String] password(required) The password of a user.
44
+ # @param [String] username(required) The username of a user.
43
45
  # @param [Hash] options A customizable set of options.
44
46
  # @option options [String] :name The name of a user. Defaults to email.
45
47
  # @option options [String] :skype The skype of a user.
@@ -48,16 +50,30 @@ class Gitlab::Client
48
50
  # @option options [Integer] :projects_limit The limit of projects for a user.
49
51
  # @return [Gitlab::ObjectifiedHash] Information about created user.
50
52
  def create_user(*args)
51
- options = Hash === args.last ? args.pop : {}
52
- body = if args[2]
53
- { email: args[0], password: args[1], username: args[2] }
54
- else
55
- { email: args[0], password: args[1], name: args[0] }
56
- end
53
+ options = args.last.is_a?(Hash) ? args.pop : {}
54
+ raise ArgumentError, 'Missing required parameters' unless args[2]
55
+
56
+ body = { email: args[0], password: args[1], username: args[2], name: args[0] }
57
57
  body.merge!(options)
58
58
  post('/users', body: body)
59
59
  end
60
60
 
61
+ # Creates a service account.
62
+ # Requires authentication from an admin account.
63
+ #
64
+ # @example
65
+ # Gitlab.create_service_account('service_account_6018816a18e515214e0c34c2b33523fc', 'Service account user')
66
+ #
67
+ # @param [String] name (required) The email of the service account.
68
+ # @param [String] username (required) The username of the service account.
69
+ # @return [Gitlab::ObjectifiedHash] Information about created service account.
70
+ def create_service_account(*args)
71
+ raise ArgumentError, 'Missing required parameters' unless args[1]
72
+
73
+ body = { name: args[0], username: args[1] }
74
+ post('/service_accounts', body: body)
75
+ end
76
+
61
77
  # Updates a user.
62
78
  #
63
79
  # @example
@@ -73,7 +89,7 @@ class Gitlab::Client
73
89
  # @option options [String] :twitter The twitter of a user.
74
90
  # @option options [Integer] :projects_limit The limit of projects for a user.
75
91
  # @return [Gitlab::ObjectifiedHash] Information about created user.
76
- def edit_user(user_id, options={})
92
+ def edit_user(user_id, options = {})
77
93
  put("/users/#{user_id}", body: options)
78
94
  end
79
95
 
@@ -110,6 +126,39 @@ class Gitlab::Client
110
126
  post("/users/#{user_id}/unblock")
111
127
  end
112
128
 
129
+ # Deactivates the specified user. Available only for admin.
130
+ #
131
+ # @example
132
+ # Gitlab.deactivate_user(15)
133
+ #
134
+ # @param [Integer] user_id The Id of user
135
+ # @return [Boolean] success or not
136
+ def deactivate_user(user_id)
137
+ post("/users/#{user_id}/deactivate")
138
+ end
139
+
140
+ # Activate the specified user. Available only for admin.
141
+ #
142
+ # @example
143
+ # Gitlab.activate_user(15)
144
+ #
145
+ # @param [Integer] user_id The Id of user
146
+ # @return [Boolean] success or not
147
+ def activate_user(user_id)
148
+ post("/users/#{user_id}/activate")
149
+ end
150
+
151
+ # Approves the specified user. Available only for admin.
152
+ #
153
+ # @example
154
+ # Gitlab.approve_user(15)
155
+ #
156
+ # @param [Integer] user_id The Id of user
157
+ # @return [Boolean] success or not
158
+ def approve_user(user_id)
159
+ post("/users/#{user_id}/approve")
160
+ end
161
+
113
162
  # Creates a new user session.
114
163
  #
115
164
  # @example
@@ -120,7 +169,21 @@ class Gitlab::Client
120
169
  # @return [Gitlab::ObjectifiedHash]
121
170
  # @note This method doesn't require private_token to be set.
122
171
  def session(email, password)
123
- post("/session", body: { email: email, password: password }, unauthenticated: true)
172
+ post('/session', body: { email: email, password: password }, unauthenticated: true)
173
+ end
174
+
175
+ # Gets a list of user activities (for admin access only).
176
+ #
177
+ # @example
178
+ # Gitlab.activities
179
+ #
180
+ # @param [Hash] options A customizable set of options.
181
+ # @option options [Integer] :page The page number.
182
+ # @option options [Integer] :per_page The number of results per page.
183
+ # @option options [String] :from The start date for paginated results.
184
+ # @return [Array<Gitlab::ObjectifiedHash>]
185
+ def activities(options = {})
186
+ get('/user/activities', query: options)
124
187
  end
125
188
 
126
189
  # Gets a list of user's SSH keys.
@@ -134,10 +197,10 @@ class Gitlab::Client
134
197
  # @option options [Integer] :per_page The number of results per page.
135
198
  # @option options [Integer] :user_id The ID of the user to retrieve the keys for.
136
199
  # @return [Array<Gitlab::ObjectifiedHash>]
137
- def ssh_keys(options={})
200
+ def ssh_keys(options = {})
138
201
  user_id = options.delete :user_id
139
202
  if user_id.to_i.zero?
140
- get("/user/keys", query: options)
203
+ get('/user/keys', query: options)
141
204
  else
142
205
  get("/users/#{user_id}/keys", query: options)
143
206
  end
@@ -161,9 +224,16 @@ class Gitlab::Client
161
224
  #
162
225
  # @param [String] title The title of an SSH key.
163
226
  # @param [String] key The SSH key body.
227
+ # @param [Hash] options A customizable set of options.
228
+ # @option options [Integer] :user_id id of the user to associate the key with
164
229
  # @return [Gitlab::ObjectifiedHash] Information about created SSH key.
165
- def create_ssh_key(title, key)
166
- post("/user/keys", body: { title: title, key: key })
230
+ def create_ssh_key(title, key, options = {})
231
+ user_id = options.delete :user_id
232
+ if user_id.to_i.zero?
233
+ post('/user/keys', body: { title: title, key: key })
234
+ else
235
+ post("/users/#{user_id}/keys", body: { title: title, key: key })
236
+ end
167
237
  end
168
238
 
169
239
  # Deletes an SSH key.
@@ -172,9 +242,16 @@ class Gitlab::Client
172
242
  # Gitlab.delete_ssh_key(1)
173
243
  #
174
244
  # @param [Integer] id The ID of a user's SSH key.
245
+ # @param [Hash] options A customizable set of options.
246
+ # @option options [Integer] :user_id id of the user to associate the key with
175
247
  # @return [Gitlab::ObjectifiedHash] Information about deleted SSH key.
176
- def delete_ssh_key(id)
177
- delete("/user/keys/#{id}")
248
+ def delete_ssh_key(id, options = {})
249
+ user_id = options.delete :user_id
250
+ if user_id.to_i.zero?
251
+ delete("/user/keys/#{id}")
252
+ else
253
+ delete("/users/#{user_id}/keys/#{id}")
254
+ end
178
255
  end
179
256
 
180
257
  # Gets user emails.
@@ -186,8 +263,8 @@ class Gitlab::Client
186
263
  #
187
264
  # @param [Integer] user_id The ID of a user.
188
265
  # @return [Gitlab::ObjectifiedHash]
189
- def emails(user_id=nil)
190
- url = user_id.to_i.zero? ? "/user/emails" : "/users/#{user_id}/emails"
266
+ def emails(user_id = nil)
267
+ url = user_id.to_i.zero? ? '/user/emails' : "/users/#{user_id}/emails"
191
268
  get(url)
192
269
  end
193
270
 
@@ -211,10 +288,15 @@ class Gitlab::Client
211
288
  #
212
289
  # @param [String] email Email address
213
290
  # @param [Integer] user_id The ID of a user.
291
+ # @param [Boolean] skip_confirmation Skip confirmation and assume e-mail is verified
214
292
  # @return [Gitlab::ObjectifiedHash]
215
- def add_email(email, user_id=nil)
216
- url = user_id.to_i.zero? ? "/user/emails" : "/users/#{user_id}/emails"
217
- post(url, body: {email: email})
293
+ def add_email(email, user_id = nil, skip_confirmation = nil)
294
+ url = user_id.to_i.zero? ? '/user/emails' : "/users/#{user_id}/emails"
295
+ if skip_confirmation.nil?
296
+ post(url, body: { email: email })
297
+ else
298
+ post(url, body: { email: email, skip_confirmation: skip_confirmation })
299
+ end
218
300
  end
219
301
 
220
302
  # Delete email
@@ -227,12 +309,12 @@ class Gitlab::Client
227
309
  # @param [Integer] id Email address ID
228
310
  # @param [Integer] user_id The ID of a user.
229
311
  # @return [Boolean]
230
- def delete_email(id, user_id=nil)
312
+ def delete_email(id, user_id = nil)
231
313
  url = user_id.to_i.zero? ? "/user/emails/#{id}" : "/users/#{user_id}/emails/#{id}"
232
314
  delete(url)
233
315
  end
234
316
 
235
- # Search for groups by name
317
+ # Search for users by name
236
318
  #
237
319
  # @example
238
320
  # Gitlab.user_search('gitlab')
@@ -242,9 +324,198 @@ class Gitlab::Client
242
324
  # @option options [String] :per_page Number of user to return per page
243
325
  # @option options [String] :page The page to retrieve
244
326
  # @return [Array<Gitlab::ObjectifiedHash>]
245
- def user_search(search, options={})
327
+ def user_search(search, options = {})
246
328
  options[:search] = search
247
- get("/users", query: options)
329
+ get('/users', query: options)
330
+ end
331
+
332
+ # Get user by username
333
+ #
334
+ # @example
335
+ # Gitlab.user_by_username('gitlab')
336
+ #
337
+ # @param [String] username A username to get.
338
+ # @param [Hash] options A customizable set of options.
339
+ # @return [Array<Gitlab::ObjectifiedHash>]
340
+ def user_by_username(username, options = {})
341
+ options[:username] = username
342
+ get('/users', query: options)
343
+ end
344
+
345
+ # Gets user custom_attributes.
346
+ #
347
+ # @example
348
+ # Gitlab.user_custom_attributes(2)
349
+ #
350
+ # @param [Integer] user_id The ID of a user.
351
+ # @return [Gitlab::ObjectifiedHash]
352
+ def user_custom_attributes(user_id)
353
+ get("/users/#{user_id}/custom_attributes")
354
+ end
355
+
356
+ # Gets single user custom_attribute.
357
+ #
358
+ # @example
359
+ # Gitlab.user_custom_attribute(key, 2)
360
+ #
361
+ # @param [String] key The custom_attributes key
362
+ # @param [Integer] user_id The ID of a user.
363
+ # @return [Gitlab::ObjectifiedHash]
364
+ def user_custom_attribute(key, user_id)
365
+ get("/users/#{user_id}/custom_attributes/#{key}")
366
+ end
367
+
368
+ # Creates a new custom_attribute
369
+ #
370
+ # @example
371
+ # Gitlab.add_custom_attribute('some_new_key', 'some_new_value', 2)
372
+ #
373
+ # @param [String] key The custom_attributes key
374
+ # @param [String] value The custom_attributes value
375
+ # @param [Integer] user_id The ID of a user.
376
+ # @return [Gitlab::ObjectifiedHash]
377
+ def add_user_custom_attribute(key, value, user_id)
378
+ url = "/users/#{user_id}/custom_attributes/#{key}"
379
+ put(url, body: { value: value })
380
+ end
381
+
382
+ # Delete custom_attribute
383
+ # Will delete a custom_attribute
384
+ #
385
+ # @example
386
+ # Gitlab.delete_user_custom_attribute('somekey', 2)
387
+ #
388
+ # @param [String] key The custom_attribute key to delete
389
+ # @param [Integer] user_id The ID of a user.
390
+ # @return [Boolean]
391
+ def delete_user_custom_attribute(key, user_id)
392
+ delete("/users/#{user_id}/custom_attributes/#{key}")
393
+ end
394
+
395
+ # Get all impersonation tokens for a user
396
+ #
397
+ # @example
398
+ # Gitlab.user_impersonation_tokens(1)
399
+ #
400
+ # @param [Integer] user_id The ID of the user.
401
+ # @param [String] state Filter impersonation tokens by state {}
402
+ # @return [Array<Gitlab::ObjectifiedHash>]
403
+ def user_impersonation_tokens(user_id)
404
+ get("/users/#{user_id}/impersonation_tokens")
405
+ end
406
+
407
+ # Get impersonation token information
408
+ #
409
+ # @example
410
+ # Gitlab.user_impersonation_token(1, 1)
411
+ #
412
+ # @param [Integer] user_id The ID of the user.
413
+ # @param [Integer] impersonation_token_id ID of the impersonation token.
414
+ # @return [Gitlab::ObjectifiedHash]
415
+ def user_impersonation_token(user_id, impersonation_token_id)
416
+ get("/users/#{user_id}/impersonation_tokens/#{impersonation_token_id}")
417
+ end
418
+
419
+ # Create impersonation token
420
+ #
421
+ # @example
422
+ # Gitlab.create_user_impersonation_token(2, "token", ["api", "read_user"])
423
+ # Gitlab.create_user_impersonation_token(2, "token", ["api", "read_user"], "1970-01-01")
424
+ #
425
+ # @param [Integer] user_id The ID of the user.
426
+ # @param [String] name Name for impersonation token.
427
+ # @param [Array<String>] scopes Array of scopes for the impersonation token
428
+ # @param [String] expires_at Date for impersonation token expiration in ISO format.
429
+ # @return [Gitlab::ObjectifiedHash]
430
+ def create_user_impersonation_token(user_id, name, scopes, expires_at = nil)
431
+ body = { name: name, scopes: scopes }
432
+ body[:expires_at] = expires_at if expires_at
433
+ post("/users/#{user_id}/impersonation_tokens", body: body)
434
+ end
435
+
436
+ # Get all personal access tokens for a user
437
+ #
438
+ # @example
439
+ # Gitlab.user_personal_access_tokens(1)
440
+ #
441
+ # @param [Integer] user_id The ID of the user.
442
+ # @return [Array<Gitlab::ObjectifiedHash>]
443
+ def user_personal_access_tokens(user_id)
444
+ get("/personal_access_tokens?user_id=#{user_id}")
445
+ end
446
+
447
+ # Create personal access token
448
+ #
449
+ # @example
450
+ # Gitlab.create_personal_access_token(2, "token", ["api", "read_user"])
451
+ # Gitlab.create_personal_access_token(2, "token", ["api", "read_user"], "1970-01-01")
452
+ #
453
+ # @param [Integer] user_id The ID of the user.
454
+ # @param [String] name Name of the personal access token.
455
+ # @param [Array<String>] scopes Array of scopes for the impersonation token
456
+ # @param [String] expires_at Date for impersonation token expiration in ISO format.
457
+ # @return [Gitlab::ObjectifiedHash]
458
+ def create_personal_access_token(user_id, name, scopes, expires_at = nil)
459
+ body = { name: name, scopes: scopes }
460
+ body[:expires_at] = expires_at if expires_at
461
+ post("/users/#{user_id}/personal_access_tokens", body: body)
462
+ end
463
+
464
+ # Rotate a personal access token
465
+ #
466
+ # @example
467
+ # Gitlab.rotate_personal_access_token(1)
468
+ #
469
+ # @param [Integer] personal_access_token_id ID of the personal access token.
470
+ # @return [Gitlab::ObjectifiedHash]
471
+ def rotate_personal_access_token(personal_access_token_id, expires_at = nil)
472
+ body = {}
473
+ body[:expires_at] = expires_at if expires_at
474
+ post("/personal_access_tokens/#{personal_access_token_id}/rotate", body: body)
475
+ end
476
+
477
+ # Revoke an impersonation token
478
+ #
479
+ # @example
480
+ # Gitlab.revoke_user_impersonation_token(1, 1)
481
+ #
482
+ # @param [Integer] user_id The ID of the user.
483
+ # @param [Integer] impersonation_token_id ID of the impersonation token.
484
+ # @return [Gitlab::ObjectifiedHash]
485
+ def revoke_user_impersonation_token(user_id, impersonation_token_id)
486
+ delete("/users/#{user_id}/impersonation_tokens/#{impersonation_token_id}")
487
+ end
488
+
489
+ # Lists all projects and groups a user is a member of
490
+ #
491
+ # @example
492
+ # Gitlab.memberships(2)
493
+ #
494
+ # @param [Integer] user_id The ID of the user.
495
+ def memberships(user_id)
496
+ get("/users/#{user_id}/memberships")
497
+ end
498
+
499
+ # Revoke a personal access token
500
+ #
501
+ # @example
502
+ # Gitlab.revoke_personal_access_token(1)
503
+ #
504
+ # @param [Integer] personal_access_token_id ID of the personal access token.
505
+ # @return [Gitlab::ObjectifiedHash]
506
+ def revoke_personal_access_token(personal_access_token_id)
507
+ delete("/personal_access_tokens/#{personal_access_token_id}")
508
+ end
509
+
510
+ # Disables two factor authentication (2FA) for the specified user.
511
+ #
512
+ # @example
513
+ # Gitlab.disable_two_factor(1)
514
+ #
515
+ # @param [Integer] id The ID of a user.
516
+ # @return [Gitlab::ObjectifiedHash]
517
+ def disable_two_factor(user_id)
518
+ patch("/users/#{user_id}/disable_two_factor")
248
519
  end
249
520
  end
250
521
  end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Gitlab::Client
4
+ # Defines methods related to version
5
+ # @see https://docs.gitlab.com/ce/api/version.html
6
+ module Versions
7
+ # Returns server version.
8
+ # @see https://docs.gitlab.com/ce/api/version.html
9
+ #
10
+ # @example
11
+ # Gitlab.version
12
+ #
13
+ # @return [Array<Gitlab::ObjectifiedHash>]
14
+ def version
15
+ get('/version')
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,79 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Gitlab::Client
4
+ # Defines methods related to wikis.
5
+ # @see https://docs.gitlab.com/ce/api/wikis.html
6
+ module Wikis
7
+ # Get all wiki pages for a given project.
8
+ #
9
+ # @example
10
+ # Gitlab.wikis(3)
11
+ # Gitlab.wikis(3, {with_content: 'Some wiki content'})
12
+ #
13
+ # @param [Integer, String] project The ID or name of a project.
14
+ # @param [Hash] options A customizable set of options.
15
+ # @option options [String] with_content(optional) Include pages content
16
+ # @return [Array<Gitlab::ObjectifiedHash>]
17
+ def wikis(project, options = {})
18
+ get("/projects/#{url_encode project}/wikis", query: options)
19
+ end
20
+
21
+ # Get a wiki page for a given project.
22
+ #
23
+ # @example
24
+ # Gitlab.wiki(3, 'home')
25
+ #
26
+ # @param [Integer, String] project The ID or name of a project.
27
+ # @param [String] slug The slug (a unique string) of the wiki page
28
+ # @return [Gitlab::ObjectifiedHash]
29
+ def wiki(project, slug)
30
+ get("/projects/#{url_encode project}/wikis/#{slug}")
31
+ end
32
+
33
+ # Creates a new wiki page for the given repository with the given title, slug, and content.
34
+ #
35
+ # @example
36
+ # Gitlab.create_wiki(3, 'Some Title', 'Some Content')
37
+ # Gitlab.create_wiki(3, 'Some Title', 'Some Content', { format: 'rdoc' })
38
+ #
39
+ # @param [Integer, String] project The ID or name of a project.
40
+ # @param [String] content The content of the wiki page.
41
+ # @param [String] title The title of the wiki page.
42
+ # @param [Hash] options A customizable set of options.
43
+ # @option options [String] format (optional) The format of the wiki page. Available formats are: markdown (default), rdoc, and asciidoc.
44
+ # @return [Gitlab::ObjectifiedHash] Information about created wiki page.
45
+ def create_wiki(project, title, content, options = {})
46
+ body = { content: content, title: title }.merge(options)
47
+ post("/projects/#{url_encode project}/wikis", body: body)
48
+ end
49
+
50
+ # Updates an existing wiki page. At least one parameter is required to update the wiki page.
51
+ #
52
+ # @example
53
+ # Gitlab.update_wiki(6, 'home', { title: 'New title' })
54
+ # Gitlab.update_wiki(6, 'home', { title: 'New title', content: 'New Message', format: 'rdoc' })
55
+ #
56
+ # @param [Integer, String] project The ID or name of a project.
57
+ # @param [String] slug The slug (a unique string) of the wiki page.
58
+ # @param [Hash] options A customizable set of options.
59
+ # @option options [String] content The content of the wiki page.
60
+ # @option options [String] title The title of the wiki page.
61
+ # @option options [String] format (optional) The format of the wiki page. Available formats are: markdown (default), rdoc, and asciidoc.
62
+ # @return [Gitlab::ObjectifiedHash] Information about updated wiki page.
63
+ def update_wiki(project, slug, options = {})
64
+ put("/projects/#{url_encode project}/wikis/#{slug}", body: options)
65
+ end
66
+
67
+ # Deletes a wiki page with a given slug.
68
+ #
69
+ # @example
70
+ # Gitlab.delete_wiki(42, 'foo')
71
+ #
72
+ # @param [Integer, String] project The ID or name of a project.
73
+ # @param [String] slug The slug (a unique string) of the wiki page.
74
+ # @return [Gitlab::ObjectifiedHash] An empty objectified hash
75
+ def delete_wiki(project, slug)
76
+ delete("/projects/#{url_encode project}/wikis/#{slug}")
77
+ end
78
+ end
79
+ end
data/lib/gitlab/client.rb CHANGED
@@ -1,66 +1,105 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Gitlab
2
4
  # Wrapper for the Gitlab REST API.
3
5
  class Client < API
4
- Dir[File.expand_path('../client/*.rb', __FILE__)].each { |f| require f }
6
+ Dir[File.expand_path('client/*.rb', __dir__)].each { |f| require f }
5
7
 
6
8
  # Please keep in alphabetical order
7
9
  include AccessRequests
10
+ include ApplicationSettings
11
+ include Avatar
8
12
  include AwardEmojis
9
13
  include Boards
10
14
  include Branches
15
+ include BroadcastMessages
11
16
  include BuildVariables
12
17
  include Builds
13
18
  include Commits
19
+ include ContainerRegistry
14
20
  include Deployments
15
21
  include Environments
22
+ include EpicIssues
23
+ include Epics
16
24
  include Events
25
+ include Features
26
+ include GroupBadges
27
+ include GroupBoards
28
+ include GroupLabels
17
29
  include GroupMilestones
18
30
  include Groups
31
+ include IssueLinks
19
32
  include Issues
20
33
  include Jobs
21
34
  include Keys
22
35
  include Labels
36
+ include Lint
37
+ include Markdown
23
38
  include MergeRequestApprovals
24
39
  include MergeRequests
40
+ include MergeTrains
25
41
  include Milestones
26
42
  include Namespaces
27
43
  include Notes
44
+ include Packages
28
45
  include PipelineSchedules
29
46
  include PipelineTriggers
30
47
  include Pipelines
48
+ include ProjectBadges
49
+ include ProjectClusters
50
+ include ProjectExports
51
+ include ProjectReleaseLinks
52
+ include ProjectReleases
31
53
  include Projects
54
+ include ProtectedTags
55
+ include RemoteMirrors
32
56
  include Repositories
33
57
  include RepositoryFiles
58
+ include RepositorySubmodules
59
+ include ResourceLabelEvents
60
+ include ResourceStateEvents
34
61
  include Runners
62
+ include Search
35
63
  include Services
36
64
  include Sidekiq
37
65
  include Snippets
38
66
  include SystemHooks
39
67
  include Tags
68
+ include Templates
40
69
  include Todos
41
70
  include Users
71
+ include UserSnippets
72
+ include Versions
73
+ include Wikis
42
74
 
43
75
  # Text representation of the client, masking private token.
44
76
  #
45
77
  # @return [String]
46
78
  def inspect
47
79
  inspected = super
48
-
49
- if @private_token
50
- inspected = inspected.sub! @private_token, only_show_last_four_chars(@private_token)
51
- end
52
-
80
+ inspected = redact_private_token(inspected, @private_token) if @private_token
53
81
  inspected
54
82
  end
55
83
 
56
- def url_encode(s)
57
- URI.encode(s.to_s, /\W/)
84
+ # Utility method for URL encoding of a string.
85
+ # Copied from https://ruby-doc.org/stdlib-2.7.0/libdoc/erb/rdoc/ERB/Util.html
86
+ #
87
+ # @return [String]
88
+ def url_encode(url)
89
+ url.to_s.b.gsub(/[^a-zA-Z0-9_\-.~]/n) { |m| sprintf('%%%02X', m.unpack1('C')) } # rubocop:disable Style/FormatString
58
90
  end
59
91
 
60
92
  private
61
93
 
94
+ def redact_private_token(inspected, private_token)
95
+ redacted = only_show_last_four_chars(private_token)
96
+ inspected.sub %(@private_token="#{private_token}"), %(@private_token="#{redacted}")
97
+ end
98
+
62
99
  def only_show_last_four_chars(token)
63
- "#{'*' * (token.size - 4)}#{token[-4..-1]}"
100
+ return '****' if token.size <= 4
101
+
102
+ "#{'*' * (token.size - 4)}#{token[-4..]}"
64
103
  end
65
104
  end
66
105
  end