diff --git a/src/formats/GitHubContext.Format.ps1xml b/src/formats/GitHubContext.Format.ps1xml index 638e3d673..5897f2b75 100644 --- a/src/formats/GitHubContext.Format.ps1xml +++ b/src/formats/GitHubContext.Format.ps1xml @@ -53,6 +53,9 @@ + + Name + HostName @@ -95,9 +98,6 @@ DatabaseID - - ID - Owner diff --git a/src/functions/private/Commands/ConvertFrom-GitHubOutput.ps1 b/src/functions/private/Commands/ConvertFrom-GitHubOutput.ps1 index 3e74ee36c..c89a6cc91 100644 --- a/src/functions/private/Commands/ConvertFrom-GitHubOutput.ps1 +++ b/src/functions/private/Commands/ConvertFrom-GitHubOutput.ps1 @@ -20,7 +20,7 @@ Numbers=12345 '@ - $content | ConvertFrom-GitHubOutput + ConvertFrom-GitHubOutput -OutputContent $content zen : something else result : @{MyOutput=Hello, World!; Status=Success} @@ -38,12 +38,9 @@ [CmdletBinding()] param( # The input data to convert - [Parameter( - Mandatory, - ValueFromPipeline - )] - [AllowNull()] - [string[]] $InputData, + [Parameter(Mandatory)] + [AllowEmptyString()] + [string] $OutputContent, # Whether to convert the input data to a hashtable [switch] $AsHashtable @@ -52,37 +49,34 @@ begin { $stackPath = Get-PSCallStackPath Write-Debug "[$stackPath] - Start" - $lines = @() } process { Write-Debug "[$stackPath] - Process - Start" - if (-not $InputData) { - $InputData = '' + $lines = $OutputContent -split [System.Environment]::NewLine + Write-Debug "[$stackPath] - Output lines: $($lines.Count)" + if ($lines.count -eq 0) { + return @{} } - foreach ($line in $InputData) { - Write-Debug "Line: $line" - $lines += $line -split "`n" - } - Write-Debug "[$stackPath] - End - Start" - # Initialize variables + $result = @{} $i = 0 - - Write-Debug "Lines: $($lines.Count)" - $lines | ForEach-Object { Write-Debug "[$_]" } - + $pad = $lines.count.ToString().Length while ($i -lt $lines.Count) { + $lineNumber = ($i + 1).ToString().PadLeft($pad) $line = $lines[$i].Trim() - Write-Debug "[$line]" + Write-Debug "[$lineNumber]: [$line]" - # Check for key=value pattern + # Check for key=value pattern (single-line) if ($line -match '^([^=]+)=(.*)$') { - Write-Debug ' - key=value pattern' + Write-Debug ' - Single-line pattern' $key = $Matches[1].Trim() $value = $Matches[2] - if ([string]::IsNullOrWhiteSpace($value) -or [string]::IsNullOrEmpty($value)) { + Write-Debug " - Single-line pattern - [$key] = [$value]" + # Check for empty value + if ([string]::IsNullOrWhiteSpace($value) -or [string]::IsNullOrEmpty($value) -or $value.Length -eq 0) { + Write-Debug ' - Single-line pattern - Empty value' $result[$key] = '' $i++ continue @@ -90,7 +84,7 @@ # Attempt to parse JSON if (Test-Json $value -ErrorAction SilentlyContinue) { - Write-Debug "[$key] - value is JSON" + Write-Debug " - Single-line pattern - value is JSON" $value = ConvertFrom-Json $value -AsHashtable:$AsHashtable } @@ -99,38 +93,42 @@ continue } - # Check for key<