|
| 1 | +function VersionDate-Subject-MergesWithPRLink-CategorizedSorted { |
| 2 | + [CmdletBinding()] |
| 3 | + param( |
| 4 | + [Parameter(Mandatory=$true)] |
| 5 | + [ValidateScript({Test-Path -Path $_ -PathType Container})] |
| 6 | + [string]$Path |
| 7 | + , |
| 8 | + [Parameter(Mandatory=$true)] |
| 9 | + [ValidateNotNullOrEmpty()] |
| 10 | + [string]$Ref |
| 11 | + ) |
| 12 | + |
| 13 | + $ErrorActionPreference = 'Stop' |
| 14 | + |
| 15 | + try { |
| 16 | + $previousRelease = Get-RepositoryReleasePrevious -Path $Path -Ref $Ref -ErrorAction SilentlyContinue |
| 17 | + $funcArgs = @{ |
| 18 | + Path = $Path |
| 19 | + FirstRef = $Ref |
| 20 | + PrettyFormat = '%h %B' |
| 21 | + Merges = $true |
| 22 | + } |
| 23 | + if ($previousRelease) { $funcArgs['SecondRef'] = @($previousRelease)[0] } |
| 24 | + $commitHistory = Get-RepositoryCommitHistory @funcArgs |
| 25 | + $commitHistoryCollection = & { |
| 26 | + $next = $false |
| 27 | + $commitHistory | ? { $_ } | % { |
| 28 | + if ($next -eq $false) { |
| 29 | + if ($_ -match '^[a-z0-9]{7} Merge pull request #(\d+) from .+') { |
| 30 | + $prNum = $matches[1] |
| 31 | + $next = $true |
| 32 | + } |
| 33 | + }else { |
| 34 | + "$_ (#$prNum)" |
| 35 | + $next = $false |
| 36 | + } |
| 37 | + } |
| 38 | + } |
| 39 | + $commitHistoryCategory = @( |
| 40 | + @{ |
| 41 | + Title = 'Breaking' |
| 42 | + Name = @( |
| 43 | + 'Breaking' |
| 44 | + 'breaking-change' |
| 45 | + ) |
| 46 | + } |
| 47 | + @{ |
| 48 | + Title = 'Features' |
| 49 | + Name = @( |
| 50 | + 'Feature' |
| 51 | + 'feat' |
| 52 | + ) |
| 53 | + } |
| 54 | + @{ |
| 55 | + Title = 'Enhancements' |
| 56 | + Name = @( |
| 57 | + 'Enhancement' |
| 58 | + ) |
| 59 | + } |
| 60 | + @{ |
| 61 | + Title = 'Performance' |
| 62 | + Name = @( |
| 63 | + 'Performance' |
| 64 | + 'perf' |
| 65 | + ) |
| 66 | + } |
| 67 | + @{ |
| 68 | + Title = 'Change' |
| 69 | + Name = @( |
| 70 | + 'Change' |
| 71 | + ) |
| 72 | + } |
| 73 | + @{ |
| 74 | + Title = 'Refactors' |
| 75 | + Name = @( |
| 76 | + 'Refactor' |
| 77 | + ) |
| 78 | + } |
| 79 | + @{ |
| 80 | + Title = 'Build' |
| 81 | + Name = @( |
| 82 | + 'Build' |
| 83 | + ) |
| 84 | + } |
| 85 | + @{ |
| 86 | + Title = 'CI' |
| 87 | + Name = @( |
| 88 | + 'CI' |
| 89 | + ) |
| 90 | + } |
| 91 | + @{ |
| 92 | + Title = 'Tests' |
| 93 | + Name = @( |
| 94 | + 'Test' |
| 95 | + ) |
| 96 | + } |
| 97 | + @{ |
| 98 | + Title = 'Fixes' |
| 99 | + Name = @( |
| 100 | + 'Fix' |
| 101 | + ) |
| 102 | + } |
| 103 | + @{ |
| 104 | + Title = 'Style' |
| 105 | + Name = @( |
| 106 | + 'Style' |
| 107 | + ) |
| 108 | + } |
| 109 | + @{ |
| 110 | + Title = 'Documentation' |
| 111 | + Name = @( |
| 112 | + 'Docs' |
| 113 | + ) |
| 114 | + } |
| 115 | + @{ |
| 116 | + Title = 'Chore' |
| 117 | + Name = @( |
| 118 | + 'Chore' |
| 119 | + ) |
| 120 | + } |
| 121 | + ) |
| 122 | + $commitHistoryCategoryNone = @{ |
| 123 | + Title = 'Others' |
| 124 | + } |
| 125 | + $commitHistoryCategorizedCollection = New-Object System.Collections.ArrayList |
| 126 | + $commitHistoryUncategorizedCollection = New-Object System.Collections.ArrayList |
| 127 | + $commitHistoryCollection | % { |
| 128 | + if ($_ -match "^(\s*[a-zA-Z0-9_\-]+\s*)(\(\s*[a-zA-Z0-9_\-\/]+\s*\)\s*)*:(.+)") { |
| 129 | + $commitHistoryCategorizedCollection.Add($_) > $null |
| 130 | + }else { |
| 131 | + $commitHistoryUncategorizedCollection.Add($_) > $null |
| 132 | + } |
| 133 | + } |
| 134 | + $commitHistoryCategorizedCustomCollection = $commitHistoryCategorizedCollection | % { |
| 135 | + $matchInfo = $_ | Select-String -Pattern "^(.+)" |
| 136 | + if ($matchInfo) { |
| 137 | + [PSCustomObject]@{ |
| 138 | + Subject = $matchInfo.Matches.Groups[1].Value |
| 139 | + } |
| 140 | + } |
| 141 | + } |
| 142 | + $commitHistoryUncategorizedCustomCollection = $commitHistoryUncategorizedCollection | % { |
| 143 | + $matchInfo = $_ | Select-String -Pattern "^(.+)" |
| 144 | + if ($matchInfo) { |
| 145 | + [PSCustomObject]@{ |
| 146 | + Subject = $matchInfo.Matches.Groups[1].Value |
| 147 | + } |
| 148 | + } |
| 149 | + } |
| 150 | + $releaseBody = & { |
| 151 | +@" |
| 152 | +## $Ref ($(Get-Date -UFormat '%Y-%m-%d')) |
| 153 | +"@ |
| 154 | + foreach ($c in $commitHistoryCategory) { |
| 155 | + $iscommitHistoryCategoryTitleOutputted = $false |
| 156 | + $commitHistoryCategorizedCustomCollection | Sort-Object -Property Subject -CaseSensitive | % { |
| 157 | + foreach ($n in $c['Name']) { |
| 158 | + if ("$($_.Subject)" -match "^(\s*$n\s*)(\(\s*[a-zA-Z0-9_\-\/]+\s*\)\s*)*:(.+)") { |
| 159 | + if (!$iscommitHistoryCategoryTitleOutputted) { |
| 160 | +@" |
| 161 | +
|
| 162 | +### $($c['Title']) |
| 163 | +
|
| 164 | +"@ |
| 165 | + $iscommitHistoryCategoryTitleOutputted = $true |
| 166 | + } |
| 167 | +@" |
| 168 | +* $($_.Subject) |
| 169 | +"@ |
| 170 | + break |
| 171 | + } |
| 172 | + } |
| 173 | + } |
| 174 | + } |
| 175 | + if ($commitHistoryUncategorizedCustomCollection) { |
| 176 | +@" |
| 177 | +
|
| 178 | +### $($commitHistoryCategoryNone['Title']) |
| 179 | +
|
| 180 | +"@ |
| 181 | + $commitHistoryUncategorizedCustomCollection | Sort-Object -Property Subject -CaseSensitive | % { |
| 182 | +@" |
| 183 | +* $($_.Subject) |
| 184 | +"@ |
| 185 | + } |
| 186 | + } |
| 187 | + } |
| 188 | + $releaseBody |
| 189 | + }catch { |
| 190 | + Write-Error -Exception $_.Exception -Message $_.Exception.Message -Category $_.CategoryInfo.Category -TargetObject $_.TargetObject |
| 191 | + } |
| 192 | +} |
0 commit comments