33. " ${PSScriptRoot} \SemVer.ps1"
44
55$RELEASE_TITLE_REGEX = " (?<releaseNoteTitle>^\#+\s+(?<version>$ ( [AzureEngSemanticVersion ]::SEMVER_REGEX) )(\s+(?<releaseStatus>\(.+\))))"
6- $SECTIONS_HEADER_REGEX = " ^###+ \s(?<sectionName>.*)"
6+ $SECTION_HEADER_REGEX_SUFFIX = " ## \s(?<sectionName>.*)"
77$CHANGELOG_UNRELEASED_STATUS = " (Unreleased)"
88$CHANGELOG_DATE_FORMAT = " yyyy-MM-dd"
99$RecommendedSectionHeaders = @ (" Features Added" , " Breaking Changes" , " Bugs Fixed" , " Other Changes" )
@@ -49,6 +49,7 @@ function Get-ChangeLogEntriesFromContent {
4949 $initialAtxHeader = $matches [" HeaderLevel" ]
5050 }
5151
52+ $sectionHeaderRegex = " ^${initialAtxHeader}${SECTION_HEADER_REGEX_SUFFIX} "
5253 $changeLogEntries | Add-Member - NotePropertyName " InitialAtxHeader" - NotePropertyValue $initialAtxHeader
5354 $releaseTitleAtxHeader = $initialAtxHeader + " #"
5455
@@ -67,7 +68,7 @@ function Get-ChangeLogEntriesFromContent {
6768 }
6869 else {
6970 if ($changeLogEntry ) {
70- if ($line.Trim () -match $SECTIONS_HEADER_REGEX )
71+ if ($line.Trim () -match $sectionHeaderRegex )
7172 {
7273 $sectionName = $matches [" sectionName" ].Trim()
7374 $changeLogEntry.Sections [$sectionName ] = @ ()
@@ -136,16 +137,24 @@ function Confirm-ChangeLogEntry {
136137 [String ]$ChangeLogLocation ,
137138 [Parameter (Mandatory = $true )]
138139 [String ]$VersionString ,
139- [boolean ]$ForRelease = $false
140+ [boolean ]$ForRelease = $false ,
141+ [Switch ]$SantizeEntry
140142 )
141143
142- $changeLogEntry = Get-ChangeLogEntry - ChangeLogLocation $ChangeLogLocation - VersionString $VersionString
144+ $changeLogEntries = Get-ChangeLogEntries - ChangeLogLocation $ChangeLogLocation
145+ $changeLogEntry = $changeLogEntries [$VersionString ]
143146
144147 if (! $changeLogEntry ) {
145148 LogError " ChangeLog[${ChangeLogLocation} ] does not have an entry for version ${VersionString} ."
146149 return $false
147150 }
148151
152+ if ($SantizeEntry )
153+ {
154+ Remove-EmptySections - ChangeLogEntry $changeLogEntry - InitialAtxHeader $changeLogEntries.InitialAtxHeader
155+ Set-ChangeLogContent - ChangeLogLocation $ChangeLogLocation - ChangeLogEntries $changeLogEntries
156+ }
157+
149158 Write-Host " Found the following change log entry for version '${VersionString} ' in [${ChangeLogLocation} ]."
150159 Write-Host " -----"
151160 Write-Host (ChangeLogEntryAsString $changeLogEntry )
@@ -308,24 +317,26 @@ function Set-ChangeLogContent {
308317function Remove-EmptySections {
309318 param (
310319 [Parameter (Mandatory = $true )]
311- $ChangeLogEntry
320+ $ChangeLogEntry ,
321+ $InitialAtxHeader = " #"
312322 )
313323
324+ $sectionHeaderRegex = " ^${InitialAtxHeader}${SECTION_HEADER_REGEX_SUFFIX} "
314325 $releaseContent = $ChangeLogEntry.ReleaseContent
315326
316327 if ($releaseContent.Count -gt 0 )
317328 {
318329 $parsedSections = $ChangeLogEntry.Sections
319330 $sanitizedReleaseContent = New-Object System.Collections.ArrayList(, $releaseContent )
320331
321- foreach ($key in @ ($parsedSections.Key ))
332+ foreach ($key in @ ($parsedSections.Keys ))
322333 {
323334 if ([System.String ]::IsNullOrWhiteSpace($parsedSections [$key ]))
324335 {
325336 for ($i = 0 ; $i -lt $sanitizedReleaseContent.Count ; $i ++ )
326337 {
327338 $line = $sanitizedReleaseContent [$i ]
328- if ($line -match $SECTIONS_HEADER_REGEX -and $matches [" sectionName" ].Trim() -eq $key )
339+ if ($line -match $sectionHeaderRegex -and $matches [" sectionName" ].Trim() -eq $key )
329340 {
330341 $sanitizedReleaseContent.RemoveAt ($i )
331342 while ($i -lt $sanitizedReleaseContent.Count -and [System.String ]::IsNullOrWhiteSpace($sanitizedReleaseContent [$i ]))
@@ -340,5 +351,4 @@ function Remove-EmptySections {
340351 }
341352 $ChangeLogEntry.ReleaseContent = $sanitizedReleaseContent.ToArray ()
342353 }
343- return $changeLogEntry
344- }
354+ }
0 commit comments