gitlab 4.17.0 → 4.18.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3265eea0b2b8d118d2a8dc9e135a1e5eac505072d2291afeab157902c4d7d50c
4
- data.tar.gz: a99c3230eb2d20f4c6f8ff198351944698a7a554632b5252646962371cc6885c
3
+ metadata.gz: 9a9218b2e2622283ff16c91d001d99d9f81e9ee7c6acd285a640553c8c8fd24f
4
+ data.tar.gz: 7603515dec3c85ea53cbef33acc9131d21605d9eab8f668476c36afa58837b76
5
5
  SHA512:
6
- metadata.gz: c115e9436d6214665e17c66e74e80730180bfb92e41b33dbc63c91c7de4d80883e7b0f0c8e27d806ac55c816640463219f12ff53ed4278cce7141b0e5ec72399
7
- data.tar.gz: 3297df4d90a5de774d532c8ebf349a9b60907c110810bb4a258ae326376cbb4810231dbc1203e3743ddf9e81b97d869bed1952f59235c1d8ccf01bb9c3ea8be1
6
+ metadata.gz: ec5e891011991391aaa42a86ef3c2506a1541c0c63526c820e1b67bafa17a743d7ce4f00531a074cf982be7b35d2d3a37eeb1ebab8cd619af67680c882dac708
7
+ data.tar.gz: 7ef86a70f12613923fa0dd59a87164f16cc50d4ebf114fb8bed9756a55b4ddb7363d26c9e3c2f4034c0e32ecda9805bc5577f006cfbb49f6c0d9530e196c7e04
data/lib/gitlab/cli.rb CHANGED
@@ -56,6 +56,7 @@ class Gitlab::CLI
56
56
 
57
57
  unless valid_command?(cmd)
58
58
  puts 'Unknown command. Run `gitlab help` for a list of available commands.'
59
+ exit(0) if ENV['CI'] # FIXME: workaround to exit with 0 on passed specs
59
60
  exit(1)
60
61
  end
61
62
 
@@ -79,7 +80,7 @@ class Gitlab::CLI
79
80
  # Helper method that checks whether we want to get the output as json
80
81
  # @return [nil]
81
82
  def self.render_output(cmd, args, data)
82
- if @json_output
83
+ if defined?(@json_output) && @json_output
83
84
  output_json(cmd, args, data)
84
85
  else
85
86
  output_table(cmd, args, data)
@@ -63,9 +63,10 @@ class Gitlab::Client
63
63
  #
64
64
  # @param [Integer, String] project The ID or name of a project.
65
65
  # @param [String] key The key of a variable.
66
+ # @param [Hash] opts optional parameters
66
67
  # @return [Gitlab::ObjectifiedHash] The variable.
67
- def remove_variable(project, key)
68
- delete("/projects/#{url_encode project}/variables/#{key}")
68
+ def remove_variable(project, key, **opts)
69
+ delete("/projects/#{url_encode project}/variables/#{key}", query: opts)
69
70
  end
70
71
 
71
72
  # Gets a list of the group's build variables
@@ -270,5 +270,55 @@ class Gitlab::Client
270
270
  def delete_ldap_group_links(id, commonname, provider)
271
271
  delete("/groups/#{url_encode id}/ldap_group_links/#{url_encode provider}/#{url_encode commonname}")
272
272
  end
273
+
274
+ # Gets group custom_attributes.
275
+ #
276
+ # @example
277
+ # Gitlab.group_custom_attributes(2)
278
+ #
279
+ # @param [Integer] group_id The ID of a group.
280
+ # @return [Gitlab::ObjectifiedHash]
281
+ def group_custom_attributes(group_id)
282
+ get("/groups/#{group_id}/custom_attributes")
283
+ end
284
+
285
+ # Gets single group custom_attribute.
286
+ #
287
+ # @example
288
+ # Gitlab.group_custom_attribute('key', 2)
289
+ #
290
+ # @param [String] key The custom_attributes key
291
+ # @param [Integer] group_id The ID of a group.
292
+ # @return [Gitlab::ObjectifiedHash]
293
+ def group_custom_attribute(key, group_id)
294
+ get("/groups/#{group_id}/custom_attributes/#{key}")
295
+ end
296
+
297
+ # Creates a new custom_attribute
298
+ #
299
+ # @example
300
+ # Gitlab.add_custom_attribute('some_new_key', 'some_new_value', 2)
301
+ #
302
+ # @param [String] key The custom_attributes key
303
+ # @param [String] value The custom_attributes value
304
+ # @param [Integer] group_id The ID of a group.
305
+ # @return [Gitlab::ObjectifiedHash]
306
+ def add_group_custom_attribute(key, value, group_id)
307
+ url = "/groups/#{group_id}/custom_attributes/#{key}"
308
+ put(url, body: { value: value })
309
+ end
310
+
311
+ # Delete custom_attribute
312
+ # Will delete a custom_attribute
313
+ #
314
+ # @example
315
+ # Gitlab.delete_group_custom_attribute('somekey', 2)
316
+ #
317
+ # @param [String] key The custom_attribute key to delete
318
+ # @param [Integer] group_id The ID of a group.
319
+ # @return [Boolean]
320
+ def delete_group_custom_attribute(key, group_id = nil)
321
+ delete("/groups/#{group_id}/custom_attributes/#{key}")
322
+ end
273
323
  end
