Skip to content

Commit

Permalink
🚀 [Feature]: Update required version of Context module to 7.0.2 (#…
Browse files Browse the repository at this point in the history
…306)

## Description

This pull request updates the dependency on `Context` to `7.0.2` which
no longer relies on `SecretStore` and `SecretManagement` PowerShell
modules, but contains its own local vault logic.

### Module Version Updates:

* Updated the required version of the `Context` module from `6.0.0` to
`7.0.2` across multiple files, including `examples/Connecting.ps1`,
`src/functions/private/Auth/Context/Remove-GitHubContext.ps1`,
`src/functions/private/Auth/Context/Set-GitHubContext.ps1`,
`src/functions/private/Auth/DeviceFlow/Update-GitHubUserAccessToken.ps1`,
`src/functions/private/Config/Initialize-GitHubConfig.ps1`,
`src/functions/public/Auth/Context/Get-GitHubContext.ps1`,
`src/functions/public/Config/Remove-GitHubConfig.ps1`, and
`src/functions/public/Config/Set-GitHubConfig.ps1`.

### Code Cleanup:

* Removed references to `Microsoft.PowerShell.SecretManagement` from
`examples/Connecting.ps1`, `tests/GitHub.Tests.ps1`, and
`tools/utilities/Local-Testing.ps1`.
* Cleaned up unused or redundant code in `tests/GitHub.Tests.ps1` by
removing `Get-SecretInfo` and `Get-SecretVault` commands.

## Type of change

<!-- Use the check-boxes [x] on the options that are relevant. -->

- [ ] 📖 [Docs]
- [ ] 🪲 [Fix]
- [ ] 🩹 [Patch]
- [ ] ⚠️ [Security fix]
- [x] 🚀 [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
  • Loading branch information
MariusStorhaug authored Feb 10, 2025
1 parent ef6c4aa commit 58ad447
Show file tree
Hide file tree
Showing 11 changed files with 16 additions and 38 deletions.
13 changes: 1 addition & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,21 +204,10 @@ Get-Command -Module GitHub

- [Generic HTTP Status Codes (MDN)](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status)

### Inspiration Behind the Project
### Alternative GitHub PowerShell Modules

- [Microsoft's PowerShellForGitHub](https://github.com/microsoft/PowerShellForGitHub)
- [PSGitHub by pcgeek86](https://github.com/pcgeek86/PSGitHub)
- [PSSodium by TylerLeonhardt](https://github.com/TylerLeonhardt/PSSodium)
- [libsodium NuGet Package](https://www.nuget.org/packages/Sodium.Core/)
- [GitHubActions by ebekker](https://github.com/ebekker/pwsh-github-action-tools)
- [powershell-devops by smokedlinq](https://github.com/smokedlinq/powershell-devops)
- [GitHubActionsToolkit by hugoalh-studio](https://github.com/hugoalh-studio/ghactions-toolkit-powershell)

### Authentication and Login

- [PowerShell for GitHub on GitHub Marketplace](https://github.com/apps/powershell-for-github)
- [Building a CLI with a GitHub App](https://docs.github.com/en/apps/creating-github-apps/writing-code-for-a-github-app/building-a-cli-with-a-github-app)

### Module Configuration and Environment

- [GH Environment for GitHub CLI](https://cli.github.com/manual/gh_help_environment)
8 changes: 3 additions & 5 deletions examples/Connecting.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '6.0.0' }
#Requires -Modules @{ ModuleName = 'Microsoft.PowerShell.SecretManagement'; RequiredVersion = '1.1.2' }
#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '7.0.2' }

###
### CONNECTING
Expand Down Expand Up @@ -49,9 +48,8 @@ Set-GitHubDefaultContext -Context 'msx.ghe.com/MariusStorhaug'
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
Get-GitHubContext -Context 'msx.ghe.com/MariusStorhaug'
Get-Context -ID 'PSModule.GitHub/msx.ghe.com/MariusStorhaug'

###
### DISCONNECTING
Expand Down
8 changes: 4 additions & 4 deletions src/functions/private/Auth/Context/Remove-GitHubContext.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '6.0.0' }
#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '7.0.2' }

filter Remove-GitHubContext {
<#
Expand All @@ -16,9 +16,9 @@ filter Remove-GitHubContext {
Removes all contexts from the vault.
.EXAMPLE
Remove-Context -ID 'MySecret'
Remove-Context -ID 'MyContext'
Removes the context called 'MySecret' from the vault.
Removes the context called 'MyContext' from the vault.
#>
[OutputType([void])]
[CmdletBinding(SupportsShouldProcess)]
Expand All @@ -38,7 +38,7 @@ filter Remove-GitHubContext {
process {
$ID = "$($script:GitHub.Config.ID)/$Context"

if ($PSCmdlet.ShouldProcess('Remove-Secret', $context.Name)) {
if ($PSCmdlet.ShouldProcess($context.Name, 'Remove context')) {
Remove-Context -ID $ID
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/functions/private/Auth/Context/Set-GitHubContext.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '6.0.0' }
#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '7.0.2' }

function Set-GitHubContext {
<#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,4 @@
Write-Debug "[$stackPath] - End"
}
}
#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '6.0.0' }
#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '7.0.2' }
2 changes: 1 addition & 1 deletion src/functions/private/Config/Initialize-GitHubConfig.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '6.0.0' }
#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '7.0.2' }

function Initialize-GitHubConfig {
<#
Expand Down
2 changes: 1 addition & 1 deletion src/functions/public/Auth/Context/Get-GitHubContext.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '6.0.0' }
#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '7.0.2' }

function Get-GitHubContext {
<#
Expand Down
2 changes: 1 addition & 1 deletion src/functions/public/Config/Remove-GitHubConfig.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '6.0.0' }
#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '7.0.2' }

function Remove-GitHubConfig {
<#
Expand Down
2 changes: 1 addition & 1 deletion src/functions/public/Config/Set-GitHubConfig.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '6.0.0' }
#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '7.0.2' }

function Set-GitHubConfig {
<#
Expand Down
5 changes: 1 addition & 4 deletions tests/GitHub.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#Requires -Modules @{ ModuleName = 'Microsoft.PowerShell.SecretManagement'; RequiredVersion = '1.1.2' }
#Requires -Modules @{ ModuleName = 'Pester'; RequiredVersion = '5.7.1' }
#Requires -Modules @{ ModuleName = 'Pester'; RequiredVersion = '5.7.1' }

[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
'PSUseDeclaredVarsMoreThanAssignments', '',
Expand All @@ -13,8 +12,6 @@
param()

BeforeAll {
Get-SecretInfo | Remove-Secret
Get-SecretVault | Unregister-SecretVault
Get-Module -ListAvailable -Name Context | Sort-Object -Property Version | Select-Object -Last 1 | Import-Module -Force
}

Expand Down
8 changes: 1 addition & 7 deletions tools/utilities/Local-Testing.ps1
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
#Requires -Modules @{ ModuleName = 'Microsoft.PowerShell.SecretManagement'; RequiredVersion = '1.1.2' }

#####
#####
Get-Module -Name GitHub -ListAvailable
Get-Module -Name GitHub* -ListAvailable | Remove-Module -Force
Get-Module -Name GitHub* -ListAvailable | Uninstall-Module -Force -AllVersions
Get-Module -Name GitHub -ListAvailable

Get-SecretVault | Unregister-SecretVault

Get-SecretVault
Get-SecretInfo
Get-Module -Name GitHub -ListAvailable
$VerbosePreference = 'Continue'

Expand Down

0 comments on commit 58ad447

Please sign in to comment.