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
/
Copy pathGet-GitLabProject.ps1
127 lines (116 loc) · 4.33 KB
/
Get-GitLabProject.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
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
function Get-GitLabProject
{
<#
.SYNOPSIS
Gets Gitlab projects
.DESCRIPTION
The Get-GitlabProject function returns one or more projects specified.
By default this function returns all projects that the authenticated user is authorized for.
By passing -Starred or -Owned only starred or owned projects are returned.
By passing -Archived or -Visibility ('public','internal','private') results can be further narrowed.
if you have the ID of a project you can specify the projectID by passing $ProjectID
.EXAMPLE
Get-GitLabProject
---------------------------------------------------------------
Returns all projects that the authenticated user is authorized for.
.EXAMPLE
Get-GitLabProject -ProjectID 20
---------------------------------------------------------------
Return Project with ID 20
.EXAMPLE
Get-GitLabProject -archived
---------------------------------------------------------------
Only Return Archived Projects
#>
[CmdletBinding(DefaultparametersetName = 'AllProjects')]
[Alias()]
[OutputType()]
Param
(
# Limit the result by Archived status
[Parameter(ParameterSetName = 'AllProjects',
HelpMessage = 'limit by archived status',
Mandatory = $false)]
[Parameter(ParameterSetName = 'AllProjectsOwned',
HelpMessage = 'limit by archived status',
Mandatory = $false)]
[Parameter(ParameterSetName = 'AllProjectsStarred',
HelpMessage = 'limit by archived status',
Mandatory = $false)]
[switch]$Archived,
# Search for a project.
[Parameter(ParameterSetName = 'AllProjects',
HelpMessage = 'Search for a project.',
Mandatory = $false)]
[Parameter(ParameterSetName = 'AllProjectsOwned',
HelpMessage = 'Search for a project.',
Mandatory = $false)]
[Parameter(ParameterSetName = 'AllProjectsStarred',
HelpMessage = 'Search for a project.',
Mandatory = $false)]
[string]$Search,
# Limit the result by visibility
[Parameter(ParameterSetName = 'AllProjects',
HelpMessage = 'limit by visibility public, internal, private',
Mandatory = $false)]
[Parameter(ParameterSetName = 'AllProjectsOwned',
HelpMessage = 'limit by visibility public, internal, private',
Mandatory = $false)]
[Parameter(ParameterSetName = 'AllProjectsStarred',
HelpMessage = 'limit by visibility public, internal, private',
Mandatory = $false)]
[validateset('public','internal','private')]
[switch]$Visibility,
# Limit the result by Starred status
[Parameter(ParameterSetName = 'AllProjectsStarred',
HelpMessage = 'limit by starred status',
Mandatory = $true)]
[switch]$Starred,
# Limit the result by Owned status
[Parameter(ParameterSetName = 'AllProjectsOwned',
HelpMessage = 'limit by owned status',
Mandatory = $true)]
[switch]$Owned,
# The ID of the project
[Parameter(ParameterSetName = 'SingleProject',
HelpMessage = 'The ID of a project',
Mandatory = $true)]
[Alias('ID')]
[String]$ProjectID,
# 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 = 'projects'
$parameters = @{}
if($PSCmdlet.ParameterSetName -like 'AllProjects*')
{
if($archived)
{
$parameters.archived = 'true'
}
if($visibility)
{
$parameters.visibility = $visibility
}
if($search){
$parameters.search=$search
}
if($starred)
{
$apiurl += '/starred'
}
if($owned)
{
$apiurl += '/owned'
}
}
if($PSCmdlet.ParameterSetName -like 'SingleProject*')
{
$apiurl += "/$([System.Web.HttpUtility]::UrlEncode($projectId))"
}
$GitlabConnect.callapi($apiurl,$httpmethod,$parameters)
}