Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🩹 [Patch]: Allow Set-GitHubDefaultContext to take context as pipeline #274

Merged
merged 9 commits into from
Jan 22, 2025
Merged
9 changes: 6 additions & 3 deletions Coverage.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@
<table>
<tr>
<td>Available functions</td>
<td>1009</td>
<td>1015</td>
</tr>
<tr>
<td>Covered functions</td>
<td>160</td>
</tr>
<tr>
<td>Missing functions</td>
<td>849</td>
<td>855</td>
</tr>
<tr>
<td>Coverage</td>
<td>15.86%</td>
<td>15.76%</td>
</tr>
</table>

Expand Down Expand Up @@ -247,6 +247,9 @@
| `/orgs/{org}/settings/billing/actions` | | :x: | | | |
| `/orgs/{org}/settings/billing/packages` | | :x: | | | |
| `/orgs/{org}/settings/billing/shared-storage` | | :x: | | | |
| `/orgs/{org}/settings/network-configurations` | | :x: | | :x: | |
| `/orgs/{org}/settings/network-configurations/{network_configuration_id}` | :x: | :x: | :x: | | |
| `/orgs/{org}/settings/network-settings/{network_settings_id}` | | :x: | | | |
| `/orgs/{org}/team/{team_slug}/copilot/metrics` | | :x: | | | |
| `/orgs/{org}/team/{team_slug}/copilot/usage` | | :x: | | | |
| `/orgs/{org}/teams` | | :white_check_mark: | | :white_check_mark: | |
Expand Down
9 changes: 9 additions & 0 deletions examples/Connecting.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ Get-GitHubContext -Context 'msx.ghe.com/MariusStorhaug'
# Take a name dynamically from Get-GitHubContext? Autocomplete the name
Set-GitHubDefaultContext -Context 'msx.ghe.com/MariusStorhaug'

# Set a specific context as the default context using pipeline
'msx.ghe.com/MariusStorhaug' | Set-GitHubDefaultContext

Get-GitHubContext -Context 'github.com/MariusStorhaug' | Set-GitHubDefaultContext

# Abstraction layers on GitHubContexts
Get-GitHubContext -Context 'msx.ghe.com/MariusStorhaug' # Only manages secrets prefixed with 'Context:PSModule.GitHub/'
Get-Context -ID 'PSModule.GitHub/msx.ghe.com/MariusStorhaug' # Only manages secrets prefixed with 'Context:', handles conversion to/from JSON
Get-Secret -Name 'Context:PSModule.GitHub/msx.ghe.com/MariusStorhaug' # Only manages secrets storage on the system

###
### DISCONNECTING
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,18 @@
param(
# The context to run the command in. Used to get the details for the API call.
# Can be either a string or a GitHubContext object.
[Parameter()]
[Parameter(ValueFromPipeline)]
[object] $Context = (Get-GitHubContext)
)

begin {
$stackPath = Get-PSCallStackPath
Write-Debug "[$stackPath] - Start"
$Context = Resolve-GitHubContext -Context $Context
}

process {
Write-Debug "Setting default context to [$Context]"
$Context = Resolve-GitHubContext -Context $Context
if ($PSCmdlet.ShouldProcess("$Context", 'Set default context')) {
Set-GitHubConfig -Name 'DefaultContext' -Value $Context.Name
}
Expand Down
18 changes: 18 additions & 0 deletions tests/GitHub.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,28 @@ Describe 'GitHub' {
Write-Verbose ($contexts | Out-String) -Verbose
($contexts).Count | Should -Be 3
}
}
Context 'DefaultContext' {
BeforeAll {
Connect-GitHub
}
It 'Set-GitHubDefaultContext - Can swap context to another' {
Write-Verbose (Get-GitHubContext -ListAvailable | Out-String) -Verbose
{ Set-GitHubDefaultContext -Context 'github.com/github-actions/Organization/PSModule' } | Should -Not -Throw
Get-GitHubConfig -Name 'DefaultContext' | Should -Be 'github.com/github-actions/Organization/PSModule'
}

It 'Set-GitHubDefaultContext - Can swap context to another using pipeline - String' {
Write-Verbose (Get-GitHubContext -ListAvailable | Out-String) -Verbose
{ 'github.com/psmodule-user' | Set-GitHubDefaultContext } | Should -Not -Throw
Get-GitHubConfig -Name 'DefaultContext' | Should -Be 'github.com/psmodule-user'
}

It 'Set-GitHubDefaultContext - Can swap context to another using pipeline - Context object' {
Write-Verbose (Get-GitHubContext -ListAvailable | Out-String) -Verbose
{ Get-GitHubContext -Context 'github.com/psmodule-org-app' | Set-GitHubDefaultContext } | Should -Not -Throw
Get-GitHubConfig -Name 'DefaultContext' | Should -Be 'github.com/psmodule-org-app'
}
}
Context 'Status' -ForEach @('public', 'eu') {
It 'Get-GitHubScheduledMaintenance - Gets scheduled maintenance for <_>' {
Expand Down
Loading