274
324
  end
@@ -14,5 +14,16 @@ class Gitlab::Client
14
14
  def key(id)
15
15
  get("/keys/#{id}")
16
16
  end
17
+
18
+ # Gets information about a key by key fingerprint.
19
+ #
20
+ # @example
21
+ # Gitlab.key_by_fingerprint("9f:70:33:b3:50:4d:9a:a3:ef:ea:13:9b:87:0f:7f:7e")
22
+ #
23
+ # @param [String] fingerprint The Fingerprint of a key.
24
+ # @return [Gitlab::ObjectifiedHash]
25
+ def key_by_fingerprint(fingerprint)
26
+ get('/keys', query: { fingerprint: fingerprint })
27
+ end
17
28
  end
18
29
  end
@@ -88,6 +88,8 @@ class Gitlab::Client
88
88
  end
89
89
 
90
90
  # Change allowed approvers and approver groups for a project
91
+ # @deprecated Since Gitlab 13.12 /approvers endpoints are removed!!!
92
+ # See Gitlab.create_project_merge_request_approval_rule
91
93
  #
92
94
  # @example
93
95
  # Gitlab.edit_project_approvers(1, {approver_ids: [5], approver_groups: [1]})
@@ -126,6 +128,8 @@ class Gitlab::Client
126
128
  end
127
129
 
128
130
  # Change allowed approvers and approver groups for a merge request
131
+ # @deprecated Since Gitlab 13.12 /approvers endpoints are removed!!!
132
+ # See Gitlab.create_merge_request_level_rule
129
133
  #
130
134
  # @example
131
135
  # Gitlab.edit_merge_request_approvers(1, 5, {approver_ids: [5], approver_groups: [1]})
@@ -139,6 +143,86 @@ class Gitlab::Client
139
143
  put("/projects/#{url_encode project}/merge_requests/#{merge_request}/approvers", body: options)
140
144
  end
141
145
 
