gitlab 4.19.0 → 4.20.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 020a259d1d6822f810e1dc2c112d59bf46d453b7cf1840299c0f4d7208f4ac97
4
- data.tar.gz: 791cce56832e0089a9dc1c25efedf2d5fe1569e43b40f820ab4c935dede9222b
3
+ metadata.gz: d58bc8bfb06b02cb27fd0f8c6baf1ffc8909564ae70ca62b61fb967b8ba9d755
4
+ data.tar.gz: 887314d85742186b23c467ab9772b2ab0c1a188d9edcf17a845d72e1eb806dc1
5
5
  SHA512:
6
- metadata.gz: cebd397716351c091a448af4305e81f9ca188df3c966291d1d55e5b9cc01a0ba534c65716acd5f121017e09a87209bffcf688976e36deffe1385b81360d29dd0
7
- data.tar.gz: b972182f6edb9d0418f850172652585397d1601713e8c5e171342f382f73a1169c0c79fd068b48cecf21deddc5be933daeb20b75d1b31329e9eb82e94c3c1965
6
+ metadata.gz: e748fc1e87b17a885dd20233a12a84305ef45b1349c1c8c307f422b48c647a04521aafd67c826a8f8f27021ed65d81e003b6871343403531bf5dae0d140ed4a2
7
+ data.tar.gz: cf03878ea622f0ed5c576831d0660a69248283d9e4d336e99ec1d94f554361fecea3297901ef0ce713b381c61e05f23d04af3bba31bcfb7cee9e12756c3d57e9
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Gitlab
2
2
 
