diff --git a/utilities/tools/Get-FormattedGitHubRelease.ps1 b/utilities/tools/Get-FormattedGitHubRelease.ps1 index 38f00ebe7b..1f90b4844b 100644 --- a/utilities/tools/Get-FormattedGitHubRelease.ps1 +++ b/utilities/tools/Get-FormattedGitHubRelease.ps1 @@ -78,17 +78,21 @@ function Get-FormattedGitHubRelease { Write-Error "Request failed. Reponse: [$response]" } - $content = $response.Body -split '\n' | Where-Object { + $changedContent = $response.Body -split '\n' | Where-Object { $_ -like '`**' -and # For example: * [Modules] Update scope @carml in https://github.com/Azure/ResourceModules/pull/0 $_ -notlike '`* @*' -and # For example: @carml made their first contribution in https://github.com/Azure/ResourceModules/pull/0 $_ -notlike '`*`**' # For example: **Full Changelog**: https://github.com/Azure/ResourceModules/compare/v0.0.0...v1.0.0 } + $newContributorsContent = $response.Body -split '\n' | Where-Object { + $_ -like '`* @*' # For example: @carml made their first contribution in https://github.com/Azure/ResourceModules/pull/0 + } + # =================== # # Analyze content # # =================== # - $correctlyFormatted = $content | Where-Object { $_ -match '$* \[.*' } - $incorrectlyFormatted = $content | Where-Object { $_ -notmatch '$* \[.*' } + $correctlyFormatted = $changedContent | Where-Object { $_ -match '$* \[.*' } + $incorrectlyFormatted = $changedContent | Where-Object { $_ -notmatch '$* \[.*' } if ($incorrectlyFormatted.Count -gt 0) { Write-Verbose '#############################' -Verbose @@ -102,13 +106,29 @@ function Get-FormattedGitHubRelease { # Process content # # =================== # $categories = @() + $contributors = @() foreach ($line in $correctlyFormatted) { - $match = [regex]::Match($line, '\[(.+?)\].+') - $categories += $match.Captures.Groups[1].Value + $matchCategory = [regex]::Match($line, '\[(.+?)\].+') + $categories += $matchCategory.Captures.Groups[1].Value + $matchContributor = [regex]::Match($line, 'by \@(.*?)\s') + $contributors += $matchContributor.Value } $foundCategories = $categories | Select-Object -Unique + $foundContributors = $contributors | Select-Object -Unique + + $newContributors = @() + foreach ($line in $newContributorsContent) { + $matchNewContributor = [regex]::Match($line, '\@(.*?)\s') + $newContributors += $matchNewContributor.Value + } $output = @() + + # PRs by category # + # =================== # + $output += '' + $output += '### Highlights' + $output += '' foreach ($category in $foundCategories) { $output += "***$category***" $categoryItems = $correctlyFormatted | Where-Object { $_ -imatch ".+\[$category\].+" } @@ -123,5 +143,39 @@ function Get-FormattedGitHubRelease { $output += '' } + # Contributors # + # ================ # + $output += '' + $output += '### Contributors' + $output += '' + $output += '| GH handle | GH name |' + $output += '| :-- | :-- |' + foreach ($contributor in $foundContributors) { + $contributorHandle = $contributor -replace 'by @', '' + $requestInputObject = @{ + Method = 'GET' + Uri = "https://api.github.com/users/$contributorHandle" + Headers = @{ + Authorization = "Bearer $PersonalAccessToken" + } + } + $response = Invoke-RestMethod @requestInputObject + $contributorName = $response.name + $contributorNames += $contributorName + ', ' + $output += ('| {0} | {1} |' -f $contributorHandle, $contributorName) + } + + $output += '' + $output += '* CC: ' + $contributorNames + + # Statistics # + # ================ # + $output += '' + $output += '### Statistics' + $output += '' + $output += "* Count of Merged PRs: $($changedContent.count)" + $output += "* Count of Contributors: $($foundContributors.count)" + $output += "* Count of New Contributors: $($newContributors.count)" + $output += '' return $output }