Skip to content

Commit 6a676e4

Browse files
Robert Holtrjmholt
Robert Holt
authored andcommitted
Add verbosity, fix whitespace bugs
1 parent caa3bb4 commit 6a676e4

File tree

3 files changed

+83
-42
lines changed

3 files changed

+83
-42
lines changed

tools/ChangelogTools.psm1

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ filter Get-ChangeInfoFromCommit
6666

6767
foreach ($singleCommit in $Commit)
6868
{
69+
Write-Verbose "Getting change information for commit $($Commit.Hash)"
70+
6971
$changelogItem = [ChangeInfo]@{
7072
Commit = $singleCommit
7173
BodyText = $singleCommit.Body
@@ -163,6 +165,8 @@ filter New-ChangelogEntry
163165
$subject = $Matches[1]
164166
}
165167

168+
Write-Verbose "Assembled changelog entry for commit $($Change.Commit.Hash)"
169+
166170
return [ChangelogEntry]@{
167171
IssueLink = $issueLink
168172
PRLink = $prLink
@@ -338,15 +342,19 @@ filter Skip-IgnoredChange
338342

339343
:outer foreach ($chg in $Change)
340344
{
345+
$msg = $chg.Subject
341346
if ($chg.ContributingUser -in $User)
342347
{
348+
$u = $chg.ContributingUser
349+
Write-Verbose "Skipping change from user '$u': '$msg'"
343350
continue
344351
}
345352

346353
foreach ($chgCommitLabel in $chg.Commit.CommitLabels)
347354
{
348355
if ($chgCommitLabel -in $CommitLabel)
349356
{
357+
Write-Verbose "Skipping change with commit label '$chgCommitLabel': '$msg'"
350358
continue outer
351359
}
352360
}
@@ -355,6 +363,7 @@ filter Skip-IgnoredChange
355363
{
356364
if ($chgIssueLabel -in $IssueLabel)
357365
{
366+
Write-Verbose "Skipping change with issue label '$chgIssueLabel': '$msg'"
358367
continue outer
359368
}
360369
}
@@ -363,6 +372,7 @@ filter Skip-IgnoredChange
363372
{
364373
if ($chgPRLabel -in $PRLabel)
365374
{
375+
Write-Verbose "Skipping change with PR label '$chgPRLabel': '$msg'"
366376
continue outer
367377
}
368378
}

tools/GitHubTools.psm1

Lines changed: 45 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,8 @@ function Copy-GitRepository
288288
New-Item -Path $containingDir -ItemType Directory -ErrorAction Stop
289289
}
290290

291+
Write-Verbose "Cloning git repository '$OriginRemote' to path '$Destination'"
292+
291293
Exec { git clone --single-branch --branch $CloneBranch $OriginRemote $Destination }
292294

293295
Push-Location $Destination
@@ -335,9 +337,9 @@ function Submit-GitChanges
335337
[string]
336338
$Branch,
337339

338-
[Parameter(Mandatory)]
340+
[Parameter()]
339341
[string]
340-
$RepositoryLocation,
342+
$RepositoryLocation = (Get-Location),
341343

342344
[Parameter()]
343345
[string[]]
@@ -369,6 +371,9 @@ function Submit-GitChanges
369371
{
370372
Exec { git add -A }
371373
}
374+
375+
Write-Verbose "Commiting and pushing changes in '$RepositoryLocation' to '$Remote/$Branch'"
376+
372377
Exec { git commit -m $Message }
373378
Exec { git push $Remote $Branch }
374379
}
@@ -429,6 +434,8 @@ function Get-GitCommit
429434
$organization = $originDetails.Organization
430435
$repository = $originDetails.Repository
431436

437+
Write-Verbose "Getting local git commit data"
438+
432439
$format = '%H||%P||%aN||%aE||%s'
433440
$commits = Exec { git --no-pager log "$SinceRef..$UntilRef" --format=$format }
434441

@@ -457,6 +464,7 @@ function Get-GitCommit
457464
}
458465

