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 pathNew-GitlabProject.ps1
257 lines (234 loc) · 9.14 KB
/
New-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
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
function New-GitLabProject
{
<#
.SYNOPSIS
GCreate a new Project
.DESCRIPTION
The New-GitLabProject function creates a new project.
Defaults namespace to current user's namespace and path on name.
returns new project when -PassThru is specified
.EXAMPLE
New-GitLabProject -Name 'GitLab-API'
---------------------------------------------------------------
creates a new project named 'Gitlab-API'
.EXAMPLE
New-GitLabProject -Name 'GitLab-API' -PassThru
---------------------------------------------------------------
creates a new project named 'Gitlab-API' and returns the projects object
.EXAMPLE
New-GitLabProject -Name 'GitLab-API' -container_registry_enabled $true
---------------------------------------------------------------
Creates a new project named 'Gitlab-API' with container Registry enabled.
#>
[CmdletBinding(DefaultParameterSetName='VisibilityCustom')]
[Alias()]
[OutputType()]
Param
(
#The Name of the new project
[Parameter(HelpMessage='new project name',
Mandatory=$true)]
[string]$Name,
#custom repository name for new project. By default generated based on name
[Parameter(HelpMessage='custom repository name for new project. By default generated based on name',
Mandatory=$false)]
[string]$path,
#namespace for the new project (defaults to user)
[Parameter(HelpMessage='namespace for the new project (defaults to user)',
Mandatory=$false)]
[int]$namespace_id,
# Short project description
[Parameter(HelpMessage='short project description',
Mandatory=$false)]
[string]$description,
# Specify if issues are enabled for this project
[Parameter(HelpMessage='Are issues enabled for this project',
Mandatory=$false)]
[boolean]$issues_enabled,
# Specify if Merge Requests are enabled for this project
[Parameter(HelpMessage='Are Merge Requests enabled for this project',
Mandatory=$false)]
[boolean]$merge_requests_enabled,
# Specify if builds are enabled for this project
[Parameter(HelpMessage='Are Builds enabled for this project',
Mandatory=$false)]
[Alias("builds_enabled")]
[boolean]$jobs_enabled,
# Specify if a wiki is enabled for this project
[Parameter(HelpMessage='is the wiki enabled for this project',
Mandatory=$false)]
[boolean]$wiki_enabled,
# Specify if snippets are enabled for this project
[Parameter(HelpMessage='are snippets enabled for this project',
Mandatory=$false)]
[boolean]$snippets_enabled,
# Specify if Issues are enabled for this project
[Parameter(HelpMessage='are issues enabled for this project',
Mandatory=$false)]
[boolean]$container_registry_enabled,
# Specify if Shared runners are enabled for this project
[Parameter(HelpMessage='are shared runners enabled for this project',
Mandatory=$false)]
[boolean]$shared_runners_enabled,
# Specify Project Visibility
# Private. visibility_level is 0. Project access must be granted explicitly for each user.
# Internal. visibility_level is 10. The project can be cloned by any logged in user.
# Public. visibility_level is 20. The project can be cloned without any authentication.
[Parameter(ParameterSetName = 'VisibilityCustom',
HelpMessage = "Private. visibility_level is 0. Project access must be granted explicitly for each user. `r`n Internal. visibility_level is 10. The project can be cloned by any logged in user. `r`n Public. visibility_level is 20. The project can be cloned without any authentication.",
Mandatory = $false)]
[validateset("private","internal","public")]
[Alias("visibility_level")]
[int]$visibility,
# Is Visibility Public, if true same as setting visibility_level = 20
[Parameter(ParameterSetName = 'VisibilityPublic',
HelpMessage='if true same as setting visibility = public',
Mandatory=$false)]
[switch]$public,
# Sepecify Import URL, used to import a project from an external repository.
[Parameter(HelpMessage='use an import url to import the project',
Mandatory=$false)]
[string]$import_url,
# Enables pull mirroring in a project
[Parameter(HelpMessage='Enables pull mirroring in a project',
Mandatory=$false)]
[boolean]$mirror,
# Pull mirroring triggers builds
[Parameter(HelpMessage='Pull mirroring triggers builds',
Mandatory=$false)]
[boolean]$mirror_trigger_builds,
# Specify if builds are publicly accessible
[Parameter(HelpMessage='are build public',
Mandatory=$false)]
[boolean]$public_builds,
# Existing GitlabConnector Object, can be retrieved with Get-GitlabConnect
[Parameter(HelpMessage = 'Specify Existing GitlabConnector',
Mandatory = $false,
DontShow = $true)]
[psobject]$GitlabConnect = (Get-GitlabConnect),
# Passthru the created project
[Parameter(HelpMessage='Passthru the created project',
Mandatory=$false)]
[switch]$PassThru
)
$httpmethod = 'post'
$apiurl = 'projects'
$parameters = @{}
$parameters =@{}
#name
if($name){
$parameters.'name' = $name
}
#path
if($path){
$parameters.path = $path
}
#default_branch
if($default_branch){
$parameters.'default_branch' = $default_branch
}
#description
if($PSCmdlet.MyInvocation.BoundParameters.keys -contains 'description'){
$parameters.description = $description
}
#namespace
if($PSCmdlet.MyInvocation.BoundParameters.keys -contains 'namespace_id'){
$parameters.namespace_id = $namespace_id
}
#issues_enabled
if($PSCmdlet.MyInvocation.BoundParameters.keys -contains 'issues_enabled'){
if($issues_enabled){
$parameters.issues_enabled = 'true'
}
else{
$parameters.issues_enabled = 'false'
}
}
#merge_requests_enabled
if($PSCmdlet.MyInvocation.BoundParameters.keys -contains 'merge_requests_enabled'){
if($merge_requests_enabled){
$parameters.merge_requests_enabled = 'true'
}
else{
$parameters.merge_requests_enabled = 'false'
}
}
#builds_enabled
if($PSCmdlet.MyInvocation.BoundParameters.keys -contains 'jobs_enabled'){
if($builds_enabled){
$parameters.jobs_enabled = 'true'
}
else{
$parameters.jobs_enabled = 'false'
}
}
#wiki_enabled
if($PSCmdlet.MyInvocation.BoundParameters.keys -contains 'wiki_enabled'){
if($wiki_enabled){
$parameters.wiki_enabled = 'true'
}
else{
$parameters.wiki_enabled = 'false'
}
}
#snippets_enabled
if($PSCmdlet.MyInvocation.BoundParameters.keys -contains 'snippets_enabled'){
if($snippets_enabled){
$parameters.snippets_enabled = 'true'
}
else{
$parameters.snippets_enabled = 'false'
}
}
#container_registry_enabled
if($PSCmdlet.MyInvocation.BoundParameters.keys -contains 'container_registry_enabled'){
if($container_registry_enabled){
$parameters.container_registry_enabled = 'true'
}
else{
$parameters.container_registry_enabled = 'false'
}
}
#shared_runners_enabled
if($PSCmdlet.MyInvocation.BoundParameters.keys -contains 'shared_runners_enabled'){
if($shared_runners_enabled){
$parameters.shared_runners_enabled = 'true'
}
else{
$parameters.shared_runners_enabled = 'false'
}
}
#visibility_level
if($PSCmdlet.MyInvocation.BoundParameters.keys -contains 'visibility_level'){
$parameters.'visibility' = $visibility_level
} elseif($PSCmdlet.MyInvocation.BoundParameters.keys -contains 'public'){
if($public){
$parameters.visibility = 'public'
} else {
$parameters.visibility = 'private'
}
}
#public_builds
if($PSCmdlet.MyInvocation.BoundParameters.keys -contains 'public_builds'){
if($public_builds){
$parameters.public_builds = 'true'
}
else{
$parameters.public_builds = 'false'
}
}
# import_url
if ($PSCmdlet.MyInvocation.BoundParameters.keys -contains 'import_url') {
$parameters.import_url = $import_url
}
if ($PSCmdlet.MyInvocation.BoundParameters.keys -contains 'mirror') {
$parameters.mirror = "$mirror".ToLower()
}
if ($PSCmdlet.MyInvocation.BoundParameters.keys -contains 'mirror_trigger_builds') {
$parameters.mirror_trigger_builds = "$mirror_trigger_builds".ToLower()
}
$newproj = $GitlabConnect.callapi($apiurl,$httpmethod,$parameters)
if($PassThru){
return $newproj
}
}