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.
- checksums.yaml +7 -0
- data/lib/gitlab/api.rb +16 -0
- data/lib/gitlab/client/access_requests.rb +103 -0
- data/lib/gitlab/client/application_settings.rb +172 -0
- data/lib/gitlab/client/avatar.rb +21 -0
- data/lib/gitlab/client/award_emojis.rb +137 -0
- data/lib/gitlab/client/boards.rb +146 -0
- data/lib/gitlab/client/branches.rb +135 -0
- data/lib/gitlab/client/broadcast_messages.rb +75 -0
- data/lib/gitlab/client/build_variables.rb +135 -0
- data/lib/gitlab/client/builds.rb +108 -0
- data/lib/gitlab/client/commits.rb +216 -0
- data/lib/gitlab/client/container_registry.rb +90 -0
- data/lib/gitlab/client/deployments.rb +34 -0
- data/lib/gitlab/client/environments.rb +89 -0
- data/lib/gitlab/client/epic_issues.rb +23 -0
- data/lib/gitlab/client/epics.rb +73 -0
- data/lib/gitlab/client/events.rb +60 -0
- data/lib/gitlab/client/features.rb +48 -0
- data/lib/gitlab/client/group_badges.rb +88 -0
- data/lib/gitlab/client/group_boards.rb +141 -0
- data/lib/gitlab/client/group_labels.rb +88 -0
- data/lib/gitlab/client/group_milestones.rb +94 -0
- data/lib/gitlab/client/groups.rb +526 -0
- data/lib/gitlab/client/issue_links.rb +48 -0
- data/lib/gitlab/client/issues.rb +242 -0
- data/lib/gitlab/client/jobs.rb +250 -0
- data/lib/gitlab/client/keys.rb +29 -0
- data/lib/gitlab/client/labels.rb +88 -0
- data/lib/gitlab/client/lint.rb +19 -0
- data/lib/gitlab/client/markdown.rb +23 -0
- data/lib/gitlab/client/merge_request_approvals.rb +265 -0
- data/lib/gitlab/client/merge_requests.rb +415 -0
- data/lib/gitlab/client/merge_trains.rb +55 -0
- data/lib/gitlab/client/milestones.rb +106 -0
- data/lib/gitlab/client/namespaces.rb +22 -0
- data/lib/gitlab/client/notes.rb +313 -0
- data/lib/gitlab/client/packages.rb +95 -0
- data/lib/gitlab/client/pipeline_schedules.rb +159 -0
- data/lib/gitlab/client/pipeline_triggers.rb +103 -0
- data/lib/gitlab/client/pipelines.rb +130 -0
- data/lib/gitlab/client/project_badges.rb +85 -0
- data/lib/gitlab/client/project_clusters.rb +83 -0
- data/lib/gitlab/client/project_exports.rb +54 -0
- data/lib/gitlab/client/project_release_links.rb +76 -0
- data/lib/gitlab/client/project_releases.rb +90 -0
- data/lib/gitlab/client/projects.rb +792 -0
- data/lib/gitlab/client/protected_tags.rb +59 -0
- data/lib/gitlab/client/remote_mirrors.rb +90 -0
- data/lib/gitlab/client/repositories.rb +130 -0
- data/lib/gitlab/client/repository_files.rb +131 -0
- data/lib/gitlab/client/repository_submodules.rb +27 -0
- data/lib/gitlab/client/resource_label_events.rb +82 -0
- data/lib/gitlab/client/resource_state_events.rb +57 -0
- data/lib/gitlab/client/runners.rb +278 -0
- data/lib/gitlab/client/search.rb +66 -0
- data/lib/gitlab/client/services.rb +53 -0
- data/lib/gitlab/client/sidekiq.rb +39 -0
- data/lib/gitlab/client/snippets.rb +95 -0
- data/lib/gitlab/client/system_hooks.rb +64 -0
- data/lib/gitlab/client/tags.rb +97 -0
- data/lib/gitlab/client/templates.rb +100 -0
- data/lib/gitlab/client/todos.rb +46 -0
- data/lib/gitlab/client/user_snippets.rb +114 -0
- data/lib/gitlab/client/users.rb +521 -0
- data/lib/gitlab/client/versions.rb +18 -0
- data/lib/gitlab/client/wikis.rb +79 -0
- data/lib/gitlab/client.rb +96 -0
- data/lib/gitlab/configuration.rb +36 -0
- data/lib/gitlab/error.rb +114 -0
- data/lib/gitlab/file_response.rb +43 -0
- data/lib/gitlab/headers/page_links.rb +32 -0
- data/lib/gitlab/headers/total.rb +24 -0
- data/lib/gitlab/objectified_hash.rb +44 -0
- data/lib/gitlab/paginated_response.rb +114 -0
- data/lib/gitlab/request.rb +144 -0
- data/lib/gitlab/version.rb +5 -0
- data/lib/gitlab.rb +36 -0
- metadata +156 -0
|
@@ -0,0 +1,521 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class Gitlab::Client
|
|
4
|
+
# Defines methods related to users.
|
|
5
|
+
# @see https://docs.gitlab.com/ce/api/users.html
|
|
6
|
+
# @see https://docs.gitlab.com/ce/api/session.html
|
|
7
|
+
module Users
|
|
8
|
+
# Gets a list of users.
|
|
9
|
+
#
|
|
10
|
+
# @example
|
|
11
|
+
# Gitlab.users
|
|
12
|
+
#
|
|
13
|
+
# @param [Hash] options A customizable set of options.
|
|
14
|
+
# @option options [Integer] :page The page number.
|
|
15
|
+
# @option options [Integer] :per_page The number of results per page.
|
|
16
|
+
# @return [Array<Gitlab::ObjectifiedHash>]
|
|
17
|
+
def users(options = {})
|
|
18
|
+
get('/users', query: options)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# Gets information about a user.
|
|
22
|
+
# Will return information about an authorized user if no ID passed.
|
|
23
|
+
#
|
|
24
|
+
# @example
|
|
25
|
+
# Gitlab.user
|
|
26
|
+
# Gitlab.user(2)
|
|
27
|
+
#
|
|
28
|
+
# @param [Integer] id The ID of a user.
|
|
29
|
+
# @return [Gitlab::ObjectifiedHash]
|
|
30
|
+
def user(id = nil)
|
|
31
|
+
id.to_i.zero? ? get('/user') : get("/users/#{id}")
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# Creates a new user.
|
|
35
|
+
# Requires authentication from an admin account.
|
|
36
|
+
#
|
|
37
|
+
# @example
|
|
38
|
+
# Gitlab.create_user('joe@foo.org', 'secret', 'joe', { name: 'Joe Smith' })
|
|
39
|
+
# or
|
|
40
|
+
# Gitlab.create_user('joe@foo.org', 'secret', 'joe')
|
|
41
|
+
#
|
|
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.
|
|
45
|
+
# @param [Hash] options A customizable set of options.
|
|
46
|
+
# @option options [String] :name The name of a user. Defaults to email.
|
|
47
|
+
# @option options [String] :skype The skype of a user.
|
|
48
|
+
# @option options [String] :linkedin The linkedin of a user.
|
|
49
|
+
# @option options [String] :twitter The twitter of a user.
|
|
50
|
+
# @option options [Integer] :projects_limit The limit of projects for a user.
|
|
51
|
+
# @return [Gitlab::ObjectifiedHash] Information about created user.
|
|
52
|
+
def create_user(*args)
|
|
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
|
+
body.merge!(options)
|
|
58
|
+
post('/users', body: body)
|
|
59
|
+
end
|
|
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
|
+
|
|
77
|
+
# Updates a user.
|
|
78
|
+
#
|
|
79
|
+
# @example
|
|
80
|
+
# Gitlab.edit_user(15, { email: 'joe.smith@foo.org', projects_limit: 20 })
|
|
81
|
+
#
|
|
82
|
+
# @param [Integer] id The ID of a user.
|
|
83
|
+
# @param [Hash] options A customizable set of options.
|
|
84
|
+
# @option options [String] :email The email of a user.
|
|
85
|
+
# @option options [String] :password The password of a user.
|
|
86
|
+
# @option options [String] :name The name of a user. Defaults to email.
|
|
87
|
+
# @option options [String] :skype The skype of a user.
|
|
88
|
+
# @option options [String] :linkedin The linkedin of a user.
|
|
89
|
+
# @option options [String] :twitter The twitter of a user.
|
|
90
|
+
# @option options [Integer] :projects_limit The limit of projects for a user.
|
|
91
|
+
# @return [Gitlab::ObjectifiedHash] Information about created user.
|
|
92
|
+
def edit_user(user_id, options = {})
|
|
93
|
+
put("/users/#{user_id}", body: options)
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
# Deletes a user.
|
|
97
|
+
#
|
|
98
|
+
# @example
|
|
99
|
+
# Gitlab.delete_user(1)
|
|
100
|
+
#
|
|
101
|
+
# @param [Integer] id The ID of a user.
|
|
102
|
+
# @return [Gitlab::ObjectifiedHash] Information about deleted user.
|
|
103
|
+
def delete_user(user_id)
|
|
104
|
+
delete("/users/#{user_id}")
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
# Blocks the specified user. Available only for admin.
|
|
108
|
+
#
|
|
109
|
+
# @example
|
|
110
|
+
# Gitlab.block_user(15)
|
|
111
|
+
#
|
|
112
|
+
# @param [Integer] user_id The Id of user
|
|
113
|
+
# @return [Boolean] success or not
|
|
114
|
+
def block_user(user_id)
|
|
115
|
+
post("/users/#{user_id}/block")
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
# Unblocks the specified user. Available only for admin.
|
|
119
|
+
#
|
|
120
|
+
# @example
|
|
121
|
+
# Gitlab.unblock_user(15)
|
|
122
|
+
#
|
|
123
|
+
# @param [Integer] user_id The Id of user
|
|
124
|
+
# @return [Boolean] success or not
|
|
125
|
+
def unblock_user(user_id)
|
|
126
|
+
post("/users/#{user_id}/unblock")
|
|
127
|
+
end
|
|
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
|
+
|
|
162
|
+
# Creates a new user session.
|
|
163
|
+
#
|
|
164
|
+
# @example
|
|
165
|
+
# Gitlab.session('jack@example.com', 'secret12345')
|
|
166
|
+
#
|
|
167
|
+
# @param [String] email The email of a user.
|
|
168
|
+
# @param [String] password The password of a user.
|
|
169
|
+
# @return [Gitlab::ObjectifiedHash]
|
|
170
|
+
# @note This method doesn't require private_token to be set.
|
|
171
|
+
def session(email, password)
|
|
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)
|
|
187
|
+
end
|
|
188
|
+
|
|
189
|
+
# Gets a list of user's SSH keys.
|
|
190
|
+
#
|
|
191
|
+
# @example
|
|
192
|
+
# Gitlab.ssh_keys
|
|
193
|
+
# Gitlab.ssh_keys({ user_id: 2 })
|
|
194
|
+
#
|
|
195
|
+
# @param [Hash] options A customizable set of options.
|
|
196
|
+
# @option options [Integer] :page The page number.
|
|
197
|
+
# @option options [Integer] :per_page The number of results per page.
|
|
198
|
+
# @option options [Integer] :user_id The ID of the user to retrieve the keys for.
|
|
199
|
+
# @return [Array<Gitlab::ObjectifiedHash>]
|
|
200
|
+
def ssh_keys(options = {})
|
|
201
|
+
user_id = options.delete :user_id
|
|
202
|
+
if user_id.to_i.zero?
|
|
203
|
+
get('/user/keys', query: options)
|
|
204
|
+
else
|
|
205
|
+
get("/users/#{user_id}/keys", query: options)
|
|
206
|
+
end
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
# Gets information about SSH key.
|
|
210
|
+
#
|
|
211
|
+
# @example
|
|
212
|
+
# Gitlab.ssh_key(1)
|
|
213
|
+
#
|
|
214
|
+
# @param [Integer] id The ID of a user's SSH key.
|
|
215
|
+
# @return [Gitlab::ObjectifiedHash]
|
|
216
|
+
def ssh_key(id)
|
|
217
|
+
get("/user/keys/#{id}")
|
|
218
|
+
end
|
|
219
|
+
|
|
220
|
+
# Creates a new SSH key.
|
|
221
|
+
#
|
|
222
|
+
# @example
|
|
223
|
+
# Gitlab.create_ssh_key('key title', 'key body')
|
|
224
|
+
#
|
|
225
|
+
# @param [String] title The title of an SSH key.
|
|
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
|
|
229
|
+
# @return [Gitlab::ObjectifiedHash] Information about created SSH 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
|
|
237
|
+
end
|
|
238
|
+
|
|
239
|
+
# Deletes an SSH key.
|
|
240
|
+
#
|
|
241
|
+
# @example
|
|
242
|
+
# Gitlab.delete_ssh_key(1)
|
|
243
|
+
#
|
|
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
|
|
247
|
+
# @return [Gitlab::ObjectifiedHash] Information about deleted SSH key.
|
|
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
|
|
255
|
+
end
|
|
256
|
+
|
|
257
|
+
# Gets user emails.
|
|
258
|
+
# Will return emails an authorized user if no user ID passed.
|
|
259
|
+
#
|
|
260
|
+
# @example
|
|
261
|
+
# Gitlab.emails
|
|
262
|
+
# Gitlab.emails(2)
|
|
263
|
+
#
|
|
264
|
+
# @param [Integer] user_id The ID of a user.
|
|
265
|
+
# @return [Gitlab::ObjectifiedHash]
|
|
266
|
+
def emails(user_id = nil)
|
|
267
|
+
url = user_id.to_i.zero? ? '/user/emails' : "/users/#{user_id}/emails"
|
|
268
|
+
get(url)
|
|
269
|
+
end
|
|
270
|
+
|
|
271
|
+
# Get a single email.
|
|
272
|
+
#
|
|
273
|
+
# @example
|
|
274
|
+
# Gitlab.email(3)
|
|
275
|
+
#
|
|
276
|
+
# @param [Integer] id The ID of a email.
|
|
277
|
+
# @return [Gitlab::ObjectifiedHash]
|
|
278
|
+
def email(id)
|
|
279
|
+
get("/user/emails/#{id}")
|
|
280
|
+
end
|
|
281
|
+
|
|
282
|
+
# Creates a new email
|
|
283
|
+
# Will create a new email an authorized user if no user ID passed.
|
|
284
|
+
#
|
|
285
|
+
# @example
|
|
286
|
+
# Gitlab.add_email('email@example.com')
|
|
287
|
+
# Gitlab.add_email('email@example.com', 2)
|
|
288
|
+
#
|
|
289
|
+
# @param [String] email Email address
|
|
290
|
+
# @param [Integer] user_id The ID of a user.
|
|
291
|
+
# @param [Boolean] skip_confirmation Skip confirmation and assume e-mail is verified
|
|
292
|
+
# @return [Gitlab::ObjectifiedHash]
|
|
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
|
|
300
|
+
end
|
|
301
|
+
|
|
302
|
+
# Delete email
|
|
303
|
+
# Will delete a email an authorized user if no user ID passed.
|
|
304
|
+
#
|
|
305
|
+
# @example
|
|
306
|
+
# Gitlab.delete_email(2)
|
|
307
|
+
# Gitlab.delete_email(3, 2)
|
|
308
|
+
#
|
|
309
|
+
# @param [Integer] id Email address ID
|
|
310
|
+
# @param [Integer] user_id The ID of a user.
|
|
311
|
+
# @return [Boolean]
|
|
312
|
+
def delete_email(id, user_id = nil)
|
|
313
|
+
url = user_id.to_i.zero? ? "/user/emails/#{id}" : "/users/#{user_id}/emails/#{id}"
|
|
314
|
+
delete(url)
|
|
315
|
+
end
|
|
316
|
+
|
|
317
|
+
# Search for users by name
|
|
318
|
+
#
|
|
319
|
+
# @example
|
|
320
|
+
# Gitlab.user_search('gitlab')
|
|
321
|
+
#
|
|
322
|
+
# @param [String] search A string to search for in user names and paths.
|
|
323
|
+
# @param [Hash] options A customizable set of options.
|
|
324
|
+
# @option options [String] :per_page Number of user to return per page
|
|
325
|
+
# @option options [String] :page The page to retrieve
|
|
326
|
+
# @return [Array<Gitlab::ObjectifiedHash>]
|
|
327
|
+
def user_search(search, options = {})
|
|
328
|
+
options[:search] = search
|
|
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")
|
|
519
|
+
end
|
|
520
|
+
end
|
|
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
|