Skip to content

Commit 8a986f3

Browse files
🩹 [Patch]: Refactor GitHub connection handling and improve output formatting in init and boilerplate scripts
1 parent 6fadddd commit 8a986f3

File tree

2 files changed

+22
-13
lines changed

2 files changed

+22
-13
lines changed

β€Žscripts/boilerplate.ps1β€Ž

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,12 @@ try {
1616
Get-InstalledPSResource | Select-Object Name, Version, Prerelease | Sort-Object -Property Name | Format-Table -AutoSize
1717
}
1818

19-
LogGroup ' - GitHub connection' {
20-
if ($providedClientID -and $providedPrivateKey) {
21-
Connect-GitHub -ClientID $env:GITHUB_ACTION_INPUT_ClientID -PrivateKey $env:GITHUB_ACTION_INPUT_PrivateKey -Silent -PassThru |
22-
Select-Object * | Format-List
23-
} elseif ($providedToken) {
24-
Connect-GitHub -Token $env:GITHUB_ACTION_INPUT_Token -Silent -PassThru |
25-
Select-Object * | Format-List
26-
} else {
27-
Write-Output 'No connection provided'
28-
}
19+
LogGroup ' - GitHub connection - Default' {
20+
Get-GitHubContext | Format-List
21+
}
22+
23+
LogGroup ' - GitHub connection - List' {
24+
Get-GitHubContext -ListAvailable | Format-Table
2925
}
3026

3127
LogGroup ' - Configuration' {

β€Žscripts/init.ps1β€Ž

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
[CmdletBinding()]
2-
param()
2+
param(
3+
[string]$Name = 'GitHub-Script - Init'
4+
)
35

46
$scriptName = $MyInvocation.MyCommand.Name
57
Write-Debug "[$scriptName] - Start"
@@ -8,7 +10,8 @@ try {
810
$env:PSMODULE_GITHUB_SCRIPT = $true
911

1012
if ($VerbosePreference -eq 'Continue') {
11-
Write-Output '┏━━━━━┫ GitHub-Script - Init ┣━━━━━┓'
13+
$title = "┏━━━━━┫ $Name ┣━━━━━┓"
14+
Write-Output $title
1215
Write-Output '::group:: - SetupGitHub PowerShell module'
1316
}
1417
$Name = 'GitHub'
@@ -76,7 +79,17 @@ try {
7679
Write-Verbose "$($moduleStatus | Format-List)"
7780
if ($VerbosePreference -eq 'Continue') {
7881
Write-Output '::endgroup::'
79-
Write-Output '┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛'
82+
Write-Output '::group:: - GitHub connection'
83+
}
84+
if ($providedClientID -and $providedPrivateKey) {
85+
Connect-GitHub -ClientID $env:GITHUB_ACTION_INPUT_ClientID -PrivateKey $env:GITHUB_ACTION_INPUT_PrivateKey -Silent
86+
} elseif ($providedToken) {
87+
Connect-GitHub -Token $env:GITHUB_ACTION_INPUT_Token -Silent
88+
}
89+
if ($VerbosePreference -eq 'Continue') {
90+
Write-Output '::endgroup::'
91+
$endingFence = 'β”—' + ('━' * ($title.Length - 2)) + 'β”›'
92+
Write-Output $endingFence
8093
}
8194
} catch {
8295
throw $_

0 commit comments

Comments
Β (0)