Skip to content

Commit

Permalink
Merge pull request #27 from johlju/fix/issue-#25
Browse files Browse the repository at this point in the history
Get-ChangeLogData: Correctly returns a PSCustomTable or null
  • Loading branch information
natescherer authored Dec 12, 2022
2 parents 7da86a3 + d439a4d commit 30d8821
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 17 deletions.
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
[1.0.0]: https://github.com/natescherer/ChangelogManagement/tree/v1.0.0
25 changes: 14 additions & 11 deletions src/public/Get-ChangelogData.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -94,6 +95,8 @@ function Get-ChangelogData {
Security = $UnreleasedSecurity
}
}
} else {
$Output.Unreleased = $null
}

# Construct the $Output.Released array
Expand Down Expand Up @@ -139,4 +142,4 @@ function Get-ChangelogData {
}

$Output
}
}
7 changes: 2 additions & 5 deletions test/ChangelogManagement.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down

0 comments on commit 30d8821

Please sign in to comment.