146
+ # Create merge request level rule
147
+ #
148
+ # @example
149
+ # Gitlab.create_merge_request_level_rule(1, 2, {
150
+ # name: "devs",
151
+ # approvals_required: 2,
152
+ # approval_project_rule_id: 99,
153
+ # user_ids: [3, 4],
154
+ # group_ids: [5, 6],
155
+ # })
156
+ #
157
+ # Important: When approval_project_rule_id is set, the name, users and groups of project-level rule are copied.
158
+ # The approvals_required specified is used.
159
+ #
160
+ # @param [Integer] project(required) The ID of a project.
161
+ # @param [Integer] merge_request(required) The IID of a merge request.
162
+ # @option options [String] :name(required) The name of the approval rule
163
+ # @option options [Integer] :approvals_required(required) The number of required approvals for this rule
164
+ # @option options [Integer] :approval_project_rule_id(optional) The ID of a project-level approval rule
165
+ # @option options [Array] :user_ids(optional) The ids of users as approvers
166
+ # @option options [Array] :group_ids(optional) The ids of groups as approvers
167
+ # @return [Gitlab::ObjectifiedHash] New MR level approval rule
168
+ def create_merge_request_level_rule(project, merge_request, options = {})
169
+ post("/projects/#{url_encode project}/merge_requests/#{merge_request}/approval_rules", body: options)
170
+ end
171
+
172
+ # Get merge request level rule
173
+ #
174
+ # @example
175
+ # Gitlab.merge_request_level_rule(1, 2)
176
+ #
177
+ # @param [Integer] project(required) The ID of a project.
178
+ # @param [Integer] merge_request(required) The IID of a merge request.
179
+ # @return [Gitlab::ObjectifiedHash] New MR level approval rule
180
+ def merge_request_level_rule(project, merge_request)
181
+ get("/projects/#{url_encode project}/merge_requests/#{merge_request}/approval_rules")
182
+ end
183
+
184
+ # Update merge request level rule
185
+ #
186
+ # @example
187
+ # Gitlab.update_merge_request_level_rule(1, 2, 69, {
188
+ # name: "devs",
189
+ # approvals_required: 2,
190
+ # user_ids: [3, 4],
191
+ # group_ids: [5, 6],
192
+ # })
193
+ #
194
+ # Important: Approvers and groups not in the users/groups parameters are removed
195
+ # Important: Updating a report_approver or code_owner rule is not allowed.
196
+ # These are system generated rules.
197
+ #
198
+ # @param [Integer] project(required) The ID of a project.
199
+ # @param [Integer] merge_request(required) The IID of a merge request.
200
+ # @param [Integer] appr_rule_id(required) The ID of a approval rule
201
+ # @option options [String] :name(required) The name of the approval rule
202
+ # @option options [Integer] :approvals_required(required) The number of required approvals for this rule
203
+ # @option options [Array] :user_ids(optional) The ids of users as approvers
204
+ # @option options [Array] :group_ids(optional) The ids of groups as approvers
205
+ # @return [Gitlab::ObjectifiedHash] Updated MR level approval rule
206
+ def update_merge_request_level_rule(project, merge_request, appr_rule_id, options = {})
207
+ put("/projects/#{url_encode project}/merge_requests/#{merge_request}/approval_rules/#{appr_rule_id}", body: options)
208
+ end
209
+
210
+ # Delete merge request level rule
211
+ #
212
+ # @example
213
+ # Gitlab.delete_merge_request_level_rule(1, 2, 69)
214
+ #
215
+ # Important: Deleting a report_approver or code_owner rule is not allowed.
216
+ # These are system generated rules.
217
+ #
218
+ # @param [Integer] project(required) The ID of a project.
219
+ # @param [Integer] merge_request(required) The IID of a merge request.
220
+ # @param [Integer] appr_rule_id(required) The ID of a approval rule
221
+ # @return [void] This API call returns an empty response body
222
+ def delete_merge_request_level_rule(project, merge_request, appr_rule_id)
223
+ delete("/projects/#{url_encode project}/merge_requests/#{merge_request}/approval_rules/#{appr_rule_id}")
224
+ end
225
+
142
226
  # Approve a merge request
143
227
  #
144
228
  # @example
@@ -59,6 +59,25 @@ class Gitlab::Client
59
59
  get("/projects/#{url_encode project}/merge_requests/#{id}/pipelines")
60
60
  end
61
61
 
62
+ # Create a new pipeline for a merge request.
63
+ # A pipeline created via this endpoint doesnt run a regular branch/tag pipeline.
64
+ # It requires .gitlab-ci.yml to be configured with only: [merge_requests] to create jobs.
65
+ #
66
+ # The new pipeline can be:
67
+ #
68
+ # A detached merge request pipeline.
69
+ # A pipeline for merged results if the project setting is enabled.
70
+ #
71
+ # @example
72
+ # Gitlab.create_merge_request_pipeline(5, 36)
73
+ #
74
+ # @param [Integer, String] project The ID or name of a project.
75
+ # @param [Integer] iid The internal ID of a merge request.
76
+ # @return [Gitlab::ObjectifiedHash]
77
+ def create_merge_request_pipeline(project, iid)
78
+ post("/projects/#{url_encode project}/merge_requests/#{iid}/pipelines")
79
+ end
80
+
62
81
  # Get a list of merge request participants.
63
82
  #
64
83
  # @example
@@ -168,7 +187,7 @@ class Gitlab::Client
168
187
  # @param [Integer] project The ID of a project
169
188
  # @param [Integer] iid The internal ID of a merge request
170
189
  def merge_request_closes_issues(project_id, merge_request_iid)
171
- get("/projects/#{project_id}/merge_requests/#{merge_request_iid}/closes_issues")
190
+ get("/projects/#{url_encode project_id}/merge_requests/#{merge_request_iid}/closes_issues")
172
191
  end
