Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
b452f31
examples
Dec 13, 2024
885d09a
Move examples
MariusStorhaug Dec 13, 2024
531bca2
Add a GitHub AuthType Enum
MariusStorhaug Dec 13, 2024
16835a7
Add GitHubAuthType data type on GitHubContext.AuthType
MariusStorhaug Dec 13, 2024
ba99044
Use GitHubAuthType on Assert-GitHubContext
MariusStorhaug Dec 13, 2024
d534a61
Add Assert-GitHubContext on Get-GitHubAppWebhookConfiguration
MariusStorhaug Dec 13, 2024
7d93e87
Rename AuthType
MariusStorhaug Dec 13, 2024
a72d31c
Introduce UserGitHubContextAuthAppType enum and update DeviceFlowType…
MariusStorhaug Dec 13, 2024
00c9b10
Change ApiBaseUri type from string to uri in GitHubContext class
MariusStorhaug Dec 13, 2024
4728a22
Refactor GitHubContext to use enums for Type, AuthType, and TokenType…
MariusStorhaug Dec 13, 2024
c45a1c8
Add .ToString() for enum values
MariusStorhaug Dec 13, 2024
18f050b
Fix
MariusStorhaug Dec 13, 2024
2027edb
Refactor GitHub App scripts to use Assert-GitHubContext for App authe…
MariusStorhaug Dec 13, 2024
b24bfd6
revert
MariusStorhaug Dec 13, 2024
f1b4506
Refactor Get-GitHubContext and Set-GitHubContext to use string litera…
MariusStorhaug Dec 13, 2024
e2872c7
Refactor GitHub App scripts to streamline context resolution and auth…
MariusStorhaug Dec 13, 2024
929261b
Refactor Set-GitHubContext to improve context type handling and verbo…
MariusStorhaug Dec 13, 2024
1f31463
Refactor context type annotations to use 'object' for improved flexib…
MariusStorhaug Dec 13, 2024
ed10aac
Merge branch 'main' of https://github.com/PSModule/GitHub into classc…
MariusStorhaug Dec 13, 2024
e780683
Update output type annotations to use 'GitHubContext' for improved ty…
MariusStorhaug Dec 13, 2024
7b4aec1
Fix regex switch statement to correctly evaluate authentication type …
MariusStorhaug Dec 14, 2024
5173300
Refactor Assert-GitHubContext to use 'object' for Context parameter a…
MariusStorhaug Dec 14, 2024
ce2e8cb
Fix URI
MariusStorhaug Dec 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/classes/public/Context/GitHubContext.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class GitHubContext : Context {
class GitHubContext : Context {
# The GitHub Context Name.
# HostName/Username or HostName/AppSlug
# github.com/Octocat
Expand All @@ -18,7 +18,7 @@

# The API base URI.
# https://api.github.com
[string] $ApiBaseUri
[uri] $ApiBaseUri

# The GitHub API version.
# 2022-11-28
Expand Down
2 changes: 1 addition & 1 deletion src/functions/public/API/Invoke-GitHubAPI.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@
$headers | Remove-HashtableEntry -NullOrEmptyValues

if (-not $URI) {
$URI = ("$ApiBaseUri/" -replace '/$', '') + ("/$ApiEndpoint" -replace '^/', '')
$URI = ("$ApiBaseUri" -replace '/$'), ("$ApiEndpoint" -replace '^/') -join '/'
}

$APICall = @{
Expand Down
1 change: 1 addition & 0 deletions src/functions/public/Apps/GitHub Apps/Get-GitHubApp.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
)

$Context = Resolve-GitHubContext -Context $Context
Assert-GitHubContext -Context $Context -AuthType App

switch ($PSCmdlet.ParameterSetName) {
'BySlug' {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
)

$Context = Resolve-GitHubContext -Context $Context
Assert-GitHubContext -Context $Context -AuthType App

$inputObject = @{
Context = $Context
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
)

$Context = Resolve-GitHubContext -Context $Context
Assert-GitHubContext -Context $Context -AuthType App

$inputObject = @{
Context = $Context
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
)

$Context = Resolve-GitHubContext -Context $Context
Assert-GitHubContext -Context $Context -AuthType App

$inputObject = @{
Context = $Context
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
)

$Context = Resolve-GitHubContext -Context $Context
Assert-GitHubContext -Context $Context -AuthType App

$inputObject = @{
Context = $Context
Expand Down
19 changes: 15 additions & 4 deletions src/functions/public/Auth/Assert-GitHubContext.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,27 @@
Mandatory,
ValueFromPipeline
)]
[GitHubContext] $Context,
[object] $Context,

# The required authtypes for the command.
[Parameter(Mandatory)]
[string[]] $AuthType
)

$command = (Get-PSCallStack)[1].Command
begin {
$commandName = $MyInvocation.MyCommand.Name
Write-Verbose "[$commandName] - Start"
}

process {
$command = (Get-PSCallStack)[1].Command

if ($Context.AuthType -notin $AuthType) {
throw "The context '$($Context.Name)' does not match the required AuthTypes [$AuthType] for [$command]."
}
}

if ($Context.AuthType -notin $AuthType) {
throw "The context '$($Context.Name)' does not match the required AuthTypes [$AuthType] for [$command]."
end {
Write-Verbose "[$commandName] - End"
}
}
12 changes: 6 additions & 6 deletions src/functions/public/Auth/Connect-GitHubApp.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function Connect-GitHubApp {
function Connect-GitHubApp {
<#
.SYNOPSIS
Connects to GitHub as a installation using a GitHub App.
Expand Down Expand Up @@ -104,7 +104,7 @@
AuthType = [string]'IAT'
TokenType = [string]'ghs'
DisplayName = [string]$Context.DisplayName
ApiBaseUri = [string]$Context.ApiBaseUri
ApiBaseUri = [uri]$Context.ApiBaseUri
ApiVersion = [string]$Context.ApiVersion
HostName = [string]$Context.HostName
ClientID = [string]$Context.ClientID
Expand All @@ -113,18 +113,18 @@
Events = [string[]]$installation.events
TargetType = [string]$installation.target_type
Token = [securestring]$token.Token
TokenExpirationDate = [string]$token.ExpiresAt
TokenExpirationDate = [datetime]$token.ExpiresAt
}

switch ($installation.target_type) {
'User' {
$contextParams['TargetName'] = $installation.account.login
$contextParams['TargetName'] = [string]$installation.account.login
}
'Organization' {
$contextParams['TargetName'] = $installation.account.login
$contextParams['TargetName'] = [string]$installation.account.login
}
'Enterprise' {
$contextParams['TargetName'] = $installation.account.slug
$contextParams['TargetName'] = [string]$installation.account.slug
}
}
Write-Verbose 'Logging in using a managed installation access token...'
Expand Down