diff --git a/modules/Rulebook.Update.psm1 b/modules/Rulebook.Update.psm1 index 218467d..fe0e7a7 100644 --- a/modules/Rulebook.Update.psm1 +++ b/modules/Rulebook.Update.psm1 @@ -1002,6 +1002,9 @@ function Get-EffectiveDiffBlock { .DESCRIPTION The rendering of Validate.ps1, shared by the update and the scan pull request bodies. Endpoints in the order of -Diff (settings order). + .NOTES + The array is returned with a leading comma so that a one-element result stays an array. Callers assign it + directly or to [string[]] and never wrap the call in @(), which would nest it and print System.String[] (#75). #> [CmdletBinding()] [OutputType([string[]])] @@ -1226,7 +1229,9 @@ function ConvertTo-UpdateSummary { [void]$text.AppendLine('## Effective diff').AppendLine().AppendLine($diffNote).AppendLine() } elseif ($null -ne $Result -and @($Result.Diff).Count -gt 0) { [void]$text.AppendLine('## Effective diff').AppendLine() - [void]$text.Append((@(Get-EffectiveDiffBlock -Diff @($Result.Diff)) -join '')) + # Get-EffectiveDiffBlock returns its array with a comma; @() around it would nest it and print System.String[] (#75). + [string[]]$blocks = Get-EffectiveDiffBlock -Diff @($Result.Diff) + [void]$text.Append(($blocks -join '')) } if ($Plan.ReleaseNotesShipped -and -not [string]::IsNullOrWhiteSpace($Plan.ReleaseNotes)) { [void]$text.AppendLine('## Release notes').AppendLine().AppendLine((ConvertTo-ReleaseNotesMarkdown -Text $Plan.ReleaseNotes)).AppendLine() diff --git a/tests/Rulebook.Update.Tests.ps1 b/tests/Rulebook.Update.Tests.ps1 index a7594d4..c6b207f 100644 --- a/tests/Rulebook.Update.Tests.ps1 +++ b/tests/Rulebook.Update.Tests.ps1 @@ -1086,6 +1086,14 @@ Describe 'ConvertTo-UpdatePullRequestBody and ConvertTo-UpdateSummary' { $summary | Should-MatchString '(?m)^## Release notes\n\n### v1\.1$' } + It 'writes the effective diff tables into the summary, not System.String[] (#75)' { + $row = [pscustomobject]@{ Endpoint = 'recommended.default'; File = 'rulesets/recommended.ruleset.json'; Id = 'LC0031'; Before = 'Warning'; After = 'Error'; BeforeSource = 'default'; AfterSource = 'level:recommended'; AfterDetail = $null; Change = 'action'; ListedAfter = $true } + $result = [pscustomobject]@{ Result = 'pull-request'; PullRequestUrl = 'https://github.com/Contoso/rulebook/pull/3'; Fallback = $false; Diff = @($row) } + $summary = ConvertTo-UpdateSummary -Plan $plan -Result $result -Mode update + $summary | Should-MatchString '(?m)^## Effective diff\n\n### `recommended\.default` \(`rulesets/recommended\.ruleset\.json`\)\n\n\| Id \| Before \| After \| Decided by \|\n\|---\|---\|---\|---\|\n\| LC0031 \| Warning \| Error \| level:recommended \|$' + $summary | Should-NotMatchString 'System\.String\[\]' + } + It 'writes the check summary with the change table' { $summary = ConvertTo-UpdateSummary -Plan $plan -Mode check -Message 'Updates available' $summary | Should-MatchString '(?m)^## Template update check$'