Skip to content

Change changelog script to use PSES syntax #1486

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 17, 2018
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
107 changes: 91 additions & 16 deletions tools/Get-PowerShellExtensionChangelog.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,12 @@ $Script:powershell_team = @(

$Script:powershell_team_emails = @(
"[email protected]"
"[email protected]"
)

# Very active contributors; keep their email-login mappings here to save a few queries to Github.
$Script:community_login_map = @{}

class CommitNode {
[string] $Hash
[string[]] $Parents
Expand Down Expand Up @@ -148,6 +152,66 @@ function New-CommitNode
}
}

function Get-PRNumberFromCommitSubject
{
param(
[string]$CommitSubject
)

if (-not $CommitSubject)
{
return $null
}

if (-not ($CommitSubject -match '(.*)\(#(\d+)\)$'))
{
return $null
}

return @{
Message = $Matches[1]
PR = $Matches[2]
}
}

function New-ChangeLogEntry
{
param(
[ValidateNotNullOrEmpty()][string]$RepositoryName,
[ValidateNotNullOrEmpty()][string]$CommitMessage,
[int]$PRNumber,
[string]$UserToThank,
[switch]$IsBreakingChange
)

$repoUrl = "https://github.com/PowerShell/$RepositoryName"

$entry = if ($PRNumber)
{
"- [$RepositoryName #$PRNumber]($repoUrl/pulls/$PRNumber) -"
}
else
{
"- [$RepositoryName]($repoUrl) -"
}

$entry += "`n "

if ($IsBreakingChange)
{
$entry += "[Breaking Change] "
}

$entry += $CommitMessage

if ($UserToThank)
{
$entry += " (Thanks @$UserToThank!)"
}

return $entry
}

##############################
#.SYNOPSIS
#Generate the draft change log of the git repo in the current directory
Expand Down Expand Up @@ -179,6 +243,9 @@ function Get-ChangeLog
[Parameter(Mandatory)]
[string]$RepoUri,

[Parameter(Mandatory)]
[string]$RepoName,

[Parameter()]
[switch]$HasCherryPick
)
Expand Down Expand Up @@ -233,31 +300,39 @@ function Get-ChangeLog
$new_commits = $new_commits_during_last_release + $new_commits_after_last_release
}

# They are very active contributors, so we keep their email-login mappings here to save a few queries to Github.
$community_login_map = @{}

foreach ($commit in $new_commits) {
if ($commit.AuthorEmail.EndsWith("@microsoft.com") -or $powershell_team -contains $commit.AuthorName -or $powershell_team_emails -contains $commit.AuthorEmail) {
$commit.ChangeLogMessage = "- {0}" -f $commit.Subject
} else {
if ($community_login_map.ContainsKey($commit.AuthorEmail)) {
$commit.AuthorGitHubLogin = $community_login_map[$commit.AuthorEmail]
} else {
$messageParts = Get-PRNumberFromCommitSubject $commit.Subject
if ($messageParts)
{
$message = $messageParts.Message
$prNumber = $messageParts.PR
}
else
{
$message = $commit.Subject
}

if (-not ($commit.AuthorEmail.EndsWith("@microsoft.com") -or ($powershell_team -contains $commit.AuthorName) -or ($powershell_team_emails -contains $commit.AuthorEmail)))
{
if ($Script:community_login_map.ContainsKey($commit.AuthorEmail))
{
$commit.AuthorGitHubLogin = $Script:community_login_map[$commit.AuthorEmail]
}
else
{
$uri = "$RepoUri/commits/$($commit.Hash)"
$response = Invoke-WebRequest -Uri $uri -Method Get -Headers $header -ErrorAction SilentlyContinue
if($response)
{
$content = ConvertFrom-Json -InputObject $response.Content
$commit.AuthorGitHubLogin = $content.author.login
$community_login_map[$commit.AuthorEmail] = $commit.AuthorGitHubLogin
$Script:community_login_map[$commit.AuthorEmail] = $commit.AuthorGitHubLogin
}
}
$commit.ChangeLogMessage = "- {0} (Thanks @{1}!)" -f $commit.Subject, $commit.AuthorGitHubLogin
$userToThank = $commit.AuthorGitHubLogin
}

if ($commit.IsBreakingChange) {
$commit.ChangeLogMessage = "{0} [Breaking Change]" -f $commit.ChangeLogMessage
}
$commit.ChangeLogMessage = New-ChangeLogEntry -RepositoryName $RepoName -CommitMessage $message -PRNumber $prNumber -UserToThank $userToThank -IsBreakingChange:$commit.IsBreakingChange
}

$new_commits | Sort-Object -Descending -Property IsBreakingChange | ForEach-Object -MemberName ChangeLogMessage
Expand Down Expand Up @@ -301,9 +376,9 @@ function Get-PowerShellExtensionChangeLog {
[switch]$HasCherryPick
)

$vscodePowerShell = Get-ChangeLog -LastReleaseTag $LastReleaseTag -Token $Token -HasCherryPick:$HasCherryPick.IsPresent -RepoUri 'https://api.github.com/repos/PowerShell/vscode-powershell'
$vscodePowerShell = Get-ChangeLog -LastReleaseTag $LastReleaseTag -Token $Token -HasCherryPick:$HasCherryPick.IsPresent -RepoUri 'https://api.github.com/repos/PowerShell/vscode-powershell' -RepoName 'vscode-PowerShell'
Push-Location ../PowerShellEditorServices
$pses = Get-ChangeLog -LastReleaseTag $LastReleaseTag -Token $Token -HasCherryPick:$HasCherryPick.IsPresent -RepoUri 'https://api.github.com/repos/PowerShell/PowerShellEditorServices'
$pses = Get-ChangeLog -LastReleaseTag $LastReleaseTag -Token $Token -HasCherryPick:$HasCherryPick.IsPresent -RepoUri 'https://api.github.com/repos/PowerShell/PowerShellEditorServices' -RepoName 'PowerShellEditorServices'
Pop-Location

return @"
Expand Down