fs-gitlab 4.18.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +270 -0
  3. data/LICENSE.txt +24 -0
  4. data/README.md +260 -0
  5. data/exe/gitlab +11 -0
  6. data/lib/gitlab/api.rb +24 -0
  7. data/lib/gitlab/cli.rb +89 -0
  8. data/lib/gitlab/cli_helpers.rb +243 -0
  9. data/lib/gitlab/client/access_requests.rb +103 -0
  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 +137 -0
  13. data/lib/gitlab/client/boards.rb +146 -0
  14. data/lib/gitlab/client/branches.rb +135 -0
  15. data/lib/gitlab/client/broadcast_messages.rb +75 -0
  16. data/lib/gitlab/client/build_variables.rb +135 -0
  17. data/lib/gitlab/client/builds.rb +108 -0
  18. data/lib/gitlab/client/commits.rb +216 -0
  19. data/lib/gitlab/client/container_registry.rb +85 -0
  20. data/lib/gitlab/client/deployments.rb +34 -0
  21. data/lib/gitlab/client/environments.rb +89 -0
  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 +60 -0
  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 +94 -0
  30. data/lib/gitlab/client/groups.rb +358 -0
  31. data/lib/gitlab/client/issue_links.rb +48 -0
  32. data/lib/gitlab/client/issues.rb +231 -0
  33. data/lib/gitlab/client/jobs.rb +250 -0
  34. data/lib/gitlab/client/keys.rb +29 -0
  35. data/lib/gitlab/client/labels.rb +88 -0
  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 +265 -0
  39. data/lib/gitlab/client/merge_requests.rb +386 -0
  40. data/lib/gitlab/client/milestones.rb +106 -0
  41. data/lib/gitlab/client/namespaces.rb +22 -0
  42. data/lib/gitlab/client/notes.rb +313 -0
  43. data/lib/gitlab/client/packages.rb +95 -0
  44. data/lib/gitlab/client/pipeline_schedules.rb +147 -0
  45. data/lib/gitlab/client/pipeline_triggers.rb +103 -0
  46. data/lib/gitlab/client/pipelines.rb +105 -0
  47. data/lib/gitlab/client/project_badges.rb +85 -0
  48. data/lib/gitlab/client/project_clusters.rb +83 -0
  49. data/lib/gitlab/client/project_release_links.rb +76 -0
  50. data/lib/gitlab/client/project_releases.rb +79 -0
  51. data/lib/gitlab/client/projects.rb +708 -0
  52. data/lib/gitlab/client/protected_tags.rb +59 -0
  53. data/lib/gitlab/client/remote_mirrors.rb +51 -0
  54. data/lib/gitlab/client/repositories.rb +113 -0
  55. data/lib/gitlab/client/repository_files.rb +131 -0
  56. data/lib/gitlab/client/repository_submodules.rb +27 -0
  57. data/lib/gitlab/client/resource_label_events.rb +82 -0
  58. data/lib/gitlab/client/resource_state_events.rb +57 -0
  59. data/lib/gitlab/client/runners.rb +211 -0
  60. data/lib/gitlab/client/search.rb +66 -0
  61. data/lib/gitlab/client/services.rb +53 -0
  62. data/lib/gitlab/client/sidekiq.rb +39 -0
  63. data/lib/gitlab/client/snippets.rb +95 -0
  64. data/lib/gitlab/client/system_hooks.rb +64 -0
  65. data/lib/gitlab/client/tags.rb +97 -0
  66. data/lib/gitlab/client/templates.rb +100 -0
  67. data/lib/gitlab/client/todos.rb +46 -0
  68. data/lib/gitlab/client/user_snippets.rb +114 -0
  69. data/lib/gitlab/client/users.rb +397 -0
  70. data/lib/gitlab/client/versions.rb +18 -0
  71. data/lib/gitlab/client/wikis.rb +79 -0
  72. data/lib/gitlab/client.rb +95 -0
  73. data/lib/gitlab/configuration.rb +57 -0
  74. data/lib/gitlab/error.rb +170 -0
  75. data/lib/gitlab/file_response.rb +48 -0
  76. data/lib/gitlab/help.rb +94 -0
  77. data/lib/gitlab/objectified_hash.rb +51 -0
  78. data/lib/gitlab/page_links.rb +35 -0
  79. data/lib/gitlab/paginated_response.rb +110 -0
  80. data/lib/gitlab/request.rb +109 -0
  81. data/lib/gitlab/shell.rb +83 -0
  82. data/lib/gitlab/shell_history.rb +57 -0
  83. data/lib/gitlab/version.rb +5 -0
  84. data/lib/gitlab.rb +56 -0
  85. metadata +204 -0
