-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: Add
VersionDate-Subject-MergesWithPRLink-CategorizedSorted
…
… variant
- Loading branch information
1 parent
0042d75
commit 3555a26
Showing
4 changed files
with
199 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
196 changes: 196 additions & 0 deletions
196
...leaseManager/generate/variants/VersionDate-Subject-MergesWithPRLink-CategorizedSorted.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
} |