This repository has been archived by the owner on Sep 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Get-GitLabGroup.ps1
98 lines (85 loc) · 3.43 KB
/
Get-GitLabGroup.ps1
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
function Get-GitLabGroup {
<#
.SYNOPSIS
Gets Gitlab groups.
.DESCRIPTION
The Get-GitLabGroup function returns one or more projects specified.
By default this function returns all groups.
By passing -Accessable or -Owned only accessable or owned groups are retrieved.
By passing -OnlyRoot only top level groups are returned.
if you have the ID of a group you can specify the group ID by passing -GroupId.
.EXAMPLE
Get-GitLabGroup
---------------------------------------------------------------
Returns all groups that are available.
.EXAMPLE
Get-GitLabGroup -GroupID 20
---------------------------------------------------------------
Return Group with ID 20
#>
[CmdletBinding(DefaultparametersetName = 'AllGroups')]
[Alias()]
[OutputType()]
Param (
# Search for a project.
[Parameter(ParameterSetName = 'AllGroups',
HelpMessage = 'Search for a group.',
Mandatory = $false)]
[string]$Search,
# Limit the result by Owned status
[Parameter(ParameterSetName = 'AllGroups',
HelpMessage = 'limit by accessability; defautls to $false for admins, $true for other users',
Mandatory = $false)]
[switch]$Accessable,
# Limit the result by Owned status
[Parameter(ParameterSetName = 'AllGroups',
HelpMessage = 'limit by owned status',
Mandatory = $false)]
[switch]$Owned,
# Limit the result to root groups
[Parameter(ParameterSetName = 'AllGroups',
HelpMessage = 'limit to root level groups',
Mandatory = $false)]
[switch]$OnlyRoot,
# Limit the result to root groups
[Parameter(ParameterSetName = 'AllGroups',
HelpMessage = 'also list detailed group information as if querying a single group (slower)',
Mandatory = $false)]
[switch]$Details = $false,
# The ID of the project
[Parameter(ParameterSetName = 'SingleGroup',
HelpMessage = 'The ID of a group',
Mandatory = $true)]
[Alias('ID')]
[String]$GroupId,
# Existing GitlabConnector Object, can be retrieved with Get-GitlabConnect
[Parameter(HelpMessage = 'Specify Existing GitlabConnector',
Mandatory = $false,
DontShow = $true)]
[psobject]$GitlabConnect = (Get-GitlabConnect)
)
$httpmethod = 'get'
$apiurl = 'groups'
$parameters = @{}
if($PSCmdlet.ParameterSetName -like 'AllGroups*') {
if($PSCmdlet.MyInvocation.BoundParameters.keys -contains 'Accessable'){
$parameters.all_available = "$(-not $accessable)".ToLower()
}
if($PSCmdlet.MyInvocation.BoundParameters.keys -contains 'Owned'){
$parameters.visibility = "$Owned".ToLower();
}
if($PSCmdlet.MyInvocation.BoundParameters.keys -contains 'Search'){
$parameters.search=$search
}
}
if($PSCmdlet.ParameterSetName -like 'SingleGroup*')
{
$apiurl += "/$([System.Web.HttpUtility]::UrlEncode($groupId))"
}
if ($details) {
$GitlabConnect.callapi($apiurl,$httpmethod,$parameters) `
| %{ Get-GitLabGroup -GroupId $_.id }
} else {
$GitlabConnect.callapi($apiurl,$httpmethod,$parameters)
}
}