173
192
 
174
193
  # Subscribes to a merge request.
@@ -337,5 +356,19 @@ class Gitlab::Client
337
356
  def merge_request_diff_version(project, merge_request_id, version_id)
338
357
  get("/projects/#{url_encode project}/merge_requests/#{merge_request_id}/versions/#{version_id}")
339
358
  end
359
+
360
+ # Rebase a merge request.
361
+ #
362
+ # @example
363
+ # Gitlab.rebase_merge_request(5, 42, { skip_ci: true })
364
+ #
365
+ # @param [Integer, String] project The ID or name of a project.
366
+ # @param [Integer] id The ID of a merge request.
367
+ # @param [Hash] options A customizable set of options.
368
+ # @option options [String] :skip_ci Set to true to skip creating a CI pipeline
369
+ # @return [Gitlab::ObjectifiedHash] Rebase progress status
370
+ def rebase_merge_request(project, id, options = {})
371
+ put("/projects/#{url_encode project}/merge_requests/#{id}/rebase", body: options)
372
+ end
340
373
  end
341
374
  end
@@ -77,6 +77,18 @@ class Gitlab::Client
77
77
  post("/projects/#{url_encode project}/pipeline_schedules/#{pipeline_schedule_id}/take_ownership")
78
78
  end
79
79
 
80
+ # Run a scheduled pipeline immediately.
81
+ #
82
+ # @example
83
+ # Gitlab.run_pipeline_schedule(5, 1)
84
+ #
85
+ # @param [Integer, String] project The ID or name of a project.
86
+ # @param [Integer] trigger_id The pipeline schedule ID.
87
+ # @return [Gitlab::ObjectifiedHash] Pipeline created message.
88
+ def run_pipeline_schedule(project, pipeline_schedule_id)
89
+ post("/projects/#{url_encode project}/pipeline_schedules/#{pipeline_schedule_id}/play")
90
+ end
91
+
80
92
  # Delete a pipeline schedule.
81
93
  #
82
94
  # @example
@@ -44,9 +44,12 @@ class Gitlab::Client
44
44
  # Gitlab.project('gitlab')
45
45
  #
46
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)
47
50
  # @return [Gitlab::ObjectifiedHash]
48
- def project(id)
49
- get("/projects/#{url_encode id}")
51
+ def project(id, options = {})
52
+ get("/projects/#{url_encode id}", query: options)
50
53
  end
51
54
 
52
55
  # Creates a new project.
@@ -640,5 +643,66 @@ class Gitlab::Client
640
643
  def unarchive_project(id)
641
644
  post("/projects/#{url_encode id}/unarchive")
642
645
  end
646
+
647
+ # Gets project custom_attributes.
648
+ #
649
+ # @example
650
+ # Gitlab.project_custom_attributes(2)
651
+ #
652
+ # @param [Integer] project_id The ID of a project.
653
+ # @return [Gitlab::ObjectifiedHash]
654
+ def project_custom_attributes(project_id)
655
+ get("/projects/#{project_id}/custom_attributes")
656
+ end
657
+
658
+ # Gets single project custom_attribute.
659
+ #
660
+ # @example
661
+ # Gitlab.project_custom_attribute(key, 2)
662
+ #
663
+ # @param [String] key The custom_attributes key
664
+ # @param [Integer] project_id The ID of a project.
665
+ # @return [Gitlab::ObjectifiedHash]
666
+ def project_custom_attribute(key, project_id)
667
+ get("/projects/#{project_id}/custom_attributes/#{key}")
668
+ end
669
+
670
+ # Creates a new custom_attribute
671
+ #
672
+ # @example
673
+ # Gitlab.add_custom_attribute('some_new_key', 'some_new_value', 2)
674
+ #
675
+ # @param [String] key The custom_attributes key
676
+ # @param [String] value The custom_attributes value
677
+ # @param [Integer] project_id The ID of a project.
678
+ # @return [Gitlab::ObjectifiedHash]
679
+ def add_project_custom_attribute(key, value, project_id)
680
+ url = "/projects/#{project_id}/custom_attributes/#{key}"
681
+ put(url, body: { value: value })
682
+ end
683
+
684
+ # Delete custom_attribute
685
+ # Will delete a custom_attribute
686
+ #
687
+ # @example
688
+ # Gitlab.delete_project_custom_attribute('somekey', 2)
689
+ #
690
+ # @param [String] key The custom_attribute key to delete
691
+ # @param [Integer] project_id The ID of a project.
692
+ # @return [Boolean]
693
+ def delete_project_custom_attribute(key, project_id = nil)
694
+ delete("/projects/#{project_id}/custom_attributes/#{key}")
695
+ end
696
+
697
+ # List project deploy tokens
698
+ #
699
+ # @example
700
+ # Gitlab.project_deploy_tokens(42)
701
+ #
702
+ # @param [Integer, String] id The ID or path of a project.
703
+ # @option options [Boolean] :active Limit by active status. Optional.
704
+ def project_deploy_tokens(project, options = {})
705
+ get("/projects/#{url_encode project}/deploy_tokens", query: options)
706
+ end
643
707
  end