459466
# Query the GitHub API for more commit information
467+
Write-Verbose "Querying GitHub api for data on commit $hash"
460468
$commitVal.GitHubCommitData = Invoke-RestMethod -Method Get -Uri "https://api.github.com/repos/$organization/$repository/commits/$hash" @irmParams
461469

462470
# Look for something like 'This is a commit message (#1224)'
@@ -537,6 +545,7 @@ function New-GitHubPR
537545

538546
$headers = GetGitHubHeaders -GitHubToken $GitHubToken -Accept 'application/vnd.github.v3+json'
539547

548+
Write-Verbose "Opening new GitHub pull request on '$Organization/$Repository' with title '$Title'"
540549
Invoke-RestMethod -Method Post -Uri $uri -Body $body -Headers $headers
541550
}
542551

@@ -573,6 +582,8 @@ function Get-GitHubPR
573582
$params.Headers = GetGitHubHeaders -GitHubToken $GitHubToken
574583
}
575584

585+
Write-Verbose "Retrieving GitHub pull request #$_"
586+
576587
$prResponse = Invoke-RestMethod @params
577588

578589
[GitHubPR]@{
@@ -591,7 +602,7 @@ filter Get-GitHubIssue
591602
[CmdletBinding(DefaultParameterSetName='IssueInfo')]
592603
param(
593604
[Parameter(Mandatory, ValueFromPipeline, Position=0, ParameterSetName='IssueInfo')]
594-
[GitHubIssueInfo]
605+
[GitHubIssueInfo[]]
595606
$IssueInfo,
596607

597608
[Parameter(Mandatory, ParameterSetName='Params')]
@@ -612,34 +623,38 @@ filter Get-GitHubIssue
612623
$GitHubToken
613624
)
614625

615-
if (-not $IssueInfo)
626+
foreach ($issue in $IssueInfo)
616627
{
617-
$IssueInfo = [GitHubIssueInfo]@{
618-
Organization = $Organization
619-
Repository = $Repository
620-
Number = $Number
628+
if (-not $issue)
629+
{
630+
$issue = [GitHubIssueInfo]@{
631+
Organization = $Organization
632+
Repository = $Repository
633+
Number = $Number
634+
}
621635
}
622-
}
623636

624-
$irmParams = @{
625-
Method = 'Get'
626-
Uri = $IssueInfo.GetApiUri()
627-
}
637+
$irmParams = @{
638+
Method = 'Get'
639+
Uri = $IssueInfo.GetApiUri()
640+
}
628641

629-
if ($GitHubToken)
630-
{
631-
$irmParams.Headers = GetGitHubHeaders -GitHubToken $GitHubToken
632-
}
642+
if ($GitHubToken)
643+
{
644+
$irmParams.Headers = GetGitHubHeaders -GitHubToken $GitHubToken
645+
}
633646

634-
$issueResponse = Invoke-RestMethod @irmParams
647+
Write-Verbose "Retrieving GitHub issue #$($issue.Number)"
648+
$issueResponse = Invoke-RestMethod @irmParams
635649

636-
return [GitHubIssue]@{
637-
Organization = $IssueInfo.Organization
638-
Repository = $IssueInfo.Repository
639-
Number = $IssueInfo.Number
640-
RawResponse = $issueResponse
641-
Body = $issueResponse.body
642-
Labels = $issueResponse.labels.name
650+
return [GitHubIssue]@{
651+
Organization = $issue.Organization
652+
Repository = $issue.Repository
653+
Number = $issue.Number
654+
RawResponse = $issueResponse
655+
Body = $issueResponse.body
656+
Labels = $issueResponse.labels.name
657+
}
643658
}
644659
}
645660

@@ -703,6 +718,8 @@ function Publish-GitHubRelease
703718
$uri = "https://api.github.com/repos/$Organization/$Repository/releases"
704719
$headers = GetGitHubHeaders -GitHubToken $GitHubToken -Accept 'application/vnd.github.v3+json'
705720

721+
Write-Verbose "Publishing GitHub release '$ReleaseName' to $Organization/$Repository"
722+
706723
$response = Invoke-RestMethod -Method Post -Uri $uri -Body $restBody -Headers $headers
707724

708725
$releaseId = $response.id
@@ -729,6 +746,9 @@ function Publish-GitHubRelease
729746

730747
$assetUri = "${assetBaseUri}?name=$fileName"
731748
$headers = GetGitHubHeaders -GitHubToken $GitHubToken
749+
750+
Write-Verbose "Uploading release asset '$fileName' to release '$ReleaseName' in $Organization/$Repository"
751+
732752
# This can be very slow, but it does work
733753
$null = Invoke-RestMethod -Method Post -Uri $assetUri -InFile $asset -ContentType $contentType -Headers $headers
734754
}

