Skip to content

Commit 30d8821

Browse files
authored
Merge pull request #27 from johlju/fix/issue-#25
Get-ChangeLogData: Correctly returns a PSCustomTable or null
2 parents 7da86a3 + d439a4d commit 30d8821

File tree

3 files changed

+25
-17
lines changed

3 files changed

+25
-17
lines changed

CHANGELOG.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88

9+
### Changed
10+
11+
- 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.
12+
13+
### Fixed
14+
15+
- Get-ChangelogData will now return null for the property Unreleased if there are no Unreleased section header in the changelog.
16+
917
## [3.0.0] - 2022-11-04
1018
### Added
1119
- 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
7280
[2.1.1]: https://github.com/natescherer/ChangelogManagement/compare/v2.1.0..v2.1.1
7381
[2.1.0]: https://github.com/natescherer/ChangelogManagement/compare/v2.0.0..v2.1.0
7482
[2.0.0]: https://github.com/natescherer/ChangelogManagement/compare/v1.0.0..v2.0.0
75-
[1.0.0]: https://github.com/natescherer/ChangelogManagement/tree/v1.0.0
83+
[1.0.0]: https://github.com/natescherer/ChangelogManagement/tree/v1.0.0

src/public/Get-ChangelogData.ps1

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,19 +69,20 @@ function Get-ChangelogData {
6969
$UnreleasedTemp = $Sections[0]
7070
$Sections.Remove($UnreleasedTemp)
7171
} else {
72-
$UnreleasedTemp = ""
72+
$UnreleasedTemp = $null
7373
}
7474

75-
# Construct the $Output.Unreleased object
76-
foreach ($ChangeType in $ChangeTypes) {
77-
if ($UnreleasedTemp -notlike "*### $ChangeType*") {
78-
Set-Variable -Name "Unreleased$ChangeType" -Value $null
79-
} else {
80-
$Value = (($UnreleasedTemp -split "### $ChangeType$FileNewline")[1] -split "###")[0].TrimEnd($FileNewline) -split $FileNewline | ForEach-Object { $_.TrimStart("- ") }
81-
Set-Variable -Name "Unreleased$ChangeType" -Value $Value
75+
if ($UnreleasedTemp) {
76+
# Construct the $Output.Unreleased object
77+
foreach ($ChangeType in $ChangeTypes) {
78+
if ($UnreleasedTemp -notlike "*### $ChangeType*") {
79+
Set-Variable -Name "Unreleased$ChangeType" -Value $null
80+
} else {
81+
$Value = (($UnreleasedTemp -split "### $ChangeType$FileNewline")[1] -split "###")[0].TrimEnd($FileNewline) -split $FileNewline | ForEach-Object { $_.TrimStart("- ") }
82+
Set-Variable -Name "Unreleased$ChangeType" -Value $Value
83+
}
8284
}
83-
}
84-
if ($UnreleasedAdded -or $UnreleasedChanged -or $UnreleasedDeprecated -or $UnreleasedRemoved -or $UnreleasedFixed -or $UnreleasedSecurity) {
85+
8586
$Output.Unreleased = [PSCustomObject]@{
8687
"RawData" = $UnreleasedTemp
8788
"Link" = (($Output.Footer -split "Unreleased\]: ")[1] -split $FileNewline)[0]
@@ -94,6 +95,8 @@ function Get-ChangelogData {
9495
Security = $UnreleasedSecurity
9596
}
9697
}
98+
} else {
99+
$Output.Unreleased = $null
97100
}
98101

99102
# Construct the $Output.Released array
@@ -139,4 +142,4 @@ function Get-ChangelogData {
139142
}
140143

141144
$Output
142-
}
145+
}

test/ChangelogManagement.Tests.ps1

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -281,11 +281,8 @@ InModuleScope $ModuleName {
281281
Set-Content -Value $SeedDataNoUnreleased -Path $TestPathNoUnreleased -NoNewline
282282
$DataNoUnreleased = Get-ChangelogData -Path $TestPathNoUnreleased
283283
}
284-
It "Data.Unreleased.RawData" {
285-
$DataNoUnreleased.Unreleased.RawData | Should -BeNullOrEmpty
286-
}
287-
It "Data.Unreleased.Data" {
288-
$DataNoUnreleased.Unreleased.RawData | Should -BeNullOrEmpty
284+
It "Data.Unreleased" {
285+
$DataNoUnreleased.Unreleased | Should -BeNullOrEmpty
289286
}
290287
}
291288
It "Output.ReleaseNotes" {

0 commit comments

Comments
 (0)