Skip to content

Commit

Permalink
Enhancement (generate): Add variants supporting commit categories and…
Browse files Browse the repository at this point in the history
… authors in release notes
  • Loading branch information
joeltimothyoh committed May 20, 2024
1 parent 95b5680 commit 0e88731
Show file tree
Hide file tree
Showing 5 changed files with 318 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
}
Original file line number Diff line number Diff line change
@@ -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
}
}
Original file line number Diff line number Diff line change
@@ -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
}
}

0 comments on commit 0e88731

Please sign in to comment.