tools/changelog/updateChangelog.ps1

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using module ..\GitHubTools.psm1
77
using module ..\ChangelogTools.psm1
88

9+
[CmdletBinding()]
910
param(
1011
[Parameter(Mandatory)]
1112
[string]
@@ -60,13 +61,17 @@ function UpdateChangelogFile
6061
$Path
6162
)
6263

64+
Write-Verbose "Writing new changelog section to '$Path'"
65+
6366
$changelogLines = Get-Content -Path $Path
6467
$newContent = ($changelogLines[0..1] -join "`n`n") + $NewSection + ($changelogLines[2..$changelogLines.Length] -join "`n")
6568
Set-Content -Encoding utf8NoBOM -Value $newContent -Path $Path
6669
}
6770

6871
#region Configuration
6972

73+
Write-Verbose "Configuring settings"
74+
7075
$vscodeRepoName = 'vscode-PowerShell'
7176
$psesRepoName = 'PowerShellEditorServices'
7277

@@ -134,11 +139,15 @@ $clSectionParams = @{
134139
DateFormat = $dateFormat
135140
}
136141

137-
$psesChangelogSection = Get-GitCommit -SinceRef $SinceRef -UntilRef $UntilRef -GitHubToken $GitHubToken -RepositoryPath $PsesRepositoryPath |
138-
Get-ChangeInfoFromCommit -GitHubToken $GitHubToken |
139-
Skip-IgnoredChange @ignore |
140-
New-ChangelogEntry @clEntryParams |
141-
New-ChangelogSection @clSectionParams
142+
Write-Verbose "Creating PSES changelog"
143+
144+
$psesChangelogSection = Get-GitCommit -SinceRef $SinceRef -UntilRef $UntilRef -GitHubToken $GitHubToken -RepositoryPath $PsesRepositoryPath -Verbose:$VerbosePreference |
145+
Get-ChangeInfoFromCommit -GitHubToken $GitHubToken -Verbose:$VerbosePreference |
146+
Skip-IgnoredChange @ignore -Verbose:$VerbosePreference |
147+
New-ChangelogEntry @clEntryParams -Verbose:$VerbosePreference |
148+
New-ChangelogSection @clSectionParams -Verbose:$VerbosePreference
149+
150+
Write-Host "PSES CHANGELOG:`n`n$psesChangelogSection`n`n"
142151

143152
$cloneLocation = Join-Path ([System.IO.Path]::GetTempPath()) "${psesRepoName}_changelogupdate"
144153

@@ -148,24 +157,26 @@ $cloneParams = @{
148157
CheckoutBranch = $branchName
149158
Clobber = $true
150159
}
151-
Copy-GitRepository @cloneParams
160+
Copy-GitRepository @cloneParams -Verbose:$VerbosePreference
152161

153162
UpdateChangelogFile -NewSection $psesChangelogSection -Path "$cloneLocation/$ChangelogName"
154163

155-
Submit-GitChanges -RepositoryLocation $cloneLocation -File $GalleryFileName -Branch $branchName -Message "Update CHANGELOG for $ReleaseName"
164+
Submit-GitChanges -RepositoryLocation $cloneLocation -File $GalleryFileName -Branch $branchName -Message "Update CHANGELOG for $ReleaseName" -Verbose:$VerbosePreference
156165

