Skip to content

Commit 3eec223

Browse files
authored
Change changelog script to use PSES syntax (#1486)
1 parent 6630390 commit 3eec223

File tree

1 file changed

+91
-16
lines changed

1 file changed

+91
-16
lines changed

tools/Get-PowerShellExtensionChangelog.ps1

Lines changed: 91 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,12 @@ $Script:powershell_team = @(
5252

5353
$Script:powershell_team_emails = @(
5454
"tylerl0706@gmail.com"
55+
"rjmholt@gmail.com"
5556
)
5657

58+
# Very active contributors; keep their email-login mappings here to save a few queries to Github.
59+
$Script:community_login_map = @{}
60+
5761
class CommitNode {
5862
[string] $Hash
5963
[string[]] $Parents
@@ -148,6 +152,66 @@ function New-CommitNode
148152
}
149153
}
150154

155+
function Get-PRNumberFromCommitSubject
156+
{
157+
param(
158+
[string]$CommitSubject
159+
)
160+
161+
if (-not $CommitSubject)
162+
{
163+
return $null
164+
}
165+
166+
if (-not ($CommitSubject -match '(.*)\(#(\d+)\)$'))
167+
{
168+
return $null
169+
}
170+
171+
return @{
172+
Message = $Matches[1]
173+
PR = $Matches[2]
174+
}
175+
}
176+
177+
function New-ChangeLogEntry
178+
{
179+
param(
180+
[ValidateNotNullOrEmpty()][string]$RepositoryName,
181+
[ValidateNotNullOrEmpty()][string]$CommitMessage,
182+
[int]$PRNumber,
183+
[string]$UserToThank,
184+
[switch]$IsBreakingChange
185+
)
186+
187+
$repoUrl = "https://github.com/PowerShell/$RepositoryName"
188+
189+
$entry = if ($PRNumber)
190+
{
191+
"- [$RepositoryName #$PRNumber]($repoUrl/pulls/$PRNumber) -"
192+
}
193+
else
194+
{
195+
"- [$RepositoryName]($repoUrl) -"
196+
}
197+
198+
$entry += "`n "
199+
200+
if ($IsBreakingChange)
201+
{
202+
$entry += "[Breaking Change] "
203+
}
204+
205+
$entry += $CommitMessage
206+
207+
if ($UserToThank)
208+
{
209+
$entry += " (Thanks @$UserToThank!)"
210+
}
211+
212+
return $entry
213+
}
214+
151215
##############################
152216
#.SYNOPSIS
153217
#Generate the draft change log of the git repo in the current directory
@@ -179,6 +243,9 @@ function Get-ChangeLog
179243
[Parameter(Mandatory)]
180244
[string]$RepoUri,
181245

246+
[Parameter(Mandatory)]
247+
[string]$RepoName,
248+
182249
[Parameter()]
183250
[switch]$HasCherryPick
184251
)
@@ -233,31 +300,39 @@ function Get-ChangeLog
233300
$new_commits = $new_commits_during_last_release + $new_commits_after_last_release
234301
}
235302

236-
# They are very active contributors, so we keep their email-login mappings here to save a few queries to Github.
237-
$community_login_map = @{}
238-
239303
foreach ($commit in $new_commits) {
240-
if ($commit.AuthorEmail.EndsWith("@microsoft.com") -or $powershell_team -contains $commit.AuthorName -or $powershell_team_emails -contains $commit.AuthorEmail) {
241-
$commit.ChangeLogMessage = "- {0}" -f $commit.Subject
242-
} else {
243-
if ($community_login_map.ContainsKey($commit.AuthorEmail)) {
244-
$commit.AuthorGitHubLogin = $community_login_map[$commit.AuthorEmail]
245-
} else {
304+
$messageParts = Get-PRNumberFromCommitSubject $commit.Subject
305+
if ($messageParts)
306+
{
307+
$message = $messageParts.Message
308+
$prNumber = $messageParts.PR
309+
}
310+
else
311+
{
312+
$message = $commit.Subject
313+
}
314+
315+
if (-not ($commit.AuthorEmail.EndsWith("@microsoft.com") -or ($powershell_team -contains $commit.AuthorName) -or ($powershell_team_emails -contains $commit.AuthorEmail)))
316+
{
317+
if ($Script:community_login_map.ContainsKey($commit.AuthorEmail))
318+
{
319+
$commit.AuthorGitHubLogin = $Script:community_login_map[$commit.AuthorEmail]
320+
}
321+
else
322+
{
246323
$uri = "$RepoUri/commits/$($commit.Hash)"
247324
$response = Invoke-WebRequest -Uri $uri -Method Get -Headers $header -ErrorAction SilentlyContinue
248325
if($response)
249326
{
250327
$content = ConvertFrom-Json -InputObject $response.Content
251328
$commit.AuthorGitHubLogin = $content.author.login
252-
$community_login_map[$commit.AuthorEmail] = $commit.AuthorGitHubLogin
329+
$Script:community_login_map[$commit.AuthorEmail] = $commit.AuthorGitHubLogin
253330
}
254331
}
255-
$commit.ChangeLogMessage = "- {0} (Thanks @{1}!)" -f $commit.Subject, $commit.AuthorGitHubLogin
332+
$userToThank = $commit.AuthorGitHubLogin
256333
}
257334

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

263338
$new_commits | Sort-Object -Descending -Property IsBreakingChange | ForEach-Object -MemberName ChangeLogMessage
@@ -301,9 +376,9 @@ function Get-PowerShellExtensionChangeLog {
301376
[switch]$HasCherryPick
302377
)
303378

304-
$vscodePowerShell = Get-ChangeLog -LastReleaseTag $LastReleaseTag -Token $Token -HasCherryPick:$HasCherryPick.IsPresent -RepoUri 'https://api.github.com/repos/PowerShell/vscode-powershell'
379+
$vscodePowerShell = Get-ChangeLog -LastReleaseTag $LastReleaseTag -Token $Token -HasCherryPick:$HasCherryPick.IsPresent -RepoUri 'https://api.github.com/repos/PowerShell/vscode-powershell' -RepoName 'vscode-PowerShell'
305380
Push-Location ../PowerShellEditorServices
306-
$pses = Get-ChangeLog -LastReleaseTag $LastReleaseTag -Token $Token -HasCherryPick:$HasCherryPick.IsPresent -RepoUri 'https://api.github.com/repos/PowerShell/PowerShellEditorServices'
381+
$pses = Get-ChangeLog -LastReleaseTag $LastReleaseTag -Token $Token -HasCherryPick:$HasCherryPick.IsPresent -RepoUri 'https://api.github.com/repos/PowerShell/PowerShellEditorServices' -RepoName 'PowerShellEditorServices'
307382
Pop-Location
308383

309384
return @"

0 commit comments

Comments
 (0)