From be9abc600f835bad8dc36c0fcb490a7a04ae3c36 Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Sat, 10 Dec 2022 14:07:24 +0100 Subject: [PATCH 1/2] Get-ChangeLogData: Correctly returns a PSCustomTable or null --- CHANGELOG.md | 10 +++++++++- src/public/Get-ChangelogData.ps1 | 25 ++++++++++++++----------- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b803179..68cef97 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Changed + +- Get-ChangelogData now always outputs a PSCustomObject for the Unreleased property when there is an Unreleased section header in the changelog. The PSCustomObject property RawData will contain the Unreleased header and any change type headers that exist. The properties Added, Changed, Deprecated, Removed, Fixed, and Security will be null if there are no corresponding change type under the Unreleased section header. + +### Fixed + +- Get-ChangelogData will now return null for the property Unreleased if there are no Unreleased section header in the changelog. + ## [3.0.0] - 2022-11-04 ### Added - New LinkModes 'GitHub' and 'AzureDevOps' on Update-Changelog which remove the need to manually specify a LinkPattern @@ -72,4 +80,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 [2.1.1]: https://github.com/natescherer/ChangelogManagement/compare/v2.1.0..v2.1.1 [2.1.0]: https://github.com/natescherer/ChangelogManagement/compare/v2.0.0..v2.1.0 [2.0.0]: https://github.com/natescherer/ChangelogManagement/compare/v1.0.0..v2.0.0 -[1.0.0]: https://github.com/natescherer/ChangelogManagement/tree/v1.0.0 \ No newline at end of file +[1.0.0]: https://github.com/natescherer/ChangelogManagement/tree/v1.0.0 diff --git a/src/public/Get-ChangelogData.ps1 b/src/public/Get-ChangelogData.ps1 index 0c41d77..2fe045f 100644 --- a/src/public/Get-ChangelogData.ps1 +++ b/src/public/Get-ChangelogData.ps1 @@ -69,19 +69,20 @@ function Get-ChangelogData { $UnreleasedTemp = $Sections[0] $Sections.Remove($UnreleasedTemp) } else { - $UnreleasedTemp = "" + $UnreleasedTemp = $null } - # Construct the $Output.Unreleased object - foreach ($ChangeType in $ChangeTypes) { - if ($UnreleasedTemp -notlike "*### $ChangeType*") { - Set-Variable -Name "Unreleased$ChangeType" -Value $null - } else { - $Value = (($UnreleasedTemp -split "### $ChangeType$FileNewline")[1] -split "###")[0].TrimEnd($FileNewline) -split $FileNewline | ForEach-Object { $_.TrimStart("- ") } - Set-Variable -Name "Unreleased$ChangeType" -Value $Value + if ($UnreleasedTemp) { + # Construct the $Output.Unreleased object + foreach ($ChangeType in $ChangeTypes) { + if ($UnreleasedTemp -notlike "*### $ChangeType*") { + Set-Variable -Name "Unreleased$ChangeType" -Value $null + } else { + $Value = (($UnreleasedTemp -split "### $ChangeType$FileNewline")[1] -split "###")[0].TrimEnd($FileNewline) -split $FileNewline | ForEach-Object { $_.TrimStart("- ") } + Set-Variable -Name "Unreleased$ChangeType" -Value $Value + } } - } - if ($UnreleasedAdded -or $UnreleasedChanged -or $UnreleasedDeprecated -or $UnreleasedRemoved -or $UnreleasedFixed -or $UnreleasedSecurity) { + $Output.Unreleased = [PSCustomObject]@{ "RawData" = $UnreleasedTemp "Link" = (($Output.Footer -split "Unreleased\]: ")[1] -split $FileNewline)[0] @@ -94,6 +95,8 @@ function Get-ChangelogData { Security = $UnreleasedSecurity } } + } else { + $Output.Unreleased = $null } # Construct the $Output.Released array @@ -139,4 +142,4 @@ function Get-ChangelogData { } $Output -} \ No newline at end of file +} From d439a4d8e7dd1264dc3778d89086045e6aa358d4 Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Sat, 10 Dec 2022 14:14:12 +0100 Subject: [PATCH 2/2] Fix unit test --- test/ChangelogManagement.Tests.ps1 | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/test/ChangelogManagement.Tests.ps1 b/test/ChangelogManagement.Tests.ps1 index 0410119..0b75b9c 100644 --- a/test/ChangelogManagement.Tests.ps1 +++ b/test/ChangelogManagement.Tests.ps1 @@ -281,11 +281,8 @@ InModuleScope $ModuleName { Set-Content -Value $SeedDataNoUnreleased -Path $TestPathNoUnreleased -NoNewline $DataNoUnreleased = Get-ChangelogData -Path $TestPathNoUnreleased } - It "Data.Unreleased.RawData" { - $DataNoUnreleased.Unreleased.RawData | Should -BeNullOrEmpty - } - It "Data.Unreleased.Data" { - $DataNoUnreleased.Unreleased.RawData | Should -BeNullOrEmpty + It "Data.Unreleased" { + $DataNoUnreleased.Unreleased | Should -BeNullOrEmpty } } It "Output.ReleaseNotes" {