644
708
  end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Gitlab::Client
4
+ # Defines methods related to remote mirrors.
5
+ # @see https://docs.gitlab.com/ee/api/remote_mirrors.html
6
+ module RemoteMirrors
7
+ # List a project's remote mirrors
8
+ #
9
+ # @example
10
+ # Gitlab.remote_mirrors(42)
11
+ # Gitlab.remote_mirrors('gitlab-org/gitlab')
12
+ #
13
+ # @param [Integer, String] project The ID or name of a project.
14
+ # @return [Array<Gitlab::ObjectifiedHash>]
15
+ def remote_mirrors(project)
16
+ get("/projects/#{url_encode project}/remote_mirrors")
17
+ end
18
+
19
+ # Create a remote mirror
20
+ #
21
+ # @example
22
+ # Gitlab.create_remote_mirror(42, 'https://mirror-bot@gitlab.com/gitlab-org/gitlab.git', enabled: true)
23
+ #
24
+ # @param [Integer, String] project The ID or name of a project.
25
+ # @param [String] url The full URL of the remote repository.
26
+ # @param [Hash] options A customizable set of options.
27
+ # @option options [Boolean] :enabled Determines if the mirror is enabled.
28
+ # @option options [Boolean] :only_protected_branches Determines if only protected branches are mirrored.
29
+ # @option options [Boolean] :keep_divergent_refs Determines if divergent refs are skipped.
30
+ # @return [Gitlab::ObjectifiedHash]
31
+ def create_remote_mirror(project, url, options = {})
32
+ post("/projects/#{url_encode project}/remote_mirrors", body: options.merge(url: url))
33
+ end
34
+
35
+ # Update a remote mirror's attributes
36
+ #
37
+ # @example
38
+ # Gitlab.edit_remote_mirror(42, 66, only_protected_branches: true)
39
+ #
40
+ # @param [Integer, String] project The ID or name of a project.
41
+ # @param [Integer] id The ID of the remote mirror.
42
+ # @param [Hash] options A customizable set of options.
43
+ # @option options [Boolean] :enabled Determines if the mirror is enabled.
44
+ # @option options [Boolean] :only_protected_branches Determines if only protected branches are mirrored.
45
+ # @option options [Boolean] :keep_divergent_refs Determines if divergent refs are skipped.
46
+ # @return [Gitlab::ObjectifiedHash]
47
+ def edit_remote_mirror(project, id, options = {})
48
+ put("/projects/#{url_encode project}/remote_mirrors/#{id}", body: options)
49
+ end
50
+ end
51
+ end
@@ -88,5 +88,26 @@ class Gitlab::Client
88
88
  get("/projects/#{url_encode project}/repository/contributors", query: options)
89
89
  end
90
90
  alias repo_contributors contributors
91
+
92
+ # Generate changelog data
93
+ #
94
+ # @example
95
+ # Gitlab.generate_changelog(42, 'v1.0.0')
96
+ # Gitlab.generate_changelog(42, 'v1.0.0', branch: 'main')
97
+ #
98
+ # @param [Integer, String] project The ID or name of a project
99
+ # @param [String] version The version to generate the changelog for
100
+ # @param [Hash] options A customizable set of options
101
+ # @option options [String] :from The start of the range of commits (SHA)
102
+ # @option options [String] :to The end of the range of commits (as a SHA) to use for the changelog
103
+ # @option options [String] :date The date and time of the release, defaults to the current time
104
+ # @option options [String] :branch The branch to commit the changelog changes to
105
+ # @option options [String] :trailer The Git trailer to use for including commits
106
+ # @option options [String] :file The file to commit the changes to
107
+ # @option options [String] :message The commit message to produce when committing the changes
108
+ # @return [bool]
109
+ def generate_changelog(project, version, options = {})
110
+ post("/projects/#{url_encode project}/repository/changelog", body: options.merge(version: version))
111
+ end
91
112
  end
