Skip to content

Commit c6bb507

Browse files
pwshBotjshigetomiJustin ChungTravisEz13
authored
[release/v7.5] Check GH token availability for Get-Changelog (PowerShell#25328)
Co-authored-by: Justin Chung <124807742+jshigetomi@users.noreply.github.com> Co-authored-by: Justin Chung <chungjustin@microsoft.com> Co-authored-by: Travis Plunk <travis.plunk@microsoft.com>
1 parent 9b41681 commit c6bb507

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

tools/releaseTools.psm1

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,13 +151,20 @@ function Get-ChangeLog
151151
[Parameter(Mandatory = $true)]
152152
[string]$ThisReleaseTag,
153153

154-
[Parameter(Mandatory)]
154+
[Parameter(Mandatory = $false)]
155155
[string]$Token,
156156

157157
[Parameter()]
158158
[switch]$HasCherryPick
159159
)
160160

161+
if(-not $Token) {
162+
$Token = Get-GHDefaultAuthToken
163+
if(-not $Token) {
164+
throw "No GitHub Auth Token provided"
165+
}
166+
}
167+
161168
$tag_hash = git rev-parse "$LastReleaseTag^0"
162169
$format = '%H||%P||%aN||%aE||%s'
163170
$header = @{"Authorization"="token $Token"}
@@ -361,6 +368,29 @@ function Get-ChangeLog
361368
Write-Output "[${version}]: https://github.com/PowerShell/PowerShell/compare/${LastReleaseTag}...${ThisReleaseTag}`n"
362369
}
363370

371+
function Get-GHDefaultAuthToken {
372+
$IsGHCLIInstalled = $false
373+
if (Get-command -CommandType Application -Name gh -ErrorAction SilentlyContinue) {
374+
$IsGHCLIInstalled = $true
375+
} else {
376+
Write-Error -Message "GitHub CLI is not installed. Please install it from https://cli.github.com/" -ErrorAction Stop
377+
}
378+
379+
if ($IsGHCLIInstalled) {
380+
try {
381+
$Token = & gh auth token
382+
} catch {
383+
Write-Error -Message "Please login to GitHub CLI using 'gh auth login'"
384+
}
385+
}
386+
387+
if (-not $Token) {
388+
$Token = Read-Host -Prompt "Enter GitHub Auth Token"
389+
}
390+
391+
return $Token
392+
}
393+
364394
function PrintChangeLog($clSection, $sectionTitle, [switch] $Compress) {
365395
if ($clSection.Count -gt 0) {
366396
"### $sectionTitle`n"

0 commit comments

Comments
 (0)