From 306d03ef73103f589412c7674c9febc57d0938c6 Mon Sep 17 00:00:00 2001 From: Chris Peterson Date: Thu, 21 Apr 2022 08:40:54 -0700 Subject: [PATCH 1/4] Resolves #35 --- src/GitlabCli/GitlabCli.psd1 | 2 + src/GitlabCli/Groups.psm1 | 71 ++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+) diff --git a/src/GitlabCli/GitlabCli.psd1 b/src/GitlabCli/GitlabCli.psd1 index 4365837..2079d68 100644 --- a/src/GitlabCli/GitlabCli.psd1 +++ b/src/GitlabCli/GitlabCli.psd1 @@ -70,7 +70,9 @@ 'Get-GitlabGroup' 'New-GitlabGroup' 'Remove-GitlabGroup' + 'Rename-GitlabGroup' 'Copy-GitlabGroupToLocalFileSystem' + 'Update-GitlabGroup' 'Update-LocalGitlabGroup' 'Get-GitlabGroupVariable' 'Set-GitlabGroupVariable' diff --git a/src/GitlabCli/Groups.psm1 b/src/GitlabCli/Groups.psm1 index 02e8cf2..14511c5 100644 --- a/src/GitlabCli/Groups.psm1 +++ b/src/GitlabCli/Groups.psm1 @@ -344,3 +344,74 @@ function Remove-GitlabGroupVariable { Invoke-GitlabApi DELETE "groups/$GroupId/variables/$Key" -SiteUrl $SiteUrl -WhatIf:$WhatIf | Out-Null } + + +# https://docs.gitlab.com/ee/api/groups.html#update-group +function Update-GitlabGroup { + + [CmdletBinding()] + param ( + [Parameter(Mandatory=$true, Position=0, ValueFromPipelineByPropertyName=$true)] + [string] + $GroupId, + + [Parameter(Mandatory=$false)] + [string] + $Name, + + [Parameter(Mandatory=$false)] + [string] + $Path, + + [Parameter(Mandatory=$false)] + [ValidateSet('private', 'internal', 'public')] + [string] + $Visibility, + + [Parameter(Mandatory=$false)] + [string] + $SiteUrl, + + [switch] + [Parameter(Mandatory=$false)] + $WhatIf + ) + + $GroupId = $GroupId | ConvertTo-UrlEncoded + + $Body = @{} + + if ($Name) { + $Body.name = $Name + } + if ($Path) { + $Body.path = $Path + } + if ($Visibility) { + $Body.visibility = $Visibility + } + + Invoke-GitlabApi PUT "groups/$GroupId" -Body $Body -SiteUrl $SiteUrl -WhatIf:$WhatIf | New-WrapperObject 'Gitlab.Group' +} + +function Rename-GitlabGroup { + param ( + [Parameter(Mandatory=$false, ValueFromPipelineByPropertyName=$true)] + [string] + $GroupId = '.', + + [Parameter(Position=0, Mandatory=$true)] + [string] + $NewName, + + [Parameter(Mandatory=$false)] + [string] + $SiteUrl, + + [switch] + [Parameter(Mandatory=$false)] + $WhatIf + ) + + Update-GitlabGroup $GroupId -Name $NewName -Path $NewName -SiteUrl $SiteUrl -WhatIf:$WhatIf +} From e1d23b2c833a94a7682ebd67cad4d2f62e3209e5 Mon Sep 17 00:00:00 2001 From: Chris Peterson Date: Mon, 25 Apr 2022 17:35:28 -0700 Subject: [PATCH 2/4] Add option to get projects by user id --- src/GitlabCli/Projects.psm1 | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/GitlabCli/Projects.psm1 b/src/GitlabCli/Projects.psm1 index 640e5cf..5c66163 100644 --- a/src/GitlabCli/Projects.psm1 +++ b/src/GitlabCli/Projects.psm1 @@ -75,6 +75,14 @@ function Get-GitlabProject { [string] $GroupId, + [Parameter(Mandatory=$false, ParameterSetName='ByUser')] + [string] + $UserId, + + [Parameter(Mandatory=$false, ParameterSetName='ByUser')] + [switch] + $Mine, + [Parameter(Position=0, Mandatory=$true, ParameterSetName='ByTopics')] [string []] $Topics, @@ -132,6 +140,18 @@ function Get-GitlabProject { Where-Object { $($_.path_with_namespace).StartsWith($Group.FullPath) } | Sort-Object -Property 'Name' } + ByUser { + # https://docs.gitlab.com/ee/api/projects.html#list-user-projects + + if ($Mine) { + if ($UserId) { + Write-Warning "Ignoring '-UserId $UserId' parameter since -Mine was also provided" + } + $UserId = Get-GitlabUser -Me | Select-Object -ExpandProperty Username + } + + $Projects = Invoke-GitlabApi GET "users/$UserId/projects" + } ByTopics { $Projects = Invoke-GitlabApi GET "projects" -Query @{ topic = $Topics -join ',' From 050a79b862772450aea5fdfae4fa5e31bc36c6af Mon Sep 17 00:00:00 2001 From: Chris Peterson Date: Tue, 26 Apr 2022 15:39:37 -0700 Subject: [PATCH 3/4] Rename and improve method --- src/GitlabCli/GitlabCli.psd1 | 2 +- src/GitlabCli/Projects.psm1 | 19 +++++++++++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/GitlabCli/GitlabCli.psd1 b/src/GitlabCli/GitlabCli.psd1 index 4365837..1c9df6b 100644 --- a/src/GitlabCli/GitlabCli.psd1 +++ b/src/GitlabCli/GitlabCli.psd1 @@ -78,7 +78,7 @@ # Projects 'Get-GitlabProject' - 'Get-GitlabProjectAsTriggerPipeline' + 'ConvertTo-Triggers' 'New-GitlabProject' 'Update-GitlabProject' 'Move-GitlabProject' diff --git a/src/GitlabCli/Projects.psm1 b/src/GitlabCli/Projects.psm1 index 640e5cf..7424bcb 100644 --- a/src/GitlabCli/Projects.psm1 +++ b/src/GitlabCli/Projects.psm1 @@ -154,10 +154,15 @@ function Get-GitlabProject { Get-FilteredObject $Select } -function Get-GitlabProjectAsTriggerPipeline { +function ConvertTo-Triggers { param ( [Parameter(Mandatory=$true, ValueFromPipeline=$true)] - $InputObject + $InputObject, + + [Parameter(Mandatory=$false)] + [ValidateSet('', 'depend')] + [string] + $Strategy = 'depend' ) Begin { $Yaml = @" @@ -172,14 +177,20 @@ stages: continue } $Projects += $Object.ProjectId - $Yaml += "`n`n" $Yaml += @" + + $($Object.Name): stage: trigger trigger: project: $($Object.PathWithNamespace) - strategy: depend "@ + if ($Strategy) { + $Yaml += @" + + strategy: $Strategy +"@ + } } } End { From af6ea4c0d77c6dcc760584439ec20355823cf623 Mon Sep 17 00:00:00 2001 From: Chris Peterson Date: Tue, 26 Apr 2022 16:16:06 -0700 Subject: [PATCH 4/4] Bump version --- src/GitlabCli/GitlabCli.psd1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/GitlabCli/GitlabCli.psd1 b/src/GitlabCli/GitlabCli.psd1 index ae4193c..4708043 100644 --- a/src/GitlabCli/GitlabCli.psd1 +++ b/src/GitlabCli/GitlabCli.psd1 @@ -1,11 +1,11 @@ @{ - ModuleVersion = '1.59.0' + ModuleVersion = '1.60.0' PrivateData = @{ PSData = @{ LicenseUri = 'https://github.com/chris-peterson/pwsh-gitlab/blob/main/LICENSE' ProjectUri = 'https://github.com/chris-peterson/pwsh-gitlab' - ReleaseNotes = 'Add gitlab version' + ReleaseNotes = 'https://github.com/chris-peterson/pwsh-gitlab/pull/43' } }