Skip to content

Commit

Permalink
Add context, cleanup parameters and param handling
Browse files Browse the repository at this point in the history
  • Loading branch information
MariusStorhaug committed Dec 4, 2024
1 parent 8278e48 commit 96143ec
Show file tree
Hide file tree
Showing 56 changed files with 466 additions and 221 deletions.
8 changes: 6 additions & 2 deletions src/functions/private/Gitignore/Get-GitHubGitignoreByName.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,17 @@ filter Get-GitHubGitignoreByName {
#>
[CmdletBinding()]
param (
[Parameter(Mandatory)]
[string] $Name,

# The context to run the command in.
[Parameter()]
[ValidateNotNullOrEmpty()]
[string] $Name
[string] $Context
)

process {
$inputObject = @{
Context = $Context
APIEndpoint = "/gitignore/templates/$Name"
Accept = 'application/vnd.github.raw+json'
Method = 'GET'
Expand Down
8 changes: 6 additions & 2 deletions src/functions/private/Gitignore/Get-GitHubGitignoreList.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,19 @@ filter Get-GitHubGitignoreList {
#>
[OutputType([string[]])]
[CmdletBinding()]
param ()
param (
# The context to run the command in.
[Parameter()]
[string] $Context
)

$inputObject = @{
Context = $Context
APIEndpoint = '/gitignore/templates'
Method = 'GET'
}

Invoke-GitHubAPI @inputObject | ForEach-Object {
Write-Output $_.Response
}

}
11 changes: 7 additions & 4 deletions src/functions/private/License/Get-GitHubLicenseByName.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,18 @@ filter Get-GitHubLicenseByName {
[CmdletBinding()]
param (
# The license keyword, license name, or license SPDX ID. For example, mit or mpl-2.0.
[Parameter()]
[ValidateNotNullOrEmpty()]
[Parameter(Mandatory)]
[Alias('license')]
[string] $Name
[string] $Name,

# The context to run the command in.
[Parameter()]
[string] $Context
)

process {
$inputObject = @{
Context = $Context
APIEndpoint = "/licenses/$Name"
Accept = 'application/vnd.github+json'
Method = 'GET'
Expand All @@ -36,6 +40,5 @@ filter Get-GitHubLicenseByName {
Invoke-GitHubAPI @inputObject | ForEach-Object {
Write-Output $_.Response
}

}
}
7 changes: 6 additions & 1 deletion src/functions/private/License/Get-GitHubLicenseList.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,14 @@ filter Get-GitHubLicenseList {
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidLongLines', '', Justification = 'Contains a long link.')]
[OutputType([string[]])]
[CmdletBinding()]
param ()
param (
# The context to run the command in.
[Parameter()]
[string] $Context
)

$inputObject = @{
Context = $Context
APIEndpoint = '/licenses'
Method = 'GET'
}
Expand Down
11 changes: 8 additions & 3 deletions src/functions/private/License/Get-GitHubRepositoryLicense.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,20 @@ filter Get-GitHubRepositoryLicense {
[CmdletBinding()]
param (
# The account owner of the repository. The name is not case sensitive.
[Parameter()]
[string] $Owner = (Get-GitHubContextSetting -Name Owner),
[Parameter(Mandatory)]
[string] $Owner,

# The name of the repository without the .git extension. The name is not case sensitive.
[Parameter(Mandatory)]
[string] $Repo,

# The context to run the command in.
[Parameter()]
[string] $Repo = (Get-GitHubContextSetting -Name Repo)
[string] $Context
)

$inputObject = @{
Context = $Context
APIEndpoint = "/repos/$Owner/$Repo/license"
Accept = 'application/vnd.github+json'
Method = 'GET'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,15 @@
ValueFromPipeline,
ValueFromPipelineByPropertyName
)]
[Alias('login')]
[string] $Username
[string] $Username,

# The context to run the command in.
[Parameter()]
[string] $Context
)

$inputObject = @{
Context = $Context
APIEndpoint = "/orgs/$OrganizationName/blocks/$Username"
Method = 'PUT'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,19 @@
# The number of results per page (max 100).
[Parameter()]
[ValidateRange(1, 100)]
[int] $PerPage = 30
[int] $PerPage = 30,

# The context to run the command in.
[Parameter()]
[string] $Context
)

$body = @{
per_page = $PerPage
}

$inputObject = @{
Context = $Context
APIEndpoint = "/orgs/$OrganizationName/blocks"
Method = 'GET'
Body = $body
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,15 @@
Mandatory,
ValueFromPipelineByPropertyName
)]
[string] $Username
[string] $Username,

# The context to run the command in.
[Parameter()]
[string] $Context
)

$inputObject = @{
Context = $Context
APIEndpoint = "/orgs/$OrganizationName/blocks/$Username"
Method = 'GET'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,15 @@
ValueFromPipelineByPropertyName
)]
[Alias('login')]
[string] $Username
[string] $Username,

# The context to run the command in.
[Parameter()]
[string] $Context
)

$inputObject = @{
Context = $Context
APIEndpoint = "/orgs/$OrganizationName/blocks/$Username"
Method = 'DELETE'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@
# The number of results per page (max 100).
[Parameter()]
[ValidateRange(1, 100)]
[int] $PerPage = 30
[int] $PerPage = 30,

# The context to run the command in.
[Parameter()]
[string] $Context
)

$body = @{
Expand All @@ -38,6 +42,7 @@
}

$inputObject = @{
Context = $Context
APIEndpoint = '/organizations'
Method = 'GET'
Body = $body
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,19 @@
# The number of results per page (max 100).
[Parameter()]
[ValidateRange(1, 100)]
[int] $PerPage = 30
[int] $PerPage = 30,

# The context to run the command in.
[Parameter()]
[string] $Context
)

$body = @{
per_page = $PerPage
}

$inputObject = @{
Context = $Context
APIEndpoint = '/user/orgs'
Method = 'GET'
Body = $body
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,16 @@
[Alias('login')]
[Alias('org')]
[Alias('owner')]
[string] $OrganizationName
[string] $OrganizationName,

# The context to run the command in.
[Parameter()]
[string] $Context
)


$inputObject = @{
Context = $Context
APIEndpoint = "/orgs/$OrganizationName"
Method = 'GET'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,19 @@
# The number of results per page (max 100).
[Parameter()]
[ValidateRange(1, 100)]
[int] $PerPage = 30
[int] $PerPage = 30,

# The context to run the command in.
[Parameter()]
[string] $Context
)

$body = @{
per_page = $PerPage
}

$inputObject = @{
Context = $Context
APIEndpoint = "/users/$Username/orgs"
Method = 'GET'
Body = $body
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,25 @@
[CmdletBinding()]
param (
# The account owner of the repository. The name is not case sensitive.
[Parameter()]
[string] $Owner = (Get-GitHubContextSetting -Name Owner),
[Parameter(Mandatory)]
[string] $Owner,

# The name of the repository without the .git extension. The name is not case sensitive.
[Parameter()]
[string] $Repo = (Get-GitHubContextSetting -Name Repo),
[Parameter(Mandatory)]
[string] $Repo,

# The unique identifier of the asset.
[Parameter(Mandatory)]
[Alias('asset_id')]
[string] $ID
[string] $ID,

# The context to run the command in.
[Parameter()]
[string] $Context
)

$inputObject = @{
Context = $Context
APIEndpoint = "/repos/$Owner/$Repo/releases/assets/$ID"
Method = 'GET'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
[CmdletBinding()]
param (
# The account owner of the repository. The name is not case sensitive.
[Parameter()]
[string] $Owner = (Get-GitHubContextSetting -Name Owner),
[Parameter(Mandatory)]
[string] $Owner,

# The name of the repository without the .git extension. The name is not case sensitive.
[Parameter()]
[string] $Repo = (Get-GitHubContextSetting -Name Repo),
[Parameter(Mandatory)]
[string] $Repo,

# The unique identifier of the release.
[Parameter(
Expand All @@ -36,13 +36,19 @@
# The number of results per page (max 100).
[Parameter()]
[ValidateRange(1, 100)]
[int] $PerPage = 30
[int] $PerPage = 30,

# The context to run the command in.
[Parameter()]
[string] $Context
)

$body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case
Remove-HashtableEntry -Hashtable $body -RemoveNames 'Owner', 'Repo', 'ID'
$body = @{
per_page = $PerPage
}

$inputObject = @{
Context = $Context
APIEndpoint = "/repos/$Owner/$Repo/releases/$ID/assets"
Method = 'GET'
Body = $body
Expand Down
20 changes: 13 additions & 7 deletions src/functions/private/Releases/Releases/Get-GitHubReleaseAll.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,29 @@
[CmdletBinding()]
param (
# The account owner of the repository. The name is not case sensitive.
[Parameter()]
[string] $Owner = (Get-GitHubContextSetting -Name Owner),
[Parameter(Mandatory)]
[string] $Owner,

# The name of the repository without the .git extension. The name is not case sensitive.
[Parameter()]
[string] $Repo = (Get-GitHubContextSetting -Name Repo),
[Parameter(Mandatory)]
[string] $Repo,

# The number of results per page (max 100).
[Parameter(ParameterSetName = 'AllUsers')]
[ValidateRange(1, 100)]
[int] $PerPage = 30
[int] $PerPage = 30,

# The context to run the command in.
[Parameter()]
[string] $Context
)

$body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case
Remove-HashtableEntry -Hashtable $body -RemoveNames 'Owner', 'Repo'
$body = @{
per_page = $PerPage
}

$inputObject = @{
Context = $Context
APIEndpoint = "/repos/$Owner/$Repo/releases"
Method = 'GET'
Body = $body
Expand Down
Loading

0 comments on commit 96143ec

Please sign in to comment.