Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove custom yaml #81

Merged
merged 1 commit into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/GitlabCli/GitlabCli.psd1
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
@{
ModuleVersion = '1.113.1'
ModuleVersion = '1.114.0'

RequiredModules = @(
'powershell-yaml'
)

PrivateData = @{
PSData = @{
Expand Down
15 changes: 6 additions & 9 deletions src/GitlabCli/Jobs.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -260,25 +260,22 @@ function Test-GitlabPipelineDefinition {
function Get-GitlabPipelineDefinition {
[CmdletBinding()]
param (
[Parameter(Mandatory=$false)]
[Parameter()]
[string]
$ProjectId = '.',

[Parameter(Mandatory=$false)]
[Parameter()]
[Alias("Branch")]
[string]
$Ref,

[Parameter(Mandatory=$false)]
[Parameter()]
[string]
$SiteUrl,

[switch]
[Parameter(Mandatory=$false)]
$WhatIf
$SiteUrl
)

Get-GitlabRepositoryYmlFileContent -ProjectId $ProjectId -FilePath '.gitlab-ci.yml' -Ref $Ref -SiteUrl $SiteUrl
Get-GitlabRepositoryFileContent -ProjectId $ProjectId -Ref $Ref -FilePath '.gitlab-ci.yml' -SiteUrl $SiteUrl |
ConvertFrom-Yaml
}

<#
Expand Down
21 changes: 8 additions & 13 deletions src/GitlabCli/RepositoryFiles.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -223,32 +223,27 @@ function Get-GitlabRepositoryTree {
}

function Get-GitlabRepositoryYmlFileContent {
[Obsolete("Use Get-GitlabRepositoryFileContent instead")]
[CmdletBinding()]
param (
[Parameter(Mandatory=$false)]
[Parameter()]
[string]
$ProjectId = '.',

[Parameter(Position=0, Mandatory=$true)]
[Parameter(Position=0, Mandatory)]
[string]
$FilePath,

[Parameter(Mandatory=$false)]
[Parameter()]
[Alias("Branch")]
[string]
$Ref,

[Parameter(Mandatory=$false)]
[Parameter()]
[string]
$SiteUrl
)

$Yml = $(Get-GitlabRepositoryFileContent -ProjectId $ProjectId -Ref $Ref -FilePath $FilePath -SiteUrl $SiteUrl)
$Hash = $([YamlDotNet.Serialization.Deserializer].GetMethods() |
Where-Object { $_.Name -eq 'Deserialize' -and $_.ReturnType.Name -eq 'T' -and $_.GetParameters().ParameterType.Name -eq 'String' }). `
MakeGenericMethod(
[object]). `
Invoke($(New-Object 'YamlDotNet.Serialization.Deserializer'), $Yml)

return $Hash | ConvertTo-Json -Depth 100 | ConvertFrom-Json # the JSON "double-tap" coerces HashTables into PSCustomObject (including nested children)

Get-GitlabRepositoryFileContent -ProjectId $ProjectId -Ref $Ref -FilePath $FilePath -SiteUrl $SiteUrl |
ConvertFrom-Yaml
}
35 changes: 0 additions & 35 deletions src/GitlabCli/_Init.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -59,38 +59,3 @@ $global:GitlabIdentityPropertyNameExemptions=@{
'Gitlab.Variable' = ''
}
$global:GitlabJobLogSections = New-Object 'Collections.Generic.Stack[string]'

# Remove the following as part of https://github.com/chris-peterson/pwsh-gitlab/issues/77
# Adapted from
# https://github.com/cloudbase/powershell-yaml/blob/master/Load-Assemblies.ps1

$Here = Split-Path -Parent $MyInvocation.MyCommand.Path

function Initialize-Assembly {
$LibDir = Join-Path $Here "lib"

return [Reflection.Assembly]::LoadFrom($(Join-Path $libDir "YamlDotNet.dll"))
}

function Initialize-Assemblies {
$RequiredTypes = @(
"Parser", "MergingParser", "YamlStream",
"YamlMappingNode", "YamlSequenceNode",
"YamlScalarNode", "ChainedEventEmitter",
"Serializer", "Deserializer", "SerializerBuilder",
"StaticTypeResolver"
)

$YamlDotNet = [System.AppDomain]::CurrentDomain.GetAssemblies() | Where-Object Location -Match "YamlDotNet.dll"
if (!$YamlDotNet) {
return Initialize-Assembly
}

foreach ($i in $RequiredTypes){
if ($i -notin $YamlDotNet.DefinedTypes.Name) {
throw "YamlDotNet is loaded but missing required types ($i). Older version installed on system?"
}
}
}

Initialize-Assemblies | Out-Null