3
- [![Build Status](https://img.shields.io/github/workflow/status/NARKOZ/gitlab/CI/master)](https://github.com/NARKOZ/gitlab/actions/workflows/ci.yml)
3
+ [![Build Status](https://img.shields.io/github/actions/workflow/status/NARKOZ/gitlab/ci.yml?branch=master)](https://github.com/NARKOZ/gitlab/actions/workflows/ci.yml)
4
4
  [![Gem version](https://img.shields.io/gem/v/gitlab.svg)](https://rubygems.org/gems/gitlab)
5
5
  [![License](https://img.shields.io/badge/license-BSD-red.svg)](https://github.com/NARKOZ/gitlab/blob/master/LICENSE.txt)
6
6
 
@@ -20,7 +20,7 @@ class Gitlab::CLI
20
20
  #
21
21
  # @return [Gitlab::Client]
22
22
  def client
23
- @client ||= Gitlab::Client.new(endpoint: (Gitlab.endpoint || ''))
23
+ @client ||= Gitlab::Client.new(endpoint: Gitlab.endpoint || '')
24
24
  end
25
25
 
26
26
  # Returns method names and their owners
@@ -354,5 +354,99 @@ class Gitlab::Client
354
354
  def delete_group_custom_attribute(key, group_id = nil)
355
355
  delete("/groups/#{group_id}/custom_attributes/#{key}")
356
356
  end
357
+
358
+ # List all the specified groups hooks
359
+ #
360
+ # @example
361
+ # Gitlab.list_group_hooks(3)
362
+ #
363
+ # @param [Integer] group_id The ID of a group.
364
+ # @return [Gitlab::PaginatedResponse] List of registered hooks https://docs.gitlab.com/ee/api/groups.html#hooks
365
+ def list_group_hooks(group_id)
366
+ get("/groups/#{group_id}/hooks")
367
+ end
368
+
369
+ # get specified group hook
370
+ #
371
+ # @example
372
+ # Gitlab.group_hook(3, 1)
373
+ #
374
+ # @param [Integer] group_id The ID of a group.
375
+ # @param [Integer] hook_id The ID of the hook.
376
+ # @return [Gitlab::ObjectifiedHash] The hook https://docs.gitlab.com/ee/api/groups.html#get-group-hook
377
+ def group_hook(group_id, hook_id)
378
+ get("/groups/#{group_id}/hooks/#{hook_id}")
379
+ end
380
+
381
+ # Add a new group hook
382
+ #
383
+ # @example
384
+ # Gitlab.add_group_hook(3, "https://example.com/my-hook-receiver", {token: "verify me"})
385
+ #
386
+ # @param [Integer] group_id The ID of a group.
387
+ # @param [String] the hook url which will receive the selected events
388
+ # @option options [Boolean] :name The name of the group.
389
+ # @option options [Boolean] :push_events Trigger hook on push events
390
+ # @potion options [String] :push_events_branch_filter Trigger hook on push events for matching branches only.
391
+ # @option options [Boolean] :issues_events Trigger hook on issues events
392
+ # @option options [Boolean] :confidential_issues_events Trigger hook on confidential issues events
393
+ # @option options [Boolean] :merge_requests_events Trigger hook on merge requests events
394
+ # @option options [Boolean] :tag_push_events Trigger hook on tag push events
395
+ # @option options [Boolean] :note_events Trigger hook on note events
396
+ # @option options [Boolean] :confidential_note_events Trigger hook on confidential note events
397
+ # @option options [Boolean] :job_events Trigger hook on job events
398
+ # @option options [Boolean] :pipeline_events Trigger hook on pipeline events
399
+ # @option options [Boolean] :wiki_page_events Trigger hook on wiki page events
400
+ # @option options [Boolean] :deployment_events Trigger hook on deployment events
401
+ # @option options [Boolean] :releases_events Trigger hook on release events
402
+ # @option options [Boolean] :subgroup_events Trigger hook on subgroup events
403
+ # @option options [Boolean] :enable_ssl_verification Do SSL verification when triggering the hook
404
+ # @option options [String] :token Secret token to validate received payloads; not returned in the response
405
+ # @return [Gitlab::ObjectifiedHash] Response body matches https://docs.gitlab.com/ee/api/groups.html#get-group-hook
406
+ def add_group_hook(group_id, url, options = {})
407
+ post("/groups/#{group_id}/hooks", body: options.merge(url: url))
408
+ end
409
+
410
+ # Edit a group hook
411
+ #
412
+ # @example
413
+ # Gitlab.edit_group_hook(3, 1, "https://example.com/my-hook-receiver", {token: "verify me"})
414
+ #
415
+ # @param [Integer] group_id The ID of a group.
416
+ # @param [Integer] hook_id The ID of a group.
417
+ # @param [String] the hook url which will receive the selected events
418
+ # @option options [Boolean] :name The name of the group.
419
+ # @option options [Boolean] :push_events Trigger hook on push events
420
+ # @potion options [String] :push_events_branch_filter Trigger hook on push events for matching branches only.
421
+ # @option options [Boolean] :issues_events Trigger hook on issues events
422
+ # @option options [Boolean] :confidential_issues_events Trigger hook on confidential issues events
423
+ # @option options [Boolean] :merge_requests_events Trigger hook on merge requests events
424
+ # @option options [Boolean] :tag_push_events Trigger hook on tag push events
425
+ # @option options [Boolean] :note_events Trigger hook on note events
426
+ # @option options [Boolean] :confidential_note_events Trigger hook on confidential note events
427
+ # @option options [Boolean] :job_events Trigger hook on job events
428
+ # @option options [Boolean] :pipeline_events Trigger hook on pipeline events
429
+ # @option options [Boolean] :wiki_page_events Trigger hook on wiki page events
430
+ # @option options [Boolean] :deployment_events Trigger hook on deployment events
431
+ # @option options [Boolean] :releases_events Trigger hook on release events
432
+ # @option options [Boolean] :subgroup_events Trigger hook on subgroup events
433
+ # @option options [Boolean] :enable_ssl_verification Do SSL verification when triggering the hook
434
+ # @option options [String] :token Secret token to validate received payloads; not returned in the response
435
+ # @return [Gitlab::ObjectifiedHash] Response body matches https://docs.gitlab.com/ee/api/groups.html#edit-group-hook
436
+ def edit_group_hook(group_id, hook_id, url, options = {})
437
+ post("/groups/#{group_id}/hooks/#{hook_id}", body: options.merge(url: url))
438
+ end
439
+
440
+ # Delete a group hook
441
+ #
442
+ # @example
443
+ # Gitlab.delete_group_hook(3, 1)
444
+ #
445
+ # @param [Integer] group_id The ID of a group.
446
+ # @param [Integer] hook_id The ID of a group.
447
+ # @return [Gitlab::ObjectifiedHash] no body, will evaluate to an empty hash. https://docs.gitlab.com/ee/api/groups.html#delete-group-hook
448
+ def delete_group_hook(group_id, hook_id)
449
+ delete("/groups/#{group_id}/hooks/#{hook_id}")
450
+ end
357
451
  end
358
452
  end
@@ -227,5 +227,16 @@ class Gitlab::Client
227
227
  def merge_requests_closing_issue_on_merge(project, id)
228
228
  get("/projects/#{url_encode project}/issues/#{id}/closed_by")
229
229
  end
230
+
231
+ # List related merge requests
232
+ #
233
+ # @example
234
+ # Gitlab.related_merge_requests(3, 42)
235
+ #
236
+ # @param [Integer, String] project The ID or name of a project.
237
+ # @param [Integer] id The ID of an issue.
238
+ def related_merge_requests(project, id)
239
+ get("/projects/#{url_encode project}/issues/#{id}/related_merge_requests")
240
+ end
230
241
  end
231
242
  end
@@ -344,6 +344,18 @@ class Gitlab::Client
344
344
  delete("/projects/#{url_encode project}/merge_requests/#{merge_request_id}")
345
345
  end
346
346
 
347
+ # Gets a list of merge request diffs
348
+ #
349
+ # @example
350
+ # Gitlab.merge_request_diffs(5, 1)
351
+ # Gitlab.merge_request_diffs('gitlab', 1)
352
+ # @param [Integer, String] project The ID or name of a project.
353
+ # @param [Integer] id The ID of a merge request.
354
+ # @return [Gitlab::ObjectifiedHash] A list of the merge request diffs.
355
+ def merge_request_diffs(project, merge_request_id)
356
+ get("/projects/#{url_encode project}/merge_requests/#{merge_request_id}/diffs")
357
+ end
358
+
347
359
  # Gets a list of merge request diff versions
348
360
  #
349
361
  # @example
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Gitlab::Client
4
+ # Defines methods related to merge trains.
5
+ # @see https://docs.gitlab.com/ee/api/merge_trains.html
6
+ module MergeTrains
7
+ # Get list of merge trains for a project.
8
+ #
9
+ # @example
10
+ # Gitlab.merge_trains(1, scope: :active, sort: :asc)
11
+ #
12
+ # @param [Integer, String] project The ID or name of a project.
13
+ # @param [Hash] options A customizable set of options.
14
+ # @option options [String] :scope The scope of merge trains to return, one of: :active, :complete
15
+ # @option options [String] :sort Sort by created_at either 'asc' or 'desc'
16
+ # @return [Array<Gitlab::ObjectifiedHash>]
17
+ def merge_trains(project, options = {})
18
+ get("/projects/#{url_encode project}/merge_trains", query: options)
19
+ end
20
+
21
+ # Get all merge requests added to a merge train for the requested target branch.
22
+ #
23
+ # @param [Integer, String] project The ID or name of a project.
24
+ # @param [String] target_branch The target branch of the merge train.
25
+ # @param [Hash] options A customizable set of options.
26
+ # @option options [String] :scope The scope of merge trains to return, one of: :active, :complete
27
+ # @option options [String] :sort Sort by created_at either 'asc' or 'desc'
28
+ # @return [Array<Gitlab::ObjectifiedHash>]
29
+ def merge_train_merge_requests(project, target_branch, options = {})
30
+ get("/projects/#{url_encode project}/merge_trains/#{target_branch}", query: options)
31
+ end
32
+
33
+ # Get merge train information for the requested merge request.
34
+ #
35
+ # @param [Integer, String] project The ID or name of a project.
36
+ # @param [Integer] merge_request_iid The IID of the merge request.
37
+ # @return [Gitlab::ObjectifiedHash]
38
+ def merge_train_status(project, merge_request_iid)
39
+ get("/projects/#{url_encode project}/merge_trains/merge_requests/#{merge_request_iid}")
40
+ end
41
+
42
+ # Add a merge request to the merge train targeting the merge request’s target branch.
43
+ #
44
+ # @param [Integer, String] project The ID or name of a project.
45
+ # @param [Integer] merge_request_iid The IID of the merge request.
46
+ # @param [Hash] options A customizable set of options.
47
+ # @option options [Boolean] :when_pipeline_succeeds Add merge request to merge train when pipeline succeeds.
48
+ # @option options [String] :sha If present, the SHA must match the HEAD of the source branch, otherwise the merge fails.
49
+ # @option options [Boolean] :squash If true, the commits are squashed into a single commit on merge.
50
+ # @return [Array<Gitlab::ObjectifiedHash>] <description>
51
+ def add_merge_request_to_merge_train(project, merge_request_iid, options = {})
52
+ post("/projects/#{url_encode project}/merge_trains/merge_requests/#{merge_request_iid}", query: options)
53
+ end
54
+ end
55
+ end
@@ -43,6 +43,18 @@ class Gitlab::Client
43
43
  get("/projects/#{url_encode project}/pipelines/#{id}/test_report")
44
44
  end
45
45
 
46
+ # Gets a single pipeline's variables.
47
+ #
48
+ # @example
49
+ # Gitlab.pipeline_variables(5, 36)
50
+ #
51
+ # @param [Integer, String] project The ID or name of a project.
52
+ # @param [Integer] id The ID of a pipeline.
53
+ # @return [Array<Gitlab::ObjectifiedHash>]
54
+ def pipeline_variables(project, id)
55
+ get("/projects/#{url_encode project}/pipelines/#{id}/variables")
56
+ end
57
+
46
58
  # Create a pipeline.
47
59
  #
48
60
  # @example
@@ -101,5 +113,18 @@ class Gitlab::Client
101
113
  def delete_pipeline(project, id)
102
114
  delete("/projects/#{url_encode project}/pipelines/#{id}")
103
115
  end
116
+
117
+ # Update a pipeline metadata
118
+ #
119
+ # @example
120
+ # Gitlab.update_pipeline_metadata(5, 1, name: 'new name')
121
+ #
122
+ # @param [Integer, String] project The ID or name of a project.
123
+ # @param [Integer] id The ID of a pipeline.
124
+ # @option options [String] :name The new name of the pipeline.
125
+ # @return [Gitlab::ObjectifiedHash]
126
+ def update_pipeline_metadata(project, id, options = {})
127
+ put("/projects/#{url_encode project}/pipelines/#{id}/metadata", body: options)
128
+ end
104
129
  end
105
130
  end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Gitlab::Client
4
+ # Defines methods related to project exports.
5
+ # @see https://docs.gitlab.com/ce/api/project_import_export.html
6
+ module ProjectExports
7
+ # Start a new export
8
+ #
9
+ # @example
10
+ # Gitlab.export_project(2)
11
+ #
12
+ # @param [Integer, String] id The ID or path of a project.
13
+ # @param [Hash] options A customizable set of options.
14
+ # @option options [String] description(optional) Overrides the project description
15
+ # @option options [hash] upload(optional) Hash that contains the information to upload the exported project to a web server
16
+ # @option options [String] upload[url] TThe URL to upload the project
17
+ # @option options [String] upload[http_method](optional) The HTTP method to upload the exported project. Only PUT and POST methods allowed. Default is PUT
18
+ # @return [Gitlab::ObjectifiedHash]
19
+ def export_project(id, options = {})
20
+ post("/projects/#{url_encode id}/export", body: options)
21
+ end
22
+
23
+ # Get the status of export
24
+ #
25
+ # @example
26
+ # Gitlab.export_project_status(2)
27
+ #
28
+ # @param [Integer, String] id The ID or path of a project.
29
+ # @return [Gitlab::ObjectifiedHash]
30
+ def export_project_status(id)
31
+ get("/projects/#{url_encode id}/export")
32
+ end
33
+
34
+ # Download the finished export
35
+ #
36
+ # @example
37
+ # Gitlab.exported_project_download(2)
38
+ #
39
+ # @param [Integer, String] id The ID or path of a project.
40
+ # @return [Gitlab::FileResponse]
41
+ def exported_project_download(id)
42
+ get("/projects/#{url_encode id}/export/download",
43
+ format: nil,
44
+ headers: { Accept: 'application/octet-stream' },
45
+ parser: proc { |body, _|
46
+ if body.encoding == Encoding::ASCII_8BIT # binary response
47
+ ::Gitlab::FileResponse.new StringIO.new(body, 'rb+')
48
+ else # error with json response
49
+ ::Gitlab::Request.parse(body)
50
+ end
51
+ })
52
+ end
53
+ end
54
+ end
@@ -75,5 +75,16 @@ class Gitlab::Client
75
75
  def delete_project_release(project, tag_name)
76
76
  delete("/projects/#{url_encode project}/releases/#{tag_name}")
77
77
  end
78
+
79
+ # Gets Latest Release
80
+ #
81
+ # @example
82
+ # Gitlab.project_latest_release(5)
83
+ #
84
+ # @param [Integer, String] project The ID or name of a project
85
+ # @return [Gitlab::ObjectifiedHash] Information about the release
86
+ def project_latest_release(project)
87
+ get("/projects/#{url_encode project}/releases/permalink/latest")
88
+ end
78
89
  end
79
90
  end
@@ -207,5 +207,72 @@ class Gitlab::Client
207
207
  body = { token: token }
208
208
  post('/runners/verify', body: body)
209
209
  end
210
+
211
+ # Creates a new group runner with the new Gitlab approach (v16.0+) and returns the id/token information
212
+ # https://docs.gitlab.com/ee/api/users.html#create-a-runner
213
+ # You must use an access token with the create_runner scope
214
+ #
215
+ # @example
216
+ # Gitlab.create_group_runner(9, tag_list: ['one', 'two'])
217
+ # Gitlab.create_group_runner(9, paused: false, description: 'A note', run_untagged: true)
218
+ #
219
+ # @param [String] group(required) Group ID.
220
+ # @param [Hash] options A customizable set of options.
221
+ # @return <Gitlab::ObjectifiedHash> Response against runner registration
222
+ def create_group_runner(group, options = {})
223
+ create_runner({ runner_type: 'group_type', group_id: group }.merge(options))
224
+ end
225
+
226
+ # Creates a new project runner with the new Gitlab approach (v16.0+) and returns the id/token information
227
+ # https://docs.gitlab.com/ee/api/users.html#create-a-runner
228
+ # You must use an access token with the create_runner scope
229
+ #
230
+ # @example
231
+ # Gitlab.create_project_runner(12, tag_list: ['one', 'two'])
232
+ # Gitlab.create_project_runner(12, paused: false, description: 'A note', run_untagged: true)
233
+ #
234
+ # @param [String] project(required) Project ID.
235
+ # @param [Hash] options A customizable set of options.
236
+ # @return <Gitlab::ObjectifiedHash> Response against runner registration
237
+ def create_project_runner(project, options = {})
238
+ create_runner({ runner_type: 'project_type', project_id: project }.merge(options))
239
+ end
240
+
241
+ # Creates a new instance runner with the new Gitlab approach (v16.0+) and returns the id/token information
242
+ # You must be an administrator of the GitLab instance
243
+ # You must use an access token with the create_runner scope
244
+ # https://docs.gitlab.com/ee/api/users.html#create-a-runner
245
+ #
246
+ # @example
247
+ # Gitlab.create_instance_runner(tag_list: ['one', 'two'])
248
+ # Gitlab.create_instance_runner(paused: false, description: 'A note', run_untagged: true)
249
+ #
250
+ # @param [String] group(required) Project ID.
251
+ # @param [Hash] options A customizable set of options.
252
+ # @return <Gitlab::ObjectifiedHash> Response against runner registration
253
+ def create_instance_runner(options = {})
254
+ create_runner({ runner_type: 'instance_type' }.merge(options))
255
+ end
256
+
257
+ private
258
+
259
+ # Creates a runner linked to the current user.
260
+ # You must use an access token with the create_runner scope
261
+ # https://docs.gitlab.com/ee/api/users.html#create-a-runner
262
+ #
263
+ # @param [Hash] options(required) A customizable set of options.
264
+ # @option options [String] :description(optional) Runner description.
265
+ # @option options [Hash] :info(optional) Runner metadata.
266
+ # @option options [Boolean] :paused(optional) Whether the Runner ignores new jobs.
267
+ # @option options [Boolean] :locked(optional) Whether the Runner should be locked for current project.
268
+ # @option options [Boolean] :run_untagged(optional) Whether the Runner should handle untagged jobs.
269
+ # @option options [Array<String>] :tag_list(optional) List of Runner tags.
270
+ # @option options [String] :access_level(optional) Access level of the runner; not_protected or ref_protected.
271
+ # @option options [Integer] :maximum_timeout(optional) Maximum timeout set when this Runner will handle the job.
272
+ # @option options [String] :maintenance_note(optional) Free-form maintenance notes for the runner (1024 characters).
273
+ # @return <Gitlab::ObjectifiedHash> Response against runner registration {"id": 1, "token": foo "token_expires_at": null}
274
+ def create_runner(options)
275
+ post('/user/runners', body: options)
276
+ end
210
277
  end
211
278
  end
@@ -58,6 +58,22 @@ class Gitlab::Client
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
@@ -110,6 +126,28 @@ 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
+
113
151
  # Approves the specified user. Available only for admin.
114
152
  #
115
153
  # @example
@@ -276,7 +314,7 @@ class Gitlab::Client
276
314
  delete(url)
277
315
  end
278
316
 
279
- # Search for groups by name
317
+ # Search for users by name
280
318
  #
281
319
  # @example
282
320
  # Gitlab.user_search('gitlab')
@@ -291,6 +329,19 @@ class Gitlab::Client
291
329
  get('/users', query: options)
292
330
  end
293
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
+
294
345
  # Gets user custom_attributes.
295
346
  #
296
347
  # @example
@@ -382,6 +433,47 @@ class Gitlab::Client
382
433
  post("/users/#{user_id}/impersonation_tokens", body: body)
383
434
  end
384
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
+
385
477
  # Revoke an impersonation token
386
478
  #
387
479
  # @example
@@ -393,5 +485,37 @@ class Gitlab::Client
393
485
  def revoke_user_impersonation_token(user_id, impersonation_token_id)
394
486
  delete("/users/#{user_id}/impersonation_tokens/#{impersonation_token_id}")
395
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")
519
+ end
396
520
  end
397
521
  end
data/lib/gitlab/client.rb CHANGED
@@ -37,6 +37,7 @@ module Gitlab
37
37
  include Markdown
38
38
  include MergeRequestApprovals
39
39
  include MergeRequests
40
+ include MergeTrains
40
41
  include Milestones
41
42
  include Namespaces
42
43
  include Notes
@@ -46,6 +47,7 @@ module Gitlab
46
47
  include Pipelines
47
48
  include ProjectBadges
48
49
  include ProjectClusters
50
+ include ProjectExports
49
51
  include ProjectReleaseLinks
50
52
  include ProjectReleases
51
53
  include Projects
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Gitlab
4
+ module Headers
5
+ # Parses link header.
6
+ #
7
+ # @private
8
+ class PageLinks
9
+ HEADER_LINK = 'Link'
10
+ DELIM_LINKS = ','
11
+ LINK_REGEX = /<([^>]+)>; rel="([^"]+)"/.freeze
12
+ METAS = %w[last next first prev].freeze
13
+
14
+ attr_accessor(*METAS)
15
+
16
+ def initialize(headers)
17
+ link_header = headers[HEADER_LINK]
18
+
19
+ extract_links(link_header) if link_header && link_header =~ /(next|first|last|prev)/
20
+ end
21
+
22
+ private
23
+
24
+ def extract_links(header)
25
+ header.split(DELIM_LINKS).each do |link|
26
+ LINK_REGEX.match(link.strip) do |match|
27
+ url = match[1]
28
+ meta = match[2]
29
+ next if !url || !meta || METAS.index(meta).nil?
30
+
31
+ send("#{meta}=", url)
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Gitlab
4
+ module Headers
5
+ # Parses total header.
6
+ #
7
+ # @private
8
+ class Total
9
+ HEADER_TOTAL = 'x-total'
10
+ TOTAL_REGEX = /^\d+$/.freeze
11
+
12
+ attr_accessor :total
13
+
14
+ def initialize(headers)
15
+ header_total = headers[HEADER_TOTAL]
16
+
17
+ extract_total(header_total) if header_total
18
+ end
19
+
20
+ private
21
+
22
+ def extract_total(header_total)
23
+ TOTAL_REGEX.match(header_total.strip) do |match|
24
+ @total = match[0]
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -30,7 +30,8 @@ module Gitlab
30
30
  end
31
31
 
32
32
  def parse_headers!(headers)
33
- @links = PageLinks.new headers
33
+ @links = Headers::PageLinks.new headers
34
+ @total = Headers::Total.new headers
34
35
  end
35
36
 
36
37
  def each_page
@@ -58,6 +59,10 @@ module Gitlab
58
59
  lazy_paginate.take(limit).each(&block)
59
60
  end
60
61
 
62
+ def total
63
+ @total.total
64
+ end
65
+
61
66
  def last_page?
62
67
  !(@links.nil? || @links.last.nil?)
63
68
  end
@@ -38,7 +38,7 @@ module Gitlab
38
38
  raise Error::Parsing, 'The response is not a valid JSON'
39
39
  end
40
40
 
41
- %w[get post put delete].each do |method|
41
+ %w[get post put patch delete].each do |method|
42
42
  define_method method do |path, options = {}|
43
43
  params = options.dup
44
44
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Gitlab
4
- VERSION = '4.19.0'
4
+ VERSION = '4.20.1'
5
5
  end
data/lib/gitlab.rb CHANGED
@@ -4,7 +4,8 @@ require 'gitlab/version'
4
4
  require 'gitlab/objectified_hash'
5
5
  require 'gitlab/configuration'
6
6
  require 'gitlab/error'
7
- require 'gitlab/page_links'
7
+ require 'gitlab/headers/page_links'
8
+ require 'gitlab/headers/total'
8
9
  require 'gitlab/paginated_response'
9
10
  require 'gitlab/file_response'
10
11
  require 'gitlab/request'
@@ -49,8 +50,10 @@ module Gitlab
49
50
  #
50
51
  # @return [Array<Symbol>]
51
52
  def self.actions
53
+ # rubocop:disable Layout/LineLength
52
54
  hidden =
53
- /endpoint|private_token|auth_token|user_agent|sudo|get|post|put|\Adelete\z|validate\z|request_defaults|httparty/
55
+ /endpoint|private_token|auth_token|user_agent|sudo|get|post|put|patch|\Adelete\z|validate\z|request_defaults|httparty/
56
+ # rubocop:enable Layout/LineLength
54
57
  (Gitlab::Client.instance_methods - Object.methods).reject { |e| e[hidden] }
55
58
  end
56
59
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitlab
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.19.0
4
+ version: 4.20.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nihad Abbasov
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2022-07-10 00:00:00.000000000 Z
12
+ date: 2024-06-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httparty
@@ -130,6 +130,7 @@ files:
130
130
  - lib/gitlab/client/markdown.rb
131
131
  - lib/gitlab/client/merge_request_approvals.rb
132
132
  - lib/gitlab/client/merge_requests.rb
133
+ - lib/gitlab/client/merge_trains.rb
133
134
  - lib/gitlab/client/milestones.rb
134
135
  - lib/gitlab/client/namespaces.rb
135
136
  - lib/gitlab/client/notes.rb
@@ -139,6 +140,7 @@ files:
139
140
  - lib/gitlab/client/pipelines.rb
140
141
  - lib/gitlab/client/project_badges.rb
141
142
  - lib/gitlab/client/project_clusters.rb
143
+ - lib/gitlab/client/project_exports.rb
142
144
  - lib/gitlab/client/project_release_links.rb
143
145
  - lib/gitlab/client/project_releases.rb
144
146
  - lib/gitlab/client/projects.rb
@@ -165,9 +167,10 @@ files:
165
167
  - lib/gitlab/configuration.rb
166
168
  - lib/gitlab/error.rb
167
169
  - lib/gitlab/file_response.rb
170
+ - lib/gitlab/headers/page_links.rb
171
+ - lib/gitlab/headers/total.rb
168
172
  - lib/gitlab/help.rb
169
173
  - lib/gitlab/objectified_hash.rb
170
- - lib/gitlab/page_links.rb
171
174
  - lib/gitlab/paginated_response.rb
172
175
  - lib/gitlab/request.rb
173
176
  - lib/gitlab/shell.rb
@@ -1,35 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Gitlab
4
- # Parses link header.
5
- #
6
- # @private
7
- class PageLinks
8
- HEADER_LINK = 'Link'
9
- DELIM_LINKS = ','
10
- LINK_REGEX = /<([^>]+)>; rel="([^"]+)"/.freeze
11
- METAS = %w[last next first prev].freeze
12
-
13
- attr_accessor(*METAS)
14
-
15
- def initialize(headers)
16
- link_header = headers[HEADER_LINK]
17
-
18
- extract_links(link_header) if link_header && link_header =~ /(next|first|last|prev)/
19
- end
20
-
21
- private
22
-
23
- def extract_links(header)
24
- header.split(DELIM_LINKS).each do |link|
25
- LINK_REGEX.match(link.strip) do |match|
26
- url = match[1]
27
- meta = match[2]
28
- next if !url || !meta || METAS.index(meta).nil?
29
-
30
- send("#{meta}=", url)
31
- end
32
- end
33
- end
34
- end
35
- end