diff --git a/.vscode/tasks.json b/.vscode/tasks.json index ce96fb1..27edcde 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-MergesWithPRLinkFromMerges-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..b4518af 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-MergesWithPRLinkFromMerges-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..a23997d 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-MergesWithPRLinkFromMerges-CategorizedSorted", "VersionDate-Subject-NoMerges-Categorized", "VersionDate-Subject-NoMerges-CategorizedSorted", "VersionDate-Subject-NoMerges", diff --git a/src/PSRepositoryReleaseManager/generate/variants/VersionDate-Subject-MergesWithPRLinkFromMerges-CategorizedSorted.ps1 b/src/PSRepositoryReleaseManager/generate/variants/VersionDate-Subject-MergesWithPRLinkFromMerges-CategorizedSorted.ps1 new file mode 100644 index 0000000..f2a10d6 --- /dev/null +++ b/src/PSRepositoryReleaseManager/generate/variants/VersionDate-Subject-MergesWithPRLinkFromMerges-CategorizedSorted.ps1 @@ -0,0 +1,196 @@ +function VersionDate-Subject-MergesWithPRLinkFromMerges-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] } + $commitHistoryMerges = @( Get-RepositoryCommitHistory @funcArgs ) + $commitHistoryCollection = @( + & { + $lines = @( $commitHistoryMerges -split "`n" | % { $_.Trim() } | ? { $_ } ) + if ($lines.Count % 2) { + throw "The subject and commit body of all commits must be 1 line each" + } + if ($lines.Count -ge 2) { + $i = 0 + $lines | % { + $prNum = if ($lines[$i] -match 'Merge pull request #(\d+) from') { $matches[1] } else { 0 } + if ($i -lt $lines.Count - 1 -and $prNum) { + "$( $lines[$i+1] ) (#$prNum)" + } + $i++ + } + } + } + ) + $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 + } +}