44# Version : Version to add or replace in change log
55# Unreleased: Default is true. If it is set to false, then today's date will be set in verion title. If it is True then title will show "Unreleased"
66# ReplaceLatestEntryTitle: Replaces the latest changelog entry title.
7+ # SanitizeEntry: Removes all empty section in the entry that is updated
78
89param (
910 [Parameter (Mandatory = $true )]
@@ -13,7 +14,8 @@ param (
1314 [Boolean ]$Unreleased = $true ,
1415 [Boolean ]$ReplaceLatestEntryTitle = $false ,
1516 [String ]$ChangelogPath ,
16- [String ]$ReleaseDate
17+ [String ]$ReleaseDate ,
18+ [Boolean ]$SanitizeEntry = $false
1719)
1820Set-StrictMode - Version 3
1921
@@ -106,47 +108,12 @@ if ($LatestsSorted[0] -ne $Version) {
106108
107109if ($ReplaceLatestEntryTitle )
108110{
109- # Remove empty sections from content
110- $sanitizedContent = @ ()
111- $sectionContent = @ ()
112- $sectionContentCount = 0
113- $latesVersionContent = $ChangeLogEntries [$LatestVersion ].ReleaseContent
114-
115- foreach ($line in $latesVersionContent )
116- {
117- if ($line.StartsWith (" ### " ) -or $sectionContentCount -gt 0 )
118- {
119- if ($line.StartsWith (" #" ) -and $sectionContentCount -gt 1 )
120- {
121- $sanitizedContent += $sectionContent
122- $sectionContent = @ ()
123- $sectionContentCount = 0
124- }
125-
126- if ($line.StartsWith (" #" ) -and $sectionContentCount -eq 1 )
127- {
128- $sectionContent = @ ()
129- $sectionContentCount = 0
130- }
131-
132- $sectionContent += $line
133- if (-not [System.String ]::IsNullOrWhiteSpace($line ))
134- {
135- $sectionContentCount ++
136- }
137- }
138- elseif ($sectionContent.Count -eq 0 )
139- {
140- $sanitizedContent += $line
141- }
142- }
143-
144- if ($sectionContentCount -gt 1 )
111+ $entryToBeUpdated = $ChangeLogEntries [$LatestVersion ]
112+ if ($SanitizeEntry )
145113 {
146- $sanitizedContent += $sectionContent
114+ $entryToBeUpdated = Remove-EmptySections - ChangeLogEntry $entryToBeUpdated
147115 }
148-
149- $newChangeLogEntry = New-ChangeLogEntry - Version $Version - Status $ReleaseStatus - Content $sanitizedContent
116+ $newChangeLogEntry = New-ChangeLogEntry - Version $Version - Status $ReleaseStatus - Content $entryToBeUpdated
150117 LogDebug " Resetting latest entry title to [$ ( $newChangeLogEntry.ReleaseTitle ) ]"
151118 $ChangeLogEntries.Remove ($LatestVersion )
152119 if ($newChangeLogEntry ) {
@@ -162,6 +129,10 @@ elseif ($ChangeLogEntries.Contains($Version))
162129 LogDebug " Updating ReleaseStatus for Version [$Version ] to [$ ( $ReleaseStatus ) ]"
163130 $ChangeLogEntries [$Version ].ReleaseStatus = $ReleaseStatus
164131 $ChangeLogEntries [$Version ].ReleaseTitle = " ## $Version $ReleaseStatus "
132+ if ($SanitizeEntry )
133+ {
134+ $ChangeLogEntries [$Version ] = Remove-EmptySections - ChangeLogEntry $ChangeLogEntries [$Version ]
135+ }
165136}
166137else
167138{
0 commit comments