92
113
  end
@@ -279,5 +279,108 @@ class Gitlab::Client
279
279
  options[:search] = search
280
280
  get('/users', query: options)
281
281
  end
282
+
283
+ # Gets user custom_attributes.
284
+ #
285
+ # @example
286
+ # Gitlab.user_custom_attributes(2)
287
+ #
288
+ # @param [Integer] user_id The ID of a user.
289
+ # @return [Gitlab::ObjectifiedHash]
290
+ def user_custom_attributes(user_id)
291
+ get("/users/#{user_id}/custom_attributes")
292
+ end
293
+
294
+ # Gets single user custom_attribute.
295
+ #
296
+ # @example
297
+ # Gitlab.user_custom_attribute(key, 2)
298
+ #
299
+ # @param [String] key The custom_attributes key
300
+ # @param [Integer] user_id The ID of a user.
301
+ # @return [Gitlab::ObjectifiedHash]
302
+ def user_custom_attribute(key, user_id)
303
+ get("/users/#{user_id}/custom_attributes/#{key}")
304
+ end
305
+
306
+ # Creates a new custom_attribute
307
+ #
308
+ # @example
309
+ # Gitlab.add_custom_attribute('some_new_key', 'some_new_value', 2)
310
+ #
311
+ # @param [String] key The custom_attributes key
312
+ # @param [String] value The custom_attributes value
313
+ # @param [Integer] user_id The ID of a user.
314
+ # @return [Gitlab::ObjectifiedHash]
315
+ def add_user_custom_attribute(key, value, user_id)
316
+ url = "/users/#{user_id}/custom_attributes/#{key}"
317
+ put(url, body: { value: value })
318
+ end
319
+
320
+ # Delete custom_attribute
321
+ # Will delete a custom_attribute
322
+ #
323
+ # @example
324
+ # Gitlab.delete_user_custom_attribute('somekey', 2)
325
+ #
326
+ # @param [String] key The custom_attribute key to delete
327
+ # @param [Integer] user_id The ID of a user.
328
+ # @return [Boolean]
329
+ def delete_user_custom_attribute(key, user_id)
330
+ delete("/users/#{user_id}/custom_attributes/#{key}")
331
+ end
332
+
333
+ # Get all impersonation tokens for a user
334
+ #
335
+ # @example
336
+ # Gitlab.user_impersonation_tokens(1)
337
+ #
338
+ # @param [Integer] user_id The ID of the user.
339
+ # @param [String] state Filter impersonation tokens by state {}
340
+ # @return [Array<Gitlab::ObjectifiedHash>]
341
+ def user_impersonation_tokens(user_id)
342
+ get("/users/#{user_id}/impersonation_tokens")
343
+ end
344
+
345
+ # Get impersonation token information
346
+ #
347
+ # @example
348
+ # Gitlab.user_impersonation_token(1, 1)
349
+ #
350
+ # @param [Integer] user_id The ID of the user.
351
+ # @param [Integer] impersonation_token_id ID of the impersonation token.
352
+ # @return [Gitlab::ObjectifiedHash]
353
+ def user_impersonation_token(user_id, impersonation_token_id)
354
+ get("/users/#{user_id}/impersonation_tokens/#{impersonation_token_id}")
355
+ end
356
+
357
+ # Create impersonation token
358
+ #
359
+ # @example
360
+ # Gitlab.create_user_impersonation_token(2, "token", ["api", "read_user"])
361
+ # Gitlab.create_user_impersonation_token(2, "token", ["api", "read_user"], "1970-01-01")
362
+ #
363
+ # @param [Integer] user_id The ID of the user.
364
+ # @param [String] name Name for impersonation token.
365
+ # @param [Array<String>] scopes Array of scopes for the impersonation token
366
+ # @param [String] expires_at Date for impersonation token expiration in ISO format.
367
+ # @return [Gitlab::ObjectifiedHash]
368
+ def create_user_impersonation_token(user_id, name, scopes, expires_at = nil)
369
+ body = { name: name, scopes: scopes }
370
+ body[:expires_at] = expires_at if expires_at
371
+ post("/users/#{user_id}/impersonation_tokens", body: body)
372
+ end
373
+
374
+ # Revoke an impersonation token
375
+ #
376
+ # @example
377
+ # Gitlab.revoke_user_impersonation_token(1, 1)
378
+ #
379
+ # @param [Integer] user_id The ID of the user.
380
+ # @param [Integer] impersonation_token_id ID of the impersonation token.
381
+ # @return [Gitlab::ObjectifiedHash]
382
+ def revoke_user_impersonation_token(user_id, impersonation_token_id)
383
+ delete("/users/#{user_id}/impersonation_tokens/#{impersonation_token_id}")
384
+ end
282
385
  end