157166
#endregion
158167

159168
#region vscode-PowerShell Changelog
160169
$psesChangelogPostamble = $psesChangelogSection -split "`n"
161-
$psesChangelogPostamble = @("#### [$psesRepoName](https://github.com/$Organization/$psesRepoName)") + $psesChangelogPostamble[2..$psesChangelogPostamble.Length-1]
170+
$psesChangelogPostamble = @("#### [$psesRepoName](https://github.com/$Organization/$psesRepoName)") + $psesChangelogPostamble[2..($psesChangelogPostamble.Length-3)]
162171
$psesChangelogPostamble = $psesChangelogPostamble -join "`n"
163172

164-
$psextChangelogSection = Get-GitCommit -SinceRef $SinceRef -UntilRef $UntilRef -GitHubToken $GitHubToken -RepositoryPath $PSExtensionRepositoryPath |
165-
Get-ChangeInfoFromCommit -GitHubToken $GitHubToken |
166-
Skip-IgnoredChange @ignore |
167-
New-ChangelogEntry @clEntryParams |
168-
New-ChangelogSection @clSectionParams -Preamble "#### [$vscodeRepoName](https://github.com/$Organization/$vscodeRepoName)" -Postamble $psesChangelogPostamble
173+
$psextChangelogSection = Get-GitCommit -SinceRef $SinceRef -UntilRef $UntilRef -GitHubToken $GitHubToken -RepositoryPath $PSExtensionRepositoryPath -Verbose:$VerbosePreference |
174+
Get-ChangeInfoFromCommit -GitHubToken $GitHubToken -Verbose:$VerbosePreference |
175+
Skip-IgnoredChange @ignore -Verbose:$VerbosePreference |
176+
New-ChangelogEntry @clEntryParams -Verbose:$VerbosePreference |
177+
New-ChangelogSection @clSectionParams -Preamble "#### [$vscodeRepoName](https://github.com/$Organization/$vscodeRepoName)" -Postamble $psesChangelogPostamble -Verbose:$VerbosePreference
178+
179+
Write-Host "vscode-PowerShell CHANGELOG:`n`n$psextChangelogSection`n`n"
169180

170181
$cloneLocation = Join-Path ([System.IO.Path]::GetTempPath()) "${vscodeRepoName}_changelogupdate"
171182

@@ -175,11 +186,11 @@ $cloneParams = @{
175186
CheckoutBranch = $branchName
176187
Clobber = $true
177188
}
178-
Copy-GitRepository @cloneParams
189+
Copy-GitRepository @cloneParams -Verbose:$VerbosePreference
179190

180191
UpdateChangelogFile -NewSection $psextChangelogSection -Path "$cloneLocation/$ChangelogName"
181192

182-
Submit-GitChanges -RepositoryLocation $cloneLocation -File $GalleryFileName -Branch $branchName -Message "Update CHANGELOG for $ReleaseName"
193+
Submit-GitChanges -RepositoryLocation $cloneLocation -File $GalleryFileName -Branch $branchName -Message "Update CHANGELOG for $ReleaseName" -Verbose:$VerbosePreference
183194

184195
#endregion vscode-PowerShell Changelog
185196

@@ -194,7 +205,7 @@ $prParams = @{
194205
GitHubToken = $GitHubToken
195206
FromOrg = $FromFork
196207
}
197-
New-GitHubPR @prParams
208+
New-GitHubPR @prParams -Verbose:$VerbosePreference
198209

199210
# vscode-PowerShell PR
200211
$prParams = @{
@@ -205,6 +216,6 @@ $prParams = @{
205216
GitHubToken = $GitHubToken
206217
FromOrg = $FromFork
207218
}
208-
New-GitHubPR @prParams
219+
New-GitHubPR @prParams -Verbose:$VerbosePreference
209220

210221
#endregion PRs

0 commit comments

Comments
 (0)