From d8cff81b1282060394853ef97da7b25d0acdd35a Mon Sep 17 00:00:00 2001 From: Justin Chung Date: Thu, 6 Mar 2025 16:38:14 -0600 Subject: [PATCH 1/4] Check GH token availbility for Get-Changelog --- tools/releaseTools.psm1 | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/tools/releaseTools.psm1 b/tools/releaseTools.psm1 index 1a7cd955210..25bcccddcac 100644 --- a/tools/releaseTools.psm1 +++ b/tools/releaseTools.psm1 @@ -151,13 +151,20 @@ function Get-ChangeLog [Parameter(Mandatory = $true)] [string]$ThisReleaseTag, - [Parameter(Mandatory)] + [Parameter(Mandatory = $false)] [string]$Token, [Parameter()] [switch]$HasCherryPick ) + if(-not $Token) { + $Token = CheckForAuthToken + if(-not $Token) { + throw "No GitHub Auth Token provided" + } + } + $tag_hash = git rev-parse "$LastReleaseTag^0" $format = '%H||%P||%aN||%aE||%s' $header = @{"Authorization"="token $Token"} @@ -361,6 +368,26 @@ function Get-ChangeLog Write-Output "[${version}]: https://github.com/PowerShell/PowerShell/compare/${LastReleaseTag}...${ThisReleaseTag}`n" } +function CheckForAuthToken { + $IsGHCLIInstalled = $false + try { + & gh --version > $null 2>&1 + $IsGHCLIInstalled = $true + } catch {} + + if ($IsGHCLIInstalled) { + try { + $Token = & gh auth token + } catch {} + } + + if (-not $Token) { + $Token = Read-Host -Prompt "Enter GitHub Auth Token" + } + + return $Token +} + function PrintChangeLog($clSection, $sectionTitle, [switch] $Compress) { if ($clSection.Count -gt 0) { "### $sectionTitle`n" From db93b29a82ba9981b7b7757ed0816b95b29472b0 Mon Sep 17 00:00:00 2001 From: Justin Chung Date: Thu, 6 Mar 2025 16:44:39 -0600 Subject: [PATCH 2/4] Add error messages in catch blocks --- tools/releaseTools.psm1 | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tools/releaseTools.psm1 b/tools/releaseTools.psm1 index 25bcccddcac..a3a2aafb8e5 100644 --- a/tools/releaseTools.psm1 +++ b/tools/releaseTools.psm1 @@ -373,12 +373,16 @@ function CheckForAuthToken { try { & gh --version > $null 2>&1 $IsGHCLIInstalled = $true - } catch {} + } catch { + Write-Error -Message "GitHub CLI is not installed. Please install it from https://cli.github.com/" + } if ($IsGHCLIInstalled) { try { $Token = & gh auth token - } catch {} + } catch { + Write-Error -Message "Please login to GitHub CLI using 'gh auth login'" + } } if (-not $Token) { From ab53983c6d35ddc03775d3968295f27d9c20f7ed Mon Sep 17 00:00:00 2001 From: Justin Chung Date: Fri, 7 Mar 2025 13:14:29 -0600 Subject: [PATCH 3/4] Use Get-Command to check and use verb noun naming --- tools/releaseTools.psm1 | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/tools/releaseTools.psm1 b/tools/releaseTools.psm1 index a3a2aafb8e5..181def4df49 100644 --- a/tools/releaseTools.psm1 +++ b/tools/releaseTools.psm1 @@ -159,7 +159,7 @@ function Get-ChangeLog ) if(-not $Token) { - $Token = CheckForAuthToken + $Token = Get-GHDefaultAuthToken if(-not $Token) { throw "No GitHub Auth Token provided" } @@ -368,15 +368,13 @@ function Get-ChangeLog Write-Output "[${version}]: https://github.com/PowerShell/PowerShell/compare/${LastReleaseTag}...${ThisReleaseTag}`n" } -function CheckForAuthToken { +function Get-GHDefaultAuthToken { $IsGHCLIInstalled = $false - try { - & gh --version > $null 2>&1 + if (Get-command -CommandType Application -Name gh -ErrorAction SilentlyContinue) { $IsGHCLIInstalled = $true - } catch { - Write-Error -Message "GitHub CLI is not installed. Please install it from https://cli.github.com/" + } else { + Write-Error -Message "GitHub CLI is not installed. Please install it from https://cli.github.com/" -ErrorAction Stop } - if ($IsGHCLIInstalled) { try { $Token = & gh auth token From b4183a31005cde1441b185b65f323c3cc657c2d8 Mon Sep 17 00:00:00 2001 From: Travis Plunk Date: Fri, 7 Mar 2025 12:10:12 -0800 Subject: [PATCH 4/4] Update tools/releaseTools.psm1 --- tools/releaseTools.psm1 | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/releaseTools.psm1 b/tools/releaseTools.psm1 index 181def4df49..b034e2863dd 100644 --- a/tools/releaseTools.psm1 +++ b/tools/releaseTools.psm1 @@ -375,6 +375,7 @@ function Get-GHDefaultAuthToken { } else { Write-Error -Message "GitHub CLI is not installed. Please install it from https://cli.github.com/" -ErrorAction Stop } + if ($IsGHCLIInstalled) { try { $Token = & gh auth token