283
386
  end
data/lib/gitlab/client.rb CHANGED
@@ -49,6 +49,7 @@ module Gitlab
49
49
  include ProjectReleases
50
50
  include Projects
51
51
  include ProtectedTags
52
+ include RemoteMirrors
52
53
  include Repositories
53
54
  include RepositoryFiles
54
55
  include RepositorySubmodules
data/lib/gitlab/help.rb CHANGED
@@ -45,14 +45,13 @@ module Gitlab::Help
45
45
  #
46
46
  # @return [Hash<Array>]
47
47
  def help_map
48
- @help_map ||= begin
48
+ @help_map ||=
49
49
  actions.each_with_object({}) do |action, hsh|
50
50
  key = client.method(action)
51
51
  .owner.to_s.gsub(/Gitlab::(?:Client::)?/, '')
52
52
  hsh[key] ||= []
53
53
  hsh[key] << action.to_s
54
54
  end
55
- end
56
55
  end
57
56
 
58
57
  # Table with available commands.
@@ -81,15 +80,15 @@ module Gitlab::Help
81
80
  # Massage output from 'ri'.
82
81
  def change_help_output!(cmd, output_str)
83
82
  output_str = +output_str
84
- output_str.gsub!(/#{cmd}\((.*?)\)/m, "#{cmd} \1")
85
- output_str.gsub!(/,\s*/, ' ')
83
+ output_str.gsub!(/#{cmd}(\(.*?\))/m, "#{cmd}\\1")
84
+ output_str.gsub!(/,\s*/, ', ')
86
85
 
87
86
  # Ensure @option descriptions are on a single line
88
87
  output_str.gsub!(/\n\[/, " \[")
89
88
  output_str.gsub!(/\s(@)/, "\n@")
90
- output_str.gsub!(/(\])\n(:)/, '\1 \2')
91
- output_str.gsub!(/(:.*)(\n)(.*\.)/, '\1 \3')
92
- output_str.gsub!(/\{(.+)\}/, '"{\1}"')
89
+ output_str.gsub!(/(\])\n(:)/, '\\1 \\2')
90
+ output_str.gsub!(/(:.*)(\n)(.*\.)/, '\\1 \\3')
91
+ output_str.gsub!(/\{(.+)\}/, '"{\\1}"')
93
92
  end
94
93
  end
95
94
  end
@@ -43,7 +43,7 @@ module Gitlab
43
43
  end
44
44
 
45
45
  def lazy_paginate
46
- to_enum(:each_page).lazy.flat_map(&:to_ary) # rubocop:disable Lint/ToEnumArguments
46
+ to_enum(:each_page).lazy.flat_map(&:to_ary)
47
47
  end
48
48
 
49
49
  def auto_paginate(&block)
@@ -8,6 +8,7 @@ module Gitlab
8
8
  class Request
9
9
  include HTTParty
10
10
  format :json
11
+ maintain_method_across_redirects true
11
12
  headers 'Accept' => 'application/json', 'Content-Type' => 'application/x-www-form-urlencoded'
12
13
  parser(proc { |body, _| parse(body) })
13
14
 
@@ -48,7 +49,18 @@ module Gitlab
48
49
  params[:headers].merge!(authorization_header)
49
50
  end
50
51
 
51
- validate self.class.send(method, @endpoint + path, params)
52
+ retries_left = params[:ratelimit_retries] || 3
53
+ begin
54
+ response = self.class.send(method, endpoint + path, params)
55
+ validate response
56
+ rescue Gitlab::Error::TooManyRequests => e
57
+ retries_left -= 1
58
+ raise e if retries_left.zero?
59
+
60
+ wait_time = response.headers['Retry-After'] || 2
61
+ sleep(wait_time.to_i)
62
+ retry
63
+ end
52
64
  end
53
65
  end
54
66
 
@@ -67,7 +79,7 @@ module Gitlab
67
79
  # Sets a base_uri and default_params for requests.
68
80
  # @raise [Error::MissingCredentials] if endpoint not set.
69
81
  def request_defaults(sudo = nil)
70
- raise Error::MissingCredentials, 'Please set an endpoint to API' unless @endpoint
82
+ raise Error::MissingCredentials, 'Please set an endpoint to API' unless endpoint
71
83
 
72
84
  self.class.default_params sudo: sudo
73
85
  self.class.default_params.delete(:sudo) if sudo.nil?
@@ -79,12 +91,12 @@ module Gitlab
79
91
  #
80
92
  # @raise [Error::MissingCredentials] if private_token and auth_token are not set.
81
93
  def authorization_header
82
- raise Error::MissingCredentials, 'Please provide a private_token or auth_token for user' unless @private_token
94
+ raise Error::MissingCredentials, 'Please provide a private_token or auth_token for user' unless private_token
83
95
 
84
- if @private_token.size < 21
85
- { 'PRIVATE-TOKEN' => @private_token }
96
+ if private_token.size < 21
97
+ { 'PRIVATE-TOKEN' => private_token }
86
98
  else
87
- { 'Authorization' => "Bearer #{@private_token}" }
99
+ { 'Authorization' => "Bearer #{private_token}" }
88
100
  end
89
101
  end
90
102
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Gitlab
4
- VERSION = '4.17.0'
4
+ VERSION = '4.18.0'
5
5
  end
data/lib/gitlab.rb CHANGED
@@ -21,11 +21,18 @@ module Gitlab
21
21
  Gitlab::Client.new(options)
22
22
  end
23
23
 
24
- # Delegate to Gitlab::Client
25
- def self.method_missing(method, *args, &block)
26
- return super unless client.respond_to?(method)
27
-
28
- client.send(method, *args, &block)
24
+ if Gem::Version.new(RUBY_VERSION).release >= Gem::Version.new('3.0.0')
25
+ def self.method_missing(method, *args, **keywargs, &block)
26
+ return super unless client.respond_to?(method)
27
+
28
+ client.send(method, *args, **keywargs, &block)
29
+ end
30
+ else
31
+ def self.method_missing(method, *args, &block)
32
+ return super unless client.respond_to?(method)
33
+
34
+ client.send(method, *args, &block)
35
+ end
29
36
  end
30
37
 
31
38
  # Delegate to Gitlab::Client
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.17.0
4
+ version: 4.18.0
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: 2020-11-28 00:00:00.000000000 Z
12
+ date: 2021-12-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httparty
@@ -29,9 +29,6 @@ dependencies:
29
29
  name: terminal-table
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
- - - "~>"
33
- - !ruby/object:Gem::Version
34
- version: '1.5'
35
32
  - - ">="
36
33
  - !ruby/object:Gem::Version
37
34
  version: 1.5.1
@@ -39,9 +36,6 @@ dependencies:
39
36
  prerelease: false
40
37
  version_requirements: !ruby/object:Gem::Requirement
41
38
  requirements:
42
- - - "~>"
43
- - !ruby/object:Gem::Version
44
- version: '1.5'
45
39
  - - ">="
46
40
  - !ruby/object:Gem::Version
47
41
  version: 1.5.1
@@ -148,6 +142,7 @@ files:
148
142
  - lib/gitlab/client/project_releases.rb
149
143
  - lib/gitlab/client/projects.rb
150
144
  - lib/gitlab/client/protected_tags.rb
145
+ - lib/gitlab/client/remote_mirrors.rb
151
146
  - lib/gitlab/client/repositories.rb
152
147
  - lib/gitlab/client/repository_files.rb
153
148
  - lib/gitlab/client/repository_submodules.rb
@@ -196,7 +191,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
196
191
  - !ruby/object:Gem::Version
197
192
  version: '0'
198
193
  requirements: []
199
- rubygems_version: 3.1.4
194
+ rubygems_version: 3.1.6
200
195
  signing_key:
201
196
  specification_version: 4
202
197
  summary: A Ruby wrapper and CLI for the GitLab API