Skip to content

Commit

Permalink
Add 'Type' parameter to Get-GitHubRepository function for repository …
Browse files Browse the repository at this point in the history
…filtering
  • Loading branch information
MariusStorhaug committed Dec 15, 2024
1 parent 3ab340e commit 22db796
Showing 1 changed file with 7 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,13 @@ filter Get-GitHubRepository {
)]
[string] $Repo,

# The type of repositories to return.
[Parameter(ParameterSetName = 'MyRepos_Type')]
[Parameter(ParameterSetName = 'ListByOrg')]
[Parameter(ParameterSetName = 'ListByUser')]
[ValidateSet('all', 'owner', 'public', 'private', 'member', 'forks', 'sources')]
[string] $Type = 'all',

# The handle for the GitHub user account.
[Parameter(
Mandatory,
Expand Down Expand Up @@ -130,37 +137,6 @@ filter Get-GitHubRepository {
[object] $Context = (Get-GitHubContext)
)

dynamicparam {
$DynamicParamDictionary = New-DynamicParamDictionary

if ($PSCmdlet.ParameterSetName -in 'MyRepos_Type', 'ListByOrg', 'ListByUser') {

switch ($PSCmdlet.ParameterSetName) {
'MyRepos_Type' {
$ValidateSet = 'all', 'owner', 'public', 'private', 'member'
}
'ListByOrg' {
$ValidateSet = 'all', 'public', 'private', 'forks', 'sources', 'member'
}
'ListByUser' {
$ValidateSet = 'all', 'owner', 'member'
}
}

$dynParam = @{
Name = 'Type'
ParameterSetName = $PSCmdlet.ParameterSetName
Type = [string]
Mandatory = $false
ValidateSet = $ValidateSet
DynamicParamDictionary = $DynamicParamDictionary
}
New-DynamicParam @dynParam
}

return $DynamicParamDictionary
}

begin {
$stackPath = Get-PSCallStackPath
Write-Debug "[$stackPath] - Start"
Expand Down

0 comments on commit 22db796

Please sign in to comment.