This repository was 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
Expand file tree
/
Copy pathSet-GitlabProject.ps1
More file actions
312 lines (280 loc) · 10.6 KB
/
Copy pathSet-GitlabProject.ps1
File metadata and controls
312 lines (280 loc) · 10.6 KB
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
function Set-GitlabProject
{
<#
.SYNOPSIS
Sets the properties you specify on a project.
.DESCRIPTION
The Set-GitLabProject function sets the properties of the project you specify.
returns modified project when -PassThru is specified
.EXAMPLE
Set-GitLabProject -ProjectID 20 -Name 'New Project Name'
---------------------------------------------------------------
Sets the name for project 20 to 'New Project Name'
.EXAMPLE
Set-GitLabProject -ProjectID 20 -visibility_level 10
---------------------------------------------------------------
Sets the visibility level of project 20 to 10
#>
[CmdletBinding(DefaultParameterSetName='VisibilityCustom')]
[Alias()]
[OutputType()]
Param
(
# The Project ID
[Parameter(HelpMessage='The Project ID',
Mandatory=$true)]
[Alias('ID')]
[int]$ProjectID,
# The Name of the project.
[Parameter(HelpMessage='new project name',
Mandatory=$false)]
[string]$name,
# Custom repository name for the project.
[Parameter(HelpMessage='Custom repository name for the project.',
Mandatory=$false)]
[string]$path,
# Change default branch to specified branch
[Parameter(HelpMessage='default branch for the project',
Mandatory=$false)]
[string]$default_branch,
# 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,
# Specify if builds are publicly accessible
[Parameter(HelpMessage='are build public',
Mandatory=$false)]
[boolean]$public_builds,
# URL to import repository from
[Parameter(HelpMessage='URL to import repository from',
Mandatory=$false)]
[String]$import_url,
# Enables pull mirroring in a project
[Parameter(HelpMessage='Enables pull mirroring in a project',
Mandatory=$false)]
[boolean]$mirror,
# User responsible for all the activity surrounding a pull mirror event
[Parameter(HelpMessage='User responsible for all the activity surrounding a pull mirror event',
Mandatory=$false)]
[int]$mirror_user_id,
# Pull mirroring triggers builds
[Parameter(HelpMessage='Pull mirroring triggers builds',
Mandatory=$false)]
[boolean]$mirror_trigger_builds,
# Only mirror protected branches
[Parameter(HelpMessage='Only mirror protected branches',
Mandatory=$false)]
[boolean]$only_mirror_protected_branches,
# Pull mirror overwrites diverged branches
[Parameter(HelpMessage='Pull mirror overwrites diverged branches',
Mandatory=$false)]
[boolean]$mirror_overwrites_diverged_branches,
# Existing GitlabConnector Object, can be retrieved with Get-GitlabConnect
[Parameter(HelpMessage = 'Specify Existing GitlabConnector',
Mandatory = $false,
DontShow = $true)]
[psobject]$GitlabConnect = (Get-GitlabConnect),
# Passthru the modified project
[Parameter(HelpMessage='Passthru the modified project',
Mandatory=$false)]
[switch]$PassThru
)
$httpmethod = 'put'
$apiurl = "projects/$ProjectID"
$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'){
if($description){
$parameters.description = 'true'
}
else{
$parameters.description = 'false'
}
}
#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($jobs_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
}
# mirror
if ($PSCmdlet.MyInvocation.BoundParameters.keys -contains 'mirror') {
if($mirror){
$parameters.mirror = 'true'
}
else{
$parameters.mirror = 'false'
}
}
# mirror_user_id
if ($PSCmdlet.MyInvocation.BoundParameters.keys -contains 'mirror_user_id') {
$parameters.mirror_user_id = $mirror_user_id
}
# mirror_trigger_builds
if ($PSCmdlet.MyInvocation.BoundParameters.keys -contains 'mirror_trigger_builds') {
if($mirror_trigger_builds){
$parameters.mirror_trigger_builds = 'true'
}
else{
$parameters.mirror_trigger_builds = 'false'
}
}
# only_mirror_protected_branches
if ($PSCmdlet.MyInvocation.BoundParameters.keys -contains 'only_mirror_protected_branches') {
if($only_mirror_protected_branches){
$parameters.only_mirror_protected_branches = 'true'
}
else{
$parameters.only_mirror_protected_branches = 'false'
}
}
# mirror_overwrites_diverged_branches
if ($PSCmdlet.MyInvocation.BoundParameters.keys -contains 'mirror_overwrites_diverged_branches') {
if($mirror_overwrites_diverged_branches){
$parameters.mirror_overwrites_diverged_branches = 'true'
}
else{
$parameters.mirror_overwrites_diverged_branches = 'false'
}
}
$newproj = $GitlabConnect.callapi($apiurl,$httpmethod,$parameters)
if($PassThru){
return $newproj
}
}