From 3555a2664b04a50ec033f6b4a5a8617fcc8f4139 Mon Sep 17 00:00:00 2001 From: Leonard Jonathan Oh Date: Mon, 16 Sep 2024 13:40:26 +0000 Subject: [PATCH] Feature: Add `VersionDate-Subject-MergesWithPRLink-CategorizedSorted` variant --- .vscode/tasks.json | 1 + docs/samples/.vscode/tasks.submodule.json | 1 + .../Public/Generate-ReleaseNotes.ps1 | 1 + ...ect-MergesWithPRLink-CategorizedSorted.ps1 | 196 ++++++++++++++++++ 4 files changed, 199 insertions(+) create mode 100644 src/PSRepositoryReleaseManager/generate/variants/VersionDate-Subject-MergesWithPRLink-CategorizedSorted.ps1 diff --git a/.vscode/tasks.json b/.vscode/tasks.json index ce96fb1..40d2b2c 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -35,6 +35,7 @@ "VersionDate-HashSubjectAuthor-NoMerges-Categorized", "VersionDate-HashSubjectAuthor-NoMerges-CategorizedSorted", "VersionDate-Subject-Merges", + "VersionDate-Subject-MergesWithPRLink-CategorizedSorted", "VersionDate-Subject-NoMerges-Categorized", "VersionDate-Subject-NoMerges-CategorizedSorted", "VersionDate-Subject-NoMerges", diff --git a/docs/samples/.vscode/tasks.submodule.json b/docs/samples/.vscode/tasks.submodule.json index 6c50589..15ee266 100644 --- a/docs/samples/.vscode/tasks.submodule.json +++ b/docs/samples/.vscode/tasks.submodule.json @@ -36,6 +36,7 @@ "VersionDate-HashSubjectAuthor-NoMerges-Categorized", "VersionDate-HashSubjectAuthor-NoMerges-CategorizedSorted", "VersionDate-Subject-Merges", + "VersionDate-Subject-MergesWithPRLink-CategorizedSorted", "VersionDate-Subject-NoMerges-Categorized", "VersionDate-Subject-NoMerges-CategorizedSorted", "VersionDate-Subject-NoMerges", diff --git a/src/PSRepositoryReleaseManager/Public/Generate-ReleaseNotes.ps1 b/src/PSRepositoryReleaseManager/Public/Generate-ReleaseNotes.ps1 index 9d2efb3..562685e 100644 --- a/src/PSRepositoryReleaseManager/Public/Generate-ReleaseNotes.ps1 +++ b/src/PSRepositoryReleaseManager/Public/Generate-ReleaseNotes.ps1 @@ -26,6 +26,7 @@ function Generate-ReleaseNotes { "VersionDate-HashSubjectAuthor-NoMerges-Categorized", "VersionDate-HashSubjectAuthor-NoMerges-CategorizedSorted", "VersionDate-Subject-Merges", + "VersionDate-Subject-MergesWithPRLink-CategorizedSorted", "VersionDate-Subject-NoMerges-Categorized", "VersionDate-Subject-NoMerges-CategorizedSorted", "VersionDate-Subject-NoMerges", diff --git a/src/PSRepositoryReleaseManager/generate/variants/VersionDate-Subject-MergesWithPRLink-CategorizedSorted.ps1 b/src/PSRepositoryReleaseManager/generate/variants/VersionDate-Subject-MergesWithPRLink-CategorizedSorted.ps1 new file mode 100644 index 0000000..7bd0b29 --- /dev/null +++ b/src/PSRepositoryReleaseManager/generate/variants/VersionDate-Subject-MergesWithPRLink-CategorizedSorted.ps1 @@ -0,0 +1,196 @@ +function VersionDate-Subject-MergesWithPRLink-CategorizedSorted { + [CmdletBinding()] + param( + [Parameter(Mandatory=$true)] + [ValidateScript({Test-Path -Path $_ -PathType Container})] + [string]$Path + , + [Parameter(Mandatory=$true)] + [ValidateNotNullOrEmpty()] + [string]$Ref + ) + + $ErrorActionPreference = 'Stop' + + try { + $previousRelease = Get-RepositoryReleasePrevious -Path $Path -Ref $Ref -ErrorAction SilentlyContinue + $funcArgs = @{ + Path = $Path + FirstRef = $Ref + PrettyFormat = '%h %B' + Merges = $true + } + if ($previousRelease) { $funcArgs['SecondRef'] = @($previousRelease)[0] } + $lines = @( Get-RepositoryCommitHistory @funcArgs ) + $commitHistoryCollection = & { + $next = $false + foreach ($l in $lines) { + if ($l -match '^[a-z0-9]{7}') { + $c = [System.Collections.ArrayList]@($l) + }else { + if ($l -match '^\s*$') { + $next = $true + continue + } + if ($next) { + $next = $false + $prNum = if ($c[0] -match 'Merge pull request #(\d+) from') { $matches[1] } else { 0 } + "$l ($prNum)" + } + } + } + } + $commitHistoryCategory = @( + @{ + Title = 'Breaking' + Name = @( + 'Breaking' + 'breaking-change' + ) + } + @{ + Title = 'Features' + Name = @( + 'Feature' + 'feat' + ) + } + @{ + Title = 'Enhancements' + Name = @( + 'Enhancement' + ) + } + @{ + Title = 'Performance' + Name = @( + 'Performance' + 'perf' + ) + } + @{ + Title = 'Change' + Name = @( + 'Change' + ) + } + @{ + Title = 'Refactors' + Name = @( + 'Refactor' + ) + } + @{ + Title = 'Build' + Name = @( + 'Build' + ) + } + @{ + Title = 'CI' + Name = @( + 'CI' + ) + } + @{ + Title = 'Tests' + Name = @( + 'Test' + ) + } + @{ + Title = 'Fixes' + Name = @( + 'Fix' + ) + } + @{ + Title = 'Style' + Name = @( + 'Style' + ) + } + @{ + Title = 'Documentation' + Name = @( + 'Docs' + ) + } + @{ + Title = 'Chore' + Name = @( + 'Chore' + ) + } + ) + $commitHistoryCategoryNone = @{ + Title = 'Others' + } + $commitHistoryCategorizedCollection = New-Object System.Collections.ArrayList + $commitHistoryUncategorizedCollection = New-Object System.Collections.ArrayList + $commitHistoryCollection | % { + if ($_ -match "^(\s*[a-zA-Z0-9_\-]+\s*)(\(\s*[a-zA-Z0-9_\-\/]+\s*\)\s*)*:(.+)") { + $commitHistoryCategorizedCollection.Add($_) > $null + }else { + $commitHistoryUncategorizedCollection.Add($_) > $null + } + } + $commitHistoryCategorizedCustomCollection = $commitHistoryCategorizedCollection | % { + $matchInfo = $_ | Select-String -Pattern "^(.+)" + if ($matchInfo) { + [PSCustomObject]@{ + Subject = $matchInfo.Matches.Groups[1].Value + } + } + } + $commitHistoryUncategorizedCustomCollection = $commitHistoryUncategorizedCollection | % { + $matchInfo = $_ | Select-String -Pattern "^(.+)" + if ($matchInfo) { + [PSCustomObject]@{ + Subject = $matchInfo.Matches.Groups[1].Value + } + } + } + $releaseBody = & { +@" +## $Ref ($(Get-Date -UFormat '%Y-%m-%d')) +"@ + foreach ($c in $commitHistoryCategory) { + $iscommitHistoryCategoryTitleOutputted = $false + $commitHistoryCategorizedCustomCollection | Sort-Object -Property Subject -CaseSensitive | % { + foreach ($n in $c['Name']) { + if ("$($_.Subject)" -match "^(\s*$n\s*)(\(\s*[a-zA-Z0-9_\-\/]+\s*\)\s*)*:(.+)") { + if (!$iscommitHistoryCategoryTitleOutputted) { +@" + +### $($c['Title']) + +"@ + $iscommitHistoryCategoryTitleOutputted = $true + } +@" +* $($_.Subject) +"@ + break + } + } + } + } + if ($commitHistoryUncategorizedCustomCollection) { +@" + +### $($commitHistoryCategoryNone['Title']) + +"@ + $commitHistoryUncategorizedCustomCollection | Sort-Object -Property Subject -CaseSensitive | % { +@" +* $($_.Subject) +"@ + } + } + } + $releaseBody + }catch { + Write-Error -Exception $_.Exception -Message $_.Exception.Message -Category $_.CategoryInfo.Category -TargetObject $_.TargetObject + } +}