Skip to content

Commit

Permalink
🩹 [Patch]: Set default 'PerPage' value in the GitHubContext (#206)
Browse files Browse the repository at this point in the history
## Description

- Set default `PerPage` value in the `GitHubContext`
  - Fixes #31

## Type of change

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

- [ ] 📖 [Docs]
- [ ] 🪲 [Fix]
- [x] 🩹 [Patch]
- [ ] ⚠️ [Security fix]
- [ ] 🚀 [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 Dec 15, 2024
1 parent 76807b9 commit 77ac2d7
Show file tree
Hide file tree
Showing 53 changed files with 109 additions and 102 deletions.
3 changes: 3 additions & 0 deletions src/classes/public/Context/GitHubContext.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ class GitHubContext : Context {
# The default value for the Repo parameter.
[string] $Repo

# The default value for the 'per_page' API parameter used in 'Get' functions that support paging.
[int] $PerPage

# Simple parameterless constructor
GitHubContext() {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@

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

# 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@

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

# 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
param(
# The number of results per page (max 100).
[Parameter()]
[ValidateRange(1, 100)]
[int] $PerPage = 30,
[ValidateRange(0, 100)]
[int] $PerPage,

# 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@

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

# 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@

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

# 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@

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

# 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@

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

# Only show repositories updated after the given time.
[Parameter()]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@

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

# 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@

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

# 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
param(
# The number of results per page (max 100).
[Parameter()]
[ValidateRange(1, 100)]
[int] $PerPage = 30,
[ValidateRange(0, 100)]
[int] $PerPage,

# 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@

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

# 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.
Expand Down
4 changes: 2 additions & 2 deletions src/functions/private/Users/Emails/Get-GitHubUserAllEmail.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
param(
# The number of results per page (max 100).
[Parameter()]
[ValidateRange(1, 100)]
[int] $PerPage = 30,
[ValidateRange(0, 100)]
[int] $PerPage,

# 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
param(
# The number of results per page (max 100).
[Parameter()]
[ValidateRange(1, 100)]
[int] $PerPage = 30,
[ValidateRange(0, 100)]
[int] $PerPage,

# 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@

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

# 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
param(
# The number of results per page (max 100).
[Parameter()]
[ValidateRange(1, 100)]
[int] $PerPage = 30,
[ValidateRange(0, 100)]
[int] $PerPage,

# 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@

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

# 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
param(
# The number of results per page (max 100).
[Parameter()]
[ValidateRange(1, 100)]
[int] $PerPage = 30,
[ValidateRange(0, 100)]
[int] $PerPage,

# 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@

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

# 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
param(
# The number of results per page (max 100).
[Parameter()]
[ValidateRange(1, 100)]
[int] $PerPage = 30,
[ValidateRange(0, 100)]
[int] $PerPage,

# 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.
Expand Down
4 changes: 2 additions & 2 deletions src/functions/private/Users/Get-GitHubAllUser.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@

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

# 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.
Expand Down
4 changes: 2 additions & 2 deletions src/functions/private/Users/Keys/Get-GitHubUserKeyForUser.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@

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

# 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.
Expand Down
4 changes: 2 additions & 2 deletions src/functions/private/Users/Keys/Get-GitHubUserMyKey.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
param(
# The number of results per page (max 100).
[Parameter()]
[ValidateRange(1, 100)]
[int] $PerPage = 30,
[ValidateRange(0, 100)]
[int] $PerPage,

# 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
param(
# The number of results per page (max 100).
[Parameter()]
[ValidateRange(1, 100)]
[int] $PerPage = 30,
[ValidateRange(0, 100)]
[int] $PerPage,

# 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@

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

# 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
param(
# The number of results per page (max 100).
[Parameter()]
[ValidateRange(1, 100)]
[int] $PerPage = 30,
[ValidateRange(0, 100)]
[int] $PerPage,

# 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.
Expand Down
5 changes: 5 additions & 0 deletions src/functions/public/API/Invoke-GitHubAPI.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@
if ($Body) {
# Use body to create the query string for certain situations
if ($Method -eq 'GET') {
# If body conatins 'per_page' and its is null, set it to $context.PerPage
if ($Body['per_page'] -eq 0) {
Write-Debug "Setting per_page to the default value in context [$($Context.PerPage)]."
$Body['per_page'] = $Context.PerPage
}
$queryString = $Body | ConvertTo-QueryString
$APICall.Uri = $APICall.Uri + $queryString
} elseif ($Body -is [string]) {
Expand Down
4 changes: 2 additions & 2 deletions src/functions/public/Actions/Get-GitHubWorkflow.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@

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

# 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.
Expand Down
4 changes: 2 additions & 2 deletions src/functions/public/Actions/Get-GitHubWorkflowRun.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@

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

# 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.
Expand Down
1 change: 1 addition & 0 deletions src/functions/public/Auth/Connect-GitHubAccount.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@
Enterprise = [string]$Enterprise
Owner = [string]$Owner
Repo = [string]$Repo
PerPage = 100
}

Write-Verbose ($context | Format-Table | Out-String)
Expand Down
4 changes: 2 additions & 2 deletions src/functions/public/Organization/Get-GitHubOrganization.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@
[Parameter(ParameterSetName = 'AllOrg')]
[Parameter(ParameterSetName = 'UserOrg')]
[Parameter(ParameterSetName = '__DefaultSet')]
[ValidateRange(1, 100)]
[int] $PerPage = 30,
[ValidateRange(0, 100)]
[int] $PerPage,

# 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@

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

# 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@

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

# 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@

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

# 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.
Expand Down
4 changes: 2 additions & 2 deletions src/functions/public/Releases/Releases/Get-GitHubRelease.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@

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

# Get the latest release only
[Parameter(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ filter Get-GitHubRepository {
[Parameter(ParameterSetName = 'MyRepos')]
[Parameter(ParameterSetName = 'ListByOrg')]
[Parameter(ParameterSetName = 'ListByUser')]
[ValidateRange(1, 100)]
[int] $PerPage = 30,
[ValidateRange(0, 100)]
[int] $PerPage,

# 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.
Expand Down
Loading

0 comments on commit 77ac2d7

Please sign in to comment.