Skip to content

Commit

Permalink
Merge pull request #43 from chris-peterson/1.60
Browse files Browse the repository at this point in the history
1.60
  • Loading branch information
chris-peterson committed Apr 26, 2022
2 parents 2a802ae + af6ea4c commit dd9b35e
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 7 deletions.
8 changes: 5 additions & 3 deletions src/GitlabCli/GitlabCli.psd1
Original file line number Diff line number Diff line change
@@ -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'
}
}

Expand Down Expand Up @@ -70,15 +70,17 @@
'Get-GitlabGroup'
'New-GitlabGroup'
'Remove-GitlabGroup'
'Rename-GitlabGroup'
'Copy-GitlabGroupToLocalFileSystem'
'Update-GitlabGroup'
'Update-LocalGitlabGroup'
'Get-GitlabGroupVariable'
'Set-GitlabGroupVariable'
'Remove-GitlabGroupVariable'

# Projects
'Get-GitlabProject'
'Get-GitlabProjectAsTriggerPipeline'
'ConvertTo-Triggers'
'New-GitlabProject'
'Update-GitlabProject'
'Move-GitlabProject'
Expand Down
71 changes: 71 additions & 0 deletions src/GitlabCli/Groups.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
39 changes: 35 additions & 4 deletions src/GitlabCli/Projects.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 ','
Expand All @@ -154,10 +174,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 = @"
Expand All @@ -172,14 +197,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 {
Expand Down

0 comments on commit dd9b35e

Please sign in to comment.