Skip to content

Commit b0a7735

Browse files
🩹 [Patch]: Let Connect-GitHubApp be able to pass the context to pipeline (#223)
## Description This pull request includes enhancements to the `Connect-GitHubApp` function, adding a `PassThru` parameter, enhancing output messages, and updating tests to validate the new functionality. - Fixes #222 Enhancements to `Connect-GitHubApp` function: * [`src/functions/public/Auth/Connect-GitHubApp.ps1`](diffhunk://#diff-7d1951ca779d73ee11b11db4ade6f33f8ea5fcf052324a72d2c8e83304eaa045R64-R67): Added a `PassThru` parameter to pass the context object to the pipeline. * [`src/functions/public/Auth/Connect-GitHubApp.ps1`](diffhunk://#diff-7d1951ca779d73ee11b11db4ade6f33f8ea5fcf052324a72d2c8e83304eaa045L136-R145): Enhanced output messages to include a green checkmark. Updates to tests: * [`tests/GitHub.Tests.ps1`](diffhunk://#diff-0b1d9ba345a583adce874126c13d6edd3f789416bb9c4db5df1e18af3608554cL98-R101): Updated the test for connecting to a GitHub App Installation to validate the `PassThru` functionality and ensure the context is not null or empty. ## Type of change <!-- Use the check-boxes [x] on the options that are relevant. --> - [ ] 📖 [Docs] - [ ] 🪲 [Fix] - [x] 🩹 [Patch] - [ ] ⚠️ [Security fix] - [ ] 🚀 [Feature] - [ ] 🌟 [Breaking change] ## Checklist <!-- Use the check-boxes [x] on the options that are relevant. --> - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas
1 parent d55a1f7 commit b0a7735

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

src/functions/public/Auth/Connect-GitHubAccount.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@
306306
Write-Host "Logged in as $name!"
307307
}
308308
if ($PassThru) {
309+
Write-Debug "Passing context [$contextObj] to the pipeline."
309310
$contextObj
310311
}
311312

src/functions/public/Auth/Connect-GitHubApp.ps1

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ function Connect-GitHubApp {
6161
)]
6262
[string] $Enterprise,
6363

64+
# Passes the context object to the pipeline.
65+
[Parameter()]
66+
[switch] $PassThru,
67+
6468
# The context to run the command in. Used to get the details for the API call.
6569
# Can be either a string or a GitHubContext object.
6670
[Parameter()]
@@ -129,11 +133,16 @@ function Connect-GitHubApp {
129133
}
130134
Write-Verbose 'Logging in using a managed installation access token...'
131135
Write-Verbose ($contextParams | Format-Table | Out-String)
132-
$tmpContext = [InstallationGitHubContext]::new((Set-GitHubContext -Context $contextParams.Clone() -PassThru))
133-
Write-Verbose ($tmpContext | Format-List | Out-String)
136+
$contextObj = [InstallationGitHubContext]::new((Set-GitHubContext -Context $contextParams.Clone() -PassThru))
137+
Write-Verbose ($contextObj | Format-List | Out-String)
134138
if (-not $Silent) {
135-
$name = $tmpContext.name
136-
Write-Host "Connected $name"
139+
$name = $contextObj.name
140+
Write-Host '' -ForegroundColor Green -NoNewline
141+
Write-Host "Connected $name!"
142+
}
143+
if ($PassThru) {
144+
Write-Debug "Passing context [$contextObj] to the pipeline."
145+
Write-Output $contextObj
137146
}
138147
$contextParams.Clear()
139148
}

tests/GitHub.Tests.ps1

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,10 @@ Describe 'GitHub' {
9595
}
9696

9797
It 'Can connect to a GitHub App Installation' {
98-
{ Connect-GitHubApp -Organization 'PSModule' } | Should -Not -Throw
99-
Write-Verbose (Get-GitHubContext | Out-String) -Verbose
98+
$appContext = Connect-GitHubApp -Organization 'PSModule' -PassThru
99+
Write-Verbose ($appContext | Out-String) -Verbose
100+
$appContext | Should -Not -BeNullOrEmpty
101+
{ $appContext | Disconnect-GitHub } | Should -Not -Throw
100102
}
101103

102104
It 'Can connect to all GitHub App Installations' {

0 commit comments

Comments
 (0)