Skip to content

Commit

Permalink
Add for multiple levels of Atx Headers in the CHANGELOG.md
Browse files Browse the repository at this point in the history
  • Loading branch information
chidozieononiwu committed Sep 13, 2021
1 parent 05aad2b commit 55b00fb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
28 changes: 21 additions & 7 deletions eng/common/scripts/ChangeLog-Operations.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
. "${PSScriptRoot}\SemVer.ps1"

$RELEASE_TITLE_REGEX = "(?<releaseNoteTitle>^\#+\s+(?<version>$([AzureEngSemanticVersion]::SEMVER_REGEX))(\s+(?<releaseStatus>\(.+\))))"
$SECTIONS_HEADER_REGEX = "^###\s(?<sectionName>.*)"
$SECTIONS_HEADER_REGEX = "^###+\s(?<sectionName>.*)"
$CHANGELOG_UNRELEASED_STATUS = "(Unreleased)"
$CHANGELOG_DATE_FORMAT = "yyyy-MM-dd"
$RecommendedSectionHeaders = @("Features Added", "Breaking Changes", "Bugs Fixed", "Other Changes")
Expand Down Expand Up @@ -42,14 +42,24 @@ function Get-ChangeLogEntriesFromContent {
$changelogEntry = $null
$sectionName = $null
$changeLogEntries = [Ordered]@{}
$initialAtxHeader= "#"

if ($changeLogContent[0] -match "(?<HeaderLevel>^#+)\s.*")
{
$initialAtxHeader = $matches["HeaderLevel"]
}

$changeLogEntries | Add-Member -NotePropertyName "InitialAtxHeader" -NotePropertyValue $initialAtxHeader
$releaseTitleAtxHeader = $initialAtxHeader + "#"

try {
# walk the document, finding where the version specifiers are and creating lists
foreach ($line in $changeLogContent) {
if ($line -match $RELEASE_TITLE_REGEX) {
$changeLogEntry = [pscustomobject]@{
ReleaseVersion = $matches["version"]
ReleaseStatus = $matches["releaseStatus"]
ReleaseTitle = "## {0} {1}" -f $matches["version"], $matches["releaseStatus"]
ReleaseTitle = "$releaseTitleAtxHeader {0} {1}" -f $matches["version"], $matches["releaseStatus"]
ReleaseContent = @()
Sections = @{}
}
Expand Down Expand Up @@ -210,6 +220,7 @@ function New-ChangeLogEntry {
[ValidateNotNullOrEmpty()]
[String]$Version,
[String]$Status=$CHANGELOG_UNRELEASED_STATUS,
[String]$InitialAtxHeader="#",
[String[]]$Content
)

Expand Down Expand Up @@ -239,17 +250,20 @@ function New-ChangeLogEntry {
$Content = @()
$Content += ""

$sectionsAtxHeader = $InitialAtxHeader + "##"
foreach ($recommendedHeader in $RecommendedSectionHeaders)
{
$Content += "### $recommendedHeader"
$Content += "$sectionsAtxHeader $recommendedHeader"
$Content += ""
}
}

$releaseTitleAtxHeader = $initialAtxHeader + "#"

$newChangeLogEntry = [pscustomobject]@{
ReleaseVersion = $Version
ReleaseStatus = $Status
ReleaseTitle = "## $Version $Status"
ReleaseTitle = "$releaseTitleAtxHeader $Version $Status"
ReleaseContent = $Content
}

Expand All @@ -261,11 +275,12 @@ function Set-ChangeLogContent {
[Parameter(Mandatory = $true)]
[String]$ChangeLogLocation,
[Parameter(Mandatory = $true)]
$ChangeLogEntries
$ChangeLogEntries,
[String]$InitialAtxHeader="#"
)

$changeLogContent = @()
$changeLogContent += "# Release History"
$changeLogContent += "$InitialAtxHeader Release History"
$changeLogContent += ""

try
Expand Down Expand Up @@ -298,7 +313,6 @@ function Remove-EmptySections {
)

$releaseContent = $ChangeLogEntry.ReleaseContent
$sectionsToRemove = @()

if ($releaseContent.Count -gt 0)
{
Expand Down
6 changes: 3 additions & 3 deletions eng/common/scripts/Update-ChangeLog.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ if ($ReplaceLatestEntryTitle)
{
$entryToBeUpdated = Remove-EmptySections -ChangeLogEntry $entryToBeUpdated
}
$newChangeLogEntry = New-ChangeLogEntry -Version $Version -Status $ReleaseStatus -Content $entryToBeUpdated
$newChangeLogEntry = New-ChangeLogEntry -Version $Version -Status $ReleaseStatus -InitialAtxHeader $ChangeLogEntries.InitialAtxHeader -Content $entryToBeUpdated
LogDebug "Resetting latest entry title to [$($newChangeLogEntry.ReleaseTitle)]"
$ChangeLogEntries.Remove($LatestVersion)
if ($newChangeLogEntry) {
Expand All @@ -137,7 +137,7 @@ elseif ($ChangeLogEntries.Contains($Version))
else
{
LogDebug "Adding new ChangeLog entry for Version [$Version]"
$newChangeLogEntry = New-ChangeLogEntry -Version $Version -Status $ReleaseStatus
$newChangeLogEntry = New-ChangeLogEntry -Version $Version -Status $ReleaseStatus -InitialAtxHeader $ChangeLogEntries.InitialAtxHeader
if ($newChangeLogEntry) {
$ChangeLogEntries.Insert(0, $Version, $newChangeLogEntry)
}
Expand All @@ -147,4 +147,4 @@ else
}
}

Set-ChangeLogContent -ChangeLogLocation $ChangelogPath -ChangeLogEntries $ChangeLogEntries
Set-ChangeLogContent -ChangeLogLocation $ChangelogPath -ChangeLogEntries $ChangeLogEntries -InitialAtxHeader $ChangeLogEntries.InitialAtxHeader

0 comments on commit 55b00fb

Please sign in to comment.