@@ -0,0 +1,100 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Gitlab::Client
4
+ # Defines methods related to templates.
5
+ # @see https://docs.gitlab.com/ce/api/templates/dockerfiles.html
6
+ # @see https://docs.gitlab.com/ce/api/templates/gitignores.html
7
+ # @see https://docs.gitlab.com/ce/api/templates/gitlab_ci_ymls.html
8
+ # @see https://docs.gitlab.com/ce/api/templates/licenses.html
9
+ module Templates
10
+ # Get all Dockerfile templates.
11
+ #
12
+ # @example
13
+ # Gitlab.dockerfile_templates
14
+ #
15
+ # @return [Array<Gitlab::ObjectifiedHash>]
16
+ def dockerfile_templates
17
+ get('/templates/dockerfiles')
18
+ end
19
+
20
+ # Get a single Dockerfile template.
21
+ #
22
+ # @example
23
+ # Gitlab.dockerfile_template('Binary')
24
+ #
25
+ # @param [String] key The key of the Dockerfile template
26
+ # @return [Gitlab::ObjectifiedHash]
27
+ def dockerfile_template(key)
28
+ get("/templates/dockerfiles/#{key}")
29
+ end
30
+
31
+ # Get all gitignore templates.
32
+ #
33
+ # @example
34
+ # Gitlab.gitignore_templates
35
+ #
36
+ # @return [Array<Gitlab::ObjectifiedHash>]
37
+ def gitignore_templates
38
+ get('/templates/gitignores')
39
+ end
40
+
41
+ # Get a single gitignore template.
42
+ #
43
+ # @example
44
+ # Gitlab.gitignore_template('Ruby')
45
+ #
46
+ # @param [String] key The key of the gitignore template
47
+ # @return [Gitlab::ObjectifiedHash]
48
+ def gitignore_template(key)
49
+ get("/templates/gitignores/#{key}")
50
+ end
51
+
52
+ # Get all `gitlab_ci.yml` templates.
53
+ #
54
+ # @example
55
+ # Gitlab.gitlab_ci_yml_templates
56
+ #
57
+ # @return [Array<Gitlab::ObjectifiedHash>]
58
+ def gitlab_ci_yml_templates
59
+ get('/templates/gitlab_ci_ymls')
60
+ end
61
+
62
+ # Get a single `gitlab_ci.yml` template.
63
+ #
64
+ # @example
65
+ # Gitlab.gitlab_ci_yml_template('Ruby')
66
+ #
67
+ # @param [String] key The key of the gitlab_ci_yml template
68
+ # @return [Gitlab::ObjectifiedHash]
69
+ def gitlab_ci_yml_template(key)
70
+ get("/templates/gitlab_ci_ymls/#{key}")
71
+ end
72
+
73
+ # Get all license templates.
74
+ #
75
+ # @example
76
+ # Gitlab.license_templates
77
+ # Gitlab.license_templates(popular: true)
78
+ #
79
+ # @param [Hash] options A customizable set of options.
80
+ # @option options [Boolean] popular(optional) If passed, returns only popular licenses.
81
+ # @return [Array<Gitlab::ObjectifiedHash>]
82
+ def license_templates(options = {})
83
+ get('/templates/licenses', query: options)
84
+ end
85
+
86
+ # Get a single license template. You can pass parameters to replace the license placeholder.
87
+ #
88
+ # @example
89
+ # Gitlab.license_template('Ruby')
90
+ #
91
+ # @param [String] key The key of the license template
92
+ # @param [Hash] options A customizable set of options.
93
+ # @option options [String] project(optional) The copyrighted project name.
94
+ # @option options [String] fullname(optional) The full-name of the copyright holder
95
+ # @return [Gitlab::ObjectifiedHash]
96
+ def license_template(key, options = {})
97
+ get("/templates/licenses/#{key}", query: options)
98
+ end
99
+ end
100
+ end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Gitlab::Client
4
+ # Defines methods related to todos
5
+ # @see https://docs.gitlab.com/ce/api/todos.html
6
+ module Todos
7
+ # Gets a list of todos.
8
+ #
9
+ # @example
10
+ # Gitlab.todos
11
+ # Gitlab.todos({ action: 'assigned' })
12
+ # Gitlab.todos({ state: 'pending' })
13
+ #
14
+ # @param [Hash] options A customizable set of options.
15
+ # @option options [Integer] :action The action to be filtered. Can be `assigned`, `mentioned`, `build_failed`, `marked`, or `approval_required`.
16
+ # @option options [Integer] :author_id The ID of an author
17
+ # @option options [Integer] :project_id The ID of a project
18
+ # @option options [Integer] :state The state of the todo. Can be either `pending` or `done`
19
+ # @option options [Integer] :type The type of a todo. Can be either `Issue` or `MergeRequest`
20
+ # @return [Array<Gitlab::ObjectifiedHash>]
21
+ def todos(options = {})
22
+ get('/todos', query: options)
23
+ end
24
+
25
+ # Marks a single pending todo for the current user as done.
26
+ #
27
+ # @example
28
+ # Gitlab.mark_todo_as_done(42)
29
+ #
30
+ # @param [Integer] id The ID of the todo.
31
+ # @return [Gitlab::ObjectifiedHash]
32
+ def mark_todo_as_done(id)
33
+ post("/todos/#{id}/mark_as_done")
34
+ end
35
+
36
+ # Marks all todos for the current user as done
37
+ #
38
+ # @example
39
+ # Gitlab.mark_all_todos_as_done
40
+ #
41
+ # @return [void] This API call returns an empty response body.
42
+ def mark_all_todos_as_done
43
+ post('/todos/mark_as_done')
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,114 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Gitlab::Client
4
+ # Defines methods related to user snippets.
5
+ # @see https://docs.gitlab.com/ce/api/snippets.html
6
+ module UserSnippets
7
+ # Get a list of the snippets of the current user.
8
+ #
9
+ # @example
10
+ # Gitlab.user_snippets
11
+ #
12
+ # @return [Array<Gitlab::ObjectifiedHash>] List of snippets of current user
13
+ def user_snippets
14
+ get('/snippets')
15
+ end
16
+
17
+ # Get a single snippet.
18
+ #
19
+ # @example
20
+ # Gitlab.user_snippet(1)
21
+ #
22
+ # @param [Integer] id ID of snippet to retrieve.
23
+ # @return [Gitlab::ObjectifiedHash] Information about the user snippet
24
+ def user_snippet(id)
25
+ get("/snippets/#{id}")
26
+ end
27
+
28
+ # Get raw contents of a single snippet.
29
+ #
30
+ # @example
31
+ # Gitlab.user_snippet_raw(1)
32
+ #
33
+ # @param [Integer] id ID of snippet to retrieve.
34
+ # @return [String] User snippet text
35
+ def user_snippet_raw(id)
36
+ get("/snippets/#{id}/raw",
37
+ format: nil,
38
+ headers: { Accept: 'text/plain' },
39
+ parser: ::Gitlab::Request::Parser)
40
+ end
41
+
42
+ # Create a new snippet.
43
+ #
44
+ # @example
45
+ # Gitlab.create_user_snippet({ title: 'REST', file_name: 'api.rb', content: 'some code', description: 'Hello World snippet', visibility: 'public'})
46
+ #
47
+ # @param [Hash] options A customizable set of options.
48
+ # @option options [String] :title (required) Title of a snippet.
49
+ # @option options [String] :file_name (required) Name of a snippet file.
50
+ # @option options [String] :content (required) Content of a snippet.
51
+ # @option options [String] :description (optional) Description of a snippet.
52
+ # @option options [String] :visibility (optional) visibility of a snippet.
53
+ # @return [Gitlab::ObjectifiedHash] Information about created snippet.
54
+ def create_user_snippet(options = {})
55
+ post('/snippets', body: options)
56
+ end
57
+
58
+ # Update an existing snippet.
59
+ #
60
+ # @example
61
+ # Gitlab.edit_user_snippet(34, { file_name: 'README.txt' })
62
+ # Gitlab.edit_user_snippet(34, { file_name: 'README.txt', title: 'New title' })
63
+ #
64
+ # @param [Integer] id ID of snippet to update.
65
+ # @param [Hash] options A customizable set of options.
66
+ # @option options [String] :title (optional) Title of a snippet.
67
+ # @option options [String] :file_name (optional) Name of a snippet file.
68
+ # @option options [String] :content (optional) Content of a snippet.
69
+ # @option options [String] :description (optional) Description of a snippet.
70
+ # @option options [String] :visibility (optional) visibility of a snippet.
71
+ # @return [Gitlab::ObjectifiedHash] Information about updated snippet.
72
+ def edit_user_snippet(id, options = {})
73
+ put("/snippets/#{id}", body: options)
74
+ end
75
+
76
+ # Delete an existing snippet.
77
+ #
78
+ # @example
79
+ # Gitlab.delete_user_snippet(14)
80
+ #
81
+ # @param [Integer] id ID of snippet to delete.
82
+ # @return [void] This API call returns an empty response body.
83
+ def delete_user_snippet(id)
84
+ delete("/snippets/#{id}")
85
+ end
86
+
87
+ # List all public snippets.
88
+ #
89
+ # @example
90
+ # Gitlab.public_snippets
91
+ # Gitlab.public_snippets(per_page: 2, page: 1)
92
+ #
93
+ # @param [Hash] options A customizable set of options.
94
+ # @option options [String] :per_page (optional) Number of snippets to return per page.
95
+ # @option options [String] :page (optional) Page to retrieve.
96
+ #
97
+ # @return [Array<Gitlab::ObjectifiedHash>] List of all public snippets
98
+ def public_snippets(options = {})
99
+ get('/snippets/public', query: options)
100
+ end
101
+
102
+ # Get user agent details for a snippet.
103
+ #
104
+ # @example
105
+ # Gitlab.snippet_user_agent_details(1)
106
+ #
107
+ # @param [Integer] id ID of snippet to delete.
108
+ #
109
+ # @return [Array<Gitlab::ObjectifiedHash>] Details of the user agent
110
+ def snippet_user_agent_details(id)
111
+ get("/snippets/#{id}/user_agent_detail")
112
+ end
113
+ end
114
+ end
@@ -0,0 +1,397 @@
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
+ # Updates a user.
62
+ #
63
+ # @example
64
+ # Gitlab.edit_user(15, { email: 'joe.smith@foo.org', projects_limit: 20 })
65
+ #
66
+ # @param [Integer] id The ID of a user.
67
+ # @param [Hash] options A customizable set of options.
68
+ # @option options [String] :email The email of a user.
69
+ # @option options [String] :password The password of a user.
70
+ # @option options [String] :name The name of a user. Defaults to email.
71
+ # @option options [String] :skype The skype of a user.
72
+ # @option options [String] :linkedin The linkedin of a user.
73
+ # @option options [String] :twitter The twitter of a user.
74
+ # @option options [Integer] :projects_limit The limit of projects for a user.
75
+ # @return [Gitlab::ObjectifiedHash] Information about created user.
76
+ def edit_user(user_id, options = {})
77
+ put("/users/#{user_id}", body: options)
78
+ end
79
+
80
+ # Deletes a user.
81
+ #
82
+ # @example
83
+ # Gitlab.delete_user(1)
84
+ #
85
+ # @param [Integer] id The ID of a user.
86
+ # @return [Gitlab::ObjectifiedHash] Information about deleted user.
87
+ def delete_user(user_id)
88
+ delete("/users/#{user_id}")
89
+ end
90
+
91
+ # Blocks the specified user. Available only for admin.
92
+ #
93
+ # @example
94
+ # Gitlab.block_user(15)
95
+ #
96
+ # @param [Integer] user_id The Id of user
97
+ # @return [Boolean] success or not
98
+ def block_user(user_id)
99
+ post("/users/#{user_id}/block")
100
+ end
101
+
102
+ # Unblocks the specified user. Available only for admin.
103
+ #
104
+ # @example
105
+ # Gitlab.unblock_user(15)
106
+ #
107
+ # @param [Integer] user_id The Id of user
108
+ # @return [Boolean] success or not
109
+ def unblock_user(user_id)
110
+ post("/users/#{user_id}/unblock")
111
+ end
112
+
113
+ # Approves the specified user. Available only for admin.
114
+ #
115
+ # @example
116
+ # Gitlab.approve_user(15)
117
+ #
118
+ # @param [Integer] user_id The Id of user
119
+ # @return [Boolean] success or not
120
+ def approve_user(user_id)
121
+ post("/users/#{user_id}/approve")
122
+ end
123
+
124
+ # Creates a new user session.
125
+ #
126
+ # @example
127
+ # Gitlab.session('jack@example.com', 'secret12345')
128
+ #
129
+ # @param [String] email The email of a user.
130
+ # @param [String] password The password of a user.
131
+ # @return [Gitlab::ObjectifiedHash]
132
+ # @note This method doesn't require private_token to be set.
133
+ def session(email, password)
134
+ post('/session', body: { email: email, password: password }, unauthenticated: true)
135
+ end
136
+
137
+ # Gets a list of user activities (for admin access only).
138
+ #
139
+ # @example
140
+ # Gitlab.activities
141
+ #
142
+ # @param [Hash] options A customizable set of options.
143
+ # @option options [Integer] :page The page number.
144
+ # @option options [Integer] :per_page The number of results per page.
145
+ # @option options [String] :from The start date for paginated results.
146
+ # @return [Array<Gitlab::ObjectifiedHash>]
147
+ def activities(options = {})
148
+ get('/user/activities', query: options)
149
+ end
150
+
151
+ # Gets a list of user's SSH keys.
152
+ #
153
+ # @example
154
+ # Gitlab.ssh_keys
155
+ # Gitlab.ssh_keys({ user_id: 2 })
156
+ #
157
+ # @param [Hash] options A customizable set of options.
158
+ # @option options [Integer] :page The page number.
159
+ # @option options [Integer] :per_page The number of results per page.
160
+ # @option options [Integer] :user_id The ID of the user to retrieve the keys for.
161
+ # @return [Array<Gitlab::ObjectifiedHash>]
162
+ def ssh_keys(options = {})
163
+ user_id = options.delete :user_id
164
+ if user_id.to_i.zero?
165
+ get('/user/keys', query: options)
166
+ else
167
+ get("/users/#{user_id}/keys", query: options)
168
+ end
169
+ end
170
+
171
+ # Gets information about SSH key.
172
+ #
173
+ # @example
174
+ # Gitlab.ssh_key(1)
175
+ #
176
+ # @param [Integer] id The ID of a user's SSH key.
177
+ # @return [Gitlab::ObjectifiedHash]
178
+ def ssh_key(id)
179
+ get("/user/keys/#{id}")
180
+ end
181
+
182
+ # Creates a new SSH key.
183
+ #
184
+ # @example
185
+ # Gitlab.create_ssh_key('key title', 'key body')
186
+ #
187
+ # @param [String] title The title of an SSH key.
188
+ # @param [String] key The SSH key body.
189
+ # @param [Hash] options A customizable set of options.
190
+ # @option options [Integer] :user_id id of the user to associate the key with
191
+ # @return [Gitlab::ObjectifiedHash] Information about created SSH key.
192
+ def create_ssh_key(title, key, options = {})
193
+ user_id = options.delete :user_id
194
+ if user_id.to_i.zero?
195
+ post('/user/keys', body: { title: title, key: key })
196
+ else
197
+ post("/users/#{user_id}/keys", body: { title: title, key: key })
198
+ end
199
+ end
200
+
201
+ # Deletes an SSH key.
202
+ #
203
+ # @example
204
+ # Gitlab.delete_ssh_key(1)
205
+ #
206
+ # @param [Integer] id The ID of a user's SSH key.
207
+ # @param [Hash] options A customizable set of options.
208
+ # @option options [Integer] :user_id id of the user to associate the key with
209
+ # @return [Gitlab::ObjectifiedHash] Information about deleted SSH key.
210
+ def delete_ssh_key(id, options = {})
211
+ user_id = options.delete :user_id
212
+ if user_id.to_i.zero?
213
+ delete("/user/keys/#{id}")
214
+ else
215
+ delete("/users/#{user_id}/keys/#{id}")
216
+ end
217
+ end
218
+
219
+ # Gets user emails.
220
+ # Will return emails an authorized user if no user ID passed.
221
+ #
222
+ # @example
223
+ # Gitlab.emails
224
+ # Gitlab.emails(2)
225
+ #
226
+ # @param [Integer] user_id The ID of a user.
227
+ # @return [Gitlab::ObjectifiedHash]
228
+ def emails(user_id = nil)
229
+ url = user_id.to_i.zero? ? '/user/emails' : "/users/#{user_id}/emails"
230
+ get(url)
231
+ end
232
+
233
+ # Get a single email.
234
+ #
235
+ # @example
236
+ # Gitlab.email(3)
237
+ #
238
+ # @param [Integer] id The ID of a email.
239
+ # @return [Gitlab::ObjectifiedHash]
240
+ def email(id)
241
+ get("/user/emails/#{id}")
242
+ end
243
+
244
+ # Creates a new email
245
+ # Will create a new email an authorized user if no user ID passed.
246
+ #
247
+ # @example
248
+ # Gitlab.add_email('email@example.com')
249
+ # Gitlab.add_email('email@example.com', 2)
250
+ #
251
+ # @param [String] email Email address
252
+ # @param [Integer] user_id The ID of a user.
253
+ # @param [Boolean] skip_confirmation Skip confirmation and assume e-mail is verified
254
+ # @return [Gitlab::ObjectifiedHash]
255
+ def add_email(email, user_id = nil, skip_confirmation = nil)
256
+ url = user_id.to_i.zero? ? '/user/emails' : "/users/#{user_id}/emails"
257
+ if skip_confirmation.nil?
258
+ post(url, body: { email: email })
259
+ else
260
+ post(url, body: { email: email, skip_confirmation: skip_confirmation })
261
+ end
262
+ end
263
+
264
+ # Delete email
265
+ # Will delete a email an authorized user if no user ID passed.
266
+ #
267
+ # @example
268
+ # Gitlab.delete_email(2)
269
+ # Gitlab.delete_email(3, 2)
270
+ #
271
+ # @param [Integer] id Email address ID
272
+ # @param [Integer] user_id The ID of a user.
273
+ # @return [Boolean]
274
+ def delete_email(id, user_id = nil)
275
+ url = user_id.to_i.zero? ? "/user/emails/#{id}" : "/users/#{user_id}/emails/#{id}"
276
+ delete(url)
277
+ end
278
+
279
+ # Search for groups by name
280
+ #
281
+ # @example
282
+ # Gitlab.user_search('gitlab')
283
+ #
284
+ # @param [String] search A string to search for in user names and paths.
285
+ # @param [Hash] options A customizable set of options.
286
+ # @option options [String] :per_page Number of user to return per page
287
+ # @option options [String] :page The page to retrieve
288
+ # @return [Array<Gitlab::ObjectifiedHash>]
289
+ def user_search(search, options = {})
290
+ options[:search] = search
291
+ get('/users', query: options)
292
+ end
293
+
294
+ # Gets user custom_attributes.
295
+ #
296
+ # @example
297
+ # Gitlab.user_custom_attributes(2)
298
+ #
299
+ # @param [Integer] user_id The ID of a user.
300
+ # @return [Gitlab::ObjectifiedHash]
301
+ def user_custom_attributes(user_id)
302
+ get("/users/#{user_id}/custom_attributes")
303
+ end
304
+
305
+ # Gets single user custom_attribute.
306
+ #
307
+ # @example
308
+ # Gitlab.user_custom_attribute(key, 2)
309
+ #
310
+ # @param [String] key The custom_attributes key
311
+ # @param [Integer] user_id The ID of a user.
312
+ # @return [Gitlab::ObjectifiedHash]
313
+ def user_custom_attribute(key, user_id)
314
+ get("/users/#{user_id}/custom_attributes/#{key}")
315
+ end
316
+
317
+ # Creates a new custom_attribute
318
+ #
319
+ # @example
320
+ # Gitlab.add_custom_attribute('some_new_key', 'some_new_value', 2)
321
+ #
322
+ # @param [String] key The custom_attributes key
323
+ # @param [String] value The custom_attributes value
324
+ # @param [Integer] user_id The ID of a user.
325
+ # @return [Gitlab::ObjectifiedHash]
326
+ def add_user_custom_attribute(key, value, user_id)
327
+ url = "/users/#{user_id}/custom_attributes/#{key}"
328
+ put(url, body: { value: value })
329
+ end
330
+
331
+ # Delete custom_attribute
332
+ # Will delete a custom_attribute
333
+ #
334
+ # @example
335
+ # Gitlab.delete_user_custom_attribute('somekey', 2)
336
+ #
337
+ # @param [String] key The custom_attribute key to delete
338
+ # @param [Integer] user_id The ID of a user.
339
+ # @return [Boolean]
340
+ def delete_user_custom_attribute(key, user_id)
341
+ delete("/users/#{user_id}/custom_attributes/#{key}")
342
+ end
343
+
344
+ # Get all impersonation tokens for a user
345
+ #
346
+ # @example
347
+ # Gitlab.user_impersonation_tokens(1)
348
+ #
349
+ # @param [Integer] user_id The ID of the user.
350
+ # @param [String] state Filter impersonation tokens by state {}
351
+ # @return [Array<Gitlab::ObjectifiedHash>]
352
+ def user_impersonation_tokens(user_id)
353
+ get("/users/#{user_id}/impersonation_tokens")
354
+ end
355
+
356
+ # Get impersonation token information
357
+ #
358
+ # @example
359
+ # Gitlab.user_impersonation_token(1, 1)
360
+ #
361
+ # @param [Integer] user_id The ID of the user.
362
+ # @param [Integer] impersonation_token_id ID of the impersonation token.
363
+ # @return [Gitlab::ObjectifiedHash]
364
+ def user_impersonation_token(user_id, impersonation_token_id)
365
+ get("/users/#{user_id}/impersonation_tokens/#{impersonation_token_id}")
366
+ end
367
+
368
+ # Create impersonation token
369
+ #
370
+ # @example
371
+ # Gitlab.create_user_impersonation_token(2, "token", ["api", "read_user"])
372
+ # Gitlab.create_user_impersonation_token(2, "token", ["api", "read_user"], "1970-01-01")
373
+ #
374
+ # @param [Integer] user_id The ID of the user.
375
+ # @param [String] name Name for impersonation token.
376
+ # @param [Array<String>] scopes Array of scopes for the impersonation token
377
+ # @param [String] expires_at Date for impersonation token expiration in ISO format.
378
+ # @return [Gitlab::ObjectifiedHash]
379
+ def create_user_impersonation_token(user_id, name, scopes, expires_at = nil)
380
+ body = { name: name, scopes: scopes }
381
+ body[:expires_at] = expires_at if expires_at
382
+ post("/users/#{user_id}/impersonation_tokens", body: body)
383
+ end
384
+
385
+ # Revoke an impersonation token
386
+ #
387
+ # @example
388
+ # Gitlab.revoke_user_impersonation_token(1, 1)
389
+ #
390
+ # @param [Integer] user_id The ID of the user.
391
+ # @param [Integer] impersonation_token_id ID of the impersonation token.
392
+ # @return [Gitlab::ObjectifiedHash]
393
+ def revoke_user_impersonation_token(user_id, impersonation_token_id)
394
+ delete("/users/#{user_id}/impersonation_tokens/#{impersonation_token_id}")
395
+ end
396
+ end
397
+ 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