1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507
|
# frozen_string_literal: true
class Gitlab::Client
# Defines methods related to groups.
# @see https://docs.gitlab.com/ce/api/groups.html
module Groups
# Gets a list of groups.
#
# @example
# Gitlab.groups
# Gitlab.groups({ per_page: 40, page: 2 })
#
# @param [Hash] options A customizable set of options.
# @option options [Integer] :page The page number.
# @option options [Integer] :per_page The number of results per page.
# @return [Array<Gitlab::ObjectifiedHash>]
def groups(options = {})
get('/groups', query: options)
end
# Gets a single group.
#
# @example
# Gitlab.group(42)
#
# @param [Integer] id The ID of a group.
# @param [Hash] options A customizable set of options.
# @option options [Boolean] :with_custom_attributes Include custom attributes in response (admins only)
# @option options [Boolean] :with_projects Include details about group projects (default: true)
# @return [Gitlab::ObjectifiedHash]
def group(id, options = {})
get("/groups/#{url_encode id}", query: options)
end
# Creates a new group.
#
# @example
# Gitlab.create_group('new-group', 'group-path')
# Gitlab.create_group('gitlab', 'gitlab-path', { description: 'New Gitlab project' })
#
# @param [String] name The name of a group.
# @param [String] path The path of a group.
# @return [Gitlab::ObjectifiedHash] Information about created group.
def create_group(name, path, options = {})
body = { name: name, path: path }.merge(options)
post('/groups', body: body)
end
# Delete's a group.
#
# @example
# Gitlab.delete_group(42)
# @param [Integer] id The ID of a group
# @return [Gitlab::ObjectifiedHash] Information about the deleted group.
def delete_group(id)
delete("/groups/#{url_encode id}")
end
# Get a list of group members.
#
# @example
# Gitlab.group_members(1)
# Gitlab.group_members(1, { per_page: 40 })
#
# @param [Integer] id The ID of a group.
# @param [Hash] options A customizable set of options.
# @option options [Integer] :page The page number.
# @option options [Integer] :per_page The number of results per page.
# @return [Array<Gitlab::ObjectifiedHash>]
def group_members(id, options = {})
get("/groups/#{url_encode id}/members", query: options)
end
# Gets a list of all group members including inherited members.
#
# @example
# Gitlab.all_group_members(1)
# Gitlab.all_group_members(1, { per_page: 40 })
#
# @param [Integer] id The ID of a group.
# @param [Hash] options A customizable set of options.
# @option options [Integer] :page The page number.
# @option options [Integer] :per_page The number of results per page.
# @return [Array<Gitlab::ObjectifiedHash>]
def all_group_members(id, options = {})
get("/groups/#{url_encode id}/members/all", query: options)
end
# Get a list of descendant groups of a group.
#
# @example
# Gitlab.group_descendants(42)
#
# @param [Integer] id the ID of a group
# @param [Hash] options A customizable set of options.
# @option options [String] :skip_groups Skip the group IDs passed.
# @option options [String] :all_available Show all the groups you have access to (defaults to false for authenticated users).
# @option options [String] :search Return the list of authorized groups matching the search criteria.
# @option options [String] :order_by Order groups by name or path. Default is name.
# @option options [String] :sort Order groups in asc or desc order. Default is asc.
# @option options [String] :statistics Include group statistics (admins only).
# @option options [String] :owned Limit to groups owned by the current user.
# @return [Array<Gitlab::ObjectifiedHash>] List of all subgroups under a group
def group_descendants(id, options = {})
get("/groups/#{url_encode id}/descendant_groups", query: options)
end
# Get a list of group members that are billable.
#
# @example
# Gitlab.group_billable_members(1)
# Gitlab.group_billable_members(1, { per_page: 40 })
#
# @param [Integer] id The ID of a group.
# @param [Hash] options A customizable set of options.
# @option options [Integer] :page The page number.
# @option options [Integer] :per_page The number of results per page.
# @return [Array<Gitlab::ObjectifiedHash>]
def group_billable_members(id, options = {})
get("/groups/#{url_encode id}/billable_members", query: options)
end
# Get details of a single group member.
#
# @example
# Gitlab.group_member(1, 10)
#
# @param [Integer] team_id The ID of the group to find a member in.
# @param [Integer] user_id The user id of the member to find.
# @return [Gitlab::ObjectifiedHash] (id, username, name, email, state, access_level ...)
def group_member(team_id, user_id)
get("/groups/#{url_encode team_id}/members/#{user_id}")
end
# Gets a list of merge requests of a group.
#
# @example
# Gitlab.group_merge_requests(5)
#
# @param [Integer, String] group_id The ID or name of a group.
# @param [Hash] options A customizable set of options.
# @return [Array<Gitlab::ObjectifiedHash>]
def group_merge_requests(group, options = {})
get("/groups/#{group}/merge_requests", query: options)
end
# Adds a user to group.
#
# @example
# Gitlab.add_group_member(1, 2, 40)
#
# @param [Integer] team_id The group id to add a member to.
# @param [Integer] user_id The user id of the user to add to the team.
# @param [Integer] access_level Project access level.
# @return [Gitlab::ObjectifiedHash] Information about added team member.
def add_group_member(team_id, user_id, access_level)
post("/groups/#{url_encode team_id}/members", body: { user_id: user_id, access_level: access_level })
end
# Edit a user of a group.
#
# @example
# Gitlab.edit_group_member(1, 2, 40)
#
# @param [Integer] team_id The group id of member to edit.
# @param [Integer] user_id The user id of the user to edit.
# @param [Integer] access_level Project access level.
# @return [Gitlab::ObjectifiedHash] Information about edited team member.
def edit_group_member(team_id, user_id, access_level)
put("/groups/#{url_encode team_id}/members/#{user_id}", body: { access_level: access_level })
end
# Removes user from user group.
#
# @example
# Gitlab.remove_group_member(1, 2)
#
# @param [Integer] team_id The group ID.
# @param [Integer] user_id The ID of a user.
# @return [Gitlab::ObjectifiedHash] Information about removed team member.
def remove_group_member(team_id, user_id)
delete("/groups/#{url_encode team_id}/members/#{user_id}")
end
# Transfers a project to a group
#
# @example
# Gitlab.transfer_project_to_group(3, 50)
#
# @param [Integer] id The ID of a group.
# @param [Integer] project_id The ID of a project.
def transfer_project_to_group(id, project_id)
body = { id: id, project_id: project_id }
post("/groups/#{url_encode id}/projects/#{project_id}", body: body)
end
# Search for groups by name
#
# @example
# Gitlab.group_search('gitlab')
#
# @param [String] search A string to search for in group names and paths.
# @param [Hash] options A customizable set of options.
# @option options [String] :per_page Number of projects to return per page
# @option options [String] :page The page to retrieve
# @return [Array<Gitlab::ObjectifiedHash>]
def group_search(search, options = {})
options[:search] = search
get('/groups', query: options)
end
# Get a list of projects under a group
# @example
# Gitlab.group_projects(1)
#
# @param [Integer] id The ID of a group
# @return [Array<Gitlab::ObjectifiedHash>] List of projects under a group
def group_projects(id, options = {})
get("/groups/#{url_encode id}/projects", query: options)
end
# Get a list of subgroups under a group
# @example
# Gitlab.group_subgroups(1)
#
# @param [Integer] id the ID of a group
# @param [Hash] options A customizable set of options.
# @option options [String] :skip_groups Skip the group IDs passed.
# @option options [String] :all_available Show all the groups you have access to (defaults to false for authenticated users).
# @option options [String] :search Return the list of authorized groups matching the search criteria.
# @option options [String] :order_by Order groups by name or path. Default is name.
# @option options [String] :sort Order groups in asc or desc order. Default is asc.
# @option options [String] :statistics Include group statistics (admins only).
# @option options [String] :owned Limit to groups owned by the current user.
# @return [Array<Gitlab::ObjectifiedHash>] List of subgroups under a group
def group_subgroups(id, options = {})
get("/groups/#{url_encode id}/subgroups", query: options)
end
# Updates an existing group.
#
# @example
# Gitlab.edit_group(42)
# Gitlab.edit_group(42, { name: 'Group Name' })
#
# @param [Integer] group The ID.
# @param [Hash] options A customizable set of options
# @option options [String] :name The name of the group.
# @option options [String] :path The path of the group.
# @option options [String] :description The description of the group.
# @option options [String] :visibility The visibility level of the group. Can be private, internal, or public
# @option options [String] :lfs_enabled Enable/disable Large File Storage (LFS) for the projects in this groupr.
# @option options [String] :request_access_enabled Allow users to request member access.
# @return [Gitlab::ObjectifiedHash] Information about the edited group.
def edit_group(id, options = {})
put("/groups/#{url_encode id}", body: options)
end
# Gets a list of issues of a group.
#
# @example
# Gitlab.group_issues(5)
#
# @param [Integer, String] group_id The ID or name of a group.
# @param [Hash] options A customizable set of options.
# @return [Array<Gitlab::ObjectifiedHash>]
def group_issues(group, options = {})
get("/groups/#{group}/issues", query: options)
end
# Sync group with LDAP
#
# @example
# Gitlab.sync_ldap_group(1)
#
# @param [Integer] id The ID or name of a group.
# @return [Array<Gitlab::ObjectifiedHash>]
def sync_ldap_group(id)
post("/groups/#{url_encode id}/ldap_sync")
end
# Add LDAP group link
#
# @example
# Gitlab.add_ldap_group_links(1, 'all', 50, 'ldap')
#
# @param [Integer] id The ID of a group
# @param [String] cn The CN of a LDAP group
# @param [Integer] group_access Minimum access level for members of the LDAP group.
# @param [String] provider LDAP provider for the LDAP group
# @return [Gitlab::ObjectifiedHash] Information about added ldap group link
def add_ldap_group_links(id, commonname, group_access, provider)
post("/groups/#{url_encode id}/ldap_group_links", body: { cn: commonname, group_access: group_access, provider: provider })
end
# Delete LDAP group link
#
# @example
# Gitlab.delete_ldap_group_links(1, 'all')
#
# @param [Integer] id The ID of a group
# @param [String] cn The CN of a LDAP group
# @return [Gitlab::ObjectifiedHash] Empty hash
def delete_ldap_group_links(id, commonname, provider)
delete("/groups/#{url_encode id}/ldap_group_links/#{url_encode provider}/#{url_encode commonname}")
end
# Gets group custom_attributes.
#
# @example
# Gitlab.group_custom_attributes(2)
#
# @param [Integer] group_id The ID of a group.
# @return [Gitlab::ObjectifiedHash]
def group_custom_attributes(group_id)
get("/groups/#{group_id}/custom_attributes")
end
# Gets single group custom_attribute.
#
# @example
# Gitlab.group_custom_attribute('key', 2)
#
# @param [String] key The custom_attributes key
# @param [Integer] group_id The ID of a group.
# @return [Gitlab::ObjectifiedHash]
def group_custom_attribute(key, group_id)
get("/groups/#{group_id}/custom_attributes/#{key}")
end
# Creates a new custom_attribute
#
# @example
# Gitlab.add_custom_attribute('some_new_key', 'some_new_value', 2)
#
# @param [String] key The custom_attributes key
# @param [String] value The custom_attributes value
# @param [Integer] group_id The ID of a group.
# @return [Gitlab::ObjectifiedHash]
def add_group_custom_attribute(key, value, group_id)
url = "/groups/#{group_id}/custom_attributes/#{key}"
put(url, body: { value: value })
end
# Delete custom_attribute
# Will delete a custom_attribute
#
# @example
# Gitlab.delete_group_custom_attribute('somekey', 2)
#
# @param [String] key The custom_attribute key to delete
# @param [Integer] group_id The ID of a group.
# @return [Boolean]
def delete_group_custom_attribute(key, group_id = nil)
delete("/groups/#{group_id}/custom_attributes/#{key}")
end
# List all the specified groups hooks
#
# @example
# Gitlab.list_group_hooks(3)
#
# @param [Integer] group_id The ID of a group.
# @return [Gitlab::PaginatedResponse] List of registered hooks https://docs.gitlab.com/ee/api/groups.html#hooks
def list_group_hooks(group_id)
get("/groups/#{group_id}/hooks")
end
# get specified group hook
#
# @example
# Gitlab.group_hook(3, 1)
#
# @param [Integer] group_id The ID of a group.
# @param [Integer] hook_id The ID of the hook.
# @return [Gitlab::ObjectifiedHash] The hook https://docs.gitlab.com/ee/api/groups.html#get-group-hook
def group_hook(group_id, hook_id)
get("/groups/#{group_id}/hooks/#{hook_id}")
end
# Add a new group hook
#
# @example
# Gitlab.add_group_hook(3, "https://example.com/my-hook-receiver", {token: "verify me"})
#
# @param [Integer] group_id The ID of a group.
# @param [String] the hook url which will receive the selected events
# @option options [Boolean] :name The name of the group.
# @option options [Boolean] :push_events Trigger hook on push events
# @potion options [String] :push_events_branch_filter Trigger hook on push events for matching branches only.
# @option options [Boolean] :issues_events Trigger hook on issues events
# @option options [Boolean] :confidential_issues_events Trigger hook on confidential issues events
# @option options [Boolean] :merge_requests_events Trigger hook on merge requests events
# @option options [Boolean] :tag_push_events Trigger hook on tag push events
# @option options [Boolean] :note_events Trigger hook on note events
# @option options [Boolean] :confidential_note_events Trigger hook on confidential note events
# @option options [Boolean] :job_events Trigger hook on job events
# @option options [Boolean] :pipeline_events Trigger hook on pipeline events
# @option options [Boolean] :wiki_page_events Trigger hook on wiki page events
# @option options [Boolean] :deployment_events Trigger hook on deployment events
# @option options [Boolean] :releases_events Trigger hook on release events
# @option options [Boolean] :subgroup_events Trigger hook on subgroup events
# @option options [Boolean] :enable_ssl_verification Do SSL verification when triggering the hook
# @option options [String] :token Secret token to validate received payloads; not returned in the response
# @return [Gitlab::ObjectifiedHash] Response body matches https://docs.gitlab.com/ee/api/groups.html#get-group-hook
def add_group_hook(group_id, url, options = {})
post("/groups/#{group_id}/hooks", body: options.merge(url: url))
end
# Edit a group hook
#
# @example
# Gitlab.edit_group_hook(3, 1, "https://example.com/my-hook-receiver", {token: "verify me"})
#
# @param [Integer] group_id The ID of a group.
# @param [Integer] hook_id The ID of a group.
# @param [String] the hook url which will receive the selected events
# @option options [Boolean] :name The name of the group.
# @option options [Boolean] :push_events Trigger hook on push events
# @potion options [String] :push_events_branch_filter Trigger hook on push events for matching branches only.
# @option options [Boolean] :issues_events Trigger hook on issues events
# @option options [Boolean] :confidential_issues_events Trigger hook on confidential issues events
# @option options [Boolean] :merge_requests_events Trigger hook on merge requests events
# @option options [Boolean] :tag_push_events Trigger hook on tag push events
# @option options [Boolean] :note_events Trigger hook on note events
# @option options [Boolean] :confidential_note_events Trigger hook on confidential note events
# @option options [Boolean] :job_events Trigger hook on job events
# @option options [Boolean] :pipeline_events Trigger hook on pipeline events
# @option options [Boolean] :wiki_page_events Trigger hook on wiki page events
# @option options [Boolean] :deployment_events Trigger hook on deployment events
# @option options [Boolean] :releases_events Trigger hook on release events
# @option options [Boolean] :subgroup_events Trigger hook on subgroup events
# @option options [Boolean] :enable_ssl_verification Do SSL verification when triggering the hook
# @option options [String] :token Secret token to validate received payloads; not returned in the response
# @return [Gitlab::ObjectifiedHash] Response body matches https://docs.gitlab.com/ee/api/groups.html#edit-group-hook
def edit_group_hook(group_id, hook_id, url, options = {})
post("/groups/#{group_id}/hooks/#{hook_id}", body: options.merge(url: url))
end
# Delete a group hook
#
# @example
# Gitlab.delete_group_hook(3, 1)
#
# @param [Integer] group_id The ID of a group.
# @param [Integer] hook_id The ID of a group.
# @return [Gitlab::ObjectifiedHash] no body, will evaluate to an empty hash. https://docs.gitlab.com/ee/api/groups.html#delete-group-hook
def delete_group_hook(group_id, hook_id)
delete("/groups/#{group_id}/hooks/#{hook_id}")
end
end
# Get all access tokens for a group
#
# @example
# Gitlab.group_access_tokens(1)
#
# @param [Integer] group_id The ID of the group.
# @return [Array<Gitlab::ObjectifiedHash>]
def group_access_tokens(group_id)
get("/groups/#{group_id}/access_tokens")
end
# Get group access token information
#
# @example
# Gitlab.group_access_token(1, 1)
#
# @param [Integer] group_id The ID of the group.
# @param [Integer] group_access_token_id ID of the group access token.
# @return [Gitlab::ObjectifiedHash]
def group_access_token(group_id, group_access_token_id)
get("/groups/#{group_id}/access_tokens/#{group_access_token_id}")
end
# Create group access token
#
# @example
# Gitlab.create_group_access_token(2, "token", ["api", "read_user"])
# Gitlab.create_group_access_token(2, "token", ["api", "read_user"], 20)
# Gitlab.create_group_access_token(2, "token", ["api", "read_user"], 20, "1970-01-01")
#
# @param [Integer] group_id The ID of the group.
# @param [String] name Name for group access token.
# @param [Array<String>] scopes Array of scopes for the group access token
# @param [Integer] access_level Project access level (10: Guest, 20: Reporter, 30: Developer, 40: Maintainer, 50: Owner).
# @param [String] expires_at Date for group access token expiration in ISO format.
# @return [Gitlab::ObjectifiedHash]
def create_group_access_token(group_id, name, scopes, access_level = nil, expires_at = nil)
body = { name: name, scopes: scopes }
body[:access_level] = access_level if access_level
body[:expires_at] = expires_at if expires_at
post("/groups/#{group_id}/access_tokens", body: body)
end
# Revoke a group access token
#
# @example
# Gitlab.revoke_group_access_token(1, 1)
#
# @param [Integer] user_id The ID of the group.
# @param [Integer] group_access_token_id ID of the group access token.
# @return [Gitlab::ObjectifiedHash]
def revoke_group_access_token(group_id, group_access_token_id)
delete("/groups/#{group_id}/access_tokens/#{group_access_token_id}")
end
end
|