From 0e887311bfaa042441b53dd95d6c0961ebb375b2 Mon Sep 17 00:00:00 2001 From: Joel Timothy Oh Date: Mon, 20 May 2024 13:59:29 +0000 Subject: [PATCH] Enhancement (generate): Add variants supporting commit categories and authors in release notes --- .vscode/tasks.json | 3 + .../Public/Generate-ReleaseNotes.ps1 | 3 + ...HashSubjectAuthor-NoMerges-Categorized.ps1 | 104 ++++++++++++++++++ ...HashSubjectAuthor-NoMerges-Categorized.ps1 | 104 ++++++++++++++++++ ...ate-SubjectAuthor-NoMerges-Categorized.ps1 | 104 ++++++++++++++++++ 5 files changed, 318 insertions(+) create mode 100644 src/PSRepositoryReleaseManager/generate/variants/Changes-HashSubjectAuthor-NoMerges-Categorized.ps1 create mode 100644 src/PSRepositoryReleaseManager/generate/variants/VersionDate-HashSubjectAuthor-NoMerges-Categorized.ps1 create mode 100644 src/PSRepositoryReleaseManager/generate/variants/VersionDate-SubjectAuthor-NoMerges-Categorized.ps1 diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 255cc72..85d38e4 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -20,14 +20,17 @@ "description": "RELEASE_NOTES_VARIANT?", "type": "pickString", "options": [ + "Changes-HashSubjectAuthor-NoMerges-Categorized", "Changes-HashSubject-Merges", "Changes-HashSubject-NoMerges-Categorized", "Changes-HashSubject-NoMerges", "Changes-HashSubject", + "VersionDate-HashSubjectAuthor-NoMerges-Categorized", "VersionDate-HashSubject-Merges", "VersionDate-HashSubject-NoMerges-Categorized", "VersionDate-HashSubject-NoMerges", "VersionDate-HashSubject", + "VersionDate-SubjectAuthor-NoMerges-Categorized", "VersionDate-Subject-Merges", "VersionDate-Subject-NoMerges-Categorized", "VersionDate-Subject-NoMerges", diff --git a/src/PSRepositoryReleaseManager/Public/Generate-ReleaseNotes.ps1 b/src/PSRepositoryReleaseManager/Public/Generate-ReleaseNotes.ps1 index 149c8a9..db945fe 100644 --- a/src/PSRepositoryReleaseManager/Public/Generate-ReleaseNotes.ps1 +++ b/src/PSRepositoryReleaseManager/Public/Generate-ReleaseNotes.ps1 @@ -12,14 +12,17 @@ function Generate-ReleaseNotes { , [Parameter(Mandatory=$true)] [ValidateSet( + "Changes-HashSubjectAuthor-NoMerges-Categorized", "Changes-HashSubject-Merges", "Changes-HashSubject-NoMerges-Categorized", "Changes-HashSubject-NoMerges", "Changes-HashSubject", + "VersionDate-HashSubjectAuthor-NoMerges-Categorized", "VersionDate-HashSubject-Merges", "VersionDate-HashSubject-NoMerges-Categorized", "VersionDate-HashSubject-NoMerges", "VersionDate-HashSubject", + "VersionDate-SubjectAuthor-NoMerges-Categorized", "VersionDate-Subject-Merges", "VersionDate-Subject-NoMerges-Categorized", "VersionDate-Subject-NoMerges", diff --git a/src/PSRepositoryReleaseManager/generate/variants/Changes-HashSubjectAuthor-NoMerges-Categorized.ps1 b/src/PSRepositoryReleaseManager/generate/variants/Changes-HashSubjectAuthor-NoMerges-Categorized.ps1 new file mode 100644 index 0000000..877aa33 --- /dev/null +++ b/src/PSRepositoryReleaseManager/generate/variants/Changes-HashSubjectAuthor-NoMerges-Categorized.ps1 @@ -0,0 +1,104 @@ +function Changes-HashSubjectAuthor-NoMerges-Categorized { + [CmdletBinding()] + param( + [Parameter(Mandatory=$true)] + [ValidateScript({Test-Path -Path $_ -PathType Container})] + [string]$Path + , + [Parameter(Mandatory=$true)] + [ValidateNotNullOrEmpty()] + [string]$TagName + ) + + $ErrorActionPreference = 'Stop' + + try { + $previousRelease = Get-RepositoryReleasePrevious -Path $Path -Ref $TagName -ErrorAction SilentlyContinue + if ($previousRelease) { + "Previous release:" | Write-Verbose + $previousRelease | Write-Verbose + } + $funcArgs = @{ + Path = $Path + FirstRef = $TagName + PrettyFormat = '%h %s - `%aN`' + NoMerges = $true + } + if ($previousRelease) { $funcArgs['SecondRef'] = @($previousRelease)[0] } + $commitHistory = Get-RepositoryCommitHistory @funcArgs + $commitHistoryTrimmed = $commitHistory -split "`n" | % { $_.Trim() } | ? { $_ } + $commitCategory = @( + @{ + Name = 'Feature' + Title = 'Features' + } + @{ + Name = 'Enhancement' + Title = 'Enhancements' + } + @{ + Name = 'Refactor' + Title = 'Refactors' + } + @{ + Name = 'Test' + Title = 'Tests' + } + @{ + Name = 'Fix' + Title = 'Fixes' + } + @{ + Name = 'Docs' + Title = 'Documentation' + } + @{ + Name = 'Chore' + Title = 'Chores' + } + ) + $commitHistoryUncategorized = $commitHistoryTrimmed | % { + if (!($_ -match "^[0-9a-f]+ (\s*\w+\s*\(\s*[a-zA-Z0-9_-]+\s*\)\s*:)(.+)")) { + $_ + } + } + $releaseBody = & { +@" +## Changes +"@ + foreach ($c in $commitCategory) { + $isTitleOutputted = $false + $commitHistoryTrimmed | % { + if ($_ -match "^[0-9a-f]+ (\s*$($c['Name'])\s*\(\s*[a-zA-Z0-9_-]+\s*\)\s*:)(.+)") { + if (!$isTitleOutputted) { +@" + +### $($c['Title']) + +"@ + $isTitleOutputted = $true + } +@" +* $_ +"@ + } + } + } + if ($commitHistoryUncategorized) { +@" + +### Others + +"@ + $commitHistoryUncategorized | % { +@" +* $_ +"@ + } + } + } + $releaseBody + }catch { + Write-Error -Exception $_.Exception -Message $_.Exception.Message -Category $_.CategoryInfo.Category -TargetObject $_.TargetObject + } +} diff --git a/src/PSRepositoryReleaseManager/generate/variants/VersionDate-HashSubjectAuthor-NoMerges-Categorized.ps1 b/src/PSRepositoryReleaseManager/generate/variants/VersionDate-HashSubjectAuthor-NoMerges-Categorized.ps1 new file mode 100644 index 0000000..1ec7722 --- /dev/null +++ b/src/PSRepositoryReleaseManager/generate/variants/VersionDate-HashSubjectAuthor-NoMerges-Categorized.ps1 @@ -0,0 +1,104 @@ +function VersionDate-HashSubjectAuthor-NoMerges-Categorized { + [CmdletBinding()] + param( + [Parameter(Mandatory=$true)] + [ValidateScript({Test-Path -Path $_ -PathType Container})] + [string]$Path + , + [Parameter(Mandatory=$true)] + [ValidateNotNullOrEmpty()] + [string]$TagName + ) + + $ErrorActionPreference = 'Stop' + + try { + $previousRelease = Get-RepositoryReleasePrevious -Path $Path -Ref $TagName -ErrorAction SilentlyContinue + if ($previousRelease) { + "Previous release:" | Write-Verbose + $previousRelease | Write-Verbose + } + $funcArgs = @{ + Path = $Path + FirstRef = $TagName + PrettyFormat = '%h %s - `%aN`' + NoMerges = $true + } + if ($previousRelease) { $funcArgs['SecondRef'] = @($previousRelease)[0] } + $commitHistory = Get-RepositoryCommitHistory @funcArgs + $commitHistoryTrimmed = $commitHistory -split "`n" | % { $_.Trim() } | ? { $_ } + $commitCategory = @( + @{ + Name = 'Feature' + Title = 'Features' + } + @{ + Name = 'Enhancement' + Title = 'Enhancements' + } + @{ + Name = 'Refactor' + Title = 'Refactors' + } + @{ + Name = 'Test' + Title = 'Tests' + } + @{ + Name = 'Fix' + Title = 'Fixes' + } + @{ + Name = 'Docs' + Title = 'Documentation' + } + @{ + Name = 'Chore' + Title = 'Chores' + } + ) + $commitHistoryUncategorized = $commitHistoryTrimmed | % { + if (!($_ -match "^[0-9a-f]+ (\s*\w+\s*\(\s*[a-zA-Z0-9_-]+\s*\)\s*:)(.+)")) { + $_ + } + } + $releaseBody = & { +@" +## $TagName ($(Get-Date -UFormat '%Y-%m-%d')) +"@ + foreach ($c in $commitCategory) { + $isTitleOutputted = $false + $commitHistoryTrimmed | % { + if ($_ -match "^[0-9a-f]+ (\s*$($c['Name'])\s*\(\s*[a-zA-Z0-9_-]+\s*\)\s*:)(.+)") { + if (!$isTitleOutputted) { +@" + +### $($c['Title']) + +"@ + $isTitleOutputted = $true + } +@" +* $_ +"@ + } + } + } + if ($commitHistoryUncategorized) { +@" + +### Others + +"@ + $commitHistoryUncategorized | % { +@" +* $_ +"@ + } + } + } + $releaseBody + }catch { + Write-Error -Exception $_.Exception -Message $_.Exception.Message -Category $_.CategoryInfo.Category -TargetObject $_.TargetObject + } +} diff --git a/src/PSRepositoryReleaseManager/generate/variants/VersionDate-SubjectAuthor-NoMerges-Categorized.ps1 b/src/PSRepositoryReleaseManager/generate/variants/VersionDate-SubjectAuthor-NoMerges-Categorized.ps1 new file mode 100644 index 0000000..364df2f --- /dev/null +++ b/src/PSRepositoryReleaseManager/generate/variants/VersionDate-SubjectAuthor-NoMerges-Categorized.ps1 @@ -0,0 +1,104 @@ +function VersionDate-SubjectAuthor-NoMerges-Categorized { + [CmdletBinding()] + param( + [Parameter(Mandatory=$true)] + [ValidateScript({Test-Path -Path $_ -PathType Container})] + [string]$Path + , + [Parameter(Mandatory=$true)] + [ValidateNotNullOrEmpty()] + [string]$TagName + ) + + $ErrorActionPreference = 'Stop' + + try { + $previousRelease = Get-RepositoryReleasePrevious -Path $Path -Ref $TagName -ErrorAction SilentlyContinue + if ($previousRelease) { + "Previous release:" | Write-Verbose + $previousRelease | Write-Verbose + } + $funcArgs = @{ + Path = $Path + FirstRef = $TagName + PrettyFormat = '%s - `%aN`' + NoMerges = $true + } + if ($previousRelease) { $funcArgs['SecondRef'] = @($previousRelease)[0] } + $commitHistory = Get-RepositoryCommitHistory @funcArgs + $commitHistoryTrimmed = $commitHistory -split "`n" | % { $_.Trim() } | ? { $_ } + $commitCategory = @( + @{ + Name = 'Feature' + Title = 'Features' + } + @{ + Name = 'Enhancement' + Title = 'Enhancements' + } + @{ + Name = 'Refactor' + Title = 'Refactors' + } + @{ + Name = 'Test' + Title = 'Tests' + } + @{ + Name = 'Fix' + Title = 'Fixes' + } + @{ + Name = 'Docs' + Title = 'Documentation' + } + @{ + Name = 'Chore' + Title = 'Chores' + } + ) + $commitHistoryUncategorized = $commitHistoryTrimmed | % { + if (!($_ -match "^(\s*\w+\s*\(\s*[a-zA-Z0-9_-]+\s*\)\s*:)(.+)")) { + $_ + } + } + $releaseBody = & { +@" +## $TagName ($(Get-Date -UFormat '%Y-%m-%d')) +"@ + foreach ($c in $commitCategory) { + $isTitleOutputted = $false + $commitHistoryTrimmed | % { + if ($_ -match "^(\s*$($c['Name'])\s*\(\s*[a-zA-Z0-9_-]+\s*\)\s*:)(.+)") { + if (!$isTitleOutputted) { +@" + +### $($c['Title']) + +"@ + $isTitleOutputted = $true + } +@" +* $_ +"@ + } + } + } + if ($commitHistoryUncategorized) { +@" + +### Others + +"@ + $commitHistoryUncategorized | % { +@" +* $_ +"@ + } + } + } + $releaseBody + }catch { + Write-Error -Exception $_.Exception -Message $_.Exception.Message -Category $_.CategoryInfo.Category -TargetObject $_.TargetObject + } +}