Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 59 additions & 5 deletions utilities/tools/Get-FormattedGitHubRelease.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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\].+" }
Expand All @@ -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
}