Skip to content

Commit

Permalink
Remove empty sections in changelog entry as part of prepare release
Browse files Browse the repository at this point in the history
  • Loading branch information
chidozieononiwu committed Sep 15, 2021
1 parent 0d4a875 commit 969dc48
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 18 deletions.
17 changes: 12 additions & 5 deletions eng/common/scripts/ChangeLog-Operations.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,18 @@ function Confirm-ChangeLogEntry {
[String]$ChangeLogLocation,
[Parameter(Mandatory = $true)]
[String]$VersionString,
[boolean]$ForRelease = $false
[boolean]$ForRelease = $false,
[Switch]$SantizeEntry
)

$changeLogEntry = Get-ChangeLogEntry -ChangeLogLocation $ChangeLogLocation -VersionString $VersionString
$changeLogEntries = Get-ChangeLogEntries -ChangeLogLocation $ChangeLogLocation
$changeLogEntry = $changeLogEntries[$VersionString]

if ($SantizeEntry)
{
Remove-EmptySections -ChangeLogEntry $changeLogEntry
Set-ChangeLogContent -ChangeLogLocation $ChangeLogLocation -ChangeLogEntries $changeLogEntries
}

if (!$changeLogEntry) {
LogError "ChangeLog[${ChangeLogLocation}] does not have an entry for version ${VersionString}."
Expand Down Expand Up @@ -318,7 +326,7 @@ function Remove-EmptySections {
$parsedSections = $ChangeLogEntry.Sections
$sanitizedReleaseContent = New-Object System.Collections.ArrayList(,$releaseContent)

foreach ($key in @($parsedSections.Key))
foreach ($key in @($parsedSections.Keys))
{
if ([System.String]::IsNullOrWhiteSpace($parsedSections[$key]))
{
Expand All @@ -340,5 +348,4 @@ function Remove-EmptySections {
}
$ChangeLogEntry.ReleaseContent = $sanitizedReleaseContent.ToArray()
}
return $changeLogEntry
}
}
1 change: 1 addition & 0 deletions eng/common/scripts/Prepare-Release.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ else
exit 1
}

Sanitize-ChangeLogEntry -ChangeLogLocation $packageProperties.ChangeLogPath -VersionString $newVersion
$changelogIsValid = Confirm-ChangeLogEntry -ChangeLogLocation $packageProperties.ChangeLogPath -VersionString $newVersion -ForRelease $true

if (!$changelogIsValid)
Expand Down
15 changes: 2 additions & 13 deletions eng/common/scripts/Update-ChangeLog.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
# Version : Version to add or replace in change log
# 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"
# ReplaceLatestEntryTitle: Replaces the latest changelog entry title.
# SanitizeEntry: Removes all empty section in the entry that is updated

param (
[Parameter(Mandatory = $true)]
Expand All @@ -14,8 +13,7 @@ param (
[Boolean]$Unreleased = $true,
[Boolean]$ReplaceLatestEntryTitle = $false,
[String]$ChangelogPath,
[String]$ReleaseDate,
[Boolean]$SanitizeEntry = $false
[String]$ReleaseDate
)
Set-StrictMode -Version 3

Expand Down Expand Up @@ -108,12 +106,7 @@ if ($LatestsSorted[0] -ne $Version) {

if ($ReplaceLatestEntryTitle)
{
$entryToBeUpdated = $ChangeLogEntries[$LatestVersion]
if ($SanitizeEntry)
{
$entryToBeUpdated = Remove-EmptySections -ChangeLogEntry $entryToBeUpdated
}
$newChangeLogEntry = New-ChangeLogEntry -Version $Version -Status $ReleaseStatus -InitialAtxHeader $ChangeLogEntries.InitialAtxHeader -Content $entryToBeUpdated
$newChangeLogEntry = New-ChangeLogEntry -Version $Version -Status $ReleaseStatus -InitialAtxHeader $ChangeLogEntries.InitialAtxHeader -Content $ChangeLogEntries[$LatestVersion]
LogDebug "Resetting latest entry title to [$($newChangeLogEntry.ReleaseTitle)]"
$ChangeLogEntries.Remove($LatestVersion)
if ($newChangeLogEntry) {
Expand All @@ -129,10 +122,6 @@ elseif ($ChangeLogEntries.Contains($Version))
LogDebug "Updating ReleaseStatus for Version [$Version] to [$($ReleaseStatus)]"
$ChangeLogEntries[$Version].ReleaseStatus = $ReleaseStatus
$ChangeLogEntries[$Version].ReleaseTitle = "$($ChangeLogEntries.InitialAtxHeader)# $Version $ReleaseStatus"
if ($SanitizeEntry)
{
$ChangeLogEntries[$Version] = Remove-EmptySections -ChangeLogEntry $ChangeLogEntries[$Version]
}
}
else
{
Expand Down

0 comments on commit 969dc48

Please sign in to comment.