diff --git a/CodingStandard.md b/CodingStandard.md new file mode 100644 index 000000000..f460d9d09 --- /dev/null +++ b/CodingStandard.md @@ -0,0 +1,186 @@ +# Coding Standards for `GitHub` + +Start by reading the general coding standards for [`PSModule`](https://psmodule.io/docs) which is the basis for all modules in the framework. +Additions or adjustments to those defaults are covered in this document to ensure that the modules drive consistancy for all developers. + +## General Coding Standards + +1. **PowerShell Keywords** + - All PowerShell keywords (e.g. `if`, `return`, `throw`, `function`, `param`) **must** be in lowercase. + +2. **Brace Style** + - Use **One True Bracing Style (OTBS)**. + - Opening brace on the same line as the statement; closing brace on its own line. + +3. **Coverage** + - We do **not** need 100% coverage of the GitHub API. + - Maintain a separate file listing the endpoints you intentionally **do not** cover, so the coverage report can mark them accordingly (e.g., ⚠️). + +4. **Convert Filter Types** + - Wherever filters are used, ensure they are implemented as standard PowerShell functions with `begin`, `process`, and `end` blocks. + +--- + +## Functions + +- **Grouping** + - Group functions by the *object type* they handle, using folders named for that object type (e.g. “Repository”), **not** by the API endpoint URL. + +- **Naming** + - Public function name format: **`Verb-GitHubNoun`**. + - Private function name format: **`Verb-GitHubNoun`** (same style but no aliases). + - **`Get-`** functions must **not** include `[CmdletBinding(SupportsShouldProcess)]`. You only use `SupportsShouldProcess` on commands that change or remove data (`Set-`, `Remove-`, `Add-`, etc.). + +- **Default Parameter Sets** + - Do **not** declare `DefaultParameterSetName = '__AllParameterSets'`. + - Only specify a `DefaultParameterSetName` if it is actually different from the first parameter set. + +- **One API Call = One Function** + - If you find that a single function is handling multiple distinct API calls, split it into multiple functions. + +- **Public vs. Private** + 1. **Public Functions** + - Support pipeline input if appropriate. + - Should begin by calling `Resolve-GitHubContext` to handle the `Context` parameter, which can be either a string or a `GitHubContext` object. + - Use parameter sets (with `begin`, `process`, `end`) if you have multiple ways to call the same logical operation. + - If choosing among multiple underlying private functions, use a `switch` statement in the `process` block keyed on the parameter set name. + - If a parameter like `$Repository` is missing, you can default to `$Context.Repo`. If no value is found, **throw** an error. + 2. **Private Functions** + - **No pipeline input**. + - No aliases on either the function or its parameters. + - **`Context` is mandatory** (type `GitHubContext`), since public functions should already have resolved it. + - **`Owner`, `Organization`, `ID`, `Repository`** are also mandatory if required by the endpoint. + - Must not contain logic to default parameters from `Context`; that is resolved in public functions. + +--- + +## Documentation for Functions + +All function documentation follows standard PowerShell help conventions, with some notes: + +1. **.SYNOPSIS**, **.DESCRIPTION**, **.EXAMPLES** + - Examples in your code should include fencing (e.g., triple backticks) because the PSModule framework removes default fences. + +2. **.PARAMETER** + - Do **not** store parameter documentation in a comment block separate from the parameter. Instead, use inline parameter documentation via the `[Parameter()]` attribute and descriptions in triple-slash (`///`) comments above each parameter. + +3. **.NOTES** + - Include a link to the official documentation (if any) that the function is based on, so it’s discoverable via online help. + +4. **.LINK** + - First link should be the function’s own local documentation (generated for the PowerShell module). + - Additional links can point to official GitHub or API documentation. + +--- + +## Parameter Guidelines + +1. **Always Declare [Parameter()]** + - Every parameter must explicitly have a `[Parameter()]` attribute, even if empty. + - Place these attributes in a consistent order (see **Parameter Attributes Order** below). + +2. **Parameter Types** + - Always specify a type, e.g. `[string] $Owner` (rather than `$Owner` alone). + +3. **Parameter Naming** + - Use **PascalCase** for parameters. + - Convert snake_case from the API docs to **PascalCase** in the function. + - **`ID`** should be the short name. If needed, add an alias for a long form (e.g., `[Alias('SomeLongName')]`) or for a different style (`'id'`, `'Id'`), depending on user expectations. + - If the function name implies the object (e.g., `Get-GitHubRepository`), do **not** name the parameter `RepositoryId`. Just `ID` (or `Name`, etc.) suffices. Keep it object-oriented rather than repeating the context. + - `Owner` should always have the aliases: `Organization` and `User`. + - `Username` can have the alias `Login` if relevant for a particular API. + - Use `Repository` (not `Repo`). If you need an alias for backward compatibility, add `[Alias('Repo')]`. + +4. **Parameter Attribute Order** + 1. `[Parameter()]` + 2. `[ValidateNotNullOrEmpty()]` or other validation attributes + 3. `[Alias()]` if any + 4. Then the parameter definition itself: `[string] $ParamName` + +5. **Parameter Defaulting** + - For **public** functions, if the user hasn’t provided a parameter (like `$Repository`), default it from the context: + ```powershell + if (-not $Repository) { + $Repository = $Context.Repo + } + if (-not $Repository) { + throw "Repository not specified and not found in the context." + } + ``` + - For **private** functions, the calling function should already have done this. Private functions assume mandatory parameters. + +6. **Remove `[org]` Alias** + - Do not use `[Alias('org')]` on the `$Organization` parameter. Use `[Alias('User','Organization')]` on `$Owner` instead. + +--- + +## Function Content & Flow + +1. **Structure** + - Always use `begin`, `process`, and `end` blocks. + - **`begin`**: Validate parameters, call `Assert-GitHubContext` if needed, set up any local state. + - Add a comment stating which permissions are required for the API call. + - **`process`**: Main logic, including pipeline handling if public. + - **`end`**: Cleanup if necessary. + +2. **ShouldProcess** + - Only use `[CmdletBinding(SupportsShouldProcess)]` for commands that create, update, or remove data. **Do not** apply it to `Get-` commands. + +3. **API Method Naming** + - Use PascalCase for the method in your splat (e.g., `Post`, `Delete`, `Put`, `Get`). + - The `Method` property in your hashtable to `Invoke-GitHubAPI` (or other REST calls) should reflect that standard. + +4. **Splatting** + - Always splat the API call. The standard order in the splat is: + 1. `Method` + 2. `APIEndpoint` (or `Endpoint`, with `APIEndpoint` as an alias if necessary) + 3. `Body` + 4. `Context` + - Body is always a hashtable containing the payload for `POST`, `PATCH`, or `PUT` calls. + +5. **Removing String Checks** + - Do **not** use `if ([string]::IsNullOrEmpty($Param))`. Instead, check `-not $Param` or rely on `[ValidateNotNullOrEmpty()]`. + +6. **Pipeline Output** + - After calling `Invoke-GitHubAPI @inputObject`, you can **either**: + - `ForEach-Object { Write-Output $_.Response }` + - or `Select-Object -ExpandProperty Response` + - Choose which pattern best fits your scenario, but be consistent within a function. + +--- + +## Classes + +1. **One Class per Resource** + - Each distinct resource type gets its own `.ps1` or `.psm1` with a single class definition. + +2. **Property and Method Naming** + - Use PascalCase for all public properties and methods. + +3. **Return Types / Interfaces** + - Each class that you return should have a consistent interface. + - Remove any properties that are purely “API wrapper” fields (e.g., raw HTTP artifacts that aren’t relevant to the user). + +--- + +## Additional Notes + +1. **Endpoint Coverage File** + - Maintain a list of endpoints you’re deliberately **not** implementing, so that your coverage reporting can include a ⚠️ for them. + +2. **Parameter Name Design** + - Use object-oriented naming that reflects the entity. For example, if the function is `Remove-GitHubRepository`, simply use `-ID` (or `-Name`) rather than `-RepositoryID`. + +3. **Aliases** + - Private functions have **no** aliases (function-level or parameter-level). + - Public functions can add aliases where it makes sense (`Owner` has `-User`/`-Organization`, `Repository` might have `-Repo` alias if needed, `Username` might have `-Login`). + +4. **Mandatory Context for Private** + - Private functions must always expect a resolved `[GitHubContext] $Context`. Public functions handle any string-based or null context resolution logic. + +5. **We Do Not Have to Cover Every Possible API** + - Some endpoints (e.g., “hovercards” or other rarely used features) can be excluded. + +--- + +That’s it. This spec captures all the bullet points and original guidelines in one place. Use it as the authoritative reference for coding style, function naming, parameter declarations, and general best practices in your module. diff --git a/examples/Apps/AppManagement.ps1 b/examples/Apps/AppManagement.ps1 index de8a5c69e..041d19f19 100644 --- a/examples/Apps/AppManagement.ps1 +++ b/examples/Apps/AppManagement.ps1 @@ -2,7 +2,7 @@ $appIDs = @( 'Iv1.f26b61bc99e69405' ) -$orgs = Get-GitHubEnterpriseInstallableOrganization -Enterprise 'msx' +$orgs = Get-GitHubAppInstallableOrganization -Enterprise 'msx' foreach ($org in $orgs) { foreach ($appID in $appIDs) { Install-GitHubAppOnEnterpriseOrganization -Enterprise msx -Organization $org.login -ClientID $appID -RepositorySelection all diff --git a/examples/Apps/EnterpriseApps.ps1 b/examples/Apps/EnterpriseApps.ps1 index c41e8b007..69de8c402 100644 --- a/examples/Apps/EnterpriseApps.ps1 +++ b/examples/Apps/EnterpriseApps.ps1 @@ -19,12 +19,8 @@ filter Install-GithubApp { [string] $AppID ) - begin { - - } - process { - $installableOrgs = Get-GitHubEnterpriseInstallableOrganization -Enterprise $Enterprise -Debug -Verbose + $installableOrgs = Get-GitHubAppInstallableOrganization -Enterprise $Enterprise -Debug -Verbose $orgs = $installableOrgs | Where-Object { $_.login -like $organization } foreach ($org in $orgs) { foreach ($appIDitem in $AppID) { @@ -37,12 +33,8 @@ filter Install-GithubApp { } } } - - end { - - } } -$appIDs | Install-GithubApp -Organization $organization -Debug -Verbose +$appIDs | Install-GitHubApp -Organization $organization -Debug -Verbose $installation = Get-GitHubAppInstallation diff --git a/examples/Connecting.ps1 b/examples/Connecting.ps1 index b687a282b..87b0c600c 100644 --- a/examples/Connecting.ps1 +++ b/examples/Connecting.ps1 @@ -1,4 +1,7 @@ -### +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '6.0.0' } +#Requires -Modules @{ ModuleName = 'Microsoft.PowerShell.SecretManagement'; RequiredVersion = '1.1.2' } + +### ### CONNECTING ### diff --git a/examples/Teams/Get-AllTeams.ps1 b/examples/Teams/Get-AllTeams.ps1 deleted file mode 100644 index 5f282702b..000000000 --- a/examples/Teams/Get-AllTeams.ps1 +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/scripts/Update-CoverageReport.ps1 b/scripts/Update-CoverageReport.ps1 index ab0fd749d..c809cf743 100644 --- a/scripts/Update-CoverageReport.ps1 +++ b/scripts/Update-CoverageReport.ps1 @@ -1,4 +1,4 @@ -#Requires -Modules MarkdownPS +#Requires -Modules @{ ModuleName = 'MarkdownPS'; RequiredVersion = '1.10' } [CmdletBinding()] param() diff --git a/src/classes/public/Config/GitHubConfig.ps1 b/src/classes/public/Config/GitHubConfig.ps1 index 02fdd1eb5..32a7b5bfc 100644 --- a/src/classes/public/Config/GitHubConfig.ps1 +++ b/src/classes/public/Config/GitHubConfig.ps1 @@ -23,7 +23,7 @@ # The default value for the HTTP protocol version. [string] $HttpVersion - # The default value for the 'per_page' API parameter used in 'Get' functions that support paging. + # The default value for the 'per_page' API parameter used in 'GET' functions that support paging. [int] $PerPage # Simple parameterless constructor diff --git a/src/classes/public/Context/GitHubContext.ps1 b/src/classes/public/Context/GitHubContext.ps1 index 8d54ac1b9..8145217cd 100644 --- a/src/classes/public/Context/GitHubContext.ps1 +++ b/src/classes/public/Context/GitHubContext.ps1 @@ -53,13 +53,13 @@ # The default value for the Owner parameter. [string] $Owner - # The default value for the Repo parameter. - [string] $Repo + # The default value for the Repository parameter. + [string] $Repository # The default value for the HTTP protocol version. [string] $HttpVersion - # The default value for the 'per_page' API parameter used in 'Get' functions that support paging. + # The default value for the 'per_page' API parameter used in 'GET' functions that support paging. [int] $PerPage # Simple parameterless constructor diff --git a/src/functions/private/Actions/Get-GitHubWorkflowRunByRepo.ps1 b/src/functions/private/Actions/Get-GitHubWorkflowRunByRepo.ps1 index 9032bef8a..dfc12141b 100644 --- a/src/functions/private/Actions/Get-GitHubWorkflowRunByRepo.ps1 +++ b/src/functions/private/Actions/Get-GitHubWorkflowRunByRepo.ps1 @@ -12,19 +12,19 @@ `created`, `event`, `head_sha`, `status`. .EXAMPLE - Get-GitHubWorkflowRunByRepo -Owner 'owner' -Repo 'repo' + Get-GitHubWorkflowRunByRepo -Owner 'owner' -Repository 'repo' Lists all workflow runs for a repository. .EXAMPLE - Get-GitHubWorkflowRunByRepo -Owner 'owner' -Repo 'repo' -Actor 'octocat' -Branch 'main' -Event 'push' -Status 'success' + Get-GitHubWorkflowRunByRepo -Owner 'owner' -Repository 'repo' -Actor 'octocat' -Branch 'main' -Event 'push' -Status 'success' Lists all workflow runs for a repository with the specified actor, branch, event, and status. .NOTES [List workflow runs for a repository](https://docs.github.com/rest/actions/workflow-runs?apiVersion=2022-11-28#list-workflow-runs-for-a-repository) #> - [CmdletBinding(DefaultParameterSetName = 'Repo')] + [CmdletBinding()] [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidLongLines', '', Justification = 'Contains a long link.')] [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidAssignmentToAutomaticVariable', 'Event', Justification = 'A parameter that is used in the api call.')] @@ -35,7 +35,7 @@ # The name of the repository. The name is not case sensitive. [Parameter(Mandatory)] - [string] $Repo, + [string] $Repository, # Returns someone's workflow runs. Use the login for the user who created the push associated with the check suite or workflow run. [Parameter()] @@ -82,53 +82,38 @@ [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. - [Parameter()] - [object] $Context = (Get-GitHubContext) + [Parameter(Mandatory)] + [object] $Context ) begin { $stackPath = Get-PSCallStackPath Write-Debug "[$stackPath] - Start" - $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - if ([string]::IsNullOrEmpty($Owner)) { - $Owner = $Context.Owner + } + + process { + $body = @{ + actor = $Actor + branch = $Branch + event = $Event + status = $Status + created = $Created + exclude_pull_requests = $ExcludePullRequests + check_suite_id = $CheckSuiteID + head_sha = $HeadSHA + per_page = $PerPage } - Write-Debug "Owner: [$Owner]" - if ([string]::IsNullOrEmpty($Repo)) { - $Repo = $Context.Repo + $inputObject = @{ + Method = 'GET' + APIEndpoint = "/repos/$Owner/$Repository/actions/runs" + Body = $body + Context = $Context } - Write-Debug "Repo: [$Repo]" - } - process { - try { - $body = @{ - actor = $Actor - branch = $Branch - event = $Event - status = $Status - created = $Created - exclude_pull_requests = $ExcludePullRequests - check_suite_id = $CheckSuiteID - head_sha = $HeadSHA - per_page = $PerPage - } - - $inputObject = @{ - Context = $Context - APIEndpoint = "/repos/$Owner/$Repo/actions/runs" - Method = 'GET' - Body = $body - } - - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response.workflow_runs - } - } catch { - throw $_ + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response.workflow_runs } } diff --git a/src/functions/private/Actions/Get-GitHubWorkflowRunByWorkflow.ps1 b/src/functions/private/Actions/Get-GitHubWorkflowRunByWorkflow.ps1 index e07a5fbca..d1dbde61b 100644 --- a/src/functions/private/Actions/Get-GitHubWorkflowRunByWorkflow.ps1 +++ b/src/functions/private/Actions/Get-GitHubWorkflowRunByWorkflow.ps1 @@ -13,12 +13,12 @@ `created`, `event`, `head_sha`, `status`. .EXAMPLE - Get-GitHubWorkflowRunByWorkflow -Owner 'octocat' -Repo 'Hello-World' -ID '42' + Get-GitHubWorkflowRunByWorkflow -Owner 'octocat' -Repository 'Hello-World' -ID '42' Gets all workflow runs for the workflow with the ID `42` in the repository `Hello-World` owned by `octocat`. .EXAMPLE - Get-GitHubWorkflowRunByWorkflow -Owner 'octocat' -Repo 'Hello-World' -ID '42' -Actor 'octocat' -Branch 'main' -Event 'push' -Status 'success' + Get-GitHubWorkflowRunByWorkflow -Owner 'octocat' -Repository 'Hello-World' -ID '42' -Actor 'octocat' -Branch 'main' -Event 'push' -Status 'success' Gets all workflow runs for the workflow with the ID `42` in the repository `Hello-World` owned by `octocat` that were triggered by the user `octocat` on the branch `main` and have the status `success`. @@ -26,7 +26,7 @@ .NOTES [List workflow runs for a workflow](https://docs.github.com/rest/actions/workflow-runs?apiVersion=2022-11-28#list-workflow-runs-for-a-workflow) #> - [CmdletBinding(DefaultParameterSetName = 'Repo')] + [CmdletBinding()] [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidLongLines', '', Justification = 'Contains a long link.')] [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidAssignmentToAutomaticVariable', 'Event', Justification = 'A parameter that is used in the api call.')] @@ -37,7 +37,7 @@ # The name of the repository. The name is not case sensitive. [Parameter(Mandatory)] - [string] $Repo, + [string] $Repository, # The ID of the workflow. You can also pass the workflow filename as a string. [Parameter(Mandatory)] @@ -89,53 +89,38 @@ [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. - [Parameter()] - [object] $Context = (Get-GitHubContext) + [Parameter(Mandatory)] + [object] $Context ) begin { $stackPath = Get-PSCallStackPath Write-Debug "[$stackPath] - Start" - $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - if ([string]::IsNullOrEmpty($Owner)) { - $Owner = $Context.Owner + } + + process { + $body = @{ + actor = $Actor + branch = $Branch + event = $Event + status = $Status + created = $Created + exclude_pull_requests = $ExcludePullRequests + check_suite_id = $CheckSuiteID + head_sha = $HeadSHA + per_page = $PerPage } - Write-Debug "Owner: [$Owner]" - if ([string]::IsNullOrEmpty($Repo)) { - $Repo = $Context.Repo + $inputObject = @{ + Context = $Context + APIEndpoint = "/repos/$Owner/$Repository/actions/workflows/$ID/runs" + Method = 'GET' + Body = $body } - Write-Debug "Repo: [$Repo]" - } - process { - try { - $body = @{ - actor = $Actor - branch = $Branch - event = $Event - status = $Status - created = $Created - exclude_pull_requests = $ExcludePullRequests - check_suite_id = $CheckSuiteID - head_sha = $HeadSHA - per_page = $PerPage - } - - $inputObject = @{ - Context = $Context - APIEndpoint = "/repos/$Owner/$Repo/actions/workflows/$ID/runs" - Method = 'GET' - Body = $body - } - - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response.workflow_runs - } - } catch { - throw $_ + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response.workflow_runs } } diff --git a/src/functions/private/Actions/Import-GitHubEventData.ps1 b/src/functions/private/Actions/Import-GitHubEventData.ps1 index def1ed332..fa5cf33de 100644 --- a/src/functions/private/Actions/Import-GitHubEventData.ps1 +++ b/src/functions/private/Actions/Import-GitHubEventData.ps1 @@ -25,50 +25,46 @@ function Import-GitHubEventData { } process { - try { - $gitHubEventJson = Get-Content -Path $env:GITHUB_EVENT_PATH - $gitHubEvent = $gitHubEventJson | ConvertFrom-Json + $gitHubEventJson = Get-Content -Path $env:GITHUB_EVENT_PATH + $gitHubEvent = $gitHubEventJson | ConvertFrom-Json - $eventAction = $gitHubEvent.action - $eventSender = $gitHubEvent.sender | Select-Object -Property login, type, id, node_id, html_url - $eventEnterprise = $gitHubEvent.enterprise | Select-Object -Property name, slug, id, node_id, html_url - $eventOrganization = $gitHubEvent.organization | Select-Object -Property login, id, node_id - $eventOwner = $gitHubEvent.repository.owner | Select-Object -Property login, type, id, node_id, html_url - $eventRepository = $gitHubEvent.repository | Select-Object -Property name, full_name, html_url, id, node_id, default_branch + $eventAction = $gitHubEvent.action + $eventSender = $gitHubEvent.sender | Select-Object -Property login, type, id, node_id, html_url + $eventEnterprise = $gitHubEvent.enterprise | Select-Object -Property name, slug, id, node_id, html_url + $eventOrganization = $gitHubEvent.organization | Select-Object -Property login, id, node_id + $eventOwner = $gitHubEvent.repository.owner | Select-Object -Property login, type, id, node_id, html_url + $eventRepository = $gitHubEvent.repository | Select-Object -Property name, full_name, html_url, id, node_id, default_branch - $gitHubEvent = $gitHubEvent | Select-Object -ExcludeProperty action, sender, enterprise, organization, repository + $gitHubEvent = $gitHubEvent | Select-Object -ExcludeProperty action, sender, enterprise, organization, repository - $hashtable = @{} - $gitHubEvent.PSObject.Properties | ForEach-Object { - $name = $_.Name - $name = $name | ConvertTo-CasingStyle -To PascalCase - $hashtable[$name] = $_.Value - } - $gitHubEvent = [pscustomobject]$hashtable + $hashtable = @{} + $gitHubEvent.PSObject.Properties | ForEach-Object { + $name = $_.Name + $name = $name | ConvertTo-CasingStyle -To PascalCase + $hashtable[$name] = $_.Value + } + $gitHubEvent = [pscustomobject]$hashtable - $gitHubEvent | Add-Member -MemberType NoteProperty -Name Type -Value $env:GITHUB_EVENT_NAME -Force - if ($eventAction) { - $gitHubEvent | Add-Member -MemberType NoteProperty -Name Action -Value $eventAction -Force - } - if ($eventSender) { - $gitHubEvent | Add-Member -MemberType NoteProperty -Name Sender -Value $eventSender -Force - } - if ($eventEnterprise) { - $gitHubEvent | Add-Member -MemberType NoteProperty -Name Enterprise -Value $eventEnterprise -Force - } - if ($eventOrganization) { - $gitHubEvent | Add-Member -MemberType NoteProperty -Name Organization -Value $eventOrganization -Force - } - if ($eventOwner) { - $gitHubEvent | Add-Member -MemberType NoteProperty -Name Owner -Value $eventOwner -Force - } - if ($eventRepository) { - $gitHubEvent | Add-Member -MemberType NoteProperty -Name Repository -Value $eventRepository -Force - } - $script:GitHub.Event = $gitHubEvent - } catch { - throw $_ + $gitHubEvent | Add-Member -MemberType NoteProperty -Name Type -Value $env:GITHUB_EVENT_NAME -Force + if ($eventAction) { + $gitHubEvent | Add-Member -MemberType NoteProperty -Name Action -Value $eventAction -Force + } + if ($eventSender) { + $gitHubEvent | Add-Member -MemberType NoteProperty -Name Sender -Value $eventSender -Force + } + if ($eventEnterprise) { + $gitHubEvent | Add-Member -MemberType NoteProperty -Name Enterprise -Value $eventEnterprise -Force + } + if ($eventOrganization) { + $gitHubEvent | Add-Member -MemberType NoteProperty -Name Organization -Value $eventOrganization -Force + } + if ($eventOwner) { + $gitHubEvent | Add-Member -MemberType NoteProperty -Name Owner -Value $eventOwner -Force + } + if ($eventRepository) { + $gitHubEvent | Add-Member -MemberType NoteProperty -Name Repository -Value $eventRepository -Force } + $script:GitHub.Event = $gitHubEvent } end { diff --git a/src/functions/private/Actions/Import-GitHubRunnerData.ps1 b/src/functions/private/Actions/Import-GitHubRunnerData.ps1 index 82dbd59e0..3a8ae9542 100644 --- a/src/functions/private/Actions/Import-GitHubRunnerData.ps1 +++ b/src/functions/private/Actions/Import-GitHubRunnerData.ps1 @@ -23,21 +23,17 @@ } process { - try { - $script:GitHub.Runner = [pscustomobject]@{ - Name = $env:RUNNER_NAME - OS = $env:RUNNER_OS - Arch = $env:RUNNER_ARCH - Environment = $env:RUNNER_ENVIRONMENT - Temp = $env:RUNNER_TEMP - Perflog = $env:RUNNER_PERFLOG - ToolCache = $env:RUNNER_TOOL_CACHE - TrackingID = $env:RUNNER_TRACKING_ID - Workspace = $env:RUNNER_WORKSPACE - Processors = [System.Environment]::ProcessorCount - } - } catch { - throw $_ + $script:GitHub.Runner = [pscustomobject]@{ + Name = $env:RUNNER_NAME + OS = $env:RUNNER_OS + Arch = $env:RUNNER_ARCH + Environment = $env:RUNNER_ENVIRONMENT + Temp = $env:RUNNER_TEMP + Perflog = $env:RUNNER_PERFLOG + ToolCache = $env:RUNNER_TOOL_CACHE + TrackingID = $env:RUNNER_TRACKING_ID + Workspace = $env:RUNNER_WORKSPACE + Processors = [System.Environment]::ProcessorCount } } diff --git a/src/functions/private/Apps/GitHub Apps/Get-GitHubAppByName.ps1 b/src/functions/private/Apps/GitHub Apps/Get-GitHubAppByName.ps1 index df1b98df9..c6e9d0f0e 100644 --- a/src/functions/private/Apps/GitHub Apps/Get-GitHubAppByName.ps1 +++ b/src/functions/private/Apps/GitHub Apps/Get-GitHubAppByName.ps1 @@ -25,31 +25,25 @@ [string] $AppSlug, # 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. - [Parameter()] - [object] $Context = (Get-GitHubContext) + [Parameter(Mandatory)] + [object] $Context ) begin { $stackPath = Get-PSCallStackPath Write-Debug "[$stackPath] - Start" - $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT } process { - try { - $inputObject = @{ - Context = $Context - APIEndpoint = "/apps/$AppSlug" - Method = 'GET' - } - - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } - } catch { - throw $_ + $inputObject = @{ + Context = $Context + APIEndpoint = "/apps/$AppSlug" + Method = 'GET' + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } } end { diff --git a/src/functions/public/Apps/GitHub Apps/Get-GitHubAppInstallation.ps1 b/src/functions/private/Apps/GitHub Apps/Get-GitHubAppInstallationForAuthenticatedApp.ps1 similarity index 58% rename from src/functions/public/Apps/GitHub Apps/Get-GitHubAppInstallation.ps1 rename to src/functions/private/Apps/GitHub Apps/Get-GitHubAppInstallationForAuthenticatedApp.ps1 index d65c0e5f1..43f409f6c 100644 --- a/src/functions/public/Apps/GitHub Apps/Get-GitHubAppInstallation.ps1 +++ b/src/functions/private/Apps/GitHub Apps/Get-GitHubAppInstallationForAuthenticatedApp.ps1 @@ -1,7 +1,7 @@ -filter Get-GitHubAppInstallation { +function Get-GitHubAppInstallationForAuthenticatedApp { <# .SYNOPSIS - List installations for the authenticated app + List installations for the authenticated app. .DESCRIPTION The permissions the installation has are included under the `permissions` key. @@ -10,7 +10,7 @@ to access this endpoint. .EXAMPLE - Get-GitHubAppInstallation + Get-GitHubAppInstallationForAuthenticatedApp List installations for the authenticated app. @@ -20,31 +20,25 @@ [CmdletBinding()] param( # 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. - [Parameter()] - [object] $Context = (Get-GitHubContext) + [Parameter(Mandatory)] + [object] $Context ) begin { $stackPath = Get-PSCallStackPath Write-Debug "[$stackPath] - Start" - $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType APP } process { - try { - $inputObject = @{ - Context = $Context - APIEndpoint = '/app/installations' - Method = 'GET' - } - - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } - } catch { - throw $_ + $inputObject = @{ + Context = $Context + APIEndpoint = '/app/installations' + Method = 'GET' + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } } diff --git a/src/functions/private/Apps/GitHub Apps/Get-GitHubAuthenticatedApp.ps1 b/src/functions/private/Apps/GitHub Apps/Get-GitHubAuthenticatedApp.ps1 index c32b49a48..f7f0c4cba 100644 --- a/src/functions/private/Apps/GitHub Apps/Get-GitHubAuthenticatedApp.ps1 +++ b/src/functions/private/Apps/GitHub Apps/Get-GitHubAuthenticatedApp.ps1 @@ -24,33 +24,25 @@ [CmdletBinding()] param( # 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. - [Parameter()] - [object] $Context = (Get-GitHubContext) + [Parameter(Mandatory)] + [object] $Context ) begin { $stackPath = Get-PSCallStackPath Write-Debug "[$stackPath] - Start" - $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType App } process { - try { - $Context = Resolve-GitHubContext -Context $Context - - $inputObject = @{ - Context = $Context - APIEndpoint = '/app' - Method = 'GET' - } - - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } - } catch { - throw $_ + $inputObject = @{ + Method = 'GET' + APIEndpoint = '/app' + Context = $Context + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } } end { diff --git a/src/functions/private/Apps/GitHub Apps/Get-GitHubEnterpriseOrganizationAppInstallation.ps1 b/src/functions/private/Apps/GitHub Apps/Get-GitHubEnterpriseOrganizationAppInstallation.ps1 new file mode 100644 index 000000000..dde6598a6 --- /dev/null +++ b/src/functions/private/Apps/GitHub Apps/Get-GitHubEnterpriseOrganizationAppInstallation.ps1 @@ -0,0 +1,73 @@ +function Get-GitHubEnterpriseOrganizationAppInstallation { + <# + .SYNOPSIS + List GitHub Apps installed on an enterprise-owned organization + + .DESCRIPTION + Lists the GitHub App installations associated with the given enterprise-owned organization. + + The authenticated GitHub App must be installed on the enterprise and be granted the Enterprise/organization_installations (read) permission. + + .EXAMPLE + Get-GitHubEnterpriseOrganizationAppInstallation -ENterprise 'msx' -Organization 'github' + + Gets all GitHub Apps in the organization `github` in the enterprise `msx`. + + .NOTES + [List GitHub Apps installed on an enterprise-owned organization]() + #> + [OutputType([pscustomobject])] + [CmdletBinding()] + param( + # The enterprise slug or ID. + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName + )] + [string] $Enterprise, + + # The organization name. The name is not case sensitive. + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName + )] + [string] $Organization, + + # The number of results per page (max 100). + [Parameter()] + [ValidateRange(0, 100)] + [int] $PerPage, + + # The context to run the command in. Used to get the details for the API call. + [Parameter(Mandatory)] + [object] $Context + ) + + begin { + $stackPath = Get-PSCallStackPath + Write-Debug "[$stackPath] - Start" + Assert-GitHubContext -Context $Context -AuthType IAT, UAT + # Enterprise_organization_installations=read + } + + process { + $body = @{ + per_page = $PerPage + } + + $inputObject = @{ + Method = 'GET' + APIEndpoint = "/enterprises/$Enterprise/apps/organizations/$Organization/installations" + Body = $body + Context = $Context + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } + } + + end { + Write-Debug "[$stackPath] - End" + } +} diff --git a/src/functions/public/Organization/Get-GitHubOrganizationAppInstallation.ps1 b/src/functions/private/Apps/GitHub Apps/Get-GitHubOrganizationAppInstallation.ps1 similarity index 61% rename from src/functions/public/Organization/Get-GitHubOrganizationAppInstallation.ps1 rename to src/functions/private/Apps/GitHub Apps/Get-GitHubOrganizationAppInstallation.ps1 index a7a0f8b35..818e26128 100644 --- a/src/functions/public/Organization/Get-GitHubOrganizationAppInstallation.ps1 +++ b/src/functions/private/Apps/GitHub Apps/Get-GitHubOrganizationAppInstallation.ps1 @@ -1,4 +1,4 @@ -filter Get-GitHubOrganizationAppInstallation { +function Get-GitHubOrganizationAppInstallation { <# .SYNOPSIS List app installations for an organization @@ -24,9 +24,6 @@ ValueFromPipeline, ValueFromPipelineByPropertyName )] - [Alias('org')] - [Alias('owner')] - [Alias('login')] [string] $Organization, # The number of results per page (max 100). @@ -35,41 +32,30 @@ [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. - [Parameter()] - [object] $Context = (Get-GitHubContext) + [Parameter(Mandatory)] + [object] $Context ) begin { $stackPath = Get-PSCallStackPath Write-Debug "[$stackPath] - Start" - $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - - if ([string]::IsNullOrEmpty($Owner)) { - $Owner = $Context.Owner - } - Write-Debug "Owner: [$Owner]" } process { - try { - $body = @{ - per_page = $PerPage - } + $body = @{ + per_page = $PerPage + } - $inputObject = @{ - Context = $Context - APIEndpoint = "/orgs/$Organization/installations" - Method = 'GET' - Body = $body - } + $inputObject = @{ + Method = 'GET' + APIEndpoint = "/orgs/$Organization/installations" + Body = $body + Context = $Context + } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response.installations - } - } catch { - throw $_ + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response.installations } } diff --git a/src/functions/public/Enterprise/Install-GitHubAppOnEnterpriseOrganization.ps1 b/src/functions/private/Apps/GitHub Apps/Install-GitHubAppOnEnterpriseOrganization.ps1 similarity index 58% rename from src/functions/public/Enterprise/Install-GitHubAppOnEnterpriseOrganization.ps1 rename to src/functions/private/Apps/GitHub Apps/Install-GitHubAppOnEnterpriseOrganization.ps1 index 2f72c5f66..86ad14af4 100644 --- a/src/functions/public/Enterprise/Install-GitHubAppOnEnterpriseOrganization.ps1 +++ b/src/functions/private/Apps/GitHub Apps/Install-GitHubAppOnEnterpriseOrganization.ps1 @@ -14,7 +14,7 @@ [CmdletBinding()] param( # The enterprise slug or ID. - [Parameter()] + [Parameter(Mandatory)] [string] $Enterprise, # The organization name. The name is not case sensitive. @@ -28,52 +28,43 @@ # The repository selection for the GitHub App. Can be one of: # - all - all repositories that the authenticated GitHub App installation can access. # - selected - select specific repositories. - [Parameter()] + [Parameter(Mandatory)] [ValidateSet('all', 'selected')] - [string] $RepositorySelection = 'all', + [string] $RepositorySelection, # The names of the repositories to which the installation will be granted access. [Parameter()] [string[]] $Repositories, # 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. - [Parameter()] - [object] $Context = (Get-GitHubContext) + [Parameter(Mandatory)] + [object] $Context ) begin { $stackPath = Get-PSCallStackPath Write-Debug "[$stackPath] - Start" - $Context = Resolve-GitHubContext -Context $Context - Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - if ([string]::IsNullOrEmpty($Enterprise)) { - $Enterprise = $Context.Enterprise - } - Write-Debug "Enterprise: [$Enterprise]" + Assert-GitHubContext -Context $Context -AuthType IAT, UAT + # enterprise_organization_installations=write } process { - try { - $body = @{ - client_id = $ClientID - repository_selection = $RepositorySelection - repositories = $Repositories - } - $body | Remove-HashtableEntry -NullOrEmptyValues + $body = @{ + client_id = $ClientID + repository_selection = $RepositorySelection + repositories = $Repositories + } + $body | Remove-HashtableEntry -NullOrEmptyValues - $inputObject = @{ - Context = $Context - APIEndpoint = "/enterprises/$Enterprise/apps/organizations/$Organization/installations" - Method = 'Post' - Body = $body - } + $inputObject = @{ + Method = 'POST' + APIEndpoint = "/enterprises/$Enterprise/apps/organizations/$Organization/installations" + Body = $body + Context = $Context + } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } - } catch { - throw $_ + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } } diff --git a/src/functions/public/Enterprise/Uninstall-GitHubAppOnEnterpriseOrganization.ps1 b/src/functions/private/Apps/GitHub Apps/Uninstall-GitHubAppOnEnterpriseOrganization.ps1 similarity index 59% rename from src/functions/public/Enterprise/Uninstall-GitHubAppOnEnterpriseOrganization.ps1 rename to src/functions/private/Apps/GitHub Apps/Uninstall-GitHubAppOnEnterpriseOrganization.ps1 index 92596632c..5555145e4 100644 --- a/src/functions/public/Enterprise/Uninstall-GitHubAppOnEnterpriseOrganization.ps1 +++ b/src/functions/private/Apps/GitHub Apps/Uninstall-GitHubAppOnEnterpriseOrganization.ps1 @@ -16,7 +16,7 @@ [CmdletBinding()] param( # The enterprise slug or ID. - [Parameter()] + [Parameter(Mandatory)] [string] $Enterprise, # The organization name. The name is not case sensitive. @@ -25,39 +25,29 @@ # The client ID of the GitHub App to install. [Parameter(Mandatory)] - [Alias('installation_id')] - [string] $InstallationID, + [string] $ID, # 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. - [Parameter()] - [object] $Context = (Get-GitHubContext) + [Parameter(Mandatory)] + [object] $Context ) begin { $stackPath = Get-PSCallStackPath Write-Debug "[$stackPath] - Start" - $Context = Resolve-GitHubContext -Context $Context - Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - if ([string]::IsNullOrEmpty($Enterprise)) { - $Enterprise = $Context.Enterprise - } - Write-Debug "Enterprise: [$Enterprise]" + Assert-GitHubContext -Context $Context -AuthType IAT, UAT + #enterprise_organization_installations=write } process { - try { - $inputObject = @{ - Context = $Context - APIEndpoint = "/enterprises/$Enterprise/apps/organizations/$Organization/installations/$InstallationID}" - Method = 'Delete' - } + $inputObject = @{ + Method = 'DELETE' + APIEndpoint = "/enterprises/$Enterprise/apps/organizations/$Organization/installations/$ID" + Context = $Context + } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } - } catch { - throw $_ + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } } diff --git a/src/functions/private/Apps/Webhooks/Get-GitHubAppWebhookDeliveryByID.ps1 b/src/functions/private/Apps/Webhooks/Get-GitHubAppWebhookDeliveryByID.ps1 index 6b6e77462..d2a451fb1 100644 --- a/src/functions/private/Apps/Webhooks/Get-GitHubAppWebhookDeliveryByID.ps1 +++ b/src/functions/private/Apps/Webhooks/Get-GitHubAppWebhookDeliveryByID.ps1 @@ -23,53 +23,47 @@ param( # The ID of the delivery. [Parameter(Mandatory)] - [Alias('DeliveryID', 'delivery_id')] + [Alias('delivery_id', 'DeliveryID')] [string] $ID, # 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. - [Parameter()] - [object] $Context = (Get-GitHubContext) + [Parameter(Mandatory)] + [object] $Context ) begin { $stackPath = Get-PSCallStackPath Write-Debug "[$stackPath] - Start" - $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType APP } process { - try { - $inputObject = @{ - Context = $Context - APIEndpoint = "/app/hook/deliveries/$ID" - Method = 'GET' - } + $inputObject = @{ + Method = 'GET' + APIEndpoint = "/app/hook/deliveries/$ID" + Context = $Context + } - Invoke-GitHubAPI @inputObject | ForEach-Object { - [GitHubWebhook]( - @{ - ID = $_.id - GUID = $_.guid - DeliveredAt = $_.delivered_at - Redelivery = $_.redelivery - Duration = $_.duration - Status = $_.status - StatusCode = $_.status_code - Event = $_.event - Action = $_.action - InstallationID = $_.installation.id - RepositoryID = $_.repository.id - ThrottledAt = $_.throttled_at - URL = $_.url - Request = $_.request - Response = $_.response - } - ) - } - } catch { - throw $_ + Invoke-GitHubAPI @inputObject | ForEach-Object { + [GitHubWebhook]( + @{ + ID = $_.id + GUID = $_.guid + DeliveredAt = $_.delivered_at + Redelivery = $_.redelivery + Duration = $_.duration + Status = $_.status + StatusCode = $_.status_code + Event = $_.event + Action = $_.action + InstallationID = $_.installation.id + RepositoryID = $_.repository.id + ThrottledAt = $_.throttled_at + URL = $_.url + Request = $_.request + Response = $_.response + } + ) } } diff --git a/src/functions/private/Apps/Webhooks/Get-GitHubAppWebhookDeliveryByList.ps1 b/src/functions/private/Apps/Webhooks/Get-GitHubAppWebhookDeliveryByList.ps1 index 1be9aff19..243c15c8a 100644 --- a/src/functions/private/Apps/Webhooks/Get-GitHubAppWebhookDeliveryByList.ps1 +++ b/src/functions/private/Apps/Webhooks/Get-GitHubAppWebhookDeliveryByList.ps1 @@ -26,56 +26,50 @@ [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. - [Parameter()] - [object] $Context = (Get-GitHubContext) + [Parameter(Mandatory)] + [object] $Context ) begin { $stackPath = Get-PSCallStackPath Write-Debug "[$stackPath] - Start" - $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType APP } process { - try { - $body = @{ - per_page = $PerPage - } + $body = @{ + per_page = $PerPage + } - $inputObject = @{ - Context = $Context - APIEndpoint = '/app/hook/deliveries' - Method = 'GET' - Body = $body - } + $inputObject = @{ + Method = 'GET' + APIEndpoint = '/app/hook/deliveries' + Body = $body + Context = $Context + } - Invoke-GitHubAPI @inputObject | ForEach-Object { - $_.Response | ForEach-Object { - [GitHubWebhook]( - @{ - ID = $_.id - GUID = $_.guid - DeliveredAt = $_.delivered_at - Redelivery = $_.redelivery - Duration = $_.duration - Status = $_.status - StatusCode = $_.status_code - Event = $_.event - Action = $_.action - InstallationID = $_.installation.id - RepositoryID = $_.repository.id - ThrottledAt = $_.throttled_at - URL = $_.url - Request = $_.request - Response = $_.response - } - ) - } + Invoke-GitHubAPI @inputObject | ForEach-Object { + $_.Response | ForEach-Object { + [GitHubWebhook]( + @{ + ID = $_.id + GUID = $_.guid + DeliveredAt = $_.delivered_at + Redelivery = $_.redelivery + Duration = $_.duration + Status = $_.status + StatusCode = $_.status_code + Event = $_.event + Action = $_.action + InstallationID = $_.installation.id + RepositoryID = $_.repository.id + ThrottledAt = $_.throttled_at + URL = $_.url + Request = $_.request + Response = $_.response + } + ) } - } catch { - throw $_ } } diff --git a/src/functions/private/Apps/Webhooks/Get-GitHubAppWebhookDeliveryToRedeliver.ps1 b/src/functions/private/Apps/Webhooks/Get-GitHubAppWebhookDeliveryToRedeliver.ps1 index 9bb7ce43c..0b084c8ef 100644 --- a/src/functions/private/Apps/Webhooks/Get-GitHubAppWebhookDeliveryToRedeliver.ps1 +++ b/src/functions/private/Apps/Webhooks/Get-GitHubAppWebhookDeliveryToRedeliver.ps1 @@ -24,46 +24,40 @@ [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. - [Parameter()] - [object] $Context = (Get-GitHubContext) + [Parameter(Mandatory)] + [object] $Context ) begin { $stackPath = Get-PSCallStackPath Write-Debug "[$stackPath] - Start" - $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType APP } process { - try { - $checkPoint = (Get-Date).AddHours($TimeSpan) - Get-GitHubAppWebhookDeliveryByList -Context $Context -PerPage $PerPage | Where-Object { $_.DeliveredAt -gt $checkPoint } | - Group-Object -Property GUID | Where-Object { $_.Group.Status -notcontains 'OK' } | ForEach-Object { - $refObject = $_.Group | Sort-Object -Property DeliveredAt - [GitHubWebhookRedelivery]@{ - Attempts = $_.Count - GUID = $_.Name - Status = $refObject.Status - StatusCode = $refObject.StatusCode - Event = $refObject.Event - Action = $refObject.Action - Duration = $_.Group.Duration | Measure-Object -Average | Select-Object -ExpandProperty Average - ID = $refObject.ID - DeliveredAt = $refObject.DeliveredAt - Redelivery = $refObject.Redelivery - InstallationID = $refObject.InstallationID - RepositoryID = $refObject.RepositoryID - ThrottledAt = $refObject.ThrottledAt - URL = $refObject.URL - Request = $refObject.Request - Response = $refObject.Response - } + $checkPoint = (Get-Date).AddHours($TimeSpan) + Get-GitHubAppWebhookDeliveryByList -Context $Context -PerPage $PerPage | Where-Object { $_.DeliveredAt -gt $checkPoint } | + Group-Object -Property GUID | Where-Object { $_.Group.Status -notcontains 'OK' } | ForEach-Object { + $refObject = $_.Group | Sort-Object -Property DeliveredAt + [GitHubWebhookRedelivery]@{ + Attempts = $_.Count + GUID = $_.Name + Status = $refObject.Status + StatusCode = $refObject.StatusCode + Event = $refObject.Event + Action = $refObject.Action + Duration = $_.Group.Duration | Measure-Object -Average | Select-Object -ExpandProperty Average + ID = $refObject.ID + DeliveredAt = $refObject.DeliveredAt + Redelivery = $refObject.Redelivery + InstallationID = $refObject.InstallationID + RepositoryID = $refObject.RepositoryID + ThrottledAt = $refObject.ThrottledAt + URL = $refObject.URL + Request = $refObject.Request + Response = $refObject.Response } - } catch { - throw $_ - } + } } end { diff --git a/src/functions/private/Auth/Context/Assert-GitHubContext.ps1 b/src/functions/private/Auth/Context/Assert-GitHubContext.ps1 index d54844545..4bfe1d32b 100644 --- a/src/functions/private/Auth/Context/Assert-GitHubContext.ps1 +++ b/src/functions/private/Auth/Context/Assert-GitHubContext.ps1 @@ -8,7 +8,7 @@ If the context does not meet the requirements, an error is thrown. .EXAMPLE - Assert-GitHubContext -Context 'github.com/Octocat' -TokenType 'App' + Assert-GitHubContext -Context 'github.com/Octocat' -AuthType 'App' #> [OutputType([void])] [CmdletBinding()] @@ -23,6 +23,11 @@ # The required authtypes for the command. [Parameter(Mandatory)] [string[]] $AuthType + + # TODO: Implement permission check + # # The required permission for the command. + # [Parameter()] + # [string] $Permission ) begin { @@ -36,6 +41,10 @@ if ($Context.AuthType -notin $AuthType) { throw "The context '$($Context.Name)' does not match the required AuthTypes [$AuthType] for [$command]." } + # TODO: Implement permission check + # if ($Context.AuthType -in 'IAT' -and $Context.Permission -notin $Permission) { + # throw "The context '$($Context.Name)' does not match the required Permission [$Permission] for [$command]." + # } } end { diff --git a/src/functions/private/Auth/Context/Resolve-GitHubContext.ps1 b/src/functions/private/Auth/Context/Resolve-GitHubContext.ps1 index dffd3960e..60f1b3158 100644 --- a/src/functions/private/Auth/Context/Resolve-GitHubContext.ps1 +++ b/src/functions/private/Auth/Context/Resolve-GitHubContext.ps1 @@ -25,8 +25,11 @@ param( # The context to resolve into an object. Used to get the details for the API call. # Can be either a string or a GitHubContext object. - [Parameter(ValueFromPipeline)] - [object] $Context = (Get-GitHubContext) + [Parameter( + Mandatory, + ValueFromPipeline + )] + [object] $Context ) begin { @@ -36,36 +39,33 @@ } process { - try { - if ($Context -is [string]) { - $contextName = $Context - Write-Debug "Getting context: [$contextName]" - $Context = Get-GitHubContext -Context $contextName - } - - if (-not $Context) { - throw "Please provide a valid context or log in using 'Connect-GitHub'." - } + if ($Context -is [string]) { + $contextName = $Context + Write-Debug "Getting context: [$contextName]" + $Context = Get-GitHubContext -Context $contextName + } - # switch ($Context.Type) { - # 'App' { - # $availableContexts = Get-GitHubContext -ListAvailable | - # Where-Object { $_.Type -eq 'Installation' -and $_.ClientID -eq $Context.ClientID } - # $params = Get-FunctionParameter -Scope 2 - # Write-Debug 'Resolving parameters used in called function' - # Write-Debug ($params | Out-String) - # if ($params.Keys -in 'Owner', 'Organization') { - # $Context = $availableContexts | Where-Object { $_.Owner -eq $params.Owner } - # } - # } - # } - } catch { - throw $_ + if (-not $Context) { + throw "Please provide a valid context or log in using 'Connect-GitHub'." } + + # TODO: Implement App installation context resolution + # switch ($Context.Type) { + # 'App' { + # $availableContexts = Get-GitHubContext -ListAvailable | + # Where-Object { $_.Type -eq 'Installation' -and $_.ClientID -eq $Context.ClientID } + # $params = Get-FunctionParameter -Scope 2 + # Write-Debug 'Resolving parameters used in called function' + # Write-Debug ($params | Out-String) + # if ($params.Keys -in 'Owner', 'Organization') { + # $Context = $availableContexts | Where-Object { $_.Owner -eq $params.Owner } + # } + # } + # } + Write-Output $Context } end { Write-Debug "[$stackPath] - End" - Write-Output $Context } } diff --git a/src/functions/private/Auth/Context/Set-GitHubContext.ps1 b/src/functions/private/Auth/Context/Set-GitHubContext.ps1 index 5f3af22ad..60c829d4e 100644 --- a/src/functions/private/Auth/Context/Set-GitHubContext.ps1 +++ b/src/functions/private/Auth/Context/Set-GitHubContext.ps1 @@ -17,7 +17,7 @@ function Set-GitHubContext { AuthType = 'PAT' Enterprise = 'msx' Owner = 'octocat' - Repo = 'Hello-World' + Repository = 'Hello-World' } Set-GitHubContext -Context $context @@ -52,7 +52,7 @@ function Set-GitHubContext { # Run functions to get info on the temporary context. try { Write-Debug "Getting info on the context [$($contextObj['AuthType'])]." - switch -Regex ($($contextObj['AuthType'])) { + switch -Regex (($contextObj['AuthType'])) { 'PAT|UAT|IAT' { $viewer = Get-GitHubViewer -Context $contextObj $viewer | Out-String -Stream | ForEach-Object { Write-Debug $_ } @@ -79,10 +79,10 @@ function Set-GitHubContext { $contextObj['Type'] = 'Installation' if ([string]::IsNullOrEmpty($contextObj['DisplayName'])) { try { - $app = Get-GitHubApp -AppSlug $contextObj['Username'] -Context $contextObj + $app = Get-GitHubApp -Name $contextObj['Username'] -Context $contextObj $contextObj['DisplayName'] = [string]$app.name } catch { - Write-Warning "Failed to get the GitHub App with the slug: [$($contextObj['Username'])]." + Write-Debug "Failed to get the GitHub App with the slug: [$($contextObj['Username'])]." } } if ($script:GitHub.EnvironmentType -eq 'GHA') { @@ -92,11 +92,11 @@ function Set-GitHubContext { $enterprise = $gitHubEvent.enterprise.slug $organization = $gitHubEvent.organization.login $owner = $gitHubEvent.repository.owner.login - $repo = $gitHubEvent.repository.name + $Repository = $gitHubEvent.repository.name $gh_sender = $gitHubEvent.sender.login # sender is an automatic variable in Powershell Write-Debug "Enterprise: $enterprise" Write-Debug "Organization: $organization" - Write-Debug "Repository: $repo" + Write-Debug "Repository: $Repository" Write-Debug "Repository Owner: $owner" Write-Debug "Repository Owner Type: $installationType" Write-Debug "Sender: $gh_sender" @@ -106,8 +106,8 @@ function Set-GitHubContext { if ([string]::IsNullOrEmpty($contextObj['Owner'])) { $contextObj['Owner'] = [string]$owner } - if ([string]::IsNullOrEmpty($contextObj['Repo'])) { - $contextObj['Repo'] = [string]$repo + if ([string]::IsNullOrEmpty($contextObj['Repository'])) { + $contextObj['Repository'] = [string]$Repository } if ([string]::IsNullOrEmpty($contextObj['InstallationType'])) { $contextObj['InstallationType'] = [string]$installationType diff --git a/src/functions/private/Auth/DeviceFlow/Invoke-GitHubDeviceFlowLogin.ps1 b/src/functions/private/Auth/DeviceFlow/Invoke-GitHubDeviceFlowLogin.ps1 index abce72717..32afe8622 100644 --- a/src/functions/private/Auth/DeviceFlow/Invoke-GitHubDeviceFlowLogin.ps1 +++ b/src/functions/private/Auth/DeviceFlow/Invoke-GitHubDeviceFlowLogin.ps1 @@ -47,31 +47,27 @@ } process { - try { - do { - if ($RefreshToken) { - $tokenResponse = Wait-GitHubAccessToken -ClientID $ClientID -RefreshToken $RefreshToken -HostName $HostName - } else { - $deviceCodeResponse = Request-GitHubDeviceCode -ClientID $ClientID -Scope $Scope -HostName $HostName + do { + if ($RefreshToken) { + $tokenResponse = Wait-GitHubAccessToken -ClientID $ClientID -RefreshToken $RefreshToken -HostName $HostName + } else { + $deviceCodeResponse = Request-GitHubDeviceCode -ClientID $ClientID -Scope $Scope -HostName $HostName - $deviceCode = $deviceCodeResponse.device_code - $interval = $deviceCodeResponse.interval - $userCode = $deviceCodeResponse.user_code - $verificationUri = $deviceCodeResponse.verification_uri + $deviceCode = $deviceCodeResponse.device_code + $interval = $deviceCodeResponse.interval + $userCode = $deviceCodeResponse.user_code + $verificationUri = $deviceCodeResponse.verification_uri - Write-Host '! ' -ForegroundColor DarkYellow -NoNewline - Write-Host "We added the code to your clipboard: [$userCode]" - $userCode | Set-Clipboard - Read-Host "Press Enter to open $HostName in your browser..." - Start-Process $verificationUri + Write-Host '! ' -ForegroundColor DarkYellow -NoNewline + Write-Host "We added the code to your clipboard: [$userCode]" + $userCode | Set-Clipboard + Read-Host "Press Enter to open $HostName in your browser..." + Start-Process $verificationUri - $tokenResponse = Wait-GitHubAccessToken -DeviceCode $deviceCode -ClientID $ClientID -Interval $interval -HostName $HostName - } - } while ($tokenResponse.error) - $tokenResponse - } catch { - throw $_ - } + $tokenResponse = Wait-GitHubAccessToken -DeviceCode $deviceCode -ClientID $ClientID -Interval $interval -HostName $HostName + } + } while ($tokenResponse.error) + $tokenResponse } end { diff --git a/src/functions/private/Auth/DeviceFlow/Request-GitHubAccessToken.ps1 b/src/functions/private/Auth/DeviceFlow/Request-GitHubAccessToken.ps1 index 5592d1e78..ed32bc697 100644 --- a/src/functions/private/Auth/DeviceFlow/Request-GitHubAccessToken.ps1 +++ b/src/functions/private/Auth/DeviceFlow/Request-GitHubAccessToken.ps1 @@ -66,24 +66,22 @@ } } + $headers = @{ + 'Accept' = 'application/json' + } + $RESTParams = @{ - Uri = "https://$HostName/login/oauth/access_token" Method = 'POST' + Uri = "https://$HostName/login/oauth/access_token" + Headers = $headers Body = $body - Headers = @{ 'Accept' = 'application/json' } } - try { - Write-Debug ($RESTParams.GetEnumerator() | Out-String) - - $tokenResponse = Invoke-RestMethod @RESTParams -Verbose:$false + Write-Debug ($RESTParams.GetEnumerator() | Out-String) + $tokenResponse = Invoke-RestMethod @RESTParams -Verbose:$false + Write-Debug ($tokenResponse | ConvertTo-Json | Out-String) + return $tokenResponse - Write-Debug ($tokenResponse | ConvertTo-Json | Out-String) - return $tokenResponse - } catch { - Write-Error $_ - throw $_ - } } end { diff --git a/src/functions/private/Auth/DeviceFlow/Request-GitHubDeviceCode.ps1 b/src/functions/private/Auth/DeviceFlow/Request-GitHubDeviceCode.ps1 index 8a0b22662..9341aedec 100644 --- a/src/functions/private/Auth/DeviceFlow/Request-GitHubDeviceCode.ps1 +++ b/src/functions/private/Auth/DeviceFlow/Request-GitHubDeviceCode.ps1 @@ -50,21 +50,15 @@ } $RESTParams = @{ - Uri = "https://$HostName/login/device/code" Method = 'POST' - Body = $body + Uri = "https://$HostName/login/device/code" Headers = $headers + Body = $body } - try { - Write-Debug ($RESTParams.GetEnumerator() | Out-String) - - $deviceCodeResponse = Invoke-RestMethod @RESTParams -Verbose:$false - return $deviceCodeResponse - } catch { - Write-Error $_ - throw $_ - } + Write-Debug ($RESTParams.GetEnumerator() | Out-String) + $deviceCodeResponse = Invoke-RestMethod @RESTParams -Verbose:$false + return $deviceCodeResponse } end { diff --git a/src/functions/private/Auth/DeviceFlow/Test-GitHubAccessTokenRefreshRequired.ps1 b/src/functions/private/Auth/DeviceFlow/Test-GitHubAccessTokenRefreshRequired.ps1 index a4e6f3059..1c2740a09 100644 --- a/src/functions/private/Auth/DeviceFlow/Test-GitHubAccessTokenRefreshRequired.ps1 +++ b/src/functions/private/Auth/DeviceFlow/Test-GitHubAccessTokenRefreshRequired.ps1 @@ -16,25 +16,20 @@ param( # 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. - [Parameter()] - [object] $Context = (Get-GitHubContext) + [Parameter(Mandatory)] + [object] $Context ) begin { $stackPath = Get-PSCallStackPath Write-Debug "[$stackPath] - Start" - $Context = Resolve-GitHubContext -Context $Context } process { - try { - $tokenExpirationDate = $Context.TokenExpirationDate - $currentDateTime = Get-Date - $remainingDuration = [datetime]$tokenExpirationDate - $currentDateTime - $remainingDuration.TotalHours -lt $script:GitHub.Config.AccessTokenGracePeriodInHours - } catch { - throw $_ - } + $tokenExpirationDate = $Context.TokenExpirationDate + $currentDateTime = Get-Date + $remainingDuration = [datetime]$tokenExpirationDate - $currentDateTime + $remainingDuration.TotalHours -lt $script:GitHub.Config.AccessTokenGracePeriodInHours } end { diff --git a/src/functions/private/Auth/DeviceFlow/Update-GitHubUserAccessToken.ps1 b/src/functions/private/Auth/DeviceFlow/Update-GitHubUserAccessToken.ps1 index 2ff339983..cc1b013e1 100644 --- a/src/functions/private/Auth/DeviceFlow/Update-GitHubUserAccessToken.ps1 +++ b/src/functions/private/Auth/DeviceFlow/Update-GitHubUserAccessToken.ps1 @@ -27,8 +27,8 @@ param( # 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. - [Parameter()] - [object] $Context = (Get-GitHubContext), + [Parameter(Mandatory)] + [object] $Context, # Return the new access token. [Parameter()] @@ -38,67 +38,64 @@ begin { $stackPath = Get-PSCallStackPath Write-Debug "[$stackPath] - Start" - $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType UAT } process { - try { - Write-Verbose "Reusing previously stored ClientID: [$($Context.AuthClientID)]" - $authClientID = $Context.AuthClientID - $accessTokenValidity = [datetime]($Context.TokenExpirationDate) - (Get-Date) - $accessTokenIsValid = $accessTokenValidity.Seconds -gt 0 - $hours = $accessTokenValidity.Hours.ToString().PadLeft(2, '0') - $minutes = $accessTokenValidity.Minutes.ToString().PadLeft(2, '0') - $seconds = $accessTokenValidity.Seconds.ToString().PadLeft(2, '0') - $accessTokenValidityText = "$hours`:$minutes`:$seconds" - if ($accessTokenIsValid) { - if ($accessTokenValidity.TotalHours -gt $script:GitHub.Config.AccessTokenGracePeriodInHours) { - if (-not $Silent) { - Write-Host '✓ ' -ForegroundColor Green -NoNewline - Write-Host "Access token is still valid for $accessTokenValidityText ..." - } - return - } else { - if (-not $Silent) { - Write-Host '⚠ ' -ForegroundColor Yellow -NoNewline - Write-Host "Access token remaining validity $accessTokenValidityText. Refreshing access token..." - } - $tokenResponse = Invoke-GitHubDeviceFlowLogin -ClientID $authClientID -RefreshToken ($Context.RefreshToken) -HostName $Context.HostName + Write-Verbose "Reusing previously stored ClientID: [$($Context.AuthClientID)]" + $authClientID = $Context.AuthClientID + $accessTokenValidity = [datetime]($Context.TokenExpirationDate) - (Get-Date) + $accessTokenIsValid = $accessTokenValidity.Seconds -gt 0 + $hours = $accessTokenValidity.Hours.ToString().PadLeft(2, '0') + $minutes = $accessTokenValidity.Minutes.ToString().PadLeft(2, '0') + $seconds = $accessTokenValidity.Seconds.ToString().PadLeft(2, '0') + $accessTokenValidityText = "$hours`:$minutes`:$seconds" + if ($accessTokenIsValid) { + if ($accessTokenValidity.TotalHours -gt $script:GitHub.Config.AccessTokenGracePeriodInHours) { + if (-not $Silent) { + Write-Host '✓ ' -ForegroundColor Green -NoNewline + Write-Host "Access token is still valid for $accessTokenValidityText ..." } + return } else { - $refreshTokenValidity = [datetime]($Context.RefreshTokenExpirationDate) - (Get-Date) - $refreshTokenIsValid = $refreshTokenValidity.Seconds -gt 0 - if ($refreshTokenIsValid) { - if (-not $Silent) { - Write-Host '⚠ ' -ForegroundColor Yellow -NoNewline - Write-Host 'Access token expired. Refreshing access token...' - } - $tokenResponse = Invoke-GitHubDeviceFlowLogin -ClientID $authClientID -RefreshToken ($Context.RefreshToken) -HostName $Context.HostName - } else { - Write-Verbose "Using $Mode authentication..." - $tokenResponse = Invoke-GitHubDeviceFlowLogin -ClientID $authClientID -Scope $Scope -HostName $Context.HostName + if (-not $Silent) { + Write-Host '⚠ ' -ForegroundColor Yellow -NoNewline + Write-Host "Access token remaining validity $accessTokenValidityText. Refreshing access token..." } + $tokenResponse = Invoke-GitHubDeviceFlowLogin -ClientID $authClientID -RefreshToken ($Context.RefreshToken) -HostName $Context.HostName } - $Context.Token = ConvertTo-SecureString -AsPlainText $tokenResponse.access_token - $Context.TokenExpirationDate = (Get-Date).AddSeconds($tokenResponse.expires_in) - $Context.TokenType = $tokenResponse.access_token -replace $script:GitHub.TokenPrefixPattern - $Context.RefreshToken = ConvertTo-SecureString -AsPlainText $tokenResponse.refresh_token - $Context.RefreshTokenExpirationDate = (Get-Date).AddSeconds($tokenResponse.refresh_token_expires_in) - - if ($PSCmdlet.ShouldProcess('Access token', 'Update/refresh')) { - Set-Context -Context $Context -ID $Context.ID + } else { + $refreshTokenValidity = [datetime]($Context.RefreshTokenExpirationDate) - (Get-Date) + $refreshTokenIsValid = $refreshTokenValidity.Seconds -gt 0 + if ($refreshTokenIsValid) { + if (-not $Silent) { + Write-Host '⚠ ' -ForegroundColor Yellow -NoNewline + Write-Host 'Access token expired. Refreshing access token...' + } + $tokenResponse = Invoke-GitHubDeviceFlowLogin -ClientID $authClientID -RefreshToken ($Context.RefreshToken) -HostName $Context.HostName + } else { + Write-Verbose "Using $Mode authentication..." + $tokenResponse = Invoke-GitHubDeviceFlowLogin -ClientID $authClientID -Scope $Scope -HostName $Context.HostName } + } + $Context.Token = ConvertTo-SecureString -AsPlainText $tokenResponse.access_token + $Context.TokenExpirationDate = (Get-Date).AddSeconds($tokenResponse.expires_in) + $Context.TokenType = $tokenResponse.access_token -replace $script:GitHub.TokenPrefixPattern + $Context.RefreshToken = ConvertTo-SecureString -AsPlainText $tokenResponse.refresh_token + $Context.RefreshTokenExpirationDate = (Get-Date).AddSeconds($tokenResponse.refresh_token_expires_in) - if ($PassThru) { - $Context.Token - } - } catch { - throw $_ + if ($PSCmdlet.ShouldProcess('Access token', 'Update/refresh')) { + Set-Context -Context $Context -ID $Context.ID + } + + if ($PassThru) { + $Context.Token } + } end { Write-Debug "[$stackPath] - End" } } +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '6.0.0' } diff --git a/src/functions/private/Auth/DeviceFlow/Wait-GitHubAccessToken.ps1 b/src/functions/private/Auth/DeviceFlow/Wait-GitHubAccessToken.ps1 index d57426197..6d1c65924 100644 --- a/src/functions/private/Auth/DeviceFlow/Wait-GitHubAccessToken.ps1 +++ b/src/functions/private/Auth/DeviceFlow/Wait-GitHubAccessToken.ps1 @@ -55,74 +55,70 @@ } process { - try { - do { - if ($RefreshToken) { - $response = Request-GitHubAccessToken -ClientID $ClientID -RefreshToken $RefreshToken -HostName $HostName - } else { - $response = Request-GitHubAccessToken -ClientID $ClientID -DeviceCode $DeviceCode -HostName $HostName - } - if ($response.error) { - switch ($response.error) { - 'authorization_pending' { - # The user has not yet entered the code. - # Wait, then poll again. - Write-Debug $response.error_description - Start-Sleep -Seconds $interval - continue - } - 'slow_down' { - # The app polled too fast. - # Wait for the interval plus 5 seconds, then poll again. - Write-Debug $response.error_description - Start-Sleep -Seconds ($interval + 5) - continue - } - 'expired_token' { - # The 'device_code' expired, and the process needs to restart. - Write-Error $response.error_description - exit 1 - } - 'unsupported_grant_type' { - # The 'grant_type' is not supported. - Write-Error $response.error_description - exit 1 - } - 'incorrect_client_credentials' { - # The 'client_id' is not valid. - Write-Error $response.error_description - exit 1 - } - 'incorrect_device_code' { - # The 'device_code' is not valid. - Write-Error $response.error_description - exit 2 - } - 'access_denied' { - # The user cancelled the process. Stop polling. - Write-Error $response.error_description - exit 1 - } - 'device_flow_disabled' { - # The GitHub App does not support the Device Flow. - Write-Error $response.error_description - exit 1 - } - default { - # The response contains an access token. Stop polling. - Write-Error 'Unknown error:' - Write-Error $response.error - Write-Error $response.error_description - Write-Error $response.error_uri - break - } + do { + if ($RefreshToken) { + $response = Request-GitHubAccessToken -ClientID $ClientID -RefreshToken $RefreshToken -HostName $HostName + } else { + $response = Request-GitHubAccessToken -ClientID $ClientID -DeviceCode $DeviceCode -HostName $HostName + } + if ($response.error) { + switch ($response.error) { + 'authorization_pending' { + # The user has not yet entered the code. + # Wait, then poll again. + Write-Debug $response.error_description + Start-Sleep -Seconds $interval + continue + } + 'slow_down' { + # The app polled too fast. + # Wait for the interval plus 5 seconds, then poll again. + Write-Debug $response.error_description + Start-Sleep -Seconds ($interval + 5) + continue + } + 'expired_token' { + # The 'device_code' expired, and the process needs to restart. + Write-Error $response.error_description + exit 1 + } + 'unsupported_grant_type' { + # The 'grant_type' is not supported. + Write-Error $response.error_description + exit 1 + } + 'incorrect_client_credentials' { + # The 'client_id' is not valid. + Write-Error $response.error_description + exit 1 + } + 'incorrect_device_code' { + # The 'device_code' is not valid. + Write-Error $response.error_description + exit 2 + } + 'access_denied' { + # The user cancelled the process. Stop polling. + Write-Error $response.error_description + exit 1 + } + 'device_flow_disabled' { + # The GitHub App does not support the Device Flow. + Write-Error $response.error_description + exit 1 + } + default { + # The response contains an access token. Stop polling. + Write-Error 'Unknown error:' + Write-Error $response.error + Write-Error $response.error_description + Write-Error $response.error_uri + break } } - } until ($response.access_token) - $response - } catch { - throw $_ - } + } + } until ($response.access_token) + $response } end { diff --git a/src/functions/private/Commands/ConvertTo-GitHubOutput.ps1 b/src/functions/private/Commands/ConvertTo-GitHubOutput.ps1 index 2d78140d7..39877374a 100644 --- a/src/functions/private/Commands/ConvertTo-GitHubOutput.ps1 +++ b/src/functions/private/Commands/ConvertTo-GitHubOutput.ps1 @@ -52,46 +52,42 @@ } process { - try { - $outputLines = @() + $outputLines = @() - Write-Debug "Input object type: $($InputObject.GetType().Name)" - Write-Debug "Input object value:" - Write-Debug ($InputObject | Out-String) - - if ($InputObject -is [hashtable]) { - $InputObject = [PSCustomObject]$InputObject - } + Write-Debug "Input object type: $($InputObject.GetType().Name)" + Write-Debug 'Input object value:' + Write-Debug ($InputObject | Out-String) - foreach ($property in $InputObject.PSObject.Properties) { - $key = $property.Name - $value = $property.Value + if ($InputObject -is [hashtable]) { + $InputObject = [PSCustomObject]$InputObject + } - Write-Debug "Processing property: $key" - Write-Debug "Property value type: $($value.GetType().Name)" - Write-Debug "Property value:" - Write-Debug ($InputObject | Out-String) + foreach ($property in $InputObject.PSObject.Properties) { + $key = $property.Name + $value = $property.Value - # Convert hashtable or PSCustomObject to compressed JSON - if ($value -is [hashtable] -or $value -is [PSCustomObject]) { - Write-Debug "Converting property value to JSON" - $value = $value | ConvertTo-Json -Compress -Depth 100 - Write-Debug 'Property value:' - Write-Debug $value - } + Write-Debug "Processing property: $key" + Write-Debug "Property value type: $($value.GetType().Name)" + Write-Debug 'Property value:' + Write-Debug ($InputObject | Out-String) - $guid = [Guid]::NewGuid().ToString() - $EOFMarker = "EOF_$guid" - $outputLines += "$key<<$EOFMarker" - $outputLines += $value - $outputLines += $EOFMarker + # Convert hashtable or PSCustomObject to compressed JSON + if ($value -is [hashtable] -or $value -is [PSCustomObject]) { + Write-Debug 'Converting property value to JSON' + $value = $value | ConvertTo-Json -Compress -Depth 100 + Write-Debug 'Property value:' + Write-Debug $value } - Write-Debug "Output lines:" - Write-Debug ($outputLines | Out-String) - $outputLines - } catch { - throw $_ + + $guid = [Guid]::NewGuid().ToString() + $EOFMarker = "EOF_$guid" + $outputLines += "$key<<$EOFMarker" + $outputLines += $value + $outputLines += $EOFMarker } + Write-Debug 'Output lines:' + Write-Debug ($outputLines | Out-String) + $outputLines } end { diff --git a/src/functions/private/Config/Initialize-GitHubConfig.ps1 b/src/functions/private/Config/Initialize-GitHubConfig.ps1 index fce061650..619ba8df5 100644 --- a/src/functions/private/Config/Initialize-GitHubConfig.ps1 +++ b/src/functions/private/Config/Initialize-GitHubConfig.ps1 @@ -31,35 +31,30 @@ function Initialize-GitHubConfig { } process { - try { - Write-Debug "Force: [$Force]" - if ($Force) { - Write-Debug 'Forcing initialization of GitHubConfig.' - $context = Set-Context -ID $script:GitHub.DefaultConfig.ID -Context $script:GitHub.DefaultConfig -PassThru - $script:GitHub.Config = [GitHubConfig]$context - return - } + Write-Debug "Force: [$Force]" + if ($Force) { + Write-Debug 'Forcing initialization of GitHubConfig.' + $context = Set-Context -ID $script:GitHub.DefaultConfig.ID -Context $script:GitHub.DefaultConfig -PassThru + $script:GitHub.Config = [GitHubConfig]$context + return + } - Write-Debug "GitHubConfig ID: [$($script:GitHub.Config.ID)]" - if ($null -ne $script:GitHub.Config) { - Write-Debug 'GitHubConfig already initialized and available in memory.' - return - } + Write-Debug "GitHubConfig ID: [$($script:GitHub.Config.ID)]" + if ($null -ne $script:GitHub.Config) { + Write-Debug 'GitHubConfig already initialized and available in memory.' + return + } - Write-Debug 'Attempt to load the stored GitHubConfig from ContextVault' - $context = Get-Context -ID $script:GitHub.DefaultConfig.ID - if ($context) { - Write-Debug 'GitHubConfig loaded into memory.' - $script:GitHub.Config = [GitHubConfig]$context - return - } - Write-Debug 'Initializing GitHubConfig from defaults' - $context = Set-Context -ID $script:GitHub.DefaultConfig.ID -Context $script:GitHub.DefaultConfig -PassThru + Write-Debug 'Attempt to load the stored GitHubConfig from ContextVault' + $context = Get-Context -ID $script:GitHub.DefaultConfig.ID + if ($context) { + Write-Debug 'GitHubConfig loaded into memory.' $script:GitHub.Config = [GitHubConfig]$context - } catch { - Write-Error $_ - throw 'Failed to initialize GitHub config' + return } + Write-Debug 'Initializing GitHubConfig from defaults' + $context = Set-Context -ID $script:GitHub.DefaultConfig.ID -Context $script:GitHub.DefaultConfig -PassThru + $script:GitHub.Config = [GitHubConfig]$context } end { diff --git a/src/functions/private/Gitignore/Get-GitHubGitignoreByName.ps1 b/src/functions/private/Gitignore/Get-GitHubGitignoreByName.ps1 index e3c0fbc1d..037907a32 100644 --- a/src/functions/private/Gitignore/Get-GitHubGitignoreByName.ps1 +++ b/src/functions/private/Gitignore/Get-GitHubGitignoreByName.ps1 @@ -23,31 +23,26 @@ # 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. - [Parameter()] - [object] $Context = (Get-GitHubContext) + [Parameter(Mandatory)] + [object] $Context ) begin { $stackPath = Get-PSCallStackPath Write-Debug "[$stackPath] - Start" - $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT } process { - try { - $inputObject = @{ - Context = $Context - APIEndpoint = "/gitignore/templates/$Name" - Accept = 'application/vnd.github.raw+json' - Method = 'GET' - } - - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } - } catch { - throw $_ + $inputObject = @{ + Method = 'GET' + APIEndpoint = "/gitignore/templates/$Name" + Accept = 'application/vnd.github.raw+json' + Context = $Context + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } } diff --git a/src/functions/private/Gitignore/Get-GitHubGitignoreList.ps1 b/src/functions/private/Gitignore/Get-GitHubGitignoreList.ps1 index 7d1c70942..e5e925cef 100644 --- a/src/functions/private/Gitignore/Get-GitHubGitignoreList.ps1 +++ b/src/functions/private/Gitignore/Get-GitHubGitignoreList.ps1 @@ -21,30 +21,25 @@ param( # 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. - [Parameter()] - [object] $Context = (Get-GitHubContext) + [Parameter(Mandatory)] + [object] $Context ) begin { $stackPath = Get-PSCallStackPath Write-Debug "[$stackPath] - Start" - $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT } process { - try { - $inputObject = @{ - Context = $Context - APIEndpoint = '/gitignore/templates' - Method = 'GET' - } - - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } - } catch { - throw $_ + $inputObject = @{ + Method = 'GET' + APIEndpoint = '/gitignore/templates' + Context = $Context + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } } diff --git a/src/functions/private/License/Get-GitHubLicenseByName.ps1 b/src/functions/private/License/Get-GitHubLicenseByName.ps1 index a058020c9..6bf335b71 100644 --- a/src/functions/private/License/Get-GitHubLicenseByName.ps1 +++ b/src/functions/private/License/Get-GitHubLicenseByName.ps1 @@ -26,31 +26,26 @@ # 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. - [Parameter()] - [object] $Context = (Get-GitHubContext) + [Parameter(Mandatory)] + [object] $Context ) begin { $stackPath = Get-PSCallStackPath Write-Debug "[$stackPath] - Start" - $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT } process { - try { - $inputObject = @{ - Context = $Context - APIEndpoint = "/licenses/$Name" - Accept = 'application/vnd.github+json' - Method = 'GET' - } - - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } - } catch { - throw $_ + $inputObject = @{ + Method = 'GET' + APIEndpoint = "/licenses/$Name" + Accept = 'application/vnd.github+json' + Context = $Context + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } } diff --git a/src/functions/private/License/Get-GitHubLicenseList.ps1 b/src/functions/private/License/Get-GitHubLicenseList.ps1 index 718f95b42..ea035e964 100644 --- a/src/functions/private/License/Get-GitHubLicenseList.ps1 +++ b/src/functions/private/License/Get-GitHubLicenseList.ps1 @@ -22,30 +22,25 @@ param( # 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. - [Parameter()] - [object] $Context = (Get-GitHubContext) + [Parameter(Mandatory)] + [object] $Context ) begin { $stackPath = Get-PSCallStackPath Write-Debug "[$stackPath] - Start" - $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT } process { - try { - $inputObject = @{ - Context = $Context - APIEndpoint = '/licenses' - Method = 'GET' - } - - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } - } catch { - throw $_ + $inputObject = @{ + Method = 'GET' + APIEndpoint = '/licenses' + Context = $Context + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } } diff --git a/src/functions/private/License/Get-GitHubRepositoryLicense.ps1 b/src/functions/private/License/Get-GitHubRepositoryLicense.ps1 index e3c066468..de5ce94c0 100644 --- a/src/functions/private/License/Get-GitHubRepositoryLicense.ps1 +++ b/src/functions/private/License/Get-GitHubRepositoryLicense.ps1 @@ -10,7 +10,7 @@ [custom media types](https://docs.github.com/rest/overview/media-types) for retrieving the raw license content or rendered license HTML. .EXAMPLE - Get-GitHubRepositoryLicense -Owner 'octocat' -Repo 'Hello-World' + Get-GitHubRepositoryLicense -Owner 'octocat' -Repository 'Hello-World' Get the license for the Hello-World repository from the octocat account. @@ -21,12 +21,12 @@ [CmdletBinding()] param( # The account owner of the repository. The name is not case sensitive. - [Parameter()] + [Parameter(Mandatory)] [string] $Owner, # The name of the repository without the .git extension. The name is not case sensitive. - [Parameter()] - [string] $Repo, + [Parameter(Mandatory)] + [string] $Repository, # The type of data to return. Can be either 'raw' or 'html'. [Parameter()] @@ -35,49 +35,34 @@ # 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. - [Parameter()] - [object] $Context = (Get-GitHubContext) + [Parameter(Mandatory)] + [object] $Context ) begin { $stackPath = Get-PSCallStackPath Write-Debug "[$stackPath] - Start" - $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT + } - if ([string]::IsNullOrEmpty($Owner)) { - $Owner = $Context.Owner - } - Write-Debug "Owner: [$Owner]" - - if ([string]::IsNullOrEmpty($Repo)) { - $Repo = $Context.Repo - } - Write-Debug "Repo: [$Repo]" - + process { $contentType = switch ($Type) { 'raw' { 'application/vnd.github.raw+json' } 'html' { 'application/vnd.github.html+json' } } - } - process { - try { - $inputObject = @{ - Context = $Context - APIEndpoint = "/repos/$Owner/$Repo/license" - ContentType = $contentType - Method = 'GET' - } + $inputObject = @{ + Method = 'GET' + APIEndpoint = "/repos/$Owner/$Repository/license" + ContentType = $contentType + Context = $Context + } - Invoke-GitHubAPI @inputObject | ForEach-Object { - $Response = $_.Response - $rawContent = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($Response.content)) - $Response | Add-Member -NotePropertyName 'raw_content' -NotePropertyValue $rawContent -Force - $Response - } - } catch { - throw $_ + Invoke-GitHubAPI @inputObject | ForEach-Object { + $Response = $_.Response + $rawContent = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($Response.content)) + $Response | Add-Member -NotePropertyName 'raw_content' -NotePropertyValue $rawContent -Force + $Response } } end { diff --git a/src/functions/private/Organization/Blocking/Block-GitHubUserByOrganization.ps1 b/src/functions/private/Organization/Blocking/Block-GitHubUserByOrganization.ps1 index 791b61942..90b9e5602 100644 --- a/src/functions/private/Organization/Blocking/Block-GitHubUserByOrganization.ps1 +++ b/src/functions/private/Organization/Blocking/Block-GitHubUserByOrganization.ps1 @@ -25,8 +25,6 @@ ValueFromPipeline, ValueFromPipelineByPropertyName )] - [Alias('org')] - [Alias('owner')] [Alias('login')] [string] $Organization, @@ -40,36 +38,24 @@ # 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. - [Parameter()] - [object] $Context = (Get-GitHubContext) + [Parameter(Mandatory)] + [object] $Context ) begin { $stackPath = Get-PSCallStackPath Write-Debug "[$stackPath] - Start" - $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT } process { $inputObject = @{ - Context = $Context - APIEndpoint = "/orgs/$Organization/blocks/$Username" Method = 'PUT' + APIEndpoint = "/orgs/$Organization/blocks/$Username" + Context = $Context } - try { - $null = (Invoke-GitHubAPI @inputObject) - # Should we check if user is already blocked and return true if so? - return $true - } catch { - if ($_.Exception.Response.StatusCode.Value__ -eq 422) { - return $false - } else { - Write-Error $_.Exception.Response - throw $_ - } - } + Invoke-GitHubAPI @inputObject } end { diff --git a/src/functions/private/Organization/Blocking/Get-GitHubBlockedUserByOrganization.ps1 b/src/functions/private/Organization/Blocking/Get-GitHubBlockedUserByOrganization.ps1 index d99be05ef..ec1076277 100644 --- a/src/functions/private/Organization/Blocking/Get-GitHubBlockedUserByOrganization.ps1 +++ b/src/functions/private/Organization/Blocking/Get-GitHubBlockedUserByOrganization.ps1 @@ -19,8 +19,6 @@ param( # The organization name. The name is not case sensitive. [Parameter(Mandatory)] - [Alias('org')] - [Alias('owner')] [Alias('login')] [string] $Organization, @@ -31,35 +29,30 @@ # 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. - [Parameter()] - [object] $Context = (Get-GitHubContext) + [Parameter(Mandatory)] + [object] $Context ) begin { $stackPath = Get-PSCallStackPath Write-Debug "[$stackPath] - Start" - $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT } process { - try { - $body = @{ - per_page = $PerPage - } + $body = @{ + per_page = $PerPage + } - $inputObject = @{ - Context = $Context - APIEndpoint = "/orgs/$Organization/blocks" - Method = 'GET' - Body = $body - } + $inputObject = @{ + Method = 'GET' + APIEndpoint = "/orgs/$Organization/blocks" + Body = $body + Context = $Context + } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } - } catch { - throw $_ + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } } end { diff --git a/src/functions/private/Organization/Blocking/Test-GitHubBlockedUserByOrganization.ps1 b/src/functions/private/Organization/Blocking/Test-GitHubBlockedUserByOrganization.ps1 index 2ea904246..5a6a1729e 100644 --- a/src/functions/private/Organization/Blocking/Test-GitHubBlockedUserByOrganization.ps1 +++ b/src/functions/private/Organization/Blocking/Test-GitHubBlockedUserByOrganization.ps1 @@ -25,8 +25,6 @@ ValueFromPipeline, ValueFromPipelineByPropertyName )] - [Alias('org')] - [Alias('owner')] [Alias('login')] [string] $Organization, @@ -39,33 +37,24 @@ # 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. - [Parameter()] - [object] $Context = (Get-GitHubContext) + [Parameter(Mandatory)] + [object] $Context ) begin { $stackPath = Get-PSCallStackPath Write-Debug "[$stackPath] - Start" - $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT } process { $inputObject = @{ - Context = $Context - APIEndpoint = "/orgs/$Organization/blocks/$Username" Method = 'GET' + APIEndpoint = "/orgs/$Organization/blocks/$Username" + Context = $Context } - try { - (Invoke-GitHubAPI @inputObject).StatusCode -eq 204 - } catch { - if ($_.Exception.Response.StatusCode.Value__ -eq 404) { - return $false - } else { - throw $_ - } - } + Invoke-GitHubAPI @inputObject } end { diff --git a/src/functions/private/Organization/Blocking/Unblock-GitHubUserByOrganization.ps1 b/src/functions/private/Organization/Blocking/Unblock-GitHubUserByOrganization.ps1 index 978360299..feac1635c 100644 --- a/src/functions/private/Organization/Blocking/Unblock-GitHubUserByOrganization.ps1 +++ b/src/functions/private/Organization/Blocking/Unblock-GitHubUserByOrganization.ps1 @@ -24,8 +24,6 @@ ValueFromPipeline, ValueFromPipelineByPropertyName )] - [Alias('org')] - [Alias('owner')] [Alias('login')] [string] $Organization, @@ -40,31 +38,23 @@ # 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. - [Parameter()] - [object] $Context = (Get-GitHubContext) + [Parameter(Mandatory)] + [object] $Context ) begin { $stackPath = Get-PSCallStackPath Write-Debug "[$stackPath] - Start" - $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT } process { $inputObject = @{ - Context = $Context - APIEndpoint = "/orgs/$Organization/blocks/$Username" Method = 'DELETE' + APIEndpoint = "/orgs/$Organization/blocks/$Username" + Context = $Context } - - try { - $null = (Invoke-GitHubAPI @inputObject) - return $true - } catch { - Write-Error $_.Exception.Response - throw $_ - } + Invoke-GitHubAPI @inputObject } end { diff --git a/src/functions/private/Organization/Get-GitHubAllOrganization.ps1 b/src/functions/private/Organization/Get-GitHubAllOrganization.ps1 index d8a1102d8..143b24978 100644 --- a/src/functions/private/Organization/Get-GitHubAllOrganization.ps1 +++ b/src/functions/private/Organization/Get-GitHubAllOrganization.ps1 @@ -33,36 +33,31 @@ # 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. - [Parameter()] - [object] $Context = (Get-GitHubContext) + [Parameter(Mandatory)] + [object] $Context ) begin { $stackPath = Get-PSCallStackPath Write-Debug "[$stackPath] - Start" - $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT } process { - try { - $body = @{ - since = $Since - per_page = $PerPage - } + $body = @{ + since = $Since + per_page = $PerPage + } - $inputObject = @{ - Context = $Context - APIEndpoint = '/organizations' - Method = 'GET' - Body = $body - } + $inputObject = @{ + Method = 'GET' + APIEndpoint = '/organizations' + Body = $body + Context = $Context + } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } - } catch { - throw $_ + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } } end { diff --git a/src/functions/private/Organization/Get-GitHubMyOrganization.ps1 b/src/functions/private/Organization/Get-GitHubMyOrganization.ps1 index b561dcb69..b2cf45b2c 100644 --- a/src/functions/private/Organization/Get-GitHubMyOrganization.ps1 +++ b/src/functions/private/Organization/Get-GitHubMyOrganization.ps1 @@ -32,35 +32,30 @@ # 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. - [Parameter()] - [object] $Context = (Get-GitHubContext) + [Parameter(Mandatory)] + [object] $Context ) begin { $stackPath = Get-PSCallStackPath Write-Debug "[$stackPath] - Start" - $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT } process { - try { - $body = @{ - per_page = $PerPage - } + $body = @{ + per_page = $PerPage + } - $inputObject = @{ - Context = $Context - APIEndpoint = '/user/orgs' - Method = 'GET' - Body = $body - } + $inputObject = @{ + Method = 'GET' + APIEndpoint = '/user/orgs' + Body = $body + Context = $Context + } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } - } catch { - throw $_ + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } } diff --git a/src/functions/private/Organization/Get-GitHubOrganizationByName.ps1 b/src/functions/private/Organization/Get-GitHubOrganizationByName.ps1 index bceada5aa..82044c881 100644 --- a/src/functions/private/Organization/Get-GitHubOrganizationByName.ps1 +++ b/src/functions/private/Organization/Get-GitHubOrganizationByName.ps1 @@ -32,36 +32,29 @@ ValueFromPipelineByPropertyName )] [Alias('login')] - [Alias('org')] - [Alias('owner')] [string] $Organization, # 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. - [Parameter()] - [object] $Context = (Get-GitHubContext) + [Parameter(Mandatory)] + [object] $Context ) begin { $stackPath = Get-PSCallStackPath Write-Debug "[$stackPath] - Start" - $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT } process { - try { - $inputObject = @{ - Context = $Context - APIEndpoint = "/orgs/$Organization" - Method = 'GET' - } + $inputObject = @{ + Method = 'GET' + APIEndpoint = "/orgs/$Organization" + Context = $Context + } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } - } catch { - throw $_ + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } } end { diff --git a/src/functions/private/Organization/Get-GitHubUserOrganization.ps1 b/src/functions/private/Organization/Get-GitHubUserOrganization.ps1 index e66124df4..5da211dfc 100644 --- a/src/functions/private/Organization/Get-GitHubUserOrganization.ps1 +++ b/src/functions/private/Organization/Get-GitHubUserOrganization.ps1 @@ -34,35 +34,30 @@ # 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. - [Parameter()] - [object] $Context = (Get-GitHubContext) + [Parameter(Mandatory)] + [object] $Context ) begin { $stackPath = Get-PSCallStackPath Write-Debug "[$stackPath] - Start" - $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT } process { - try { - $body = @{ - per_page = $PerPage - } + $body = @{ + per_page = $PerPage + } - $inputObject = @{ - Context = $Context - APIEndpoint = "/users/$Username/orgs" - Method = 'GET' - Body = $body - } + $inputObject = @{ + Method = 'GET' + APIEndpoint = "/users/$Username/orgs" + Body = $body + Context = $Context + } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } - } catch { - throw $_ + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } } end { diff --git a/src/functions/private/Releases/Assets/Get-GitHubReleaseAssetByID.ps1 b/src/functions/private/Releases/Assets/Get-GitHubReleaseAssetByID.ps1 index c40692353..e7a739fba 100644 --- a/src/functions/private/Releases/Assets/Get-GitHubReleaseAssetByID.ps1 +++ b/src/functions/private/Releases/Assets/Get-GitHubReleaseAssetByID.ps1 @@ -10,7 +10,7 @@ possible. API clients should handle both a `200` or `302` response. .EXAMPLE - Get-GitHubReleaseAssetByID -Owner 'octocat' -Repo 'hello-world' -ID '1234567' + Get-GitHubReleaseAssetByID -Owner 'octocat' -Repository 'hello-world' -ID '1234567' Gets the release asset with the ID '1234567' for the repository 'octocat/hello-world'. @@ -26,7 +26,7 @@ # The name of the repository without the .git extension. The name is not case sensitive. [Parameter(Mandatory)] - [string] $Repo, + [string] $Repository, # The unique identifier of the asset. [Parameter(Mandatory)] @@ -35,40 +35,25 @@ # 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. - [Parameter()] - [object] $Context = (Get-GitHubContext) + [Parameter(Mandatory)] + [object] $Context ) begin { $stackPath = Get-PSCallStackPath Write-Debug "[$stackPath] - Start" - $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - if ([string]::IsNullOrEmpty($Owner)) { - $Owner = $Context.Owner - } - Write-Debug "Owner: [$Owner]" - - if ([string]::IsNullOrEmpty($Repo)) { - $Repo = $Context.Repo - } - Write-Debug "Repo: [$Repo]" } process { - try { - - $inputObject = @{ - Context = $Context - APIEndpoint = "/repos/$Owner/$Repo/releases/assets/$ID" - Method = 'GET' - } + $inputObject = @{ + Method = 'GET' + APIEndpoint = "/repos/$Owner/$Repository/releases/assets/$ID" + Context = $Context + } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } - } catch { - throw $_ + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } } diff --git a/src/functions/private/Releases/Assets/Get-GitHubReleaseAssetByReleaseID.ps1 b/src/functions/private/Releases/Assets/Get-GitHubReleaseAssetByReleaseID.ps1 index 8e9fcc7f7..512f93e4a 100644 --- a/src/functions/private/Releases/Assets/Get-GitHubReleaseAssetByReleaseID.ps1 +++ b/src/functions/private/Releases/Assets/Get-GitHubReleaseAssetByReleaseID.ps1 @@ -7,7 +7,7 @@ List release assets .EXAMPLE - Get-GitHubReleaseAssetByReleaseID -Owner 'octocat' -Repo 'hello-world' -ID '1234567' + Get-GitHubReleaseAssetByReleaseID -Owner 'octocat' -Repository 'hello-world' -ID '1234567' Gets the release assets for the release with the ID '1234567' for the repository 'octocat/hello-world'. @@ -15,7 +15,7 @@ https://docs.github.com/rest/releases/assets#list-release-assets #> - [CmdletBinding()] + [CmdletBinding(DefaultParameterSetName = '__AllParameterSets')] param( # The account owner of the repository. The name is not case sensitive. [Parameter(Mandatory)] @@ -23,7 +23,7 @@ # The name of the repository without the .git extension. The name is not case sensitive. [Parameter(Mandatory)] - [string] $Repo, + [string] $Repository, # The unique identifier of the release. [Parameter( @@ -40,44 +40,30 @@ # 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. - [Parameter()] - [object] $Context = (Get-GitHubContext) + [Parameter(Mandatory)] + [object] $Context ) begin { $stackPath = Get-PSCallStackPath Write-Debug "[$stackPath] - Start" - $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - if ([string]::IsNullOrEmpty($Owner)) { - $Owner = $Context.Owner - } - Write-Debug "Owner: [$Owner]" - - if ([string]::IsNullOrEmpty($Repo)) { - $Repo = $Context.Repo - } - Write-Debug "Repo: [$Repo]" } process { - try { - $body = @{ - per_page = $PerPage - } + $body = @{ + per_page = $PerPage + } - $inputObject = @{ - Context = $Context - APIEndpoint = "/repos/$Owner/$Repo/releases/$ID/assets" - Method = 'GET' - Body = $body - } + $inputObject = @{ + Method = 'GET' + APIEndpoint = "/repos/$Owner/$Repository/releases/$ID/assets" + Body = $body + Context = $Context + } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } - } catch { - throw $_ + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } } end { diff --git a/src/functions/private/Releases/Releases/Get-GitHubReleaseAll.ps1 b/src/functions/private/Releases/Releases/Get-GitHubReleaseAll.ps1 index c35157bb8..bd5c52614 100644 --- a/src/functions/private/Releases/Releases/Get-GitHubReleaseAll.ps1 +++ b/src/functions/private/Releases/Releases/Get-GitHubReleaseAll.ps1 @@ -9,7 +9,7 @@ Information about published releases are available to everyone. Only users with push access will receive listings for draft releases. .EXAMPLE - Get-GitHubReleaseAll -Owner 'octocat' -Repo 'hello-world' + Get-GitHubReleaseAll -Owner 'octocat' -Repository 'hello-world' Gets all the releases for the repository 'hello-world' owned by 'octocat'. @@ -17,7 +17,7 @@ https://docs.github.com/rest/releases/releases#list-releases #> - [CmdletBinding()] + [CmdletBinding(DefaultParameterSetName = '__AllParameterSets')] param( # The account owner of the repository. The name is not case sensitive. [Parameter(Mandatory)] @@ -25,7 +25,7 @@ # The name of the repository without the .git extension. The name is not case sensitive. [Parameter(Mandatory)] - [string] $Repo, + [string] $Repository, # The number of results per page (max 100). [Parameter(ParameterSetName = 'AllUsers')] @@ -34,44 +34,30 @@ # 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. - [Parameter()] - [object] $Context = (Get-GitHubContext) + [Parameter(Mandatory)] + [object] $Context ) begin { $stackPath = Get-PSCallStackPath Write-Debug "[$stackPath] - Start" - $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - if ([string]::IsNullOrEmpty($Owner)) { - $Owner = $Context.Owner - } - Write-Debug "Owner: [$Owner]" - - if ([string]::IsNullOrEmpty($Repo)) { - $Repo = $Context.Repo - } - Write-Debug "Repo: [$Repo]" } process { - try { - $body = @{ - per_page = $PerPage - } + $body = @{ + per_page = $PerPage + } - $inputObject = @{ - Context = $Context - APIEndpoint = "/repos/$Owner/$Repo/releases" - Method = 'GET' - Body = $body - } + $inputObject = @{ + Method = 'GET' + APIEndpoint = "/repos/$Owner/$Repository/releases" + Body = $body + Context = $Context + } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } - } catch { - throw $_ + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } } end { diff --git a/src/functions/private/Releases/Releases/Get-GitHubReleaseByID.ps1 b/src/functions/private/Releases/Releases/Get-GitHubReleaseByID.ps1 index 5f60d311a..dc0c5c030 100644 --- a/src/functions/private/Releases/Releases/Get-GitHubReleaseByID.ps1 +++ b/src/functions/private/Releases/Releases/Get-GitHubReleaseByID.ps1 @@ -8,7 +8,7 @@ This key is a [hypermedia resource](https://docs.github.com/rest/overview/resources-in-the-rest-api#hypermedia). .EXAMPLE - Get-GitHubReleaseById -Owner 'octocat' -Repo 'hello-world' -ID '1234567' + Get-GitHubReleaseById -Owner 'octocat' -Repository 'hello-world' -ID '1234567' Gets the release with the ID '1234567' for the repository 'hello-world' owned by 'octocat'. @@ -24,7 +24,7 @@ # The name of the repository without the .git extension. The name is not case sensitive. [Parameter(Mandatory)] - [string] $Repo, + [string] $Repository, # The unique identifier of the release. [Parameter(Mandatory)] @@ -33,39 +33,25 @@ # 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. - [Parameter()] - [object] $Context = (Get-GitHubContext) + [Parameter(Mandatory)] + [object] $Context ) begin { $stackPath = Get-PSCallStackPath Write-Debug "[$stackPath] - Start" - $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - if ([string]::IsNullOrEmpty($Owner)) { - $Owner = $Context.Owner - } - Write-Debug "Owner: [$Owner]" - - if ([string]::IsNullOrEmpty($Repo)) { - $Repo = $Context.Repo - } - Write-Debug "Repo: [$Repo]" } process { - try { - $inputObject = @{ - Context = $Context - APIEndpoint = "/repos/$Owner/$Repo/releases/$ID" - Method = 'GET' - } + $inputObject = @{ + Method = 'GET' + APIEndpoint = "/repos/$Owner/$Repository/releases/$ID" + Context = $Context + } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } - } catch { - throw $_ + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } } diff --git a/src/functions/private/Releases/Releases/Get-GitHubReleaseByTagName.ps1 b/src/functions/private/Releases/Releases/Get-GitHubReleaseByTagName.ps1 index 156454bc5..519cf54f4 100644 --- a/src/functions/private/Releases/Releases/Get-GitHubReleaseByTagName.ps1 +++ b/src/functions/private/Releases/Releases/Get-GitHubReleaseByTagName.ps1 @@ -7,7 +7,7 @@ Get a published release with the specified tag. .EXAMPLE - Get-GitHubReleaseByTagName -Owner 'octocat' -Repo 'hello-world' -Tag 'v1.0.0' + Get-GitHubReleaseByTagName -Owner 'octocat' -Repository 'hello-world' -Tag 'v1.0.0' Gets the release with the tag 'v1.0.0' for the repository 'hello-world' owned by 'octocat'. @@ -23,7 +23,7 @@ # The name of the repository without the .git extension. The name is not case sensitive. [Parameter(Mandatory)] - [string] $Repo, + [string] $Repository, # The name of the tag to get a release from. [Parameter(Mandatory)] @@ -32,39 +32,25 @@ # 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. - [Parameter()] - [object] $Context = (Get-GitHubContext) + [Parameter(Mandatory)] + [object] $Context ) begin { $stackPath = Get-PSCallStackPath Write-Debug "[$stackPath] - Start" - $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - if ([string]::IsNullOrEmpty($Owner)) { - $Owner = $Context.Owner - } - Write-Debug "Owner: [$Owner]" - - if ([string]::IsNullOrEmpty($Repo)) { - $Repo = $Context.Repo - } - Write-Debug "Repo: [$Repo]" } process { - try { - $inputObject = @{ - Context = $Context - APIEndpoint = "/repos/$Owner/$Repo/releases/tags/$Tag" - Method = 'GET' - } + $inputObject = @{ + Method = 'GET' + APIEndpoint = "/repos/$Owner/$Repository/releases/tags/$Tag" + Context = $Context + } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } - } catch { - throw $_ + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } } diff --git a/src/functions/private/Releases/Releases/Get-GitHubReleaseLatest.ps1 b/src/functions/private/Releases/Releases/Get-GitHubReleaseLatest.ps1 index 8c0325899..80f7a6936 100644 --- a/src/functions/private/Releases/Releases/Get-GitHubReleaseLatest.ps1 +++ b/src/functions/private/Releases/Releases/Get-GitHubReleaseLatest.ps1 @@ -9,7 +9,7 @@ The `created_at` attribute is the date of the commit used for the release, and not the date when the release was drafted or published. .EXAMPLE - Get-GitHubReleaseLatest -Owner 'octocat' -Repo 'hello-world' + Get-GitHubReleaseLatest -Owner 'octocat' -Repository 'hello-world' Gets the latest releases for the repository 'hello-world' owned by 'octocat'. @@ -25,43 +25,29 @@ # The name of the repository without the .git extension. The name is not case sensitive. [Parameter(Mandatory)] - [string] $Repo, + [string] $Repository, # 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. - [Parameter()] - [object] $Context = (Get-GitHubContext) + [Parameter(Mandatory)] + [object] $Context ) begin { $stackPath = Get-PSCallStackPath Write-Debug "[$stackPath] - Start" - $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - if ([string]::IsNullOrEmpty($Owner)) { - $Owner = $Context.Owner - } - Write-Debug "Owner: [$Owner]" - - if ([string]::IsNullOrEmpty($Repo)) { - $Repo = $Context.Repo - } - Write-Debug "Repo: [$Repo]" } process { - try { - $inputObject = @{ - Context = $Context - APIEndpoint = "/repos/$Owner/$Repo/releases/latest" - Method = 'GET' - } + $inputObject = @{ + Method = 'GET' + APIEndpoint = "/repos/$Owner/$Repository/releases/latest" + Context = $Context + } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } - } catch { - throw $_ + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } } diff --git a/src/functions/private/Repositories/Autolinks/Get-GitHubRepositoryAutolinkById.ps1 b/src/functions/private/Repositories/Autolinks/Get-GitHubRepositoryAutolinkById.ps1 index 3a93ca727..911d64a31 100644 --- a/src/functions/private/Repositories/Autolinks/Get-GitHubRepositoryAutolinkById.ps1 +++ b/src/functions/private/Repositories/Autolinks/Get-GitHubRepositoryAutolinkById.ps1 @@ -9,7 +9,7 @@ Information about autolinks are only available to repository administrators. .EXAMPLE - Get-GitHubRepositoryAutolinkById -Owner 'octocat' -Repo 'Hello-World' -ID 1 + Get-GitHubRepositoryAutolinkById -Owner 'octocat' -Repository 'Hello-World' -ID 1 Gets the autolink with the ID 1 for the repository 'Hello-World' owned by 'octocat'. @@ -21,54 +21,41 @@ param( # The account owner of the repository. The name is not case sensitive. [Parameter(Mandatory)] - [Alias('org')] + [Alias('Organization')] + [Alias('User')] [string] $Owner, # The name of the repository without the .git extension. The name is not case sensitive. [Parameter(Mandatory)] - [string] $Repo, + [string] $Repository, # The unique identifier of the autolink. [Parameter(Mandatory)] [Alias('autolink_id')] - [Alias('ID')] - [int] $AutolinkId, + [Alias('AutolinkId')] + [int] $ID, # 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. - [Parameter()] - [object] $Context = (Get-GitHubContext) + [Parameter(Mandatory)] + [object] $Context ) begin { $stackPath = Get-PSCallStackPath Write-Debug "[$stackPath] - Start" - $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - if ([string]::IsNullOrEmpty($Owner)) { - $Owner = $Context.Owner - } - Write-Debug "Owner: [$Owner]" - - if ([string]::IsNullOrEmpty($Repo)) { - $Repo = $Context.Repo - } - Write-Debug "Repo: [$Repo]" } process { - try { - $inputObject = @{ - Context = $Context - APIEndpoint = "/repos/$Owner/$Repo/autolinks/$AutolinkId" - Method = 'GET' - } + $inputObject = @{ + Method = 'GET' + APIEndpoint = "/repos/$Owner/$Repository/autolinks/$ID" + Context = $Context + } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } - } catch { - throw $_ + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } } diff --git a/src/functions/private/Repositories/Autolinks/Get-GitHubRepositoryAutolinkList.ps1 b/src/functions/private/Repositories/Autolinks/Get-GitHubRepositoryAutolinkList.ps1 index d42736410..909c59277 100644 --- a/src/functions/private/Repositories/Autolinks/Get-GitHubRepositoryAutolinkList.ps1 +++ b/src/functions/private/Repositories/Autolinks/Get-GitHubRepositoryAutolinkList.ps1 @@ -9,7 +9,7 @@ Information about autolinks are only available to repository administrators. .EXAMPLE - Get-GitHubRepositoryAutolinkList -Owner 'octocat' -Repo 'Hello-World' + Get-GitHubRepositoryAutolinkList -Owner 'octocat' -Repository 'Hello-World' Gets all autolinks for the repository 'Hello-World' owned by 'octocat'. @@ -21,48 +21,33 @@ param( # The account owner of the repository. The name is not case sensitive. [Parameter(Mandatory)] - [Alias('org')] [string] $Owner, # The name of the repository without the .git extension. The name is not case sensitive. [Parameter(Mandatory)] - [string] $Repo, + [string] $Repository, # 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. - [Parameter()] - [object] $Context = (Get-GitHubContext) + [Parameter(Mandatory)] + [object] $Context ) begin { $stackPath = Get-PSCallStackPath Write-Debug "[$stackPath] - Start" - $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - if ([string]::IsNullOrEmpty($Owner)) { - $Owner = $Context.Owner - } - Write-Debug "Owner: [$Owner]" - - if ([string]::IsNullOrEmpty($Repo)) { - $Repo = $Context.Repo - } - Write-Debug "Repo: [$Repo]" } process { - try { - $inputObject = @{ - Context = $Context - APIEndpoint = "/repos/$Owner/$Repo/autolinks" - Method = 'GET' - } + $inputObject = @{ + Method = 'GET' + APIEndpoint = "/repos/$Owner/$Repository/autolinks" + Context = $Context + } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } - } catch { - throw $_ + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } } diff --git a/src/functions/private/Repositories/Fork/New-GitHubRepositoryAsFork.ps1 b/src/functions/private/Repositories/Fork/New-GitHubRepositoryAsFork.ps1 index 0a1e85d88..33e22db8d 100644 --- a/src/functions/private/Repositories/Fork/New-GitHubRepositoryAsFork.ps1 +++ b/src/functions/private/Repositories/Fork/New-GitHubRepositoryAsFork.ps1 @@ -46,7 +46,7 @@ # The name of the repository without the .git extension. The name is not case sensitive. [Parameter(Mandatory)] - [string] $Repo, + [string] $Repository, # The organization or person who will own the new repository. # To create a new repository in an organization, the authenticated user must be a member of the specified organization. @@ -64,53 +64,34 @@ # 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. - [Parameter()] - [object] $Context = (Get-GitHubContext) + [Parameter(Mandatory)] + [object] $Context ) begin { $stackPath = Get-PSCallStackPath Write-Debug "[$stackPath] - Start" - $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - if ([string]::IsNullOrEmpty($Owner)) { - $Owner = $Context.Owner - } - Write-Debug "Owner: [$Owner]" - - if ([string]::IsNullOrEmpty($Repo)) { - $Repo = $Context.Repo - } - Write-Debug "Repo: [$Repo]" - - if ([string]::IsNullorEmpty($Name)) { - $Name = $Repo - } - Write-Debug "Name: [$Name]" } process { - try { - $body = @{ - organization = $Organization - name = $Name - default_branch_only = $DefaultBranchOnly - } + $body = @{ + organization = $Organization + name = $Name + default_branch_only = $DefaultBranchOnly + } - $inputObject = @{ - Context = $Context - APIEndpoint = "/repos/$Owner/$Repo/forks" - Method = 'POST' - Body = $body - } + $inputObject = @{ + Method = 'POST' + APIEndpoint = "/repos/$Owner/$Repository/forks" + Body = $body + Context = $Context + } - if ($PSCmdlet.ShouldProcess("Repository [$Organization/$Name] as fork of [$Owner/$Repo]", 'Create')) { - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } + if ($PSCmdlet.ShouldProcess("Repository [$Organization/$Name] as fork of [$Owner/$Repository]", 'Create')) { + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } - } catch { - throw $_ } } diff --git a/src/functions/private/Repositories/Repositories/Get-GitHubMyRepositories.ps1 b/src/functions/private/Repositories/Repositories/Get-GitHubMyRepositories.ps1 index acdfb5eb4..e457be1c0 100644 --- a/src/functions/private/Repositories/Repositories/Get-GitHubMyRepositories.ps1 +++ b/src/functions/private/Repositories/Repositories/Get-GitHubMyRepositories.ps1 @@ -109,53 +109,48 @@ # 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. - [Parameter()] - [object] $Context = (Get-GitHubContext) + [Parameter(Mandatory)] + [object] $Context ) begin { $stackPath = Get-PSCallStackPath Write-Debug "[$stackPath] - Start" - $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT } process { - try { - $body = @{ - sort = $Sort - direction = $Direction - per_page = $PerPage - } - if ($PSBoundParameters.ContainsKey('Since')) { - $body['since'] = $Since.ToString('yyyy-MM-ddTHH:mm:ssZ') - } - if ($PSBoundParameters.ContainsKey('Before')) { - $body['before'] = $Before.ToString('yyyy-MM-ddTHH:mm:ssZ') + $body = @{ + sort = $Sort + direction = $Direction + per_page = $PerPage + } + if ($PSBoundParameters.ContainsKey('Since')) { + $body['since'] = $Since.ToString('yyyy-MM-ddTHH:mm:ssZ') + } + if ($PSBoundParameters.ContainsKey('Before')) { + $body['before'] = $Before.ToString('yyyy-MM-ddTHH:mm:ssZ') + } + Write-Debug "ParamSet: [$($PSCmdlet.ParameterSetName)]" + switch ($PSCmdlet.ParameterSetName) { + 'Aff-Vis' { + $body['affiliation'] = $Affiliation -join ',' + $body['visibility'] = $Visibility } - Write-Debug "ParamSet: [$($PSCmdlet.ParameterSetName)]" - switch ($PSCmdlet.ParameterSetName) { - 'Aff-Vis' { - $body['affiliation'] = $Affiliation -join ',' - $body['visibility'] = $Visibility - } - 'Type' { - $body['type'] = $Type - } + 'Type' { + $body['type'] = $Type } + } - $inputObject = @{ - Context = $Context - APIEndpoint = '/user/repos' - Method = 'GET' - body = $body - } + $inputObject = @{ + Method = 'GET' + APIEndpoint = '/user/repos' + body = $body + Context = $Context + } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } - } catch { - throw $_ + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } } diff --git a/src/functions/private/Repositories/Repositories/Get-GitHubRepositoryByName.ps1 b/src/functions/private/Repositories/Repositories/Get-GitHubRepositoryByName.ps1 index ff9b5f24f..c70381b38 100644 --- a/src/functions/private/Repositories/Repositories/Get-GitHubRepositoryByName.ps1 +++ b/src/functions/private/Repositories/Repositories/Get-GitHubRepositoryByName.ps1 @@ -11,7 +11,7 @@ For more information, see "[Managing security managers in your organization](https://docs.github.com/organizations/managing-peoples-access-to-your-organization-with-roles/managing-security-managers-in-your-organization)." .EXAMPLE - Get-GitHubRepositoryByName -Owner 'octocat' -Repo 'Hello-World' + Get-GitHubRepositoryByName -Owner 'octocat' -Repository 'Hello-World' Gets the repository 'Hello-World' for the organization 'octocat'. @@ -28,44 +28,29 @@ # The name of the repository without the .git extension. The name is not case sensitive. [Parameter(Mandatory)] - [string] $Repo, + [string] $Repository, # 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. - [Parameter()] - [object] $Context = (Get-GitHubContext) + [Parameter(Mandatory)] + [object] $Context ) begin { $stackPath = Get-PSCallStackPath Write-Debug "[$stackPath] - Start" - $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - if ([string]::IsNullOrEmpty($Owner)) { - $Owner = $Context.Owner - } - Write-Debug "Owner: [$Owner]" - - if ([string]::IsNullOrEmpty($Repo)) { - $Repo = $Context.Repo - } - Write-Debug "Repo: [$Repo]" } process { - try { - - $inputObject = @{ - Context = $Context - APIEndpoint = "/repos/$Owner/$Repo" - Method = 'GET' - } + $inputObject = @{ + Method = 'GET' + APIEndpoint = "/repos/$Owner/$Repository" + Context = $Context + } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } - } catch { - throw $_ + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } } diff --git a/src/functions/private/Repositories/Repositories/Get-GitHubRepositoryListByID.ps1 b/src/functions/private/Repositories/Repositories/Get-GitHubRepositoryListByID.ps1 index f3cd52686..327f46ddb 100644 --- a/src/functions/private/Repositories/Repositories/Get-GitHubRepositoryListByID.ps1 +++ b/src/functions/private/Repositories/Repositories/Get-GitHubRepositoryListByID.ps1 @@ -29,35 +29,30 @@ # 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. - [Parameter()] - [object] $Context = (Get-GitHubContext) + [Parameter(Mandatory)] + [object] $Context ) begin { $stackPath = Get-PSCallStackPath Write-Debug "[$stackPath] - Start" - $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT } process { - try { - $body = @{ - since = $Since - } + $body = @{ + since = $Since + } - $inputObject = @{ - Context = $Context - APIEndpoint = '/repositories' - Method = 'GET' - Body = $body - } + $inputObject = @{ + Method = 'GET' + APIEndpoint = '/repositories' + Body = $body + Context = $Context + } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } - } catch { - throw $_ + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } } diff --git a/src/functions/private/Repositories/Repositories/Get-GitHubRepositoryListByOrg.ps1 b/src/functions/private/Repositories/Repositories/Get-GitHubRepositoryListByOrg.ps1 index 2e24b3ac8..2d90213b9 100644 --- a/src/functions/private/Repositories/Repositories/Get-GitHubRepositoryListByOrg.ps1 +++ b/src/functions/private/Repositories/Repositories/Get-GitHubRepositoryListByOrg.ps1 @@ -58,42 +58,33 @@ # 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. - [Parameter()] - [object] $Context = (Get-GitHubContext) + [Parameter(Mandatory)] + [object] $Context ) begin { $stackPath = Get-PSCallStackPath Write-Debug "[$stackPath] - Start" - $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - if ([string]::IsNullOrEmpty($Owner)) { - $Owner = $Context.Owner - } - Write-Debug "Owner: [$Owner]" } process { - try { - $body = @{ - sort = $Sort - type = $Type - direction = $Direction - per_page = $PerPage - } - - $inputObject = @{ - Context = $Context - APIEndpoint = "/orgs/$Owner/repos" - Method = 'GET' - Body = $body - } - - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } - } catch { - throw $_ + $body = @{ + sort = $Sort + type = $Type + direction = $Direction + per_page = $PerPage + } + + $inputObject = @{ + Method = 'GET' + APIEndpoint = "/orgs/$Owner/repos" + Body = $body + Context = $Context + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } } diff --git a/src/functions/private/Repositories/Repositories/Get-GitHubRepositoryListByUser.ps1 b/src/functions/private/Repositories/Repositories/Get-GitHubRepositoryListByUser.ps1 index 70d5133e8..62be02f6f 100644 --- a/src/functions/private/Repositories/Repositories/Get-GitHubRepositoryListByUser.ps1 +++ b/src/functions/private/Repositories/Repositories/Get-GitHubRepositoryListByUser.ps1 @@ -60,47 +60,33 @@ # 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. - [Parameter()] - [object] $Context = (Get-GitHubContext) + [Parameter(Mandatory)] + [object] $Context ) begin { $stackPath = Get-PSCallStackPath Write-Debug "[$stackPath] - Start" - $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - if ([string]::IsNullOrEmpty($Owner)) { - $Owner = $Context.Owner + } + + process { + $body = @{ + sort = $Sort + type = $Type + direction = $Direction + per_page = $PerPage } - Write-Debug "Owner: [$Owner]" - if ([string]::IsNullOrEmpty($Repo)) { - $Repo = $Context.Repo + $inputObject = @{ + Method = 'GET' + APIEndpoint = "/users/$Username/repos" + Body = $body + Context = $Context } - Write-Debug "Repo: [$Repo]" - } - process { - try { - $body = @{ - sort = $Sort - type = $Type - direction = $Direction - per_page = $PerPage - } - - $inputObject = @{ - Context = $Context - APIEndpoint = "/users/$Username/repos" - Method = 'GET' - Body = $body - } - - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } - } catch { - throw $_ + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } } diff --git a/src/functions/private/Repositories/Repositories/New-GitHubRepositoryFromTemplate.ps1 b/src/functions/private/Repositories/Repositories/New-GitHubRepositoryFromTemplate.ps1 index f9bfe16b7..ccc0f6642 100644 --- a/src/functions/private/Repositories/Repositories/New-GitHubRepositoryFromTemplate.ps1 +++ b/src/functions/private/Repositories/Repositories/New-GitHubRepositoryFromTemplate.ps1 @@ -51,7 +51,6 @@ # The organization or person who will own the new repository. # To create a new repository in an organization, the authenticated user must be a member of the specified organization. [Parameter(Mandatory)] - [Alias('org')] [string] $Owner, # The name of the new repository. @@ -74,45 +73,36 @@ # 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. - [Parameter()] - [object] $Context = (Get-GitHubContext) + [Parameter(Mandatory)] + [object] $Context ) begin { $stackPath = Get-PSCallStackPath Write-Debug "[$stackPath] - Start" - $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - if ([string]::IsNullOrEmpty($Owner)) { - $Owner = $Context.Owner - } - Write-Debug "Owner: [$Owner]" } process { - try { - $body = @{ - owner = $Owner - name = $Name - description = $Description - include_all_branches = $IncludeAllBranches - private = $Private - } + $body = @{ + owner = $Owner + name = $Name + description = $Description + include_all_branches = $IncludeAllBranches + private = $Private + } - $inputObject = @{ - Context = $Context - APIEndpoint = "/repos/$TemplateOwner/$TemplateRepo/generate" - Method = 'POST' - Body = $body - } + $inputObject = @{ + Method = 'POST' + APIEndpoint = "/repos/$TemplateOwner/$TemplateRepo/generate" + Body = $body + Context = $Context + } - if ($PSCmdlet.ShouldProcess("Repository [$Owner/$Name] from template [$TemplateOwner/$TemplateRepo]", 'Create')) { - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } + if ($PSCmdlet.ShouldProcess("Repository [$Owner/$Name] from template [$TemplateOwner/$TemplateRepo]", 'Create')) { + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } - } catch { - throw $_ } } diff --git a/src/functions/private/Repositories/Repositories/New-GitHubRepositoryOrg.ps1 b/src/functions/private/Repositories/Repositories/New-GitHubRepositoryOrg.ps1 index 1eddfd0ba..8b363ec27 100644 --- a/src/functions/private/Repositories/Repositories/New-GitHubRepositoryOrg.ps1 +++ b/src/functions/private/Repositories/Repositories/New-GitHubRepositoryOrg.ps1 @@ -63,7 +63,8 @@ filter New-GitHubRepositoryOrg { param( # The account owner of the repository. The name is not case sensitive. [Parameter(Mandatory)] - [Alias('org')] + [Alias('Organization')] + [Alias('User')] [string] $Owner, # The name of the repository. @@ -183,8 +184,8 @@ filter New-GitHubRepositoryOrg { # 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. - [Parameter()] - [object] $Context = (Get-GitHubContext) + [Parameter(Mandatory)] + [object] $Context ) dynamicparam { @@ -214,56 +215,47 @@ filter New-GitHubRepositoryOrg { begin { $stackPath = Get-PSCallStackPath Write-Debug "[$stackPath] - Start" - $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT $GitignoreTemplate = $PSBoundParameters['GitignoreTemplate'] $LicenseTemplate = $PSBoundParameters['LicenseTemplate'] - if ([string]::IsNullOrEmpty($Owner)) { - $Owner = $Context.Owner - } - Write-Debug "Owner: [$Owner]" } process { - try { - $body = @{ - name = $Name - description = $Description - homepage = $Homepage - visibility = $Visibility - has_issues = $HasIssues - has_projects = $HasProjects - has_wiki = $HasWiki - has_downloads = $HasDownloads - is_template = $IsTemplate - team_id = $TeamId - auto_init = $AutoInit - allow_squash_merge = $AllowSquashMerge - allow_merge_commit = $AllowMergeCommit - allow_rebase_merge = $AllowRebaseMerge - allow_auto_merge = $AllowAutoMerge - delete_branch_on_merge = $DeleteBranchOnMerge - squash_merge_commit_title = $SquashMergeCommitTitle - squash_merge_commit_message = $SquashMergeCommitMessage - merge_commit_title = $MergeCommitTitle - merge_commit_message = $MergeCommitMessage - private = $Visibility -eq 'private' - } + $body = @{ + name = $Name + description = $Description + homepage = $Homepage + visibility = $Visibility + has_issues = $HasIssues + has_projects = $HasProjects + has_wiki = $HasWiki + has_downloads = $HasDownloads + is_template = $IsTemplate + team_id = $TeamId + auto_init = $AutoInit + allow_squash_merge = $AllowSquashMerge + allow_merge_commit = $AllowMergeCommit + allow_rebase_merge = $AllowRebaseMerge + allow_auto_merge = $AllowAutoMerge + delete_branch_on_merge = $DeleteBranchOnMerge + squash_merge_commit_title = $SquashMergeCommitTitle + squash_merge_commit_message = $SquashMergeCommitMessage + merge_commit_title = $MergeCommitTitle + merge_commit_message = $MergeCommitMessage + private = $Visibility -eq 'private' + } - $inputObject = @{ - Context = $Context - APIEndpoint = "/orgs/$Owner/repos" - Method = 'POST' - Body = $body - } + $inputObject = @{ + Method = 'POST' + APIEndpoint = "/orgs/$Owner/repos" + Body = $body + Context = $Context + } - if ($PSCmdlet.ShouldProcess("Repository in organization $Owner", 'Create')) { - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } + if ($PSCmdlet.ShouldProcess("Repository in organization $Owner", 'Create')) { + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } - } catch { - throw $_ } } diff --git a/src/functions/private/Repositories/Repositories/New-GitHubRepositoryUser.ps1 b/src/functions/private/Repositories/Repositories/New-GitHubRepositoryUser.ps1 index 3405128a5..15c3ce1a2 100644 --- a/src/functions/private/Repositories/Repositories/New-GitHubRepositoryUser.ps1 +++ b/src/functions/private/Repositories/Repositories/New-GitHubRepositoryUser.ps1 @@ -177,8 +177,8 @@ filter New-GitHubRepositoryUser { # 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. - [Parameter()] - [object] $Context = (Get-GitHubContext) + [Parameter(Mandatory)] + [object] $Context ) dynamicparam { @@ -208,52 +208,47 @@ filter New-GitHubRepositoryUser { begin { $stackPath = Get-PSCallStackPath Write-Debug "[$stackPath] - Start" - $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT $GitignoreTemplate = $PSBoundParameters['GitignoreTemplate'] $LicenseTemplate = $PSBoundParameters['LicenseTemplate'] } process { - try { - $body = @{ - name = $Name - description = $Description - homepage = $Homepage - visibility = $Visibility - has_issues = $HasIssues - has_projects = $HasProjects - has_wiki = $HasWiki - has_downloads = $HasDownloads - is_template = $IsTemplate - team_id = $TeamId - auto_init = $AutoInit - allow_squash_merge = $AllowSquashMerge - allow_merge_commit = $AllowMergeCommit - allow_rebase_merge = $AllowRebaseMerge - allow_auto_merge = $AllowAutoMerge - delete_branch_on_merge = $DeleteBranchOnMerge - squash_merge_commit_title = $SquashMergeCommitTitle - squash_merge_commit_message = $SquashMergeCommitMessage - merge_commit_title = $MergeCommitTitle - merge_commit_message = $MergeCommitMessage - private = $Visibility -eq 'private' - } + $body = @{ + name = $Name + description = $Description + homepage = $Homepage + visibility = $Visibility + has_issues = $HasIssues + has_projects = $HasProjects + has_wiki = $HasWiki + has_downloads = $HasDownloads + is_template = $IsTemplate + team_id = $TeamId + auto_init = $AutoInit + allow_squash_merge = $AllowSquashMerge + allow_merge_commit = $AllowMergeCommit + allow_rebase_merge = $AllowRebaseMerge + allow_auto_merge = $AllowAutoMerge + delete_branch_on_merge = $DeleteBranchOnMerge + squash_merge_commit_title = $SquashMergeCommitTitle + squash_merge_commit_message = $SquashMergeCommitMessage + merge_commit_title = $MergeCommitTitle + merge_commit_message = $MergeCommitMessage + private = $Visibility -eq 'private' + } - $inputObject = @{ - Context = $Context - APIEndpoint = '/user/repos' - Method = 'POST' - Body = $body - } + $inputObject = @{ + Method = 'POST' + APIEndpoint = '/user/repos' + Body = $body + Context = $Context + } - if ($PSCmdlet.ShouldProcess('Repository for user', 'Create')) { - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } + if ($PSCmdlet.ShouldProcess('Repository for user', 'Create')) { + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } - } catch { - throw $_ } } diff --git a/src/functions/private/Teams/Get-GitHubRESTTeam.ps1 b/src/functions/private/Teams/Get-GitHubRESTTeam.ps1 index dce4b2a53..807c25e3b 100644 --- a/src/functions/private/Teams/Get-GitHubRESTTeam.ps1 +++ b/src/functions/private/Teams/Get-GitHubRESTTeam.ps1 @@ -27,8 +27,7 @@ param( # The organization name. The name is not case sensitive. # If not provided, the organization from the context is used. - [Parameter()] - [Alias('Org')] + [Parameter(Mandatory)] [string] $Organization, # The slug of the team name. @@ -41,38 +40,28 @@ # 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. - [Parameter()] - [object] $Context = (Get-GitHubContext) + [Parameter(Mandatory)] + [object] $Context ) begin { $stackPath = Get-PSCallStackPath Write-Debug "[$stackPath] - Start" - $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - - if ([string]::IsNullOrEmpty($Organization)) { - $Organization = $Context.Owner - } - Write-Debug "Organization: [$Organization]" } process { - try { - $params = @{ - Organization = $Organization - Context = $Context + $params = @{ + Organization = $Organization + Context = $Context + } + switch ($PSCmdlet.ParameterSetName) { + 'GetByName' { + Get-GitHubRESTTeamByName @params -Name $Name } - switch ($PSCmdlet.ParameterSetName) { - 'GetByName' { - Get-GitHubRESTTeamByName @params -Name $Name - } - '__AllParameterSets' { - Get-GitHubTeamListByOrg @params - } + default { + Get-GitHubTeamListByOrg @params } - } catch { - throw $_ } } diff --git a/src/functions/private/Teams/Get-GitHubRESTTeamByName.ps1 b/src/functions/private/Teams/Get-GitHubRESTTeamByName.ps1 index a7fc5d519..fabed8ed5 100644 --- a/src/functions/private/Teams/Get-GitHubRESTTeamByName.ps1 +++ b/src/functions/private/Teams/Get-GitHubRESTTeamByName.ps1 @@ -20,40 +20,29 @@ # The organization name. The name is not case sensitive. [Parameter(Mandatory)] - [Alias('Org')] [string] $Organization, # 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. - [Parameter()] - [object] $Context = (Get-GitHubContext) + [Parameter(Mandatory)] + [object] $Context ) begin { $stackPath = Get-PSCallStackPath Write-Debug "[$stackPath] - Start" - $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - - if ([string]::IsNullOrEmpty($Organization)) { - $Organization = $Context.Owner - } - Write-Debug "Organization: [$Organization]" } process { - try { - $inputObject = @{ - Context = $Context - APIEndpoint = "/orgs/$Organization/teams/$Name" - Method = 'Get' - } - - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } - } catch { - throw $_ + $inputObject = @{ + Method = 'GET' + APIEndpoint = "/orgs/$Organization/teams/$Name" + Context = $Context + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } } diff --git a/src/functions/private/Teams/Get-GitHubRESTTeamListByOrg.ps1 b/src/functions/private/Teams/Get-GitHubRESTTeamListByOrg.ps1 index 4575a53b2..82a885e6e 100644 --- a/src/functions/private/Teams/Get-GitHubRESTTeamListByOrg.ps1 +++ b/src/functions/private/Teams/Get-GitHubRESTTeamListByOrg.ps1 @@ -17,40 +17,29 @@ param( # The organization name. The name is not case sensitive. [Parameter(Mandatory)] - [Alias('Org')] [string] $Organization, # 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. - [Parameter()] - [object] $Context = (Get-GitHubContext) + [Parameter(Mandatory)] + [object] $Context ) begin { $stackPath = Get-PSCallStackPath Write-Debug "[$stackPath] - Start" - $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - - if ([string]::IsNullOrEmpty($Organization)) { - $Organization = $Context.Owner - } - Write-Debug "Organization: [$Organization]" } process { - try { - $inputObject = @{ - Context = $Context - APIEndpoint = "/orgs/$Organization/teams" - Method = 'Get' - } - - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } - } catch { - throw $_ + $inputObject = @{ + Method = 'GET' + APIEndpoint = "/orgs/$Organization/teams" + Context = $Context + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } } diff --git a/src/functions/private/Teams/Get-GitHubRepoTeam.ps1 b/src/functions/private/Teams/Get-GitHubRepoTeam.ps1 index 2db1a32c4..beb962a7f 100644 --- a/src/functions/private/Teams/Get-GitHubRepoTeam.ps1 +++ b/src/functions/private/Teams/Get-GitHubRepoTeam.ps1 @@ -5,48 +5,33 @@ #> [CmdletBinding()] param( - [Parameter()] + [Parameter(Mandatory)] [string] $Owner, - [Parameter()] - [string] $Repo, + [Parameter(Mandatory)] + [string] $Repository, # 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. - [Parameter()] - [object] $Context = (Get-GitHubContext) + [Parameter(Mandatory)] + [object] $Context ) begin { $stackPath = Get-PSCallStackPath Write-Debug "[$stackPath] - Start" - $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - - if ([string]::IsNullOrEmpty($Owner)) { - $Owner = $Context.Owner - } - Write-Debug "Owner: [$Owner]" - - if ([string]::IsNullOrEmpty($Repo)) { - $Repo = $Context.Repo - } - Write-Debug "Repo: [$Repo]" } process { - try { - $inputObject = @{ - Context = $Context - APIEndpoint = "/repos/$Owner/$Repo/teams" - Method = 'Get' - } + $inputObject = @{ + Method = 'GET' + APIEndpoint = "/repos/$Owner/$Repository/teams" + Context = $Context + } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } - } catch { - throw $_ + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } } diff --git a/src/functions/private/Teams/Get-GitHubTeamBySlug.ps1 b/src/functions/private/Teams/Get-GitHubTeamBySlug.ps1 index b8675c403..b17931c58 100644 --- a/src/functions/private/Teams/Get-GitHubTeamBySlug.ps1 +++ b/src/functions/private/Teams/Get-GitHubTeamBySlug.ps1 @@ -21,30 +21,22 @@ # The organization name. The name is not case sensitive. # If not provided, the owner from the context will be used. [Parameter()] - [Alias('Org')] [string] $Organization, # 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. - [Parameter()] - [object] $Context = (Get-GitHubContext) + [Parameter(Mandatory)] + [object] $Context ) begin { $stackPath = Get-PSCallStackPath Write-Debug "[$stackPath] - Start" - $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - - if ([string]::IsNullOrEmpty($Organization)) { - $Organization = $Context.Owner - } - Write-Debug "Organization: [$Organization]" } process { - try { - $query = @" + $query = @" query(`$org: String!, `$teamSlug: String!) { organization(login: `$org) { team(slug: `$teamSlug) { @@ -76,43 +68,40 @@ query(`$org: String!, `$teamSlug: String!) { } "@ - # Variables hash that will be sent with the query - $variables = @{ - org = $Organization - teamSlug = $Slug - } - - # Send the request to the GitHub GraphQL API - $response = Invoke-GitHubGraphQLQuery -Query $query -Variables $variables -Context $Context + # Variables hash that will be sent with the query + $variables = @{ + org = $Organization + teamSlug = $Slug + } - # Extract team data - $team = $response.data.organization.team + # Send the request to the GitHub GraphQL API + $response = Invoke-GitHubGraphQLQuery -Query $query -Variables $variables -Context $Context - # Output the team object - if (-not $team) { - return - } + # Extract team data + $team = $response.data.organization.team - [GitHubTeam]( - @{ - Name = $team.name - Slug = $team.slug - NodeID = $team.id - CombinedSlug = $team.CombinedSlug - DatabaseID = $team.DatabaseId - Description = $team.description - Notifications = $team.notificationSetting -eq 'NOTIFICATIONS_ENABLED' ? $true : $false - Visible = $team.privacy -eq 'VISIBLE' ? $true : $false - ParentTeam = $team.parentTeam.slug - Organization = $team.organization.login - ChildTeams = $team.childTeams.nodes.name - CreatedAt = $team.createdAt - UpdatedAt = $team.updatedAt - } - ) - } catch { - throw $_ + # Output the team object + if (-not $team) { + return } + + [GitHubTeam]( + @{ + Name = $team.name + Slug = $team.slug + NodeID = $team.id + CombinedSlug = $team.CombinedSlug + DatabaseID = $team.DatabaseId + Description = $team.description + Notifications = $team.notificationSetting -eq 'NOTIFICATIONS_ENABLED' ? $true : $false + Visible = $team.privacy -eq 'VISIBLE' ? $true : $false + ParentTeam = $team.parentTeam.slug + Organization = $team.organization.login + ChildTeams = $team.childTeams.nodes.name + CreatedAt = $team.createdAt + UpdatedAt = $team.updatedAt + } + ) } end { diff --git a/src/functions/private/Teams/Get-GitHubTeamListByOrg.ps1 b/src/functions/private/Teams/Get-GitHubTeamListByOrg.ps1 index 24f28cb3a..5353f4a01 100644 --- a/src/functions/private/Teams/Get-GitHubTeamListByOrg.ps1 +++ b/src/functions/private/Teams/Get-GitHubTeamListByOrg.ps1 @@ -17,31 +17,23 @@ param( # The organization name. The name is not case sensitive. # If you don't provide this parameter, the command will use the owner of the context. - [Parameter()] - [Alias('Org')] + [Parameter(Mandatory)] [string] $Organization, # 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. - [Parameter()] - [object] $Context = (Get-GitHubContext) + [Parameter(Mandatory)] + [object] $Context ) begin { $stackPath = Get-PSCallStackPath Write-Debug "[$stackPath] - Start" - $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - - if ([string]::IsNullOrEmpty($Organization)) { - $Organization = $Context.Owner - } - Write-Debug "Organization: [$Organization]" } process { - try { - $query = @" + $query = @" query(`$org: String!, `$after: String) { organization(login: `$org) { teams(first: 100, after: `$after) { @@ -78,52 +70,49 @@ query(`$org: String!, `$after: String) { } "@ - # Variables hash that will be sent with the query - $variables = @{ - org = $Organization - } - - # Prepare to store results and handle pagination - $hasNextPage = $true - $after = $null + # Variables hash that will be sent with the query + $variables = @{ + org = $Organization + } - while ($hasNextPage) { - # Update the cursor for pagination - $variables['after'] = $after + # Prepare to store results and handle pagination + $hasNextPage = $true + $after = $null - # Send the request to the GitHub GraphQL API - $response = Invoke-GitHubGraphQLQuery -Query $query -Variables $variables -Context $Context + while ($hasNextPage) { + # Update the cursor for pagination + $variables['after'] = $after - # Extract team data - $teams = $response.data.organization.teams + # Send the request to the GitHub GraphQL API + $response = Invoke-GitHubGraphQLQuery -Query $query -Variables $variables -Context $Context - # Accumulate the teams in results - $teams.nodes | ForEach-Object { - [GitHubTeam]( - @{ - Name = $_.name - Slug = $_.slug - NodeID = $_.id - CombinedSlug = $_.combinedSlug - DatabaseId = $_.databaseId - Description = $_.description - Notifications = $_.notificationSetting -eq 'NOTIFICATIONS_ENABLED' ? $true : $false - Visible = $_.privacy -eq 'VISIBLE' ? $true : $false - ParentTeam = $_.parentTeam.slug - Organization = $_.organization.login - ChildTeams = $_.childTeams.nodes.name - CreatedAt = $_.createdAt - UpdatedAt = $_.updatedAt - } - ) - } + # Extract team data + $teams = $response.data.organization.teams - # Check if there's another page to fetch - $hasNextPage = $teams.pageInfo.hasNextPage - $after = $teams.pageInfo.endCursor + # Accumulate the teams in results + $teams.nodes | ForEach-Object { + [GitHubTeam]( + @{ + Name = $_.name + Slug = $_.slug + NodeID = $_.id + CombinedSlug = $_.combinedSlug + DatabaseId = $_.databaseId + Description = $_.description + Notifications = $_.notificationSetting -eq 'NOTIFICATIONS_ENABLED' ? $true : $false + Visible = $_.privacy -eq 'VISIBLE' ? $true : $false + ParentTeam = $_.parentTeam.slug + Organization = $_.organization.login + ChildTeams = $_.childTeams.nodes.name + CreatedAt = $_.createdAt + UpdatedAt = $_.updatedAt + } + ) } - } catch { - throw $_ + + # Check if there's another page to fetch + $hasNextPage = $teams.pageInfo.hasNextPage + $after = $teams.pageInfo.endCursor } } diff --git a/src/functions/private/Users/Blocking/Block-GitHubUserByUser.ps1 b/src/functions/private/Users/Blocking/Block-GitHubUserByUser.ps1 index 4f5846da0..5ded734db 100644 --- a/src/functions/private/Users/Blocking/Block-GitHubUserByUser.ps1 +++ b/src/functions/private/Users/Blocking/Block-GitHubUserByUser.ps1 @@ -29,36 +29,24 @@ # 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. - [Parameter()] - [object] $Context = (Get-GitHubContext) + [Parameter(Mandatory)] + [object] $Context ) begin { $stackPath = Get-PSCallStackPath Write-Debug "[$stackPath] - Start" - $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT } process { $inputObject = @{ - Context = $Context - APIEndpoint = "/user/blocks/$Username" Method = 'PUT' + APIEndpoint = "/user/blocks/$Username" + Context = $Context } - try { - $null = (Invoke-GitHubAPI @inputObject) - # Should we check if user is already blocked and return true if so? - return $true - } catch { - if ($_.Exception.Response.StatusCode.Value__ -eq 422) { - return $false - } else { - Write-Error $_.Exception.Response - throw $_ - } - } + Invoke-GitHubAPI @inputObject } end { diff --git a/src/functions/private/Users/Blocking/Get-GitHubBlockedUserByUser.ps1 b/src/functions/private/Users/Blocking/Get-GitHubBlockedUserByUser.ps1 index 768614871..06a0d10c8 100644 --- a/src/functions/private/Users/Blocking/Get-GitHubBlockedUserByUser.ps1 +++ b/src/functions/private/Users/Blocking/Get-GitHubBlockedUserByUser.ps1 @@ -24,35 +24,30 @@ # 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. - [Parameter()] - [object] $Context = (Get-GitHubContext) + [Parameter(Mandatory)] + [object] $Context ) begin { $stackPath = Get-PSCallStackPath Write-Debug "[$stackPath] - Start" - $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT } process { - try { - $body = @{ - per_page = $PerPage - } - - $inputObject = @{ - Context = $Context - APIEndpoint = '/user/blocks' - Method = 'GET' - Body = $body - } - - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } - } catch { - throw $_ + $body = @{ + per_page = $PerPage + } + + $inputObject = @{ + Method = 'GET' + APIEndpoint = '/user/blocks' + Body = $body + Context = $Context + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } } diff --git a/src/functions/private/Users/Blocking/Test-GitHubBlockedUserByUser.ps1 b/src/functions/private/Users/Blocking/Test-GitHubBlockedUserByUser.ps1 index ebd64b1f0..bb9f3cd47 100644 --- a/src/functions/private/Users/Blocking/Test-GitHubBlockedUserByUser.ps1 +++ b/src/functions/private/Users/Blocking/Test-GitHubBlockedUserByUser.ps1 @@ -36,42 +36,29 @@ # 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. - [Parameter()] - [object] $Context = (Get-GitHubContext) + [Parameter(Mandatory)] + [object] $Context ) begin { $stackPath = Get-PSCallStackPath Write-Debug "[$stackPath] - Start" - $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT } process { - try { - $body = @{ - per_page = $PerPage - } - - $inputObject = @{ - Context = $Context - APIEndpoint = "/user/blocks/$Username" - Method = 'GET' - Body = $body - } + $body = @{ + per_page = $PerPage + } - try { - (Invoke-GitHubAPI @inputObject).StatusCode -eq 204 - } catch { - if ($_.Exception.Response.StatusCode.Value__ -eq 404) { - return $false - } else { - throw $_ - } - } - } catch { - throw $_ + $inputObject = @{ + Method = 'GET' + APIEndpoint = "/user/blocks/$Username" + Body = $body + Context = $Context } + + Invoke-GitHubAPI @inputObject } end { diff --git a/src/functions/private/Users/Blocking/Unblock-GitHubUserByUser.ps1 b/src/functions/private/Users/Blocking/Unblock-GitHubUserByUser.ps1 index ef2916a5d..1a476643d 100644 --- a/src/functions/private/Users/Blocking/Unblock-GitHubUserByUser.ps1 +++ b/src/functions/private/Users/Blocking/Unblock-GitHubUserByUser.ps1 @@ -29,35 +29,24 @@ # 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. - [Parameter()] - [object] $Context = (Get-GitHubContext) + [Parameter(Mandatory)] + [object] $Context ) begin { $stackPath = Get-PSCallStackPath Write-Debug "[$stackPath] - Start" - $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT } process { - try { - $inputObject = @{ - Context = $Context - APIEndpoint = "/user/blocks/$Username" - Method = 'DELETE' - } - - try { - $null = (Invoke-GitHubAPI @inputObject) - return $true - } catch { - Write-Error $_.Exception.Response - throw $_ - } - } catch { - throw $_ + $inputObject = @{ + Method = 'DELETE' + APIEndpoint = "/user/blocks/$Username" + Context = $Context } + + Invoke-GitHubAPI @inputObject } end { diff --git a/src/functions/private/Users/Emails/Get-GitHubUserAllEmail.ps1 b/src/functions/private/Users/Emails/Get-GitHubUserAllEmail.ps1 index 9929a4dcd..2f6ed0c39 100644 --- a/src/functions/private/Users/Emails/Get-GitHubUserAllEmail.ps1 +++ b/src/functions/private/Users/Emails/Get-GitHubUserAllEmail.ps1 @@ -26,34 +26,29 @@ # 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. - [Parameter()] - [object] $Context = (Get-GitHubContext) + [Parameter(Mandatory)] + [object] $Context ) begin { $stackPath = Get-PSCallStackPath Write-Debug "[$stackPath] - Start" - $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT } process { - try { - $body = @{ - per_page = $PerPage - } - $inputObject = @{ - Context = $Context - APIEndpoint = '/user/emails' - Method = 'GET' - Body = $body - } - - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } - } catch { - throw $_ + $body = @{ + per_page = $PerPage + } + $inputObject = @{ + Method = 'GET' + APIEndpoint = '/user/emails' + Body = $body + Context = $Context + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } } diff --git a/src/functions/private/Users/Emails/Get-GitHubUserPublicEmail.ps1 b/src/functions/private/Users/Emails/Get-GitHubUserPublicEmail.ps1 index d810b0612..9472d3844 100644 --- a/src/functions/private/Users/Emails/Get-GitHubUserPublicEmail.ps1 +++ b/src/functions/private/Users/Emails/Get-GitHubUserPublicEmail.ps1 @@ -28,35 +28,30 @@ # 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. - [Parameter()] - [object] $Context = (Get-GitHubContext) + [Parameter(Mandatory)] + [object] $Context ) begin { $stackPath = Get-PSCallStackPath Write-Debug "[$stackPath] - Start" - $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT } process { - try { - $body = @{ - per_page = $PerPage - } + $body = @{ + per_page = $PerPage + } - $inputObject = @{ - Context = $Context - APIEndpoint = '/user/public_emails' - Method = 'GET' - Body = $body - } + $inputObject = @{ + Method = 'GET' + APIEndpoint = '/user/public_emails' + Body = $body + Context = $Context + } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } - } catch { - throw $_ + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } } diff --git a/src/functions/private/Users/Followers/Get-GitHubUserFollowersOfUser.ps1 b/src/functions/private/Users/Followers/Get-GitHubUserFollowersOfUser.ps1 index 5651515da..9a5717989 100644 --- a/src/functions/private/Users/Followers/Get-GitHubUserFollowersOfUser.ps1 +++ b/src/functions/private/Users/Followers/Get-GitHubUserFollowersOfUser.ps1 @@ -34,35 +34,30 @@ # 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. - [Parameter()] - [object] $Context = (Get-GitHubContext) + [Parameter(Mandatory)] + [object] $Context ) begin { $stackPath = Get-PSCallStackPath Write-Debug "[$stackPath] - Start" - $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT } process { - try { - $body = @{ - per_page = $PerPage - } + $body = @{ + per_page = $PerPage + } - $inputObject = @{ - Context = $Context - APIEndpoint = "/users/$Username/followers" - Method = 'GET' - Body = $body - } + $inputObject = @{ + Method = 'GET' + APIEndpoint = "/users/$Username/followers" + Body = $body + Context = $Context + } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } - } catch { - throw $_ + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } } diff --git a/src/functions/private/Users/Followers/Get-GitHubUserFollowingMe.ps1 b/src/functions/private/Users/Followers/Get-GitHubUserFollowingMe.ps1 index 7de86587c..1aac909a0 100644 --- a/src/functions/private/Users/Followers/Get-GitHubUserFollowingMe.ps1 +++ b/src/functions/private/Users/Followers/Get-GitHubUserFollowingMe.ps1 @@ -25,35 +25,30 @@ # 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. - [Parameter()] - [object] $Context = (Get-GitHubContext) + [Parameter(Mandatory)] + [object] $Context ) begin { $stackPath = Get-PSCallStackPath Write-Debug "[$stackPath] - Start" - $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT } process { - try { - $body = @{ - per_page = $PerPage - } - - $inputObject = @{ - Context = $Context - APIEndpoint = '/user/following' - Method = 'GET' - Body = $body - } - - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } - } catch { - throw $_ + $body = @{ + per_page = $PerPage + } + + $inputObject = @{ + Method = 'GET' + APIEndpoint = '/user/following' + Body = $body + Context = $Context + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } } diff --git a/src/functions/private/Users/Followers/Get-GitHubUserFollowingUser.ps1 b/src/functions/private/Users/Followers/Get-GitHubUserFollowingUser.ps1 index 90f9ded87..86c3ea4d4 100644 --- a/src/functions/private/Users/Followers/Get-GitHubUserFollowingUser.ps1 +++ b/src/functions/private/Users/Followers/Get-GitHubUserFollowingUser.ps1 @@ -34,35 +34,30 @@ # 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. - [Parameter()] - [object] $Context = (Get-GitHubContext) + [Parameter(Mandatory)] + [object] $Context ) begin { $stackPath = Get-PSCallStackPath Write-Debug "[$stackPath] - Start" - $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT } process { - try { - $body = @{ - per_page = $PerPage - } + $body = @{ + per_page = $PerPage + } - $inputObject = @{ - Context = $Context - APIEndpoint = "/users/$Username/following" - Method = 'GET' - Body = $body - } + $inputObject = @{ + Method = 'GET' + APIEndpoint = "/users/$Username/following" + Body = $body + Context = $Context + } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } - } catch { - throw $_ + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } } diff --git a/src/functions/private/Users/Followers/Get-GitHubUserMyFollowers.ps1 b/src/functions/private/Users/Followers/Get-GitHubUserMyFollowers.ps1 index 1d9af6015..ca171a676 100644 --- a/src/functions/private/Users/Followers/Get-GitHubUserMyFollowers.ps1 +++ b/src/functions/private/Users/Followers/Get-GitHubUserMyFollowers.ps1 @@ -16,7 +16,10 @@ #> [OutputType([pscustomobject])] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseSingularNouns', '', Justification = 'Private function, not exposed to user.')] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute( + 'PSUseSingularNouns', '', + Justification = 'Private function, not exposed to user.' + )] [CmdletBinding()] param( # The number of results per page (max 100). @@ -26,35 +29,30 @@ # 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. - [Parameter()] - [object] $Context = (Get-GitHubContext) + [Parameter(Mandatory)] + [object] $Context ) begin { $stackPath = Get-PSCallStackPath Write-Debug "[$stackPath] - Start" - $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT } process { - try { - $body = @{ - per_page = $PerPage - } + $body = @{ + per_page = $PerPage + } - $inputObject = @{ - Context = $Context - APIEndpoint = '/user/followers' - Method = 'GET' - Body = $body - } + $inputObject = @{ + Method = 'GET' + APIEndpoint = '/user/followers' + Body = $body + Context = $Context + } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } - } catch { - throw $_ + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } } diff --git a/src/functions/private/Users/Followers/Test-GitHubUserFollowedByMe.ps1 b/src/functions/private/Users/Followers/Test-GitHubUserFollowedByMe.ps1 index 483e7d52e..5b9c2eb3a 100644 --- a/src/functions/private/Users/Followers/Test-GitHubUserFollowedByMe.ps1 +++ b/src/functions/private/Users/Followers/Test-GitHubUserFollowedByMe.ps1 @@ -24,38 +24,29 @@ Mandatory, ValueFromPipelineByPropertyName )] + [Alias('login')] [string] $Username, # 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. - [Parameter()] - [object] $Context = (Get-GitHubContext) + [Parameter(Mandatory)] + [object] $Context ) begin { $stackPath = Get-PSCallStackPath Write-Debug "[$stackPath] - Start" - $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT } process { $inputObject = @{ - Context = $Context - APIEndpoint = "/user/following/$Username" Method = 'GET' + APIEndpoint = "/user/following/$Username" + Context = $Context } - try { - $null = (Invoke-GitHubAPI @inputObject) - return $true - } catch { - if ($_.Exception.Response.StatusCode.Value__ -eq 404) { - return $false - } else { - throw $_ - } - } + Invoke-GitHubAPI @inputObject } end { diff --git a/src/functions/private/Users/Followers/Test-GitHubUserFollowedByUser.ps1 b/src/functions/private/Users/Followers/Test-GitHubUserFollowedByUser.ps1 index e816d0184..711d6bd38 100644 --- a/src/functions/private/Users/Followers/Test-GitHubUserFollowedByUser.ps1 +++ b/src/functions/private/Users/Followers/Test-GitHubUserFollowedByUser.ps1 @@ -34,34 +34,24 @@ # 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. - [Parameter()] - [object] $Context = (Get-GitHubContext) + [Parameter(Mandatory)] + [object] $Context ) begin { $stackPath = Get-PSCallStackPath Write-Debug "[$stackPath] - Start" - $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT } process { $inputObject = @{ - Context = $Context - APIEndpoint = "/users/$Username/following/$Follows" Method = 'GET' + APIEndpoint = "/users/$Username/following/$Follows" + Context = $Context } - try { - $null = (Invoke-GitHubAPI @inputObject) - return $true - } catch { - if ($_.Exception.Response.StatusCode.Value__ -eq 404) { - return $false - } else { - throw $_ - } - } + Invoke-GitHubAPI @inputObject } end { diff --git a/src/functions/private/Users/GPG-Keys/Get-GitHubUserGpgKeyForUser.ps1 b/src/functions/private/Users/GPG-Keys/Get-GitHubUserGpgKeyForUser.ps1 index 2d21817b9..a4b53da27 100644 --- a/src/functions/private/Users/GPG-Keys/Get-GitHubUserGpgKeyForUser.ps1 +++ b/src/functions/private/Users/GPG-Keys/Get-GitHubUserGpgKeyForUser.ps1 @@ -23,6 +23,7 @@ Mandatory, ValueFromPipelineByPropertyName )] + [Alias('login')] [string] $Username, # The number of results per page (max 100). @@ -32,35 +33,30 @@ # 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. - [Parameter()] - [object] $Context = (Get-GitHubContext) + [Parameter(Mandatory)] + [object] $Context ) begin { $stackPath = Get-PSCallStackPath Write-Debug "[$stackPath] - Start" - $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT } process { - try { - $body = @{ - per_page = $PerPage - } + $body = @{ + per_page = $PerPage + } - $inputObject = @{ - Context = $Context - APIEndpoint = "/users/$Username/gpg_keys" - Method = 'GET' - Body = $body - } + $inputObject = @{ + Method = 'GET' + APIEndpoint = "/users/$Username/gpg_keys" + Body = $body + Context = $Context + } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } - } catch { - throw $_ + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } } diff --git a/src/functions/private/Users/GPG-Keys/Get-GitHubUserMyGpgKey.ps1 b/src/functions/private/Users/GPG-Keys/Get-GitHubUserMyGpgKey.ps1 index dfdc6d031..df23a99e2 100644 --- a/src/functions/private/Users/GPG-Keys/Get-GitHubUserMyGpgKey.ps1 +++ b/src/functions/private/Users/GPG-Keys/Get-GitHubUserMyGpgKey.ps1 @@ -27,35 +27,30 @@ # 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. - [Parameter()] - [object] $Context = (Get-GitHubContext) + [Parameter(Mandatory)] + [object] $Context ) begin { $stackPath = Get-PSCallStackPath Write-Debug "[$stackPath] - Start" - $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT } process { - try { - $body = @{ - per_page = $PerPage - } + $body = @{ + per_page = $PerPage + } - $inputObject = @{ - Context = $Context - APIEndpoint = '/user/gpg_keys' - Method = 'GET' - Body = $body - } + $inputObject = @{ + Method = 'GET' + APIEndpoint = '/user/gpg_keys' + Body = $body + Context = $Context + } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } - } catch { - throw $_ + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } } diff --git a/src/functions/private/Users/GPG-Keys/Get-GitHubUserMyGpgKeyById.ps1 b/src/functions/private/Users/GPG-Keys/Get-GitHubUserMyGpgKeyById.ps1 index 01ffbe5cf..b08e22e64 100644 --- a/src/functions/private/Users/GPG-Keys/Get-GitHubUserMyGpgKeyById.ps1 +++ b/src/functions/private/Users/GPG-Keys/Get-GitHubUserMyGpgKeyById.ps1 @@ -29,30 +29,25 @@ # 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. - [Parameter()] - [object] $Context = (Get-GitHubContext) + [Parameter(Mandatory)] + [object] $Context ) begin { $stackPath = Get-PSCallStackPath Write-Debug "[$stackPath] - Start" - $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT } process { - try { - $inputObject = @{ - Context = $Context - APIEndpoint = "/user/gpg_keys/$ID" - Method = 'GET' - } - - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } - } catch { - throw $_ + $inputObject = @{ + Method = 'GET' + APIEndpoint = "/user/gpg_keys/$ID" + Context = $Context + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } } diff --git a/src/functions/private/Users/Get-GitHubAllUser.ps1 b/src/functions/private/Users/Get-GitHubAllUser.ps1 index 1a6d095e3..f6737a8b0 100644 --- a/src/functions/private/Users/Get-GitHubAllUser.ps1 +++ b/src/functions/private/Users/Get-GitHubAllUser.ps1 @@ -18,6 +18,7 @@ .NOTES https://docs.github.com/rest/users/users#list-users #> + [Alias('Get-GitHubAllUsers')] [OutputType([pscustomobject])] [CmdletBinding()] param( @@ -32,36 +33,31 @@ # 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. - [Parameter()] - [object] $Context = (Get-GitHubContext) + [Parameter(Mandatory)] + [object] $Context ) begin { $stackPath = Get-PSCallStackPath Write-Debug "[$stackPath] - Start" - $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT } process { - try { - $body = @{ - since = $Since - per_page = $PerPage - } + $body = @{ + since = $Since + per_page = $PerPage + } - $inputObject = @{ - Context = $Context - APIEndpoint = '/users' - Method = 'GET' - Body = $body - } + $inputObject = @{ + Method = 'GET' + APIEndpoint = '/users' + Body = $body + Context = $Context + } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } - } catch { - throw $_ + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } } diff --git a/src/functions/private/Users/Get-GitHubMyUser.ps1 b/src/functions/private/Users/Get-GitHubMyUser.ps1 index b58ad6ed7..fd8e2ef99 100644 --- a/src/functions/private/Users/Get-GitHubMyUser.ps1 +++ b/src/functions/private/Users/Get-GitHubMyUser.ps1 @@ -22,30 +22,25 @@ param( # 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. - [Parameter()] - [object] $Context = (Get-GitHubContext) + [Parameter(Mandatory)] + [object] $Context ) begin { $stackPath = Get-PSCallStackPath Write-Debug "[$stackPath] - Start" - $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT } process { - try { - $inputObject = @{ - Context = $Context - APIEndpoint = '/user' - Method = 'GET' - } - - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } - } catch { - throw $_ + $inputObject = @{ + Method = 'GET' + APIEndpoint = '/user' + Context = $Context + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } } diff --git a/src/functions/private/Users/Get-GitHubUserByName.ps1 b/src/functions/private/Users/Get-GitHubUserByName.ps1 index be4c82bd1..dec316116 100644 --- a/src/functions/private/Users/Get-GitHubUserByName.ps1 +++ b/src/functions/private/Users/Get-GitHubUserByName.ps1 @@ -40,30 +40,25 @@ # 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. - [Parameter()] - [object] $Context = (Get-GitHubContext) + [Parameter(Mandatory)] + [object] $Context ) begin { $stackPath = Get-PSCallStackPath Write-Debug "[$stackPath] - Start" - $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT } process { - try { - $inputObject = @{ - Context = $Context - APIEndpoint = "/users/$Username" - Method = 'GET' - } + $inputObject = @{ + Method = 'GET' + APIEndpoint = "/users/$Username" + Context = $Context + } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } - } catch { - throw $_ + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } } diff --git a/src/functions/private/Users/Get-GitHubUserCard.ps1 b/src/functions/private/Users/Get-GitHubUserCard.ps1 index f42114014..15c78b811 100644 --- a/src/functions/private/Users/Get-GitHubUserCard.ps1 +++ b/src/functions/private/Users/Get-GitHubUserCard.ps1 @@ -41,36 +41,31 @@ # 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. - [Parameter()] - [object] $Context = (Get-GitHubContext) + [Parameter(Mandatory)] + [object] $Context ) begin { $stackPath = Get-PSCallStackPath Write-Debug "[$stackPath] - Start" - $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT } process { - try { - $body = @{ - subject_type = $SubjectType - subject_id = $SubjectID - } + $body = @{ + subject_type = $SubjectType + subject_id = $SubjectID + } - $inputObject = @{ - Context = $Context - APIEndpoint = "/users/$Username/hovercard" - Method = 'GET' - Body = $body - } + $inputObject = @{ + Method = 'GET' + APIEndpoint = "/users/$Username/hovercard" + Body = $body + Context = $Context + } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } - } catch { - throw $_ + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } } diff --git a/src/functions/private/Users/Keys/Get-GitHubUserKeyForUser.ps1 b/src/functions/private/Users/Keys/Get-GitHubUserKeyForUser.ps1 index ce4ebdccb..bc374421c 100644 --- a/src/functions/private/Users/Keys/Get-GitHubUserKeyForUser.ps1 +++ b/src/functions/private/Users/Keys/Get-GitHubUserKeyForUser.ps1 @@ -23,6 +23,7 @@ Mandatory, ValueFromPipelineByPropertyName )] + [Alias('login')] [string] $Username, # The number of results per page (max 100). @@ -32,35 +33,30 @@ # 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. - [Parameter()] - [object] $Context = (Get-GitHubContext) + [Parameter(Mandatory)] + [object] $Context ) begin { $stackPath = Get-PSCallStackPath Write-Debug "[$stackPath] - Start" - $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT } process { - try { - $body = @{ - per_page = $PerPage - } + $body = @{ + per_page = $PerPage + } - $inputObject = @{ - Context = $Context - APIEndpoint = "/users/$Username/keys" - Method = 'GET' - Body = $body - } + $inputObject = @{ + Method = 'GET' + APIEndpoint = "/users/$Username/keys" + Body = $body + Context = $Context + } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } - } catch { - throw $_ + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } } diff --git a/src/functions/private/Users/Keys/Get-GitHubUserMyKey.ps1 b/src/functions/private/Users/Keys/Get-GitHubUserMyKey.ps1 index 2ebe8ac8a..caeed8684 100644 --- a/src/functions/private/Users/Keys/Get-GitHubUserMyKey.ps1 +++ b/src/functions/private/Users/Keys/Get-GitHubUserMyKey.ps1 @@ -27,35 +27,30 @@ # 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. - [Parameter()] - [object] $Context = (Get-GitHubContext) + [Parameter(Mandatory)] + [object] $Context ) begin { $stackPath = Get-PSCallStackPath Write-Debug "[$stackPath] - Start" - $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT } process { - try { - $body = @{ - per_page = $PerPage - } + $body = @{ + per_page = $PerPage + } - $inputObject = @{ - Context = $Context - APIEndpoint = '/user/keys' - Method = 'GET' - Body = $body - } + $inputObject = @{ + Method = 'GET' + APIEndpoint = '/user/keys' + Body = $body + Context = $Context + } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } - } catch { - throw $_ + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } } diff --git a/src/functions/private/Users/Keys/Get-GitHubUserMyKeyById.ps1 b/src/functions/private/Users/Keys/Get-GitHubUserMyKeyById.ps1 index 32642acc3..b46ce6ad7 100644 --- a/src/functions/private/Users/Keys/Get-GitHubUserMyKeyById.ps1 +++ b/src/functions/private/Users/Keys/Get-GitHubUserMyKeyById.ps1 @@ -29,30 +29,25 @@ # 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. - [Parameter()] - [object] $Context = (Get-GitHubContext) + [Parameter(Mandatory)] + [object] $Context ) begin { $stackPath = Get-PSCallStackPath Write-Debug "[$stackPath] - Start" - $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT } process { - try { - $inputObject = @{ - Context = $Context - APIEndpoint = "/user/keys/$ID" - Method = 'GET' - } - - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } - } catch { - throw $_ + $inputObject = @{ + Method = 'GET' + APIEndpoint = "/user/keys/$ID" + Context = $Context + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } } diff --git a/src/functions/private/Users/SSH-Signing-Keys/Get-GitHubUserMySigningKey.ps1 b/src/functions/private/Users/SSH-Signing-Keys/Get-GitHubUserMySigningKey.ps1 index 30706acda..26f028e2d 100644 --- a/src/functions/private/Users/SSH-Signing-Keys/Get-GitHubUserMySigningKey.ps1 +++ b/src/functions/private/Users/SSH-Signing-Keys/Get-GitHubUserMySigningKey.ps1 @@ -27,35 +27,30 @@ # 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. - [Parameter()] - [object] $Context = (Get-GitHubContext) + [Parameter(Mandatory)] + [object] $Context ) begin { $stackPath = Get-PSCallStackPath Write-Debug "[$stackPath] - Start" - $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT } process { - try { - $body = @{ - per_page = $PerPage - } + $body = @{ + per_page = $PerPage + } - $inputObject = @{ - Context = $Context - APIEndpoint = '/user/ssh_signing_keys' - Method = 'GET' - Body = $body - } + $inputObject = @{ + Method = 'GET' + APIEndpoint = '/user/ssh_signing_keys' + Body = $body + Context = $Context + } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } - } catch { - throw $_ + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } } diff --git a/src/functions/private/Users/SSH-Signing-Keys/Get-GitHubUserMySigningKeyById.ps1 b/src/functions/private/Users/SSH-Signing-Keys/Get-GitHubUserMySigningKeyById.ps1 index d4db058f9..34b13c546 100644 --- a/src/functions/private/Users/SSH-Signing-Keys/Get-GitHubUserMySigningKeyById.ps1 +++ b/src/functions/private/Users/SSH-Signing-Keys/Get-GitHubUserMySigningKeyById.ps1 @@ -30,30 +30,25 @@ # 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. - [Parameter()] - [object] $Context = (Get-GitHubContext) + [Parameter(Mandatory)] + [object] $Context ) begin { $stackPath = Get-PSCallStackPath Write-Debug "[$stackPath] - Start" - $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT } process { - try { - $inputObject = @{ - Context = $Context - APIEndpoint = "/user/ssh_signing_keys/$ID" - Method = 'GET' - } - - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } - } catch { - throw $_ + $inputObject = @{ + Method = 'GET' + APIEndpoint = "/user/ssh_signing_keys/$ID" + Context = $Context + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } } diff --git a/src/functions/private/Users/SSH-Signing-Keys/Get-GitHubUserSigningKeyForUser.ps1 b/src/functions/private/Users/SSH-Signing-Keys/Get-GitHubUserSigningKeyForUser.ps1 index fccf461e5..4be8b3a64 100644 --- a/src/functions/private/Users/SSH-Signing-Keys/Get-GitHubUserSigningKeyForUser.ps1 +++ b/src/functions/private/Users/SSH-Signing-Keys/Get-GitHubUserSigningKeyForUser.ps1 @@ -23,6 +23,7 @@ Mandatory, ValueFromPipelineByPropertyName )] + [Alias('login')] [string] $Username, # The number of results per page (max 100). @@ -32,35 +33,30 @@ # 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. - [Parameter()] - [object] $Context = (Get-GitHubContext) + [Parameter(Mandatory)] + [object] $Context ) begin { $stackPath = Get-PSCallStackPath Write-Debug "[$stackPath] - Start" - $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT } process { - try { - $body = @{ - per_page = $PerPage - } + $body = @{ + per_page = $PerPage + } - $inputObject = @{ - Context = $Context - APIEndpoint = "/users/$Username/ssh_signing_keys" - Method = 'GET' - Body = $body - } + $inputObject = @{ + Method = 'GET' + APIEndpoint = "/users/$Username/ssh_signing_keys" + Body = $body + Context = $Context + } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } - } catch { - throw $_ + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } } diff --git a/src/functions/private/Users/Social-Accounts/Get-GitHubMyUserSocials.ps1 b/src/functions/private/Users/Social-Accounts/Get-GitHubMyUserSocials.ps1 index f9ff21027..d3d3a745e 100644 --- a/src/functions/private/Users/Social-Accounts/Get-GitHubMyUserSocials.ps1 +++ b/src/functions/private/Users/Social-Accounts/Get-GitHubMyUserSocials.ps1 @@ -25,35 +25,30 @@ # 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. - [Parameter()] - [object] $Context = (Get-GitHubContext) + [Parameter(Mandatory)] + [object] $Context ) begin { $stackPath = Get-PSCallStackPath Write-Debug "[$stackPath] - Start" - $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT } process { - try { - $body = @{ - per_page = $PerPage - } - - $inputObject = @{ - Context = $Context - APIEndpoint = '/user/social_accounts' - Method = 'GET' - Body = $body - } - - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } - } catch { - throw $_ + $body = @{ + per_page = $PerPage + } + + $inputObject = @{ + Method = 'GET' + APIEndpoint = '/user/social_accounts' + Body = $body + Context = $Context + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } } diff --git a/src/functions/private/Users/Social-Accounts/Get-GitHubUserSocialsByName.ps1 b/src/functions/private/Users/Social-Accounts/Get-GitHubUserSocialsByName.ps1 index 4cff51bdf..876314349 100644 --- a/src/functions/private/Users/Social-Accounts/Get-GitHubUserSocialsByName.ps1 +++ b/src/functions/private/Users/Social-Accounts/Get-GitHubUserSocialsByName.ps1 @@ -28,30 +28,25 @@ # 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. - [Parameter()] - [object] $Context = (Get-GitHubContext) + [Parameter(Mandatory)] + [object] $Context ) begin { $stackPath = Get-PSCallStackPath Write-Debug "[$stackPath] - Start" - $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT } process { - try { - $inputObject = @{ - Context = $Context - APIEndpoint = "/users/$Username/social_accounts" - Method = 'GET' - } - - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } - } catch { - throw $_ + $inputObject = @{ + Method = 'GET' + APIEndpoint = "/users/$Username/social_accounts" + Context = $Context + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } } diff --git a/src/functions/private/Utilities/Hashtable/ConvertFrom-HashTable.ps1 b/src/functions/private/Utilities/Hashtable/ConvertFrom-HashTable.ps1 index 0827535cb..4a43511f8 100644 --- a/src/functions/private/Utilities/Hashtable/ConvertFrom-HashTable.ps1 +++ b/src/functions/private/Utilities/Hashtable/ConvertFrom-HashTable.ps1 @@ -48,11 +48,7 @@ } process { - try { - $InputObject | ConvertTo-Json -Depth 100 | ConvertFrom-Json - } catch { - throw $_ - } + $InputObject | ConvertTo-Json -Depth 100 | ConvertFrom-Json } end { diff --git a/src/functions/private/Utilities/Hashtable/ConvertTo-HashTable.ps1 b/src/functions/private/Utilities/Hashtable/ConvertTo-HashTable.ps1 index b4479001c..b759ac54b 100644 --- a/src/functions/private/Utilities/Hashtable/ConvertTo-HashTable.ps1 +++ b/src/functions/private/Utilities/Hashtable/ConvertTo-HashTable.ps1 @@ -67,15 +67,11 @@ filter ConvertTo-HashTable { } process { - try { - foreach ($item in $InputObject.PSObject.Properties) { - $name = if ($NameCasingStyle) { ($item.Name | ConvertTo-CasingStyle -To $NameCasingStyle) } else { $item.Name } - $hashtable[$name] = $item.Value - } - $hashtable - } catch { - throw $_ + foreach ($item in $InputObject.PSObject.Properties) { + $name = if ($NameCasingStyle) { ($item.Name | ConvertTo-CasingStyle -To $NameCasingStyle) } else { $item.Name } + $hashtable[$name] = $item.Value } + $hashtable } end { diff --git a/src/functions/private/Utilities/Hashtable/Join-Object.ps1 b/src/functions/private/Utilities/Hashtable/Join-Object.ps1 index 3e90ae272..9bd7335f3 100644 --- a/src/functions/private/Utilities/Hashtable/Join-Object.ps1 +++ b/src/functions/private/Utilities/Hashtable/Join-Object.ps1 @@ -52,7 +52,7 @@ [OutputType([pscustomobject])] [OutputType(ParameterSetName = 'AsHashTable', [hashtable])] [Alias('Merge-Object')] - [CmdletBinding(DefaultParameterSetName = '__DefaultSet')] + [CmdletBinding()] param( # The main object to merge into. This object will be cloned, so the original object will not be modified. [Parameter( @@ -66,10 +66,7 @@ [object[]] $Overrides, # Return the result as a hashtable instead of a pscustomobject - [Parameter( - Mandatory, - ParameterSetName = 'AsHashTable' - )] + [Parameter()] [switch] $AsHashtable ) @@ -79,31 +76,26 @@ } process { - try { - - if ($Main -isnot [hashtable]) { - $Main = $Main | ConvertTo-HashTable - } - $hashtable = $Main.clone() - - foreach ($Override in $Overrides) { - if ($Override -isnot [hashtable]) { - $Override = $Override | ConvertTo-HashTable - } + if ($Main -isnot [hashtable]) { + $Main = $Main | ConvertTo-Hashtable + } + $hashtable = $Main.clone() - $Override.Keys | ForEach-Object { - $hashtable[$_] = $Override[$_] - } + foreach ($Override in $Overrides) { + if ($Override -isnot [hashtable]) { + $Override = $Override | ConvertTo-Hashtable } - if ($AsHashtable) { - return $hashtable + $Override.Keys | ForEach-Object { + $hashtable[$_] = $Override[$_] } + } - $hashtable | ConvertFrom-HashTable - } catch { - throw $_ + if ($AsHashtable) { + return $hashtable } + + $hashtable | ConvertFrom-HashTable } end { diff --git a/src/functions/private/Utilities/Hashtable/Remove-HashtableEntry.ps1 b/src/functions/private/Utilities/Hashtable/Remove-HashtableEntry.ps1 index 9b8e1c6da..e2744f2a3 100644 --- a/src/functions/private/Utilities/Hashtable/Remove-HashtableEntry.ps1 +++ b/src/functions/private/Utilities/Hashtable/Remove-HashtableEntry.ps1 @@ -60,44 +60,40 @@ } process { - try { - if ($NullOrEmptyValues) { - Write-Debug 'Remove keys with null or empty values' + if ($NullOrEmptyValues) { + Write-Debug 'Remove keys with null or empty values' ($Hashtable.GetEnumerator() | Where-Object { [string]::IsNullOrEmpty($_.Value) }) | ForEach-Object { - Write-Debug " - [$($_.Name)] - Value: [$($_.Value)] - Remove" - $Hashtable.Remove($_.Name) - } + Write-Debug " - [$($_.Name)] - Value: [$($_.Value)] - Remove" + $Hashtable.Remove($_.Name) } - if ($RemoveTypes) { - Write-Debug "Remove keys of type: [$RemoveTypes]" + } + if ($RemoveTypes) { + Write-Debug "Remove keys of type: [$RemoveTypes]" ($Hashtable.GetEnumerator() | Where-Object { ($_.Value.GetType().Name -in $RemoveTypes) }) | ForEach-Object { - Write-Debug " - [$($_.Name)] - Type: [$($_.Value.GetType().Name)] - Remove" - $Hashtable.Remove($_.Name) - } + Write-Debug " - [$($_.Name)] - Type: [$($_.Value.GetType().Name)] - Remove" + $Hashtable.Remove($_.Name) } - if ($KeepTypes) { - Write-Debug "Remove keys NOT of type: [$KeepTypes]" + } + if ($KeepTypes) { + Write-Debug "Remove keys NOT of type: [$KeepTypes]" ($Hashtable.GetEnumerator() | Where-Object { ($_.Value.GetType().Name -notin $KeepTypes) }) | ForEach-Object { - Write-Debug " - [$($_.Name)] - Type: [$($_.Value.GetType().Name)] - Remove" - $Hashtable.Remove($_.Name) - } + Write-Debug " - [$($_.Name)] - Type: [$($_.Value.GetType().Name)] - Remove" + $Hashtable.Remove($_.Name) } - if ($RemoveNames) { - Write-Debug "Remove keys named: [$RemoveNames]" + } + if ($RemoveNames) { + Write-Debug "Remove keys named: [$RemoveNames]" ($Hashtable.GetEnumerator() | Where-Object { $_.Name -in $RemoveNames }) | ForEach-Object { - Write-Debug " - [$($_.Name)] - Remove" - $Hashtable.Remove($_.Name) - } + Write-Debug " - [$($_.Name)] - Remove" + $Hashtable.Remove($_.Name) } - if ($KeepNames) { - Write-Debug "Remove keys NOT named: [$KeepNames]" + } + if ($KeepNames) { + Write-Debug "Remove keys NOT named: [$KeepNames]" ($Hashtable.GetEnumerator() | Where-Object { $_.Name -notin $KeepNames }) | ForEach-Object { - Write-Debug " - [$($_.Name)] - Remove" - $Hashtable.Remove($_.Name) - } + Write-Debug " - [$($_.Name)] - Remove" + $Hashtable.Remove($_.Name) } - } catch { - throw $_ } } diff --git a/src/functions/public/API/Invoke-GitHubAPI.ps1 b/src/functions/public/API/Invoke-GitHubAPI.ps1 index 78a6d58fb..c06dfe242 100644 --- a/src/functions/public/API/Invoke-GitHubAPI.ps1 +++ b/src/functions/public/API/Invoke-GitHubAPI.ps1 @@ -28,7 +28,8 @@ filter Invoke-GitHubAPI { param( # The HTTP method to be used for the API request. It can be one of the following: GET, POST, PUT, DELETE, or PATCH. [Parameter()] - [Microsoft.PowerShell.Commands.WebRequestMethod] $Method = 'GET', + [ValidateSet('GET', 'POST', 'PUT', 'DELETE', 'PATCH')] + $Method = 'GET', # The base URI for the GitHub API. This is usually `https://api.github.com`, but can be adjusted if necessary. [Parameter( @@ -45,6 +46,7 @@ filter Invoke-GitHubAPI { # The body of the API request. This can be a hashtable or a string. If a hashtable is provided, it will be converted to JSON. [Parameter()] + [Alias('Query')] [Object] $Body, # The 'Accept' header for the API request. If not provided, the default will be used by GitHub's API. @@ -97,7 +99,7 @@ filter Invoke-GitHubAPI { process { $Token = $Context.Token - Write-Debug "Token : [$Token]" + Write-Debug "Token : [$Token]" if ([string]::IsNullOrEmpty($HttpVersion)) { $HttpVersion = $Context.HttpVersion @@ -107,17 +109,17 @@ filter Invoke-GitHubAPI { if ([string]::IsNullOrEmpty($ApiBaseUri)) { $ApiBaseUri = $Context.ApiBaseUri } - Write-Debug "ApiBaseUri: [$ApiBaseUri]" + Write-Debug "ApiBaseUri: [$ApiBaseUri]" if ([string]::IsNullOrEmpty($ApiVersion)) { $ApiVersion = $Context.ApiVersion } - Write-Debug "ApiVersion: [$ApiVersion]" + Write-Debug "ApiVersion: [$ApiVersion]" if ([string]::IsNullOrEmpty($TokenType)) { $TokenType = $Context.TokenType } - Write-Debug "TokenType : [$TokenType]" + Write-Debug "TokenType : [$TokenType]" switch ($TokenType) { 'ghu' { diff --git a/src/functions/public/Actions/Get-GitHubEventData.ps1 b/src/functions/public/Actions/Data/Get-GitHubEventData.ps1 similarity index 100% rename from src/functions/public/Actions/Get-GitHubEventData.ps1 rename to src/functions/public/Actions/Data/Get-GitHubEventData.ps1 diff --git a/src/functions/public/Actions/Get-GitHubRunnerData.ps1 b/src/functions/public/Actions/Data/Get-GitHubRunnerData.ps1 similarity index 100% rename from src/functions/public/Actions/Get-GitHubRunnerData.ps1 rename to src/functions/public/Actions/Data/Get-GitHubRunnerData.ps1 diff --git a/src/functions/public/Actions/Get-GitHubWorkflowRun.ps1 b/src/functions/public/Actions/Workflow Run/Get-GitHubWorkflowRun.ps1 similarity index 75% rename from src/functions/public/Actions/Get-GitHubWorkflowRun.ps1 rename to src/functions/public/Actions/Workflow Run/Get-GitHubWorkflowRun.ps1 index 9635676f7..53885a2c5 100644 --- a/src/functions/public/Actions/Get-GitHubWorkflowRun.ps1 +++ b/src/functions/public/Actions/Workflow Run/Get-GitHubWorkflowRun.ps1 @@ -12,22 +12,22 @@ `event`, `head_sha`, `status`. .EXAMPLE - Get-GitHubWorkflowRun -Owner 'owner' -Repo 'repo' + Get-GitHubWorkflowRun -Owner 'owner' -Repository 'repo' Lists all workflow runs for a repository. .EXAMPLE - Get-GitHubWorkflowRun -Owner 'owner' -Repo 'repo' -Actor 'octocat' -Branch 'main' -Event 'push' -Status 'success' + Get-GitHubWorkflowRun -Owner 'owner' -Repository 'repo' -Actor 'octocat' -Branch 'main' -Event 'push' -Status 'success' Lists all workflow runs for a repository with the specified actor, branch, event, and status. .EXAMPLE - Get-GitHubWorkflowRun -Owner 'octocat' -Repo 'Hello-World' -ID '42' + Get-GitHubWorkflowRun -Owner 'octocat' -Repository 'Hello-World' -ID '42' Gets all workflow runs for the workflow with the ID `42` in the repository `Hello-World` owned by `octocat`. .EXAMPLE - Get-GitHubWorkflowRun -Owner 'octocat' -Repo 'Hello-World' -Name 'nightly.yml' -Actor 'octocat' -Branch 'main' -Event 'push' -Status 'success' + Get-GitHubWorkflowRun -Owner 'octocat' -Repository 'Hello-World' -Name 'nightly.yml' -Actor 'octocat' -Branch 'main' -Event 'push' -Status 'success' Gets all workflow runs for the workflow with the name `nightly.yml` in the repository `Hello-World` owned by `octocat` that were triggered by the user `octocat` on the branch `main` and have the status `success`. @@ -42,12 +42,20 @@ Justification = 'A parameter that is used in the api call.')] param( # The account owner of the repository. The name is not case sensitive. - [Parameter(Mandatory)] + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName + )] + [Alias('Organization')] + [Alias('User')] [string] $Owner, # The name of the repository. The name is not case sensitive. - [Parameter(Mandatory)] - [string] $Repo, + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName + )] + [string] $Repository, # The ID of the workflow. You can also pass the workflow filename as a string. [Parameter( @@ -119,50 +127,37 @@ Write-Debug "[$stackPath] - Start" $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - if ([string]::IsNullOrEmpty($Owner)) { - $Owner = $Context.Owner - } - Write-Debug "Owner: [$Owner]" - - if ([string]::IsNullOrEmpty($Repo)) { - $Repo = $Context.Repo - } - Write-Debug "Repo: [$Repo]" } process { - try { - $params = @{ - Owner = $Owner - Repo = $Repo - Actor = $Actor - Branch = $Branch - Event = $Event - Status = $Status - Created = $Created - ExcludePullRequests = $ExcludePullRequests - CheckSuiteID = $CheckSuiteID - HeadSHA = $HeadSHA - PerPage = $PerPage - } + $params = @{ + Owner = $Owner + Repository = $Repository + Actor = $Actor + Branch = $Branch + Event = $Event + Status = $Status + Created = $Created + ExcludePullRequests = $ExcludePullRequests + CheckSuiteID = $CheckSuiteID + HeadSHA = $HeadSHA + PerPage = $PerPage + } - switch ($PSCmdlet.ParameterSetName) { - 'ByID' { - $params['ID'] = $ID - Get-GitHubWorkflowRunByWorkflow @params - } + switch ($PSCmdlet.ParameterSetName) { + 'ByID' { + $params['ID'] = $ID + Get-GitHubWorkflowRunByWorkflow @params + } - 'ByName' { - $params['ID'] = (Get-GitHubWorkflow -Owner $Owner -Repo $Repo -Name $Name).id - Get-GitHubWorkflowRunByWorkflow @params - } + 'ByName' { + $params['ID'] = (Get-GitHubWorkflow -Owner $Owner -Repository $Repository -Name $Name).id + Get-GitHubWorkflowRunByWorkflow @params + } - '__AllParameterSets' { - Get-GitHubWorkflowRunByRepo @params - } + default { + Get-GitHubWorkflowRunByRepo @params } - } catch { - throw $_ } } diff --git a/src/functions/public/Actions/Remove-GitHubWorkflowRun.ps1 b/src/functions/public/Actions/Workflow Run/Remove-GitHubWorkflowRun.ps1 similarity index 64% rename from src/functions/public/Actions/Remove-GitHubWorkflowRun.ps1 rename to src/functions/public/Actions/Workflow Run/Remove-GitHubWorkflowRun.ps1 index 6aaf7c2b4..10d3374fd 100644 --- a/src/functions/public/Actions/Remove-GitHubWorkflowRun.ps1 +++ b/src/functions/public/Actions/Workflow Run/Remove-GitHubWorkflowRun.ps1 @@ -9,7 +9,7 @@ this endpoint. .EXAMPLE - Remove-GitHubWorkflowRun -Owner 'octocat' -Repo 'Hello-World' -ID 123456789 + Remove-GitHubWorkflowRun -Owner 'octocat' -Repository 'Hello-World' -ID 123456789 Deletes the workflow run with the ID 123456789 from the 'Hello-World' repository owned by 'octocat' @@ -19,20 +19,28 @@ [CmdletBinding(SupportsShouldProcess)] param( # The account owner of the repository. The name is not case sensitive. - [Parameter()] + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName + )] + [Alias('Organization')] + [Alias('User')] [string] $Owner, # The name of the repository without the .git extension. The name is not case sensitive. - [Parameter()] - [string] $Repo, + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName + )] + [string] $Repository, # The unique identifier of the workflow run. [Parameter( Mandatory, ValueFromPipelineByPropertyName )] - [Alias('ID', 'run_id')] - [string] $RunID, + [Alias('run_id', 'RunID')] + [string] $ID, # 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. @@ -45,32 +53,19 @@ Write-Debug "[$stackPath] - Start" $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - if ([string]::IsNullOrEmpty($Owner)) { - $Owner = $Context.Owner - } - Write-Debug "Owner: [$Owner]" - - if ([string]::IsNullOrEmpty($Repo)) { - $Repo = $Context.Repo - } - Write-Debug "Repo: [$Repo]" } process { - try { - $inputObject = @{ - Context = $Context - APIEndpoint = "repos/$Owner/$Repo/actions/runs/$RunID" - Method = 'DELETE' - } + $inputObject = @{ + Method = 'DELETE' + APIEndpoint = "repos/$Owner/$Repository/actions/runs/$ID" + Context = $Context + } - if ($PSCmdlet.ShouldProcess("workflow run with ID [$RunID] in [$Owner/$Repo]", 'Delete')) { - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } + if ($PSCmdlet.ShouldProcess("$Owner/$Repository/$ID", 'Delete workflow run')) { + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } - } catch { - throw $_ } } diff --git a/src/functions/public/Actions/Start-GitHubWorkflowReRun.ps1 b/src/functions/public/Actions/Workflow Run/Restart-GitHubWorkflowRun.ps1 similarity index 61% rename from src/functions/public/Actions/Start-GitHubWorkflowReRun.ps1 rename to src/functions/public/Actions/Workflow Run/Restart-GitHubWorkflowRun.ps1 index da3647fdb..907ce26b8 100644 --- a/src/functions/public/Actions/Start-GitHubWorkflowReRun.ps1 +++ b/src/functions/public/Actions/Workflow Run/Restart-GitHubWorkflowRun.ps1 @@ -1,4 +1,4 @@ -filter Start-GitHubWorkflowReRun { +filter Restart-GitHubWorkflowRun { <# .SYNOPSIS Re-run a workflow @@ -7,7 +7,7 @@ Re-runs your workflow run using its `run_id`. You can also specify a branch or tag name to re-run a workflow run from a branch .EXAMPLE - Start-GitHubWorkflowReRun -Owner 'octocat' -Repo 'Hello-World' -ID 123456789 + Start-GitHubWorkflowReRun -Owner 'octocat' -Repository 'Hello-World' -ID 123456789 .NOTES [Re-run a workflow](https://docs.github.com/en/rest/actions/workflow-runs#re-run-a-workflow) @@ -15,12 +15,20 @@ [CmdletBinding(SupportsShouldProcess)] param( # The account owner of the repository. The name is not case sensitive. - [Parameter()] + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName + )] + [Alias('Organization')] + [Alias('User')] [string] $Owner, # The name of the repository without the .git extension. The name is not case sensitive. - [Parameter()] - [string] $Repo, + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName + )] + [string] $Repository, # The unique identifier of the workflow run. [Alias('workflow_id')] @@ -41,32 +49,19 @@ Write-Debug "[$stackPath] - Start" $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - if ([string]::IsNullOrEmpty($Owner)) { - $Owner = $Context.Owner - } - Write-Debug "Owner: [$Owner]" - - if ([string]::IsNullOrEmpty($Repo)) { - $Repo = $Context.Repo - } - Write-Debug "Repo: [$Repo]" } process { - try { - $inputObject = @{ - Context = $Context - Method = 'POST' - APIEndpoint = "/repos/$Owner/$Repo/actions/runs/$ID/rerun" - } + $inputObject = @{ + Method = 'POST' + APIEndpoint = "/repos/$Owner/$Repository/actions/runs/$ID/rerun" + Context = $Context + } - if ($PSCmdlet.ShouldProcess("workflow with ID [$ID] in [$Owner/$Repo]", 'Re-run')) { - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } + if ($PSCmdlet.ShouldProcess("workflow with ID [$ID] in [$Owner/$Repository]", 'Re-run')) { + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } - } catch { - throw $_ } } diff --git a/src/functions/public/Actions/Stop-GitHubWorkflowRun.ps1 b/src/functions/public/Actions/Workflow Run/Stop-GitHubWorkflowRun.ps1 similarity index 60% rename from src/functions/public/Actions/Stop-GitHubWorkflowRun.ps1 rename to src/functions/public/Actions/Workflow Run/Stop-GitHubWorkflowRun.ps1 index cb924bdb5..052b404d9 100644 --- a/src/functions/public/Actions/Stop-GitHubWorkflowRun.ps1 +++ b/src/functions/public/Actions/Workflow Run/Stop-GitHubWorkflowRun.ps1 @@ -7,7 +7,7 @@ Cancels a workflow run using its `run_id`. You can use this endpoint to cancel a workflow run that is in progress or waiting .EXAMPLE - Stop-GitHubWorkflowRun -Owner 'octocat' -Repo 'Hello-World' -ID 123456789 + Stop-GitHubWorkflowRun -Owner 'octocat' -Repository 'Hello-World' -ID 123456789 Cancels the workflow run with the ID 123456789 from the 'Hello-World' repository owned by 'octocat' @@ -17,17 +17,25 @@ [CmdletBinding(SupportsShouldProcess)] [alias('Cancel-GitHubWorkflowRun')] param( - [Parameter()] + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName + )] + [Alias('Organization')] + [Alias('User')] [string] $Owner, - [Parameter()] - [string] $Repo, + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName + )] + [string] $Repository, - [Alias('workflow_id')] [Parameter( Mandatory, ValueFromPipelineByPropertyName )] + [Alias('workflow_id', 'WorkflowID')] [string] $ID, # The context to run the command in. Used to get the details for the API call. @@ -41,32 +49,19 @@ Write-Debug "[$stackPath] - Start" $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - if ([string]::IsNullOrEmpty($Owner)) { - $Owner = $Context.Owner - } - Write-Debug "Owner: [$Owner]" - - if ([string]::IsNullOrEmpty($Repo)) { - $Repo = $Context.Repo - } - Write-Debug "Repo: [$Repo]" } process { - try { - $inputObject = @{ - Context = $Context - Method = 'POST' - APIEndpoint = "/repos/$Owner/$Repo/actions/runs/$ID/cancel" - } + $inputObject = @{ + Method = 'POST' + APIEndpoint = "/repos/$Owner/$Repository/actions/runs/$ID/cancel" + Context = $Context + } - if ($PSCmdlet.ShouldProcess("workflow run with ID [$ID] in [$Owner/$Repo]", 'Cancel/Stop')) { - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } + if ($PSCmdlet.ShouldProcess("$Owner/$Repository/$ID", 'Cancel/Stop workflow run')) { + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } - } catch { - throw $_ } } diff --git a/src/functions/public/Actions/Disable-GitHubWorkflow.ps1 b/src/functions/public/Actions/Workflow/Disable-GitHubWorkflow.ps1 similarity index 65% rename from src/functions/public/Actions/Disable-GitHubWorkflow.ps1 rename to src/functions/public/Actions/Workflow/Disable-GitHubWorkflow.ps1 index 45e40bf45..0b5070875 100644 --- a/src/functions/public/Actions/Disable-GitHubWorkflow.ps1 +++ b/src/functions/public/Actions/Workflow/Disable-GitHubWorkflow.ps1 @@ -3,15 +3,23 @@ .NOTES [Disable a workflow](https://docs.github.com/en/rest/actions/workflows#disable-a-workflow) #> - [CmdletBinding()] + [CmdletBinding(SupportsShouldProcess)] param( # The account owner of the repository. The name is not case sensitive. - [Parameter()] + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName + )] + [Alias('Organization')] + [Alias('User')] [string] $Owner, # The name of the repository without the .git extension. The name is not case sensitive. - [Parameter()] - [string] $Repo, + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName + )] + [string] $Repository, # The ID of the workflow. You can also pass the workflow filename as a string. [Parameter( @@ -31,28 +39,17 @@ Write-Debug "[$stackPath] - Start" $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - if ([string]::IsNullOrEmpty($Owner)) { - $Owner = $Context.Owner - } - Write-Debug "Owner: [$Owner]" - - if ([string]::IsNullOrEmpty($Repo)) { - $Repo = $Context.Repo - } - Write-Debug "Repo: [$Repo]" } process { - try { - $inputObject = @{ - Context = $Context - APIEndpoint = "/repos/$Owner/$Repo/actions/workflows/$ID/disable" - Method = 'PUT' - } + $inputObject = @{ + Method = 'PUT' + APIEndpoint = "/repos/$Owner/$Repository/actions/workflows/$ID/disable" + Context = $Context + } - $null = Invoke-GitHubAPI @inputObject - } catch { - throw $_ + if ($PSCmdlet.ShouldProcess("$Owner/$Repository/$ID", 'Disable workflow')) { + Invoke-GitHubAPI @inputObject } } diff --git a/src/functions/public/Actions/Enable-GitHubWorkflow.ps1 b/src/functions/public/Actions/Workflow/Enable-GitHubWorkflow.ps1 similarity index 59% rename from src/functions/public/Actions/Enable-GitHubWorkflow.ps1 rename to src/functions/public/Actions/Workflow/Enable-GitHubWorkflow.ps1 index 4170d0f2b..26fe8df5d 100644 --- a/src/functions/public/Actions/Enable-GitHubWorkflow.ps1 +++ b/src/functions/public/Actions/Workflow/Enable-GitHubWorkflow.ps1 @@ -3,13 +3,21 @@ .NOTES [Enable a workflow](https://docs.github.com/en/rest/actions/workflows#enable-a-workflow) #> - [CmdletBinding()] + [CmdletBinding(SupportsShouldProcess)] param( - [Parameter()] + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName + )] + [Alias('Organization')] + [Alias('User')] [string] $Owner, - [Parameter()] - [string] $Repo, + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName + )] + [string] $Repository, [Parameter( Mandatory, @@ -28,28 +36,17 @@ Write-Debug "[$stackPath] - Start" $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - if ([string]::IsNullOrEmpty($Owner)) { - $Owner = $Context.Owner - } - Write-Debug "Owner: [$Owner]" - - if ([string]::IsNullOrEmpty($Repo)) { - $Repo = $Context.Repo - } - Write-Debug "Repo: [$Repo]" } process { - try { - $inputObject = @{ - Context = $Context - APIEndpoint = "/repos/$Owner/$Repo/actions/workflows/$ID/enable" - Method = 'PUT' - } - - $null = Invoke-GitHubAPI @inputObject - } catch { - throw $_ + $inputObject = @{ + Method = 'PUT' + APIEndpoint = "/repos/$Owner/$Repository/actions/workflows/$ID/enable" + Context = $Context + } + + if ($PSCmdlet.ShouldProcess("$Owner/$Repository/$ID", 'Enable workflow')) { + Invoke-GitHubAPI @inputObject } } diff --git a/src/functions/public/Actions/Get-GitHubWorkflow.ps1 b/src/functions/public/Actions/Workflow/Get-GitHubWorkflow.ps1 similarity index 60% rename from src/functions/public/Actions/Get-GitHubWorkflow.ps1 rename to src/functions/public/Actions/Workflow/Get-GitHubWorkflow.ps1 index 49f98113a..ce06cd825 100644 --- a/src/functions/public/Actions/Get-GitHubWorkflow.ps1 +++ b/src/functions/public/Actions/Workflow/Get-GitHubWorkflow.ps1 @@ -9,25 +9,33 @@ GitHub Apps must have the actions:read permission to use this endpoint. .EXAMPLE - Get-GitHubWorkflow -Owner 'octocat' -Repo 'hello-world' + Get-GitHubWorkflow -Owner 'octocat' -Repository 'hello-world' Gets all workflows in the 'octocat/hello-world' repository. .EXAMPLE - Get-GitHubWorkflow -Owner 'octocat' -Repo 'hello-world' -Name 'hello-world.yml' + Get-GitHubWorkflow -Owner 'octocat' -Repository 'hello-world' -Name 'hello-world.yml' Gets the 'hello-world.yml' workflow in the 'octocat/hello-world' repository. .NOTES [List repository workflows](https://docs.github.com/rest/actions/workflows?apiVersion=2022-11-28#list-repository-workflows) #> - [CmdletBinding(DefaultParameterSetName = 'ByName')] + [CmdletBinding()] param( - [Parameter()] + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName + )] + [Alias('Organization')] + [Alias('User')] [string] $Owner, - [Parameter()] - [string] $Repo, + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName + )] + [string] $Repository, # The number of results per page (max 100). [Parameter()] @@ -45,35 +53,22 @@ Write-Debug "[$stackPath] - Start" $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - if ([string]::IsNullOrEmpty($Owner)) { - $Owner = $Context.Owner - } - Write-Debug "Owner: [$Owner]" - - if ([string]::IsNullOrEmpty($Repo)) { - $Repo = $Context.Repo - } - Write-Debug "Repo: [$Repo]" } process { - try { - $body = @{ - per_page = $PerPage - } + $body = @{ + per_page = $PerPage + } - $inputObject = @{ - Context = $Context - APIEndpoint = "/repos/$Owner/$Repo/actions/workflows" - Method = 'GET' - Body = $body - } + $inputObject = @{ + Method = 'GET' + APIEndpoint = "/repos/$Owner/$Repository/actions/workflows" + Body = $body + Context = $Context + } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response.workflows - } - } catch { - throw $_ + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } } diff --git a/src/functions/public/Actions/Get-GitHubWorkflowUsage.ps1 b/src/functions/public/Actions/Workflow/Get-GitHubWorkflowUsage.ps1 similarity index 58% rename from src/functions/public/Actions/Get-GitHubWorkflowUsage.ps1 rename to src/functions/public/Actions/Workflow/Get-GitHubWorkflowUsage.ps1 index 22179722e..9fdcf09aa 100644 --- a/src/functions/public/Actions/Get-GitHubWorkflowUsage.ps1 +++ b/src/functions/public/Actions/Workflow/Get-GitHubWorkflowUsage.ps1 @@ -12,15 +12,21 @@ .NOTES [Get workflow usage](https://docs.github.com/en/rest/actions/workflows#get-workflow-usage) #> - [CmdletBinding( - DefaultParameterSetName = 'ByName' - )] + [CmdletBinding()] param( - [Parameter()] + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName + )] + [Alias('Organization')] + [Alias('User')] [string] $Owner, - [Parameter()] - [string] $Repo, + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName + )] + [string] $Repository, [Parameter( Mandatory, @@ -39,31 +45,17 @@ Write-Debug "[$stackPath] - Start" $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - if ([string]::IsNullOrEmpty($Owner)) { - $Owner = $Context.Owner - } - Write-Debug "Owner: [$Owner]" - - if ([string]::IsNullOrEmpty($Repo)) { - $Repo = $Context.Repo - } - Write-Debug "Repo: [$Repo]" } process { - try { - - $inputObject = @{ - Context = $Context - Method = 'GET' - APIEndpoint = "/repos/$Owner/$Repo/actions/workflows/$ID/timing" - } + $inputObject = @{ + Method = 'GET' + APIEndpoint = "/repos/$Owner/$Repository/actions/workflows/$ID/timing" + Context = $Context + } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response.billable - } - } catch { - throw $_ + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } } diff --git a/src/functions/public/Actions/Start-GitHubWorkflow.ps1 b/src/functions/public/Actions/Workflow/Start-GitHubWorkflow.ps1 similarity index 68% rename from src/functions/public/Actions/Start-GitHubWorkflow.ps1 rename to src/functions/public/Actions/Workflow/Start-GitHubWorkflow.ps1 index 5d1bd4020..e4994bf9b 100644 --- a/src/functions/public/Actions/Start-GitHubWorkflow.ps1 +++ b/src/functions/public/Actions/Workflow/Start-GitHubWorkflow.ps1 @@ -20,15 +20,23 @@ [CmdletBinding(SupportsShouldProcess)] param( # The account owner of the repository. The name is not case sensitive. - [Parameter()] + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName + )] + [Alias('Organization')] + [Alias('User')] [string] $Owner, # The name of the repository without the .git extension. The name is not case sensitive. - [Parameter()] - [string] $Repo, + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName + )] + [string] $Repository, # The ID of the workflow. - [Alias('workflow_id')] + [Alias('workflow_id', 'WorkflowID')] [Parameter( Mandatory, ValueFromPipelineByPropertyName @@ -57,38 +65,25 @@ Write-Debug "[$stackPath] - Start" $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - if ([string]::IsNullOrEmpty($Owner)) { - $Owner = $Context.Owner - } - Write-Debug "Owner: [$Owner]" - - if ([string]::IsNullOrEmpty($Repo)) { - $Repo = $Context.Repo - } - Write-Debug "Repo: [$Repo]" } process { - try { - $body = @{ - ref = $Ref - inputs = $Inputs - } + $body = @{ + ref = $Ref + inputs = $Inputs + } - $inputObject = @{ - Context = $Context - APIEndpoint = "/repos/$Owner/$Repo/actions/workflows/$ID/dispatches" - Method = 'POST' - Body = $body - } + $inputObject = @{ + Method = 'POST' + APIEndpoint = "/repos/$Owner/$Repository/actions/workflows/$ID/dispatches" + Body = $body + Context = $Context + } - if ($PSCmdlet.ShouldProcess("workflow with ID [$ID] in [$Owner/$Repo]", 'Start')) { - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } + if ($PSCmdlet.ShouldProcess("$Owner/$Repository/$ID", 'Start workflow')) { + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } - } catch { - throw $_ } } diff --git a/src/functions/public/Apps/GitHub App Installations/Add-GitHubAppInstallationRepositoryAccess.ps1 b/src/functions/public/Apps/GitHub App Installations/Add-GitHubAppInstallationRepositoryAccess.ps1 new file mode 100644 index 000000000..c15db0c18 --- /dev/null +++ b/src/functions/public/Apps/GitHub App Installations/Add-GitHubAppInstallationRepositoryAccess.ps1 @@ -0,0 +1,89 @@ +function Add-GitHubAppInstallationRepositoryAccess { + <# + .SYNOPSIS + Grant repository access to an organization installation. + + .DESCRIPTION + Grant repository access to an organization installation. + + .EXAMPLE + $params = @{ + Enterprise = 'msx' + Organization = 'PSModule' + InstallationID = 12345678 + Repositories = 'repo1', 'repo2' + } + Add-GitHubAppInstallationRepositoryAccess @params + + Grant access to the repositories 'repo1' and 'repo2' for the installation + with the ID '12345678' on the organization 'PSModule' in the enterprise 'msx'. + #> + [CmdletBinding(SupportsShouldProcess)] + param( + # The enterprise slug or ID. + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName + )] + [string] $Enterprise, + + # The organization name. The name is not case sensitive. + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName + )] + [string] $Organization, + + # The unique identifier of the installation. + # Example: '12345678' + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName + )] + [Alias('installation_id', 'InstallationID')] + [int] $ID, + + # The names of the repositories to which the installation will be granted access. + [Parameter()] + [string[]] $Repositories = @(), + + # 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. + [Parameter()] + [object] $Context = (Get-GitHubContext) + ) + + begin { + $stackPath = Get-PSCallStackPath + Write-Debug "[$stackPath] - Start" + $Context = Resolve-GitHubContext -Context $Context + Assert-GitHubContext -Context $Context -AuthType IAT, UAT + #enterprise_organization_installation_repositories=write + #enterprise_organization_installations=write + } + + process { + $body = @{ + repositories = $Repositories + } + + $inputObject = @{ + Method = 'PATCH' + APIEndpoint = "/enterprises/$Enterprise/apps/organizations/$Organization/installations/$ID/repositories/add" + Body = $body + Context = $Context + } + + if ($PSCmdlet.ShouldProcess("$Enterprise/$Organization", 'Add repo access to installation')) { + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } + } + } + + end { + Write-Debug "[$stackPath] - End" + } +} + +#SkipTest:FunctionTest:Will add a test for this function in a future PR diff --git a/src/functions/public/Apps/GitHub App Installations/Get-GitHubAppAccessibleRepository.ps1 b/src/functions/public/Apps/GitHub App Installations/Get-GitHubAppAccessibleRepository.ps1 new file mode 100644 index 000000000..3f5d442ac --- /dev/null +++ b/src/functions/public/Apps/GitHub App Installations/Get-GitHubAppAccessibleRepository.ps1 @@ -0,0 +1,79 @@ +function Get-GitHubAppAccessibleRepository { + <# + .SYNOPSIS + Get repositories belonging to an enterprise owned organization that can be made accessible to a GitHub App + + .DESCRIPTION + List the repositories belonging to an enterprise owned organization that can be made accessible to a GitHub App installed on that + organization. + + The authenticated GitHub App must be installed on the enterprise and be granted the Enterprise/enterprise_organization_installations (read) + permission. + + .EXAMPLE + $params = @{ + Enterprise = 'msx' + Organization = 'PSModule' + } + Get-GitHubAppAccessibleRepository @params + + Get the repositories that can be made accessible to a GitHub App installed on the organization 'PSModule' in the enterprise 'msx'. + #> + [CmdletBinding(SupportsShouldProcess)] + param( + # The enterprise slug or ID. + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName + )] + [string] $Enterprise, + + # The organization name. The name is not case sensitive. + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName + )] + [string] $Organization, + + # The number of results per page (max 100). + [Parameter()] + [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. + [Parameter()] + [object] $Context = (Get-GitHubContext) + ) + + begin { + $stackPath = Get-PSCallStackPath + Write-Debug "[$stackPath] - Start" + $Context = Resolve-GitHubContext -Context $Context + Assert-GitHubContext -Context $Context -AuthType IAT, UAT + # Enterprise organization installations (read) + } + + process { + $body = @{ + per_page = $PerPage + } + + $inputObject = @{ + Method = 'GET' + APIEndpoint = "/enterprises/$Enterprise/apps/installable_organizations/$Organization/accessible_repositories" + Body = $body + Context = $Context + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } + } + + end { + Write-Debug "[$stackPath] - End" + } +} + +#SkipTest:FunctionTest:Will add a test for this function in a future PR diff --git a/src/functions/public/Apps/GitHub App Installations/Get-GitHubAppInstallation.ps1 b/src/functions/public/Apps/GitHub App Installations/Get-GitHubAppInstallation.ps1 new file mode 100644 index 000000000..645e4b3d0 --- /dev/null +++ b/src/functions/public/Apps/GitHub App Installations/Get-GitHubAppInstallation.ps1 @@ -0,0 +1,84 @@ +function Get-GitHubAppInstallation { + <# + .SYNOPSIS + List installations for the authenticated app, on organization or enterprise organization. + + .DESCRIPTION + Lists the installations for the authenticated app. + If the app is installed on an enterprise, the installations for the enterprise are returned. + If the app is installed on an organization, the installations for the organization are returned. + #> + [CmdletBinding(DefaultParameterSetName = '__AllParameterSets')] + param( + # The enterprise slug or ID. + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName, + ParameterSetName = 'Enterprise' + )] + [string] $Enterprise, + + # The organization name. The name is not case sensitive. + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName, + ParameterSetName = 'Enterprise' + )] + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName, + ParameterSetName = 'Organization' + )] + [string] $Organization, + + # The number of results per page (max 100). + [Parameter( + ParameterSetName = 'Enterprise' + )] + [Parameter( + ParameterSetName = 'Organization' + )] + [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. + [Parameter()] + [object] $Context = (Get-GitHubContext) + ) + + begin { + $stackPath = Get-PSCallStackPath + Write-Debug "[$stackPath] - Start" + $Context = Resolve-GitHubContext -Context $Context + } + + process { + switch ($PSCmdlet.ParameterSetName) { + 'Enterprise' { + $params = @{ + Enterprise = $Enterprise + Organization = $Organization + PerPage = $PerPage + Context = $Context + } + Get-GitHubEnterpriseOrganizationAppInstallation @params + } + 'Organization' { + $params = @{ + Organization = $Organization + PerPage = $PerPage + Context = $Context + } + Get-GitHubOrganizationAppInstallation @params + } + default { + Get-GitHubAppInstallationForAuthenticatedApp -Context $Context + } + } + } + + end { + Write-Debug "[$stackPath] - End" + } +} diff --git a/src/functions/public/Apps/GitHub App Installations/Get-GitHubAppInstallationRepositoryAccess.ps1 b/src/functions/public/Apps/GitHub App Installations/Get-GitHubAppInstallationRepositoryAccess.ps1 new file mode 100644 index 000000000..ffdb353de --- /dev/null +++ b/src/functions/public/Apps/GitHub App Installations/Get-GitHubAppInstallationRepositoryAccess.ps1 @@ -0,0 +1,89 @@ +function Get-GitHubAppInstallationRepositoryAccess { + <# + .SYNOPSIS + Get the repositories accessible to a given GitHub App installation. + + .DESCRIPTION + Lists the repositories accessible to a given GitHub App installation on an enterprise-owned organization. + + The authenticated GitHub App must be installed on the enterprise and be granted the Enterprise/organization_installations (read) permission. + + .EXAMPLE + $params = @{ + Enterprise = 'msx' + Organization = 'PSModule' + InstallationID = 12345678 + } + Get-GitHubAppInstallationRepositoryAccess @params + + Get the repositories accessible to the GitHub App installation + with the ID '12345678' on the organization 'PSModule' in the enterprise 'msx'. + #> + [CmdletBinding()] + param( + # The enterprise slug or ID. + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName + )] + [string] $Enterprise, + + # The organization name. The name is not case sensitive. + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName + )] + [string] $Organization, + + # The unique identifier of the installation. + # Example: '12345678' + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName + )] + [Alias('installation_id', 'InstallationID')] + [int] $ID, + + # The number of results per page (max 100). + [Parameter()] + [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. + [Parameter()] + [object] $Context = (Get-GitHubContext) + ) + + begin { + $stackPath = Get-PSCallStackPath + Write-Debug "[$stackPath] - Start" + $Context = Resolve-GitHubContext -Context $Context + Assert-GitHubContext -Context $Context -AuthType IAT, UAT + #enterprise_organization_installation_repositories=read + #enterprise_organization_installations=read + } + + process { + $body = @{ + per_page = $PerPage + } + + $inputObject = @{ + Method = 'GET' + APIEndpoint = "/enterprises/$Enterprise/apps/organizations/$Organization/installations/$ID/repositories" + Body = $body + Context = $Context + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } + } + + end { + Write-Debug "[$stackPath] - End" + } +} + +#SkipTest:FunctionTest:Will add a test for this function in a future PR diff --git a/src/functions/public/Apps/GitHub App Installations/Remove-GitHubAppInstallationRepositoryAccess.ps1 b/src/functions/public/Apps/GitHub App Installations/Remove-GitHubAppInstallationRepositoryAccess.ps1 new file mode 100644 index 000000000..e6934724c --- /dev/null +++ b/src/functions/public/Apps/GitHub App Installations/Remove-GitHubAppInstallationRepositoryAccess.ps1 @@ -0,0 +1,89 @@ +function Remove-GitHubAppInstallationRepositoryAccess { + <# + .SYNOPSIS + Remove repository access to an organization installation. + + .DESCRIPTION + Remove repository access to an organization installation. + + .EXAMPLE + $params = @{ + Enterprise = 'msx' + Organization = 'PSModule' + InstallationID = 12345678 + Repositories = 'repo1', 'repo2' + } + Remove-GitHubAppInstallationRepositoryAccess @params + + Remove access to the repositories 'repo1' and 'repo2' for the installation + with the ID '12345678' on the organization 'PSModule' in the enterprise 'msx'. + #> + [CmdletBinding(SupportsShouldProcess)] + param( + # The enterprise slug or ID. + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName + )] + [string] $Enterprise, + + # The organization name. The name is not case sensitive. + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName + )] + [string] $Organization, + + # The unique identifier of the installation. + # Example: '12345678' + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName + )] + [Alias('installation_id', 'InstallationID')] + [int] $ID, + + # The names of the repositories to which the installation will be granted access. + [Parameter()] + [string[]] $Repositories = @(), + + # 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. + [Parameter()] + [object] $Context = (Get-GitHubContext) + ) + + begin { + $stackPath = Get-PSCallStackPath + Write-Debug "[$stackPath] - Start" + $Context = Resolve-GitHubContext -Context $Context + Assert-GitHubContext -Context $Context -AuthType IAT, UAT + #enterprise_organization_installation_repositories=write + #enterprise_organization_installations=write + } + + process { + $body = @{ + repositories = $Repositories + } + + $inputObject = @{ + Method = 'PATCH' + APIEndpoint = "/enterprises/$Enterprise/apps/organizations/$Organization/installations/$ID/repositories/remove" + Body = $body + Context = $Context + } + + if ($PSCmdlet.ShouldProcess("$Enterprise/$Organization - $Repositories", 'Remove repository access')) { + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } + } + } + + end { + Write-Debug "[$stackPath] - End" + } +} + +#SkipTest:FunctionTest:Will add a test for this function in a future PR diff --git a/src/functions/public/Apps/GitHub App Installations/Update-GitHubAppInstallationRepositoryAccess.ps1 b/src/functions/public/Apps/GitHub App Installations/Update-GitHubAppInstallationRepositoryAccess.ps1 new file mode 100644 index 000000000..309a890b1 --- /dev/null +++ b/src/functions/public/Apps/GitHub App Installations/Update-GitHubAppInstallationRepositoryAccess.ps1 @@ -0,0 +1,104 @@ +function Update-GitHubAppInstallationRepositoryAccess { + <# + .SYNOPSIS + Update the installation repository access between all repositories and selected repositories. + + .DESCRIPTION + Update repository access for a GitHub App installation between all repositories and selected repositories. + + .EXAMPLE + Update-GitHubAppInstallationRepositoryAccess -Enterprise 'msx' -Organization 'PSModule' -InstallationID 12345678 -RepositorySelection 'all' + + Update the repository access for the GitHub App installation with the ID '12345678' + to all repositories on the organization 'PSModule' in the enterprise 'msx'. + + .EXAMPLE + $params = @{ + Enterprise = 'msx' + Organization = 'PSModule' + InstallationID = 12345678 + RepositorySelection = 'selected' + Repositories = 'repo1', 'repo2' + } + Update-GitHubAppInstallationRepositoryAccess @params + + Update the repository access for the GitHub App installation with the ID '12345678' + to the repositories 'repo1' and 'repo2' on the organization 'PSModule' in the enterprise 'msx'. + #> + [CmdletBinding(SupportsShouldProcess)] + param( + # The enterprise slug or ID. + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName + )] + [string] $Enterprise, + + # The organization name. The name is not case sensitive. + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName)] + [string] $Organization, + + # The unique identifier of the installation. + # Example: '12345678' + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName + )] + [Alias('installation_id', 'InstallationID')] + [int] $ID, + + # The repository selection for the GitHub App. Can be one of: + # - all - all repositories that the authenticated GitHub App installation can access. + # - selected - select specific repositories. + [Parameter(Mandatory)] + [ValidateSet('all', 'selected')] + [string] $RepositorySelection, + + # The names of the repositories to which the installation will be granted access. + [Parameter()] + [string[]] $Repositories = @(), + + # 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. + [Parameter()] + [object] $Context = (Get-GitHubContext) + ) + + begin { + $stackPath = Get-PSCallStackPath + Write-Debug "[$stackPath] - Start" + $Context = Resolve-GitHubContext -Context $Context + Assert-GitHubContext -Context $Context -AuthType IAT, UAT + #enterprise_organization_installation_repositories=write + #enterprise_organization_installations=write + } + + process { + $body = @{ + repository_selection = $RepositorySelection + repositories = $Repositories + } + $body | Remove-HashtableEntry -NullOrEmptyValues + + $inputObject = @{ + Method = 'PATCH' + APIEndpoint = "/enterprises/$Enterprise/apps/organizations/$Organization/installations/$ID/repositories" + Body = $body + Context = $Context + } + + if ($PSCmdlet.ShouldProcess("$Enterprise/$Organization", 'Update repository access')) { + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response + } + } + } + + end { + Write-Debug "[$stackPath] - End" + } +} + +#SkipTest:FunctionTest:Will add a test for this function in a future PR diff --git a/src/functions/public/Apps/GitHub Apps/Get-GitHubApp.ps1 b/src/functions/public/Apps/GitHub App/Get-GitHubApp.ps1 similarity index 69% rename from src/functions/public/Apps/GitHub Apps/Get-GitHubApp.ps1 rename to src/functions/public/Apps/GitHub App/Get-GitHubApp.ps1 index 0e91cdf47..14a42f150 100644 --- a/src/functions/public/Apps/GitHub Apps/Get-GitHubApp.ps1 +++ b/src/functions/public/Apps/GitHub App/Get-GitHubApp.ps1 @@ -12,7 +12,7 @@ Get the authenticated app. .EXAMPLE - Get-GitHubApp -AppSlug 'github-actions' + Get-GitHubApp -Name 'github-actions' Get the GitHub App with the slug 'github-actions'. @@ -30,8 +30,8 @@ Mandatory, ParameterSetName = 'BySlug' )] - [Alias('Name')] - [string] $AppSlug, + [Alias('AppSlug')] + [string] $Name, # 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. @@ -43,30 +43,16 @@ $stackPath = Get-PSCallStackPath Write-Debug "[$stackPath] - Start" $Context = Resolve-GitHubContext -Context $Context - - if ([string]::IsNullOrEmpty($Owner)) { - $Owner = $Context.Owner - } - Write-Debug "Owner: [$Owner]" - - if ([string]::IsNullOrEmpty($Repo)) { - $Repo = $Context.Repo - } - Write-Debug "Repo: [$Repo]" } process { - try { - switch ($PSCmdlet.ParameterSetName) { - 'BySlug' { - Get-GitHubAppByName -AppSlug $AppSlug -Context $Context - } - default { - Get-GitHubAuthenticatedApp -Context $Context - } + switch ($PSCmdlet.ParameterSetName) { + 'BySlug' { + Get-GitHubAppByName -AppSlug $Name -Context $Context + } + default { + Get-GitHubAuthenticatedApp -Context $Context } - } catch { - throw $_ } } diff --git a/src/functions/public/Enterprise/Get-GitHubEnterpriseInstallableOrganization.ps1 b/src/functions/public/Apps/GitHub App/Get-GitHubAppInstallableOrganization.ps1 similarity index 52% rename from src/functions/public/Enterprise/Get-GitHubEnterpriseInstallableOrganization.ps1 rename to src/functions/public/Apps/GitHub App/Get-GitHubAppInstallableOrganization.ps1 index 3ec304425..153d87077 100644 --- a/src/functions/public/Enterprise/Get-GitHubEnterpriseInstallableOrganization.ps1 +++ b/src/functions/public/Apps/GitHub App/Get-GitHubAppInstallableOrganization.ps1 @@ -1,4 +1,4 @@ -function Get-GitHubEnterpriseInstallableOrganization { +function Get-GitHubAppInstallableOrganization { <# .SYNOPSIS Get enterprise-owned organizations that can have GitHub Apps installed @@ -6,18 +6,24 @@ .DESCRIPTION List of organizations owned by the enterprise on which the authenticated GitHub App installation may install other GitHub Apps. - The authenticated GitHub App must be installed on the enterprise and be granted the Enterprise/enterprise_organization_installations - (read) permission. + .NOTES + Permissions required: + - enterprise_organization_installations: read .EXAMPLE - Get-GitHubEnterpriseInstallableOrganization -Enterprise 'msx' + Get-GitHubAppInstallableOrganization -Enterprise 'msx' #> [CmdletBinding()] param( # The enterprise slug or ID. - [Parameter()] + [Parameter(Mandatory)] [string] $Enterprise, + # The number of results per page (max 100). + [Parameter()] + [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. [Parameter()] @@ -28,26 +34,24 @@ $stackPath = Get-PSCallStackPath Write-Debug "[$stackPath] - Start" $Context = Resolve-GitHubContext -Context $Context - Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - if ([string]::IsNullOrEmpty($Enterprise)) { - $Enterprise = $Context.Enterprise - } - Write-Debug "Enterprise: [$Enterprise]" + Assert-GitHubContext -Context $Context -AuthType IAT, UAT + # enterprise_organization_installations=read } process { - try { - $inputObject = @{ - Context = $Context - APIEndpoint = "/enterprises/$Enterprise/apps/installable_organizations" - Method = 'GET' - } - - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } - } catch { - throw $_ + $body = @{ + per_page = $PerPage + } + + $inputObject = @{ + Method = 'GET' + APIEndpoint = "/enterprises/$Enterprise/apps/installable_organizations" + Body = $body + Context = $Context + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } } diff --git a/src/functions/public/Apps/Get-GitHubAppJSONWebToken.ps1 b/src/functions/public/Apps/GitHub App/Get-GitHubAppJSONWebToken.ps1 similarity index 100% rename from src/functions/public/Apps/Get-GitHubAppJSONWebToken.ps1 rename to src/functions/public/Apps/GitHub App/Get-GitHubAppJSONWebToken.ps1 diff --git a/src/functions/public/Apps/GitHub App/Install-GitHubApp.ps1 b/src/functions/public/Apps/GitHub App/Install-GitHubApp.ps1 new file mode 100644 index 000000000..5eae6b157 --- /dev/null +++ b/src/functions/public/Apps/GitHub App/Install-GitHubApp.ps1 @@ -0,0 +1,94 @@ +function Install-GitHubApp { + <# + .SYNOPSIS + Install an app + + .DESCRIPTION + Installs the provided GitHub App on the specified target. + + .EXAMPLE + Install-GitHubApp -Enterprise 'msx' -Organization 'org' -ClientID '123456' -RepositorySelection 'selected' -Repositories 'repo1', 'repo2' + + Install the GitHub App with + - the client ID '123456' + - the repository selection 'selected' + - the repositories 'repo1' and 'repo2' + on the organization 'org' in the enterprise 'msx'. + + .EXAMPLE + Install-GitHubApp -Enterprise 'msx' -Organization 'org' -ClientID '123456' -RepositorySelection 'all' + + Install the GitHub App with + - the client ID '123456' + - the repository selection 'all' + on the organization 'org' in the enterprise 'msx'. + #> + [CmdletBinding(DefaultParameterSetName = '__AllParameterSets')] + param( + # The enterprise slug or ID. + [Parameter( + Mandatory, + ParameterSetName = 'EnterpriseOrganization', + ValueFromPipelineByPropertyName + )] + [string] $Enterprise, + + # The organization name. The name is not case sensitive. + [Parameter( + Mandatory, + ParameterSetName = 'EnterpriseOrganization', + ValueFromPipelineByPropertyName + )] + [string] $Organization, + + # The client ID of the GitHub App to install. + [Parameter(Mandatory)] + [string] $ClientID, + + # The repository selection for the GitHub App. Can be one of: + # - all - all repositories that the authenticated GitHub App installation can access. + # - selected - select specific repositories. + [Parameter()] + [ValidateSet('all', 'selected')] + [string] $RepositorySelection = 'selected', + + # The names of the repositories to which the installation will be granted access. + [Parameter()] + [string[]] $Repositories = @(), + + # 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. + [Parameter()] + [object] $Context = (Get-GitHubContext) + ) + + begin { + $stackPath = Get-PSCallStackPath + Write-Debug "[$stackPath] - Start" + $Context = Resolve-GitHubContext -Context $Context + Assert-GitHubContext -Context $Context -AuthType IAT, UAT + #enterprise_organization_installations=write + } + + process { + switch ($PSCmdlet.ParameterSetName) { + 'EnterpriseOrganization' { + $params = @{ + Enterprise = $Enterprise + Organization = $Organization + ClientID = $ClientID + RepositorySelection = $RepositorySelection + Repositories = $Repositories + Context = $Context + } + Install-GitHubAppOnEnterpriseOrganization @params + } + } + } + + end { + Write-Debug "[$stackPath] - End" + } +} + +#SkipTest:FunctionTest:Will add a test for this function in a future PR diff --git a/src/functions/public/Apps/GitHub Apps/New-GitHubAppInstallationAccessToken.ps1 b/src/functions/public/Apps/GitHub App/New-GitHubAppInstallationAccessToken.ps1 similarity index 84% rename from src/functions/public/Apps/GitHub Apps/New-GitHubAppInstallationAccessToken.ps1 rename to src/functions/public/Apps/GitHub App/New-GitHubAppInstallationAccessToken.ps1 index 2b9cf17c6..ab45043b2 100644 --- a/src/functions/public/Apps/GitHub Apps/New-GitHubAppInstallationAccessToken.ps1 +++ b/src/functions/public/Apps/GitHub App/New-GitHubAppInstallationAccessToken.ps1 @@ -56,8 +56,8 @@ ValueFromPipeline, ValueFromPipelineByPropertyName )] - [Alias('ID')] - [int] $InstallationID, + [Alias('installation_id', 'InstallationID')] + [int] $ID, # 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. @@ -73,31 +73,23 @@ } process { - try { - $inputObject = @{ - Context = $Context - APIEndpoint = "/app/installations/$InstallationID/access_tokens" - Method = 'Post' - } + $inputObject = @{ + Method = 'POST' + APIEndpoint = "/app/installations/$ID/access_tokens" + Context = $Context + } - Invoke-GitHubAPI @inputObject | ForEach-Object { - [pscustomobject]@{ - Token = $_.Response.token | ConvertTo-SecureString -AsPlainText -Force - ExpiresAt = $_.Response.expires_at.ToLocalTime() - Permissions = $_.Response.permissions - RepositorySelection = $_.Response.repository_selection - } + Invoke-GitHubAPI @inputObject | ForEach-Object { + [pscustomobject]@{ + Token = $_.Response.token | ConvertTo-SecureString -AsPlainText -Force + ExpiresAt = $_.Response.expires_at.ToLocalTime() + Permissions = $_.Response.permissions + RepositorySelection = $_.Response.repository_selection } - } catch { - throw $_ } } end { Write-Debug "[$stackPath] - End" } - - clean { - [System.GC]::Collect() - } } diff --git a/src/functions/public/Apps/GitHub App/Uninstall-GitHubApp.ps1 b/src/functions/public/Apps/GitHub App/Uninstall-GitHubApp.ps1 new file mode 100644 index 000000000..7d2124e74 --- /dev/null +++ b/src/functions/public/Apps/GitHub App/Uninstall-GitHubApp.ps1 @@ -0,0 +1,71 @@ +function Uninstall-GitHubApp { + <# + .SYNOPSIS + Uninstall a GitHub App. + + .DESCRIPTION + Uninstalls the provided GitHub App on the specified target. + + .EXAMPLE + Uninstall-GitHubApp -Enterprise 'msx' -Organization 'org' -InstallationID '123456' + + Uninstall the GitHub App with the installation ID '123456' from the organization 'org' in the enterprise 'msx'. + #> + [CmdletBinding(DefaultParameterSetName = '__AllParameterSets')] + param( + # The enterprise slug or ID. + [Parameter( + Mandatory, + ParameterSetName = 'EnterpriseOrganization', + ValueFromPipelineByPropertyName + )] + [string] $Enterprise, + + # The organization name. The name is not case sensitive. + [Parameter( + Mandatory, + ParameterSetName = 'EnterpriseOrganization', + ValueFromPipelineByPropertyName + )] + [string] $Organization, + + # The client ID of the GitHub App to install. + [Parameter( + Mandatory, + ValueFromPipelineByPropertyName + )] + [Alias('installation_id', 'InstallationID')] + [string] $ID, + + # 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. + [Parameter()] + [object] $Context = (Get-GitHubContext) + ) + + begin { + $stackPath = Get-PSCallStackPath + Write-Debug "[$stackPath] - Start" + $Context = Resolve-GitHubContext -Context $Context + } + + process { + switch ($PSCmdlet.ParameterSetName) { + 'EnterpriseOrganization' { + $params = @{ + Enterprise = $Enterprise + Organization = $Organization + ID = $ID + Context = $Context + } + Uninstall-GitHubAppOnEnterpriseOrganization @params + } + } + } + + end { + Write-Debug "[$stackPath] - End" + } +} + +#SkipTest:FunctionTest:Will add a test for this function in a future PR diff --git a/src/functions/public/Apps/Webhooks/Get-GitHubAppWebhookConfiguration.ps1 b/src/functions/public/Apps/Webhooks/Get-GitHubAppWebhookConfiguration.ps1 index 36a02d756..9b4441214 100644 --- a/src/functions/public/Apps/Webhooks/Get-GitHubAppWebhookConfiguration.ps1 +++ b/src/functions/public/Apps/Webhooks/Get-GitHubAppWebhookConfiguration.ps1 @@ -34,18 +34,14 @@ } process { - try { - $inputObject = @{ - Context = $Context - APIEndpoint = '/app/hook/config' - Method = 'GET' - } - - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } - } catch { - throw $_ + $inputObject = @{ + Method = 'GET' + APIEndpoint = '/app/hook/config' + Context = $Context + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } } diff --git a/src/functions/public/Apps/Webhooks/Get-GitHubAppWebhookDelivery.ps1 b/src/functions/public/Apps/Webhooks/Get-GitHubAppWebhookDelivery.ps1 index 0208f92c3..01c078b6d 100644 --- a/src/functions/public/Apps/Webhooks/Get-GitHubAppWebhookDelivery.ps1 +++ b/src/functions/public/Apps/Webhooks/Get-GitHubAppWebhookDelivery.ps1 @@ -31,7 +31,7 @@ Mandatory, ParameterSetName = 'ByID' )] - [Alias('DeliveryID', 'delivery_id')] + [Alias('delivery_id', 'DeliveryID')] [string] $ID, # Only the ones to redeliver. @@ -64,23 +64,19 @@ } process { - try { - switch ($PSCmdlet.ParameterSetName) { - 'ByID' { - Write-Debug "ByID: [$ID]" - Get-GitHubAppWebhookDeliveryByID -ID $ID -Context $Context - } - 'Redelivery' { - Write-Debug "Redelivery: [$NeedingRedelivery]" - Get-GitHubAppWebhookDeliveryToRedeliver -Context $Context -PerPage $PerPage -TimeSpan $TimeSpan - } - 'ByList' { - Write-Debug 'ByList' - Get-GitHubAppWebhookDeliveryByList -Context $Context -PerPage $PerPage - } + switch ($PSCmdlet.ParameterSetName) { + 'ByID' { + Write-Debug "ByID: [$ID]" + Get-GitHubAppWebhookDeliveryByID -ID $ID -Context $Context + } + 'Redelivery' { + Write-Debug "Redelivery: [$NeedingRedelivery]" + Get-GitHubAppWebhookDeliveryToRedeliver -Context $Context -PerPage $PerPage -TimeSpan $TimeSpan + } + default { + Write-Debug 'ByList' + Get-GitHubAppWebhookDeliveryByList -Context $Context -PerPage $PerPage } - } catch { - throw $_ } } diff --git a/src/functions/public/Apps/Webhooks/Invoke-GitHubAppWebhookReDelivery.ps1 b/src/functions/public/Apps/Webhooks/Invoke-GitHubAppWebhookReDelivery.ps1 index 7808e2af3..89a8ebecf 100644 --- a/src/functions/public/Apps/Webhooks/Invoke-GitHubAppWebhookReDelivery.ps1 +++ b/src/functions/public/Apps/Webhooks/Invoke-GitHubAppWebhookReDelivery.ps1 @@ -26,8 +26,12 @@ )] param( # The ID of the delivery. - [Parameter(Mandatory)] - [Alias('DeliveryID', 'delivery_id')] + [Parameter( + Mandatory, + ValueFromPipeline, + ValueFromPipelineByPropertyName + )] + [Alias('delivery_id', 'DeliveryID')] [string] $ID, # The context to run the command in. Used to get the details for the API call. @@ -44,20 +48,16 @@ } process { - try { - $inputObject = @{ - Context = $Context - APIEndpoint = "/app/hook/deliveries/$ID/attempts" - Method = 'post' - } + $inputObject = @{ + Method = 'POST' + APIEndpoint = "/app/hook/deliveries/$ID/attempts" + Context = $Context + } - if ($PSCmdlet.ShouldProcess('webhook delivery', 'Redeliver')) { - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } + if ($PSCmdlet.ShouldProcess("[$ID]", 'Redeliver event')) { + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } - } catch { - throw $_ } } diff --git a/src/functions/public/Apps/Webhooks/Update-GitHubAppWebhookConfiguration.ps1 b/src/functions/public/Apps/Webhooks/Update-GitHubAppWebhookConfiguration.ps1 index 734027fd6..931bc777f 100644 --- a/src/functions/public/Apps/Webhooks/Update-GitHubAppWebhookConfiguration.ps1 +++ b/src/functions/public/Apps/Webhooks/Update-GitHubAppWebhookConfiguration.ps1 @@ -37,6 +37,7 @@ # Determines whether the SSL certificate of the host for URL will be verified when delivering payloads. # We strongly recommend not setting this as you are subject to man-in-the-middle and other attacks. + [Parameter()] [switch] $InsecureSSL, # The context to run the command in. Used to get the details for the API call. @@ -53,29 +54,25 @@ } process { - try { - $body = @{ - url = $URL - content_type = $ContentType - secret = $Secret - insecure_ssl = $PSBoundParameters.ContainsKey($InsecureSSL) ? ($InsecureSSL ? 1 : 0) : $null - } - $body | Remove-HashtableEntry -NullOrEmptyValues + $body = @{ + url = $URL + content_type = $ContentType + secret = $Secret + insecure_ssl = $PSBoundParameters.ContainsKey($InsecureSSL) ? ($InsecureSSL ? 1 : 0) : $null + } + $body | Remove-HashtableEntry -NullOrEmptyValues - $inputObject = @{ - Context = $Context - APIEndpoint = '/app/hook/config' - Method = 'PATCH' - Body = $body - } + $inputObject = @{ + Method = 'PATCH' + APIEndpoint = '/app/hook/config' + Body = $body + Context = $Context + } - if ($PSCmdlet.ShouldProcess('webhook configuration', 'Update')) { - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } + if ($PSCmdlet.ShouldProcess('webhook configuration', 'Update')) { + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } - } catch { - throw $_ } } diff --git a/src/functions/public/Auth/Connect-GitHubAccount.ps1 b/src/functions/public/Auth/Connect-GitHubAccount.ps1 index 92ca09f6f..99ce6bd02 100644 --- a/src/functions/public/Auth/Connect-GitHubAccount.ps1 +++ b/src/functions/public/Auth/Connect-GitHubAccount.ps1 @@ -43,13 +43,7 @@ .NOTES [Authenticating to the REST API](https://docs.github.com/rest/overview/other-authentication-methods#authenticating-for-saml-sso) #> - [Alias('Connect-GHAccount')] [Alias('Connect-GitHub')] - [Alias('Connect-GH')] - [Alias('Login-GitHubAccount')] - [Alias('Login-GHAccount')] - [Alias('Login-GitHub')] - [Alias('Login-GH')] [OutputType([void])] [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidLongLines', '', Justification = 'Long links for documentation.')] [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingWriteHost', '', Justification = 'Is the CLI part of the module.')] @@ -116,13 +110,11 @@ # Set the default owner to use in commands. [Parameter()] [Alias('Organization')] - [Alias('Org')] [string] $Owner, # Set the default repository to use in commands. [Parameter()] - [Alias('Repository')] - [string] $Repo, + [string] $Repository, # The host to connect to. Can use $env:GITHUB_SERVER_URL to set the host, as the protocol is removed automatically. # Example: github.com, github.enterprise.com, msx.ghe.com @@ -134,8 +126,6 @@ # Suppresses the output of the function. [Parameter()] [Alias('Quiet')] - [Alias('q')] - [Alias('s')] [switch] $Silent, # Make the connected context NOT the default context. @@ -191,7 +181,7 @@ AuthType = [string]$authType Enterprise = [string]$Enterprise Owner = [string]$Owner - Repo = [string]$Repo + Repository = [string]$Repository } Write-Verbose ($context | Format-Table | Out-String) diff --git a/src/functions/public/Auth/Connect-GitHubApp.ps1 b/src/functions/public/Auth/Connect-GitHubApp.ps1 index 2b15b2dab..5c0a4abfe 100644 --- a/src/functions/public/Auth/Connect-GitHubApp.ps1 +++ b/src/functions/public/Auth/Connect-GitHubApp.ps1 @@ -41,30 +41,29 @@ [CmdletBinding(DefaultParameterSetName = '__AllParameterSets')] param( # The user account to connect to. - [Parameter( - Mandatory, - ParameterSetName = 'User' - )] - [string] $User, + [Parameter(ParameterSetName = 'Filtered')] + [SupportsWildcards()] + [string[]] $User, # The organization to connect to. - [Parameter( - Mandatory, - ParameterSetName = 'Organization' - )] - [string] $Organization, + [Parameter(ParameterSetName = 'Filtered')] + [SupportsWildcards()] + [string[]] $Organization, # The enterprise to connect to. - [Parameter( - Mandatory, - ParameterSetName = 'Enterprise' - )] - [string] $Enterprise, + [Parameter(ParameterSetName = 'Filtered')] + [SupportsWildcards()] + [string[]] $Enterprise, # Passes the context object to the pipeline. [Parameter()] [switch] $PassThru, + # Suppresses the output of the function. + [Parameter()] + [Alias('Quiet')] + [switch] $Silent, + # Set as the default context. [Parameter()] [switch] $Default, @@ -81,81 +80,96 @@ } process { - try { - $Context = $Context | Resolve-GitHubContext - $Context | Assert-GitHubContext -AuthType 'App' - - $installations = Get-GitHubAppInstallation -Context $Context - Write-Verbose "Found [$($installations.Count)] installations." - switch ($PSCmdlet.ParameterSetName) { - 'User' { - Write-Verbose "Filtering installations for user [$User]." - $installations = $installations | Where-Object { $_.target_type -eq 'User' -and $_.account.login -in $User } + $Context = $Context | Resolve-GitHubContext + $Context | Assert-GitHubContext -AuthType 'App' + + $installations = Get-GitHubAppInstallation -Context $Context + $selectedInstallations = @() + Write-Verbose "Found [$($installations.Count)] installations." + switch ($PSCmdlet.ParameterSetName) { + 'Filtered' { + $User | ForEach-Object { + $userItem = $_ + Write-Verbose "User filter: [$userItem]." + $selectedInstallations += $installations | Where-Object { + $_.target_type -eq 'User' -and $_.account.login -like $userItem + } } - 'Organization' { - Write-Verbose "Filtering installations for organization [$Organization]." - $installations = $installations | Where-Object { $_.target_type -eq 'Organization' -and $_.account.login -in $Organization } + $Organization | ForEach-Object { + $organizationItem = $_ + Write-Verbose "Organization filter: [$organizationItem]." + $selectedInstallations += $installations | Where-Object { + $_.target_type -eq 'Organization' -and $_.account.login -like $organizationItem + } } - 'Enterprise' { - Write-Verbose "Filtering installations for enterprise [$Enterprise]." - $installations = $installations | Where-Object { $_.target_type -eq 'Enterprise' -and $_.account.slug -in $Enterprise } + $Enterprise | ForEach-Object { + $enterpriseItem = $_ + Write-Verbose "Enterprise filter: [$enterpriseItem]." + $selectedInstallations += $installations | Where-Object { + $_.target_type -eq 'Enterprise' -and $_.account.slug -like $enterpriseItem + } } } + default { + Write-Verbose 'No target specified. Connecting to all installations.' + $selectedInstallations = $installations + } + } - Write-Verbose "Found [$($installations.Count)] installations for the target." - $installations | ForEach-Object { - $installation = $_ - Write-Verbose "Processing installation [$($installation.account.login)] [$($installation.id)]" - $token = New-GitHubAppInstallationAccessToken -Context $Context -InstallationID $installation.id - - $contextParams = @{ - AuthType = [string]'IAT' - TokenType = [string]'ghs' - DisplayName = [string]$Context.DisplayName - ApiBaseUri = [string]$Context.ApiBaseUri - ApiVersion = [string]$Context.ApiVersion - HostName = [string]$Context.HostName - HttpVersion = [string]$Context.HttpVersion - PerPage = [int]$Context.PerPage - ClientID = [string]$Context.ClientID - InstallationID = [string]$installation.id - Permissions = [pscustomobject]$installation.permissions - Events = [string[]]$installation.events - InstallationType = [string]$installation.target_type - Token = [securestring]$token.Token - TokenExpirationDate = [datetime]$token.ExpiresAt - } + Write-Verbose "Found [$($selectedInstallations.Count)] installations for the target." + $selectedInstallations | ForEach-Object { + $installation = $_ + Write-Verbose "Processing installation [$($installation.account.login)] [$($installation.id)]" + $token = New-GitHubAppInstallationAccessToken -Context $Context -InstallationID $installation.id + + $contextParams = @{ + AuthType = [string]'IAT' + TokenType = [string]'ghs' + DisplayName = [string]$Context.DisplayName + ApiBaseUri = [string]$Context.ApiBaseUri + ApiVersion = [string]$Context.ApiVersion + HostName = [string]$Context.HostName + HttpVersion = [string]$Context.HttpVersion + PerPage = [int]$Context.PerPage + ClientID = [string]$Context.ClientID + InstallationID = [string]$installation.id + Permissions = [pscustomobject]$installation.permissions + Events = [string[]]$installation.events + InstallationType = [string]$installation.target_type + Token = [securestring]$token.Token + TokenExpirationDate = [datetime]$token.ExpiresAt + } - $contextParams['InstallationName'] = switch ($installation.target_type) { - 'User' { - [string]$installation.account.login - } - 'Organization' { - [string]$installation.account.login - } - 'Enterprise' { - [string]$installation.account.slug - } + switch ($installation.target_type) { + 'User' { + $contextParams['InstallationName'] = [string]$installation.account.login + $contextParams['Owner'] = [string]$installation.account.login } - Write-Verbose 'Logging in using a managed installation access token...' - Write-Verbose ($contextParams | Format-Table | Out-String) - $contextObj = [InstallationGitHubContext]::new((Set-GitHubContext -Context $contextParams.Clone() -PassThru -Default:$Default)) - Write-Verbose ($contextObj | Format-List | Out-String) - if (-not $Silent) { - $name = $contextObj.name - Write-Host '✓ ' -ForegroundColor Green -NoNewline - Write-Host "Connected $name!" + 'Organization' { + $contextParams['InstallationName'] = [string]$installation.account.login + $contextParams['Owner'] = [string]$installation.account.login } - if ($PassThru) { - Write-Debug "Passing context [$contextObj] to the pipeline." - Write-Output $contextObj + 'Enterprise' { + $contextParams['InstallationName'] = [string]$installation.account.slug + $contextParams['Enterprise'] = [string]$installation.account.slug } - $contextParams.Clear() } - } catch { - Write-Error $_ - throw 'Failed to connect to GitHub using a GitHub App.' + Write-Verbose 'Logging in using a managed installation access token...' + Write-Verbose ($contextParams | Format-Table | Out-String) + $contextObj = [InstallationGitHubContext]::new((Set-GitHubContext -Context $contextParams.Clone() -PassThru -Default:$Default)) + Write-Verbose ($contextObj | Format-List | Out-String) + if (-not $Silent) { + $name = $contextObj.name + Write-Host '✓ ' -ForegroundColor Green -NoNewline + Write-Host "Connected $name!" + } + if ($PassThru) { + Write-Debug "Passing context [$contextObj] to the pipeline." + Write-Output $contextObj + } + $contextParams.Clear() } + } end { diff --git a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 index fb4615d1a..675e562e9 100644 --- a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 +++ b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 @@ -54,7 +54,7 @@ function Get-GitHubContext { $ID = "$($script:GitHub.Config.ID)/*" Write-Verbose "Getting available contexts for [$ID]" } - '__AllParameterSets' { + default { Write-Verbose 'Getting default context.' $ID = "$($script:GitHub.Config.ID)/$($script:GitHub.Config.DefaultContext)" if ([string]::IsNullOrEmpty($ID)) { diff --git a/src/functions/public/Auth/Disconnect-GitHubAccount.ps1 b/src/functions/public/Auth/Disconnect-GitHubAccount.ps1 index f66ff5372..1b2aafc29 100644 --- a/src/functions/public/Auth/Disconnect-GitHubAccount.ps1 +++ b/src/functions/public/Auth/Disconnect-GitHubAccount.ps1 @@ -16,28 +16,14 @@ Disconnects from GitHub and removes the context 'github.com/Octocat'. #> - [Alias( - 'Disconnect-GHAccount', - 'Disconnect-GitHub', - 'Disconnect-GH', - 'Logout-GitHubAccount', - 'Logout-GHAccount', - 'Logout-GitHub', - 'Logout-GH', - 'Logoff-GitHubAccount', - 'Logoff-GHAccount', - 'Logoff-GitHub', - 'Logoff-GH' - )] + [Alias('Disconnect-GitHub')] [OutputType([void])] [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingWriteHost', '', Justification = 'Is the CLI part of the module.')] [CmdletBinding()] param( - # Silently disconnects from GitHub. + # Suppresses the output of the function. [Parameter()] [Alias('Quiet')] - [Alias('q')] - [Alias('s')] [switch] $Silent, # The context to run the command with. @@ -57,21 +43,17 @@ } foreach ($contextItem in $Context) { $contextItem = Resolve-GitHubContext -Context $contextItem - try { - Remove-GitHubContext -Context $contextItem - $isDefaultContext = $contextItem.Name -eq $script:GitHub.Config.DefaultContext - if ($isDefaultContext) { - Remove-GitHubConfig -Name 'DefaultContext' - Write-Warning 'There is no longer a default context!' - Write-Warning "Please set a new default context using 'Set-GitHubDefaultContext -Name '" - } + Remove-GitHubContext -Context $contextItem + $isDefaultContext = $contextItem.Name -eq $script:GitHub.Config.DefaultContext + if ($isDefaultContext) { + Remove-GitHubConfig -Name 'DefaultContext' + Write-Warning 'There is no longer a default context!' + Write-Warning "Please set a new default context using 'Set-GitHubDefaultContext -Name '" + } - if (-not $Silent) { - Write-Host '✓ ' -ForegroundColor Green -NoNewline - Write-Host "Logged out of GitHub! [$contextItem]" - } - } catch { - throw $_ + if (-not $Silent) { + Write-Host '✓ ' -ForegroundColor Green -NoNewline + Write-Host "Logged out of GitHub! [$contextItem]" } } } diff --git a/src/functions/public/Auth/Get-GitHubViewer.ps1 b/src/functions/public/Auth/Get-GitHubViewer.ps1 index 658e4fc34..5dd7d9685 100644 --- a/src/functions/public/Auth/Get-GitHubViewer.ps1 +++ b/src/functions/public/Auth/Get-GitHubViewer.ps1 @@ -33,20 +33,16 @@ } process { - try { - $query = @" + $query = @" query { viewer { $($Fields -join "`n") } } "@ - $results = Invoke-GitHubGraphQLQuery -Query $query -Context $Context + $results = Invoke-GitHubGraphQLQuery -Query $query -Context $Context - $results.data.viewer - } catch { - throw $_ - } + $results.data.viewer } end { diff --git a/src/functions/public/Branches/Get-GitHubRepoBranch.ps1 b/src/functions/public/Branches/Get-GitHubRepoBranch.ps1 index 6617cd0dd..868519613 100644 --- a/src/functions/public/Branches/Get-GitHubRepoBranch.ps1 +++ b/src/functions/public/Branches/Get-GitHubRepoBranch.ps1 @@ -7,7 +7,7 @@ Lists all branches from a repository .EXAMPLE - Get-GitHubRepoBranch -Owner 'octocat' -Repo 'Hello-World' + Get-GitHubRepoBranch -Owner 'octocat' -Repository 'Hello-World' Gets all the branches from the 'Hello-World' repository owned by 'octocat' @@ -17,12 +17,14 @@ [CmdletBinding()] param( # The account owner of the repository. The name is not case sensitive. - [Parameter()] + [Parameter(Mandatory)] + [Alias('Organization')] + [Alias('User')] [string] $Owner, # The name of the repository without the .git extension. The name is not case sensitive. - [Parameter()] - [string] $Repo, + [Parameter(Mandatory)] + [string] $Repository, # 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. @@ -35,30 +37,17 @@ Write-Debug "[$stackPath] - Start" $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - if ([string]::IsNullOrEmpty($Owner)) { - $Owner = $Context.Owner - } - Write-Debug "Owner: [$Owner]" - - if ([string]::IsNullOrEmpty($Repo)) { - $Repo = $Context.Repo - } - Write-Debug "Repo: [$Repo]" } process { - try { - $inputObject = @{ - Context = $Context - APIEndpoint = "/repos/$Owner/$Repo/branches" - Method = 'GET' - } + $inputObject = @{ + Method = 'GET' + APIEndpoint = "/repos/$Owner/$Repository/branches" + Context = $Context + } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } - } catch { - throw $_ + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } } diff --git a/src/functions/public/Commands/Add-GitHubMask.ps1 b/src/functions/public/Commands/Add-GitHubMask.ps1 index 8b156f649..ae6a2f750 100644 --- a/src/functions/public/Commands/Add-GitHubMask.ps1 +++ b/src/functions/public/Commands/Add-GitHubMask.ps1 @@ -52,12 +52,8 @@ } process { - try { - foreach ($item in $Value) { - Write-Host "::add-mask::$item" - } - } catch { - throw $_ + foreach ($item in $Value) { + Write-Host "::add-mask::$item" } } diff --git a/src/functions/public/Commands/Add-GitHubSystemPath.ps1 b/src/functions/public/Commands/Add-GitHubSystemPath.ps1 index 2465ac7a7..ad7c9a639 100644 --- a/src/functions/public/Commands/Add-GitHubSystemPath.ps1 +++ b/src/functions/public/Commands/Add-GitHubSystemPath.ps1 @@ -30,14 +30,10 @@ } process { - try { - Write-Verbose "Current PATH: $env:PATH" - Write-Verbose "Adding system path: $Path" + Write-Verbose "Current PATH: $env:PATH" + Write-Verbose "Adding system path: $Path" - $Path | Out-File -FilePath $env:GITHUB_PATH -Append - } catch { - throw $_ - } + $Path | Out-File -FilePath $env:GITHUB_PATH -Append } end { diff --git a/src/functions/public/Commands/Disable-GitHubCommand.ps1 b/src/functions/public/Commands/Disable-GitHubCommand.ps1 index 0c8a6e1cb..0f89df98a 100644 --- a/src/functions/public/Commands/Disable-GitHubCommand.ps1 +++ b/src/functions/public/Commands/Disable-GitHubCommand.ps1 @@ -40,14 +40,10 @@ } process { - try { - $String = $String.ToLower() - - if ($env:GITHUB_ACTIONS -eq 'true') { - Write-Host "::stop-commands::$String" - } - } catch { - throw $_ + $String = $String.ToLower() + + if ($env:GITHUB_ACTIONS -eq 'true') { + Write-Host "::stop-commands::$String" } } diff --git a/src/functions/public/Commands/Enable-GitHubCommand.ps1 b/src/functions/public/Commands/Enable-GitHubCommand.ps1 index d1a0e6ee6..67d9fd008 100644 --- a/src/functions/public/Commands/Enable-GitHubCommand.ps1 +++ b/src/functions/public/Commands/Enable-GitHubCommand.ps1 @@ -39,14 +39,10 @@ } process { - try { - $String = $String.ToLower() - - if ($env:GITHUB_ACTIONS -eq 'true') { - Write-Host "::$String::" - } - } catch { - throw $_ + $String = $String.ToLower() + + if ($env:GITHUB_ACTIONS -eq 'true') { + Write-Host "::$String::" } } diff --git a/src/functions/public/Commands/Get-GitHubOutput.ps1 b/src/functions/public/Commands/Get-GitHubOutput.ps1 index 166423781..cfdbd6e6f 100644 --- a/src/functions/public/Commands/Get-GitHubOutput.ps1 +++ b/src/functions/public/Commands/Get-GitHubOutput.ps1 @@ -46,21 +46,18 @@ } process { - try { - if (-not $Path) { - throw 'The path to the GitHub output file is not set. Please set the path to the GitHub output file using the -Path parameter.' - } - Write-Debug "[$stackPath] - Output path" - Write-Debug $Path - if (-not (Test-Path -Path $Path)) { - throw "File not found: $Path" - } - - $outputContent = Get-Content -Path $Path -Raw - ConvertFrom-GitHubOutput -OutputContent $outputContent -AsHashtable:$AsHashtable - } catch { - throw $_ + if (-not $Path) { + throw 'The path to the GitHub output file is not set. Please set the path to the GitHub output file using the -Path parameter.' + } + Write-Debug "[$stackPath] - Output path" + Write-Debug $Path + if (-not (Test-Path -Path $Path)) { + throw "File not found: $Path" } + + $outputContent = Get-Content -Path $Path -Raw + ConvertFrom-GitHubOutput -OutputContent $outputContent -AsHashtable:$AsHashtable + } end { diff --git a/src/functions/public/Commands/Set-GitHubEnvironmentVariable.ps1 b/src/functions/public/Commands/Set-GitHubEnvironmentVariable.ps1 index 204d4e17f..29ecfb51c 100644 --- a/src/functions/public/Commands/Set-GitHubEnvironmentVariable.ps1 +++ b/src/functions/public/Commands/Set-GitHubEnvironmentVariable.ps1 @@ -40,19 +40,16 @@ } process { - try { - Write-Verbose "Env: [$Name] = [$Value]" + Write-Verbose "Env: [$Name] = [$Value]" - $guid = [guid]::NewGuid().Guid - $content = @" + $guid = [guid]::NewGuid().Guid + $content = @" $Name<<$guid $Value $guid "@ - $content | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append - } catch { - throw $_ - } + $content | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append + } end { diff --git a/src/functions/public/Commands/Set-GitHubLogGroup.ps1 b/src/functions/public/Commands/Set-GitHubLogGroup.ps1 index 5ac4e0845..85911531f 100644 --- a/src/functions/public/Commands/Set-GitHubLogGroup.ps1 +++ b/src/functions/public/Commands/Set-GitHubLogGroup.ps1 @@ -45,11 +45,6 @@ ) Write-Host "::group::$Name" - try { - . $ScriptBlock - } catch { - throw $_ - } + . $ScriptBlock Write-Host '::endgroup::' - } diff --git a/src/functions/public/Commands/Set-GitHubNoCommandGroup.ps1 b/src/functions/public/Commands/Set-GitHubNoCommandGroup.ps1 index 4384c7a98..c9b10ff72 100644 --- a/src/functions/public/Commands/Set-GitHubNoCommandGroup.ps1 +++ b/src/functions/public/Commands/Set-GitHubNoCommandGroup.ps1 @@ -51,11 +51,7 @@ $guid = [string][guid]::NewGuid().Guid Disable-GitHubCommand -String $guid - try { - . $ScriptBlock - } catch { - throw $_ - } + . $ScriptBlock Enable-GitHubCommand -String $guid } diff --git a/src/functions/public/Commands/Set-GitHubOutput.ps1 b/src/functions/public/Commands/Set-GitHubOutput.ps1 index ded04e4f3..bc0094814 100644 --- a/src/functions/public/Commands/Set-GitHubOutput.ps1 +++ b/src/functions/public/Commands/Set-GitHubOutput.ps1 @@ -42,51 +42,48 @@ } process { - try { - if (-not (Test-Path -Path $Path)) { - throw "File not found: $Path" - } + if (-not (Test-Path -Path $Path)) { + throw "File not found: $Path" + } - $outputs = Get-GitHubOutput -Path $Path -AsHashtable + $outputs = Get-GitHubOutput -Path $Path -AsHashtable - if ([string]::IsNullOrEmpty($env:GITHUB_ACTION)) { - Write-Warning 'Cannot create output as the step has no ID.' - } + if ([string]::IsNullOrEmpty($env:GITHUB_ACTION)) { + Write-Warning 'Cannot create output as the step has no ID.' + } - switch -Regex ($value.GetType().Name) { - 'SecureString' { - $Value = $Value | ConvertFrom-SecureString -AsPlainText - Add-Mask -Value $Value - } - 'Hashtable|PSCustomObject' { - Write-Debug 'Converting value to JSON:' - $Value = $Value | ConvertTo-Json -Compress -Depth 100 - Write-Debug $value - } - default {} + switch -Regex ($value.GetType().Name) { + 'SecureString' { + $Value = $Value | ConvertFrom-SecureString -AsPlainText + Add-Mask -Value $Value } - - Write-Verbose "Output: [$Name] = [$Value]" - - # If the script is running in a GitHub composite action, accumulate the output under the 'result' key, - # else append the key-value pair directly. - if ($env:PSMODULE_GITHUB_SCRIPT) { - Write-Debug "[$stackPath] - Running in GitHub-Script composite action" - if (-not $outputs.ContainsKey('result')) { - $outputs['result'] = @{} - } - $outputs['result'][$Name] = $Value - } else { - Write-Debug "[$stackPath] - Running in a custom action" - $outputs[$Name] = $Value + 'Hashtable|PSCustomObject' { + Write-Debug 'Converting value to JSON:' + $Value = $Value | ConvertTo-Json -Compress -Depth 100 + Write-Debug $value } + default {} + } - if ($PSCmdlet.ShouldProcess('GitHub Output', 'Set')) { - $outputs | ConvertTo-GitHubOutput | Set-Content -Path $Path + Write-Verbose "Output: [$Name] = [$Value]" + + # If the script is running in a GitHub composite action, accumulate the output under the 'result' key, + # else append the key-value pair directly. + if ($env:PSMODULE_GITHUB_SCRIPT) { + Write-Debug "[$stackPath] - Running in GitHub-Script composite action" + if (-not $outputs.ContainsKey('result')) { + $outputs['result'] = @{} } - } catch { - throw $_ + $outputs['result'][$Name] = $Value + } else { + Write-Debug "[$stackPath] - Running in a custom action" + $outputs[$Name] = $Value } + + if ($PSCmdlet.ShouldProcess('GitHub Output', 'Set')) { + $outputs | ConvertTo-GitHubOutput | Set-Content -Path $Path + } + } end { diff --git a/src/functions/public/Commands/Set-GitHubStepSummary.ps1 b/src/functions/public/Commands/Set-GitHubStepSummary.ps1 index d04e0dd2b..d13bb16f5 100644 --- a/src/functions/public/Commands/Set-GitHubStepSummary.ps1 +++ b/src/functions/public/Commands/Set-GitHubStepSummary.ps1 @@ -48,15 +48,11 @@ } process { - try { - Write-Verbose 'Step summary:' - Write-Verbose $Summary + Write-Verbose 'Step summary:' + Write-Verbose $Summary - $Append = -not $Overwrite - $Summary | Out-File -FilePath $env:GITHUB_STEP_SUMMARY -Encoding utf8 -Append:$Append - } catch { - throw $_ - } + $Append = -not $Overwrite + $Summary | Out-File -FilePath $env:GITHUB_STEP_SUMMARY -Encoding utf8 -Append:$Append } end { diff --git a/src/functions/public/Commands/Write-GitHubDebug.ps1 b/src/functions/public/Commands/Write-GitHubDebug.ps1 index e473db310..b187b4f14 100644 --- a/src/functions/public/Commands/Write-GitHubDebug.ps1 +++ b/src/functions/public/Commands/Write-GitHubDebug.ps1 @@ -41,14 +41,10 @@ } process { - try { - if ($env:GITHUB_ACTIONS -eq 'true') { - Write-Host "::debug::$Message" - } else { - Write-Debug "$Message" - } - } catch { - throw $_ + if ($env:GITHUB_ACTIONS -eq 'true') { + Write-Host "::debug::$Message" + } else { + Write-Debug "$Message" } } diff --git a/src/functions/public/Commands/Write-GitHubError.ps1 b/src/functions/public/Commands/Write-GitHubError.ps1 index 3ab1c6d87..506f54cd2 100644 --- a/src/functions/public/Commands/Write-GitHubError.ps1 +++ b/src/functions/public/Commands/Write-GitHubError.ps1 @@ -61,14 +61,10 @@ } process { - try { - if ($env:GITHUB_ACTIONS -eq 'true') { - Write-Host "::error file=$Name,line=$Line,col=$Column,endColumn=$EndColumn,endLine=$EndLine,title=$Title::$Message" - } else { - Write-Error $Message - } - } catch { - throw $_ + if ($env:GITHUB_ACTIONS -eq 'true') { + Write-Host "::error file=$Name,line=$Line,col=$Column,endColumn=$EndColumn,endLine=$EndLine,title=$Title::$Message" + } else { + Write-Error $Message } } diff --git a/src/functions/public/Commands/Write-GitHubNotice.ps1 b/src/functions/public/Commands/Write-GitHubNotice.ps1 index d206f4390..32cef882d 100644 --- a/src/functions/public/Commands/Write-GitHubNotice.ps1 +++ b/src/functions/public/Commands/Write-GitHubNotice.ps1 @@ -61,14 +61,10 @@ } process { - try { - if ($env:GITHUB_ACTIONS -eq 'true') { - Write-Host "::notice file=$Name,line=$Line,col=$Column,endColumn=$EndColumn,endLine=$EndLine,title=$Title::$Message" - } else { - Write-Host $Message - } - } catch { - throw $_ + if ($env:GITHUB_ACTIONS -eq 'true') { + Write-Host "::notice file=$Name,line=$Line,col=$Column,endColumn=$EndColumn,endLine=$EndLine,title=$Title::$Message" + } else { + Write-Host $Message } } diff --git a/src/functions/public/Commands/Write-GitHubWarning.ps1 b/src/functions/public/Commands/Write-GitHubWarning.ps1 index 22de869a4..7ca6eb747 100644 --- a/src/functions/public/Commands/Write-GitHubWarning.ps1 +++ b/src/functions/public/Commands/Write-GitHubWarning.ps1 @@ -61,14 +61,10 @@ } process { - try { - if ($env:GITHUB_ACTIONS -eq 'true') { - Write-Host "::warning file=$Name,line=$Line,col=$Column,endColumn=$EndColumn,endLine=$EndLine,title=$Title::$Message" - } else { - Write-Warning $Message - } - } catch { - throw $_ + if ($env:GITHUB_ACTIONS -eq 'true') { + Write-Host "::warning file=$Name,line=$Line,col=$Column,endColumn=$EndColumn,endLine=$EndLine,title=$Title::$Message" + } else { + Write-Warning $Message } } diff --git a/src/functions/public/Config/Get-GitHubConfig.ps1 b/src/functions/public/Config/Get-GitHubConfig.ps1 index 42633f786..a87859ee0 100644 --- a/src/functions/public/Config/Get-GitHubConfig.ps1 +++ b/src/functions/public/Config/Get-GitHubConfig.ps1 @@ -26,15 +26,11 @@ } process { - try { - if (-not $Name) { - return [GitHubConfig]($script:GitHub.Config) - } - - $script:GitHub.Config.$Name - } catch { - throw $_ + if (-not $Name) { + return [GitHubConfig]($script:GitHub.Config) } + + $script:GitHub.Config.$Name } end { diff --git a/src/functions/public/Config/Reset-GitHubConfig.ps1 b/src/functions/public/Config/Reset-GitHubConfig.ps1 index 8b2d979fa..508621e4d 100644 --- a/src/functions/public/Config/Reset-GitHubConfig.ps1 +++ b/src/functions/public/Config/Reset-GitHubConfig.ps1 @@ -21,13 +21,8 @@ } process { - try { - if ($PSCmdlet.ShouldProcess('GitHubConfig', 'Reset')) { - Initialize-GitHubConfig -Force - } - } catch { - Write-Error $_ - throw 'Failed to reset GitHub module configuration.' + if ($PSCmdlet.ShouldProcess('GitHubConfig', 'Reset')) { + Initialize-GitHubConfig -Force } } diff --git a/src/functions/public/Config/Set-GitHubConfig.ps1 b/src/functions/public/Config/Set-GitHubConfig.ps1 index 66718e18d..9985effbb 100644 --- a/src/functions/public/Config/Set-GitHubConfig.ps1 +++ b/src/functions/public/Config/Set-GitHubConfig.ps1 @@ -31,15 +31,10 @@ function Set-GitHubConfig { } process { - try { - Write-Verbose "Setting [$Name] to [$Value]" - $script:GitHub.Config.$Name = $Value - if ($PSCmdlet.ShouldProcess('ContextSetting', 'Set')) { - Set-Context -ID $script:GitHub.Config.ID -Context $script:GitHub.Config - } - } catch { - Write-Error $_ - throw 'Failed to set GitHub module configuration.' + Write-Verbose "Setting [$Name] to [$Value]" + $script:GitHub.Config.$Name = $Value + if ($PSCmdlet.ShouldProcess('ContextSetting', 'Set')) { + Set-Context -ID $script:GitHub.Config.ID -Context $script:GitHub.Config } } diff --git a/src/functions/public/Emojis/Get-GitHubEmoji.ps1 b/src/functions/public/Emojis/Get-GitHubEmoji.ps1 index e8e61bbee..76b80b280 100644 --- a/src/functions/public/Emojis/Get-GitHubEmoji.ps1 +++ b/src/functions/public/Emojis/Get-GitHubEmoji.ps1 @@ -5,7 +5,7 @@ .DESCRIPTION Lists all the emojis available to use on GitHub. - If you pass the `Destination` parameter, the emojis will be downloaded to the specified destination. + If you pass the `Path` parameter, the emojis will be downloaded to the specified destination. .EXAMPLE Get-GitHubEmoji @@ -13,7 +13,7 @@ Gets all the emojis available to use on GitHub. .EXAMPLE - Get-GitHubEmoji -Destination 'C:\Users\user\Documents\GitHub\Emojis' + Get-GitHubEmoji -Path 'C:\Users\user\Documents\GitHub\Emojis' Downloads all the emojis available to use on GitHub to the specified destination. @@ -27,7 +27,7 @@ Mandatory, ParameterSetName = 'Download' )] - [string] $Destination, + [string] $Path, # 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. @@ -43,39 +43,37 @@ } process { - try { - $inputObject = @{ - Context = $Context - APIEndpoint = '/emojis' - Method = 'GET' - } + $inputObject = @{ + Method = 'GET' + APIEndpoint = '/emojis' + Context = $Context + } - $response = Invoke-GitHubAPI @inputObject | Select-Object -ExpandProperty Response + $response = Invoke-GitHubAPI @inputObject | Select-Object -ExpandProperty Response - if ($PSCmdlet.ParameterSetName -eq 'Download') { + switch ($PSCmdlet.ParameterSetName) { + 'Download' { $failedEmojis = @() - if (-not (Test-Path -Path $Destination)) { - $null = New-Item -Path $Destination -ItemType Directory -Force + if (-not (Test-Path -Path $Path)) { + $null = New-Item -Path $Path -ItemType Directory -Force } $failedEmojis = $response.PSObject.Properties | ForEach-Object -ThrottleLimit ([System.Environment]::ProcessorCount) -Parallel { $emoji = $_ - Write-Verbose "Downloading [$($emoji.Name).png] from [$($emoji.Value)] -> [$using:Destination/$($emoji.Name).png]" + Write-Verbose "Downloading [$($emoji.Name).png] from [$($emoji.Value)] -> [$using:Path/$($emoji.Name).png]" try { - Invoke-WebRequest -Uri $emoji.Value -OutFile "$using:Destination/$($emoji.Name).png" -RetryIntervalSec 1 -MaximumRetryCount 5 + Invoke-WebRequest -Uri $emoji.Value -OutFile "$using:Path/$($emoji.Name).png" -RetryIntervalSec 1 -MaximumRetryCount 5 } catch { - $emoji - Write-Warning "Could not download [$($emoji.Name).png] from [$($emoji.Value)] -> [$using:Destination/$($emoji.Name).png]" + Write-Warning "Could not download [$($emoji.Name).png] from [$($emoji.Value)] -> [$using:Path/$($emoji.Name).png]" } } if ($failedEmojis.Count -gt 0) { Write-Warning 'Failed to download the following emojis:' $failedEmojis | Out-String -Stream | ForEach-Object { Write-Warning $_ } } - } else { + } + default { $response } - } catch { - throw $_ } } diff --git a/src/functions/public/Enterprise/Get-GitHubEnterpriseOrganization.ps1 b/src/functions/public/Enterprise/Get-GitHubEnterpriseOrganization.ps1 index 98ff3efee..d9d021aa2 100644 --- a/src/functions/public/Enterprise/Get-GitHubEnterpriseOrganization.ps1 +++ b/src/functions/public/Enterprise/Get-GitHubEnterpriseOrganization.ps1 @@ -32,8 +32,7 @@ } process { - try { - $query = @" + $query = @" query(`$enterpriseSlug: String!, `$first: Int = 100, `$after: String) { enterprise(slug: `$enterpriseSlug) { organizations(first: `$first, after: `$after) { @@ -52,39 +51,37 @@ query(`$enterpriseSlug: String!, `$first: Int = 100, `$after: String) { } "@ - # Initialize pagination variables - $variables = @{ - 'enterpriseSlug' = $Enterprise - 'first' = 100 - 'after' = $null + # Initialize pagination variables + $variables = @{ + 'enterpriseSlug' = $Enterprise + 'first' = 100 + 'after' = $null + } + $allOrgs = @() + + # Loop through pages to retrieve all organizations + do { + $response = Invoke-GitHubGraphQLQuery -Query $query -Variables $variables -Context $Context + # Check for errors + if ($response.errors) { + Write-Error "Error: $($response.errors[0].message)" + break } - $allOrgs = @() - # Loop through pages to retrieve all organizations - do { - $response = Invoke-GitHubGraphQLQuery -Query $query -Variables $variables -Context $Context - # Check for errors - if ($response.errors) { - Write-Error "Error: $($response.errors[0].message)" - break - } + # Extract organization names and add to the list + foreach ($org in $response.data.enterprise.organizations.edges) { + $allOrgs += $org.node.name + } - # Extract organization names and add to the list - foreach ($org in $response.data.enterprise.organizations.edges) { - $allOrgs += $org.node.name - } + # Update pagination cursor + $pageInfo = $response.data.enterprise.organizations.pageInfo + $variables.after = $pageInfo.endCursor - # Update pagination cursor - $pageInfo = $response.data.enterprise.organizations.pageInfo - $variables.after = $pageInfo.endCursor + } while ($pageInfo.hasNextPage -eq $true) - } while ($pageInfo.hasNextPage -eq $true) + # Output the list of organization names + $allOrgs | ForEach-Object { Write-Output $_ } - # Output the list of organization names - $allOrgs | ForEach-Object { Write-Output $_ } - } catch { - throw $_ - } } end { diff --git a/src/functions/public/Git/Get-GitHubGitConfig.ps1 b/src/functions/public/Git/Get-GitHubGitConfig.ps1 index 3698f8b0d..dff753103 100644 --- a/src/functions/public/Git/Get-GitHubGitConfig.ps1 +++ b/src/functions/public/Git/Get-GitHubGitConfig.ps1 @@ -25,47 +25,44 @@ } process { - try { - $gitExists = Get-Command -Name 'git' -ErrorAction SilentlyContinue - Write-Debug "GITEXISTS: $gitExists" - if (-not $gitExists) { - Write-Verbose 'Git is not installed. Cannot get git configuration.' - return - } + $gitExists = Get-Command -Name 'git' -ErrorAction SilentlyContinue + Write-Debug "GITEXISTS: $gitExists" + if (-not $gitExists) { + Write-Verbose 'Git is not installed. Cannot get git configuration.' + return + } - $cmdresult = git rev-parse --is-inside-work-tree 2>&1 - Write-Debug "LASTEXITCODE: $LASTEXITCODE" - Write-Debug "CMDRESULT: $cmdresult" - if ($LASTEXITCODE -ne 0) { - Write-Verbose 'Not a git repository. Cannot get git configuration.' - $Global:LASTEXITCODE = 0 - Write-Debug "Resetting LASTEXITCODE: $LASTEXITCODE" - return - } + $cmdresult = git rev-parse --is-inside-work-tree 2>&1 + Write-Debug "LASTEXITCODE: $LASTEXITCODE" + Write-Debug "CMDRESULT: $cmdresult" + if ($LASTEXITCODE -ne 0) { + Write-Verbose 'Not a git repository. Cannot get git configuration.' + $Global:LASTEXITCODE = 0 + Write-Debug "Resetting LASTEXITCODE: $LASTEXITCODE" + return + } - $config = @() - $configList = git config --$Scope --list 2>&1 - if ($LASTEXITCODE -ne 0) { - Write-Verbose "Failed to get git configuration for [$Scope]." - $global:LASTEXITCODE = 0 - Write-Debug "Resetting LASTEXITCODE: $LASTEXITCODE" - return $config - } + $config = @() + $configList = git config --$Scope --list 2>&1 + if ($LASTEXITCODE -ne 0) { + Write-Verbose "Failed to get git configuration for [$Scope]." + $global:LASTEXITCODE = 0 + Write-Debug "Resetting LASTEXITCODE: $LASTEXITCODE" + return $config + } - $configList = $configList | Sort-Object - $configList | ForEach-Object { - Write-Debug "CONFIG: $_" - $name, $value = $_ -split '=', 2 - $name = ('' + $name).Trim() - $value = ('' + $value).Trim() - $config += @{ - $name = $value - } + $configList = $configList | Sort-Object + $configList | ForEach-Object { + Write-Debug "CONFIG: $_" + $name, $value = $_ -split '=', 2 + $name = ('' + $name).Trim() + $value = ('' + $value).Trim() + $config += @{ + $name = $value } - $config - } catch { - throw $_ } + $config + } end { diff --git a/src/functions/public/Git/Set-GitHubGitConfig.ps1 b/src/functions/public/Git/Set-GitHubGitConfig.ps1 index e5d9daae0..22d2e1fa3 100644 --- a/src/functions/public/Git/Set-GitHubGitConfig.ps1 +++ b/src/functions/public/Git/Set-GitHubGitConfig.ps1 @@ -32,51 +32,48 @@ } process { - try { - $gitExists = Get-Command -Name 'git' -ErrorAction SilentlyContinue - Write-Debug "GITEXISTS: $gitExists" - if (-not $gitExists) { - Write-Verbose 'Git is not installed. Cannot configure git.' - return - } + $gitExists = Get-Command -Name 'git' -ErrorAction SilentlyContinue + Write-Debug "GITEXISTS: $gitExists" + if (-not $gitExists) { + Write-Verbose 'Git is not installed. Cannot configure git.' + return + } - $cmdresult = git rev-parse --is-inside-work-tree 2>&1 - Write-Debug "LASTEXITCODE: $LASTEXITCODE" - Write-Debug "CMDRESULT: $cmdresult" - if ($LASTEXITCODE -ne 0) { - Write-Verbose 'Not a git repository. Cannot configure git.' - $Global:LASTEXITCODE = 0 - Write-Debug "Resetting LASTEXITCODE: $LASTEXITCODE" - return - } + $cmdresult = git rev-parse --is-inside-work-tree 2>&1 + Write-Debug "LASTEXITCODE: $LASTEXITCODE" + Write-Debug "CMDRESULT: $cmdresult" + if ($LASTEXITCODE -ne 0) { + Write-Verbose 'Not a git repository. Cannot configure git.' + $Global:LASTEXITCODE = 0 + Write-Debug "Resetting LASTEXITCODE: $LASTEXITCODE" + return + } - $username = $Context.UserName - $id = $Context.DatabaseID - $token = $Context.Token | ConvertFrom-SecureString -AsPlainText - $hostName = $Context.HostName - $installationName = $Context.InstallationName - $sshUser = $Context.Enterprise ?? 'git' + $username = $Context.UserName + $id = $Context.DatabaseID + $token = $Context.Token | ConvertFrom-SecureString -AsPlainText + $hostName = $Context.HostName + $installationName = $Context.InstallationName + $sshUser = $Context.Enterprise ?? 'git' - if ($PSCmdlet.ShouldProcess("$username on $installationName", 'Set Git configuration')) { - $git = 'git' - @( - @('config', '--global', 'user.name', "$username"), - @('config', '--global', 'user.email', "$id+$username@users.noreply.github.com"), - @('config', '--global', '--add', "url.https://oauth2:$token@$hostName/$installationName.insteadOf", - "ssh://$sshUser@$hostName`:$installationName"), - @('config', '--global', '--add', "url.https://oauth2:$token@$hostName/$installationName.insteadOf", - "https://$hostName/$installationName") - ) | ForEach-Object { - Write-Verbose "$git $($_ -join ' ')" - & $git $_ - if ($LASTEXITCODE -ne 0) { - throw "Failed to run git command. ($LASTEXITCODE)" - } + if ($PSCmdlet.ShouldProcess("$username on $installationName", 'Set Git configuration')) { + $git = 'git' + @( + @('config', '--global', 'user.name', "$username"), + @('config', '--global', 'user.email', "$id+$username@users.noreply.github.com"), + @('config', '--global', '--add', "url.https://oauth2:$token@$hostName/$installationName.insteadOf", + "ssh://$sshUser@$hostName`:$installationName"), + @('config', '--global', '--add', "url.https://oauth2:$token@$hostName/$installationName.insteadOf", + "https://$hostName/$installationName") + ) | ForEach-Object { + Write-Verbose "$git $($_ -join ' ')" + & $git $_ + if ($LASTEXITCODE -ne 0) { + throw "Failed to run git command. ($LASTEXITCODE)" } } - } catch { - throw $_ } + } end { diff --git a/src/functions/public/Gitignore/Get-GitHubGitignore.ps1 b/src/functions/public/Gitignore/Get-GitHubGitignore.ps1 index 7fca1570e..f8bd75a94 100644 --- a/src/functions/public/Gitignore/Get-GitHubGitignore.ps1 +++ b/src/functions/public/Gitignore/Get-GitHubGitignore.ps1 @@ -1,6 +1,4 @@ -#Requires -Modules @{ ModuleName = 'DynamicParams'; RequiredVersion = '1.1.8' } - -filter Get-GitHubGitignore { +filter Get-GitHubGitignore { <# .SYNOPSIS Get a gitignore template or list of all gitignore templates names @@ -25,28 +23,18 @@ filter Get-GitHubGitignore { #> [CmdletBinding(DefaultParameterSetName = 'List')] param( + [Parameter( + Mandatory, + ParameterSetName = 'Name' + )] + [string] $Name, + # 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. [Parameter()] [object] $Context = (Get-GitHubContext) ) - dynamicparam { - $DynamicParamDictionary = New-DynamicParamDictionary - - $dynParam = @{ - Name = 'Name' - ParameterSetName = 'Name' - Type = [string] - Mandatory = $true - ValidateSet = Get-GitHubGitignoreList - DynamicParamDictionary = $DynamicParamDictionary - } - New-DynamicParam @dynParam - - return $DynamicParamDictionary - } - begin { $stackPath = Get-PSCallStackPath Write-Debug "[$stackPath] - Start" @@ -59,18 +47,13 @@ filter Get-GitHubGitignore { } process { - try { - $Name = $PSBoundParameters['Name'] - switch ($PSCmdlet.ParameterSetName) { - 'List' { - Get-GitHubGitignoreList -Context $Context - } - 'Name' { - Get-GitHubGitignoreByName -Name $Name -Context $Context - } + switch ($PSCmdlet.ParameterSetName) { + 'List' { + Get-GitHubGitignoreList -Context $Context + } + 'Name' { + Get-GitHubGitignoreByName -Name $Name -Context $Context } - } catch { - throw $_ } } @@ -78,3 +61,11 @@ filter Get-GitHubGitignore { Write-Debug "[$stackPath] - End" } } + +Register-ArgumentCompleter -CommandName Get-GitHubGitignore -ParameterName Name -ScriptBlock { + param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter) + $null = $commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter + Get-GitHubGitignoreList -Context $fakeBoundParameter.Context | Where-Object { $_ -like "$wordToComplete*" } | ForEach-Object { + [System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_) + } +} diff --git a/src/functions/public/GraphQL/Invoke-GitHubGraphQLQuery.ps1 b/src/functions/public/GraphQL/Invoke-GitHubGraphQLQuery.ps1 index a34a49d2d..d908028ce 100644 --- a/src/functions/public/GraphQL/Invoke-GitHubGraphQLQuery.ps1 +++ b/src/functions/public/GraphQL/Invoke-GitHubGraphQLQuery.ps1 @@ -36,22 +36,20 @@ } process { - try { - $inputObject = @{ - Context = $Context - APIEndpoint = '/graphql' - Method = 'Post' - Body = @{ - 'query' = $Query - 'variables' = $Variables - } | ConvertTo-Json - } - - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } - } catch { - throw $_ + $body = @{ + 'query' = $Query + 'variables' = $Variables + } + + $inputObject = @{ + Method = 'POST' + APIEndpoint = '/graphql' + Body = $body + Context = $Context + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } } diff --git a/src/functions/public/License/Get-GitHubLicense.ps1 b/src/functions/public/License/Get-GitHubLicense.ps1 index 8ec620b6a..ebcb95f1c 100644 --- a/src/functions/public/License/Get-GitHubLicense.ps1 +++ b/src/functions/public/License/Get-GitHubLicense.ps1 @@ -19,7 +19,7 @@ Get the mit license template .EXAMPLE - Get-GitHubLicense -Owner 'octocat' -Repo 'Hello-World' + Get-GitHubLicense -Owner 'octocat' -Repository 'Hello-World' Get the license for the Hello-World repository from the octocat account. @@ -39,7 +39,7 @@ # The name of the repository without the .git extension. The name is not case sensitive. [Parameter(ParameterSetName = 'Repository')] - [string] $Repo, + [string] $Repository, # The license keyword, license name, or license SPDX ID. For example, mit or mpl-2.0. [Parameter(ParameterSetName = 'Name')] @@ -56,32 +56,19 @@ Write-Debug "[$stackPath] - Start" $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - if ([string]::IsNullOrEmpty($Owner)) { - $Owner = $Context.Owner - } - Write-Debug "Owner: [$Owner]" - - if ([string]::IsNullOrEmpty($Repo)) { - $Repo = $Context.Repo - } - Write-Debug "Repo: [$Repo]" } process { - try { - switch ($PSCmdlet.ParameterSetName) { - 'List' { - Get-GitHubLicenseList -Context $Context - } - 'Name' { - Get-GitHubLicenseByName -Name $Name -Context $Context - } - 'Repository' { - Get-GitHubRepositoryLicense -Owner $Owner -Repo $Repo -Context $Context - } + switch ($PSCmdlet.ParameterSetName) { + 'List' { + Get-GitHubLicenseList -Context $Context + } + 'Name' { + Get-GitHubLicenseByName -Name $Name -Context $Context + } + 'Repository' { + Get-GitHubRepositoryLicense -Owner $Owner -Repository $Repository -Context $Context } - } catch { - throw $_ } } diff --git a/src/functions/public/Markdown/Get-GitHubMarkdown.ps1 b/src/functions/public/Markdown/Get-GitHubMarkdown.ps1 index 5c8633833..26ea0073a 100644 --- a/src/functions/public/Markdown/Get-GitHubMarkdown.ps1 +++ b/src/functions/public/Markdown/Get-GitHubMarkdown.ps1 @@ -31,8 +31,8 @@ [ValidateSet('markdown', 'gfm')] [string] $Mode = 'markdown', - # The repository context to use when creating references in `gfm` mode. For example, setting `context` to `octo-org/octo-repo` will change the - # text `#42` into an HTML link to issue 42 in the `octo-org/octo-repo` repository. + # The repository context to use when creating references in `gfm` mode. For example, setting `context` to `octo-org/octo-Repository` will + # change the text `#42` into an HTML link to issue 42 in the `octo-org/octo-Repository` repository. [Parameter()] [string] $RepoContext, @@ -50,25 +50,21 @@ } process { - try { - $body = @{ - context = $RepoContext - mode = $Mode - text = $Text - } + $body = @{ + context = $RepoContext + mode = $Mode + text = $Text + } - $inputObject = @{ - Context = $Context - APIEndpoint = '/markdown' - Method = 'POST' - Body = $body - } + $inputObject = @{ + Method = 'POST' + APIEndpoint = '/markdown' + Body = $body + Context = $Context + } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } - } catch { - throw $_ + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } } diff --git a/src/functions/public/Markdown/Get-GitHubMarkdownRaw.ps1 b/src/functions/public/Markdown/Get-GitHubMarkdownRaw.ps1 index cbdf5c1a6..d381f9c95 100644 --- a/src/functions/public/Markdown/Get-GitHubMarkdownRaw.ps1 +++ b/src/functions/public/Markdown/Get-GitHubMarkdownRaw.ps1 @@ -37,23 +37,20 @@ } process { - try { - $body = @{ - text = $Text - } - $inputObject = @{ - Context = $Context - APIEndpoint = '/markdown/raw' - ContentType = 'text/plain' - Method = 'POST' - Body = $body - } - - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } - } catch { - throw $_ + $body = @{ + text = $Text + } + + $inputObject = @{ + Method = 'POST' + APIEndpoint = '/markdown/raw' + ContentType = 'text/plain' + Body = $body + Context = $Context + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } } diff --git a/src/functions/public/Meta/Get-GitHubApiVersion.ps1 b/src/functions/public/Meta/Get-GitHubApiVersion.ps1 index 6b97d9e2f..363ebc3e7 100644 --- a/src/functions/public/Meta/Get-GitHubApiVersion.ps1 +++ b/src/functions/public/Meta/Get-GitHubApiVersion.ps1 @@ -31,18 +31,14 @@ } process { - try { - $inputObject = @{ - Context = $Context - ApiEndpoint = '/versions' - Method = 'GET' - } - - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } - } catch { - throw $_ + $inputObject = @{ + Method = 'GET' + ApiEndpoint = '/versions' + Context = $Context + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } } diff --git a/src/functions/public/Meta/Get-GitHubMeta.ps1 b/src/functions/public/Meta/Get-GitHubMeta.ps1 index 1aa4ece02..7d837185e 100644 --- a/src/functions/public/Meta/Get-GitHubMeta.ps1 +++ b/src/functions/public/Meta/Get-GitHubMeta.ps1 @@ -39,18 +39,14 @@ } process { - try { - $inputObject = @{ - Context = $Context - ApiEndpoint = '/meta' - Method = 'GET' - } - - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } - } catch { - throw $_ + $inputObject = @{ + Method = 'GET' + ApiEndpoint = '/meta' + Context = $Context + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } } diff --git a/src/functions/public/Meta/Get-GitHubOctocat.ps1 b/src/functions/public/Meta/Get-GitHubOctocat.ps1 index 9ea7534f3..99e0eeaae 100644 --- a/src/functions/public/Meta/Get-GitHubOctocat.ps1 +++ b/src/functions/public/Meta/Get-GitHubOctocat.ps1 @@ -24,9 +24,7 @@ param( # The words to show in Octocat's speech bubble [Parameter()] - [Alias('Say')] - [Alias('Saying')] - [string] $S, + [string] $Saying, # 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. @@ -42,23 +40,19 @@ } process { - try { - $body = @{ - s = $S - } + $body = @{ + s = $Saying + } - $inputObject = @{ - Context = $Context - APIEndpoint = '/octocat' - Method = 'GET' - Body = $body - } + $inputObject = @{ + Method = 'GET' + APIEndpoint = '/octocat' + Body = $body + Context = $Context + } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } - } catch { - throw $_ + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } } diff --git a/src/functions/public/Meta/Get-GitHubRoot.ps1 b/src/functions/public/Meta/Get-GitHubRoot.ps1 index 566100b1f..86b4ff457 100644 --- a/src/functions/public/Meta/Get-GitHubRoot.ps1 +++ b/src/functions/public/Meta/Get-GitHubRoot.ps1 @@ -30,18 +30,14 @@ } process { - try { - $inputObject = @{ - Context = $Context - APIEndpoint = '/' - Method = 'GET' - } - - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } - } catch { - throw $_ + $inputObject = @{ + Method = 'GET' + APIEndpoint = '/' + Context = $Context + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } } diff --git a/src/functions/public/Meta/Get-GitHubZen.ps1 b/src/functions/public/Meta/Get-GitHubZen.ps1 index 63cb00157..9945b8cdc 100644 --- a/src/functions/public/Meta/Get-GitHubZen.ps1 +++ b/src/functions/public/Meta/Get-GitHubZen.ps1 @@ -30,18 +30,14 @@ } process { - try { - $inputObject = @{ - Context = $Context - APIEndpoint = '/zen' - Method = 'GET' - } - - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } - } catch { - throw $_ + $inputObject = @{ + Method = 'GET' + APIEndpoint = '/zen' + Context = $Context + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } } diff --git a/src/functions/public/Organization/Get-GitHubOrganization.ps1 b/src/functions/public/Organization/Get-GitHubOrganization.ps1 index 962f71944..c715eac9e 100644 --- a/src/functions/public/Organization/Get-GitHubOrganization.ps1 +++ b/src/functions/public/Organization/Get-GitHubOrganization.ps1 @@ -33,7 +33,7 @@ [List organizations](https://docs.github.com/rest/orgs/orgs) #> [OutputType([pscustomobject])] - [CmdletBinding(DefaultParameterSetName = '__DefaultSet')] + [CmdletBinding(DefaultParameterSetName = '__AllParameterSets')] [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSReviewUnusedParameter', 'All', Justification = 'Required for parameter set')] param( # The organization name. The name is not case sensitive. @@ -42,9 +42,6 @@ ParameterSetName = 'NamedOrg', ValueFromPipelineByPropertyName )] - [Alias('login')] - [Alias('org')] - [Alias('owner')] [string] $Organization, # The handle for the GitHub user account. @@ -69,7 +66,7 @@ # The number of results per page (max 100). [Parameter(ParameterSetName = 'AllOrg')] [Parameter(ParameterSetName = 'UserOrg')] - [Parameter(ParameterSetName = '__DefaultSet')] + [Parameter(ParameterSetName = '__AllParameterSets')] [ValidateRange(0, 100)] [int] $PerPage, @@ -92,24 +89,19 @@ } process { - try { - - switch ($PSCmdlet.ParameterSetName) { - '__DefaultSet' { - Get-GitHubMyOrganization -PerPage $PerPage -Context $Context | Get-GitHubOrganizationByName -Context $Context - } - 'NamedOrg' { - Get-GitHubOrganizationByName -Organization $Organization -Context $Context - } - 'NamedUser' { - Get-GitHubUserOrganization -Username $Username -Context $Context - } - 'AllOrg' { - Get-GitHubAllOrganization -Since $Since -PerPage $PerPage -Context $Context - } + switch ($PSCmdlet.ParameterSetName) { + 'NamedOrg' { + Get-GitHubOrganizationByName -Organization $Organization -Context $Context + } + 'NamedUser' { + Get-GitHubUserOrganization -Username $Username -Context $Context + } + 'AllOrg' { + Get-GitHubAllOrganization -Since $Since -PerPage $PerPage -Context $Context + } + default { + Get-GitHubMyOrganization -PerPage $PerPage -Context $Context | Get-GitHubOrganizationByName -Context $Context } - } catch { - throw $_ } } diff --git a/src/functions/public/Organization/Members/Get-GitHubOrganizationMember.ps1 b/src/functions/public/Organization/Members/Get-GitHubOrganizationMember.ps1 index 05f0f1c51..6b8cdf5c8 100644 --- a/src/functions/public/Organization/Members/Get-GitHubOrganizationMember.ps1 +++ b/src/functions/public/Organization/Members/Get-GitHubOrganizationMember.ps1 @@ -15,7 +15,6 @@ param( # The organization name. The name is not case sensitive. [Parameter(Mandatory)] - [Alias('Org')] [string] $Organization, # Filter members returned in the list. @@ -46,33 +45,24 @@ Write-Debug "[$stackPath] - Start" $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - - if ([string]::IsNullOrEmpty($Owner)) { - $Owner = $Context.Owner - } - Write-Debug "Owner: [$Owner]" } process { - try { - $body = @{ - filter = $Filter - role = $Role - per_page = $PerPage - } + $body = @{ + filter = $Filter + role = $Role + per_page = $PerPage + } - $inputObject = @{ - Context = $Context - Body = $body - Method = 'Get' - APIEndpoint = "/orgs/$Organization/members" - } + $inputObject = @{ + Method = 'GET' + APIEndpoint = "/orgs/$Organization/members" + Body = $body + Context = $Context + } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } - } catch { - throw $_ + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } } diff --git a/src/functions/public/Organization/Members/Get-GitHubOrganizationPendingInvitation.ps1 b/src/functions/public/Organization/Members/Get-GitHubOrganizationPendingInvitation.ps1 index 6b44e355a..242b6a036 100644 --- a/src/functions/public/Organization/Members/Get-GitHubOrganizationPendingInvitation.ps1 +++ b/src/functions/public/Organization/Members/Get-GitHubOrganizationPendingInvitation.ps1 @@ -26,7 +26,6 @@ param( # The organization name. The name is not case sensitive. [Parameter(Mandatory)] - [Alias('Org')] [string] $Organization, # Filter invitations by their member role. @@ -55,33 +54,24 @@ Write-Debug "[$stackPath] - Start" $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - - if ([string]::IsNullOrEmpty($Owner)) { - $Owner = $Context.Owner - } - Write-Debug "Owner: [$Owner]" } process { - try { - $body = @{ - role = $Role - invitation_source = $InvitationSource - per_page = $PerPage - } + $body = @{ + role = $Role + invitation_source = $InvitationSource + per_page = $PerPage + } - $inputObject = @{ - Context = $Context - Body = $body - Method = 'Get' - APIEndpoint = "/orgs/$Organization/invitations" - } + $inputObject = @{ + Method = 'GET' + APIEndpoint = "/orgs/$Organization/invitations" + Body = $body + Context = $Context + } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } - } catch { - throw $_ + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } } diff --git a/src/functions/public/Organization/Members/New-GitHubOrganizationInvitation.ps1 b/src/functions/public/Organization/Members/New-GitHubOrganizationInvitation.ps1 index 65b05a70e..128a7d0f6 100644 --- a/src/functions/public/Organization/Members/New-GitHubOrganizationInvitation.ps1 +++ b/src/functions/public/Organization/Members/New-GitHubOrganizationInvitation.ps1 @@ -29,7 +29,6 @@ param( # The organization name. The name is not case sensitive. [Parameter(Mandatory)] - [Alias('Org')] [string] $Organization, # GitHub user ID for the person you are inviting. @@ -74,37 +73,28 @@ Write-Debug "[$stackPath] - Start" $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - - if ([string]::IsNullOrEmpty($Owner)) { - $Owner = $Context.Owner - } - Write-Debug "Owner: [$Owner]" } process { - try { - $body = @{ - invitee_id = $PSBoundParameters.ContainsKey('InviteeID') ? $InviteeID : $null - email = $Email - role = $Role - team_ids = $TeamIDs - } - $body | Remove-HashtableEntry -NullOrEmptyValues + $body = @{ + invitee_id = $PSBoundParameters.ContainsKey('InviteeID') ? $InviteeID : $null + email = $Email + role = $Role + team_ids = $TeamIDs + } + $body | Remove-HashtableEntry -NullOrEmptyValues - $inputObject = @{ - Context = $Context - Body = $body - Method = 'post' - APIEndpoint = "/orgs/$Organization/invitations" - } + $inputObject = @{ + Method = 'POST' + APIEndpoint = "/orgs/$Organization/invitations" + Body = $body + Context = $Context + } - if ($PSCmdlet.ShouldProcess("$InviteeID$Email to organization $Organization", 'Invite')) { - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } + if ($PSCmdlet.ShouldProcess("$InviteeID$Email to organization $Organization", 'Invite')) { + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } - } catch { - throw $_ } } diff --git a/src/functions/public/Organization/Members/Remove-GitHubOrganizationInvitation.ps1 b/src/functions/public/Organization/Members/Remove-GitHubOrganizationInvitation.ps1 index 183ebdf38..38f4ba031 100644 --- a/src/functions/public/Organization/Members/Remove-GitHubOrganizationInvitation.ps1 +++ b/src/functions/public/Organization/Members/Remove-GitHubOrganizationInvitation.ps1 @@ -22,7 +22,6 @@ param( # The organization name. The name is not case sensitive. [Parameter(Mandatory)] - [Alias('Org')] [string] $Organization, # The unique identifier of the invitation. @@ -44,24 +43,14 @@ } process { - try { - $inputObject = @{ - Context = $Context - APIEndpoint = "/orgs/$Organization/invitations/$ID" - Method = 'DELETE' - } + $inputObject = @{ + Method = 'DELETE' + APIEndpoint = "/orgs/$Organization/invitations/$ID" + Context = $Context + } - try { - if ($PSCmdlet.ShouldProcess('GitHub Organization invitation', 'Remove')) { - $null = (Invoke-GitHubAPI @inputObject) - } - return $true - } catch { - Write-Error $_.Exception.Response - throw $_ - } - } catch { - throw $_ + if ($PSCmdlet.ShouldProcess('GitHub Organization invitation', 'Remove')) { + Invoke-GitHubAPI @inputObject } } diff --git a/src/functions/public/Organization/Remove-GitHubOrganization.ps1 b/src/functions/public/Organization/Remove-GitHubOrganization.ps1 index 1bab1df3c..b0443d96f 100644 --- a/src/functions/public/Organization/Remove-GitHubOrganization.ps1 +++ b/src/functions/public/Organization/Remove-GitHubOrganization.ps1 @@ -26,9 +26,6 @@ ValueFromPipeline, ValueFromPipelineByPropertyName )] - [Alias('org')] - [Alias('owner')] - [Alias('login')] [string] $Organization, # The context to run the command in. Used to get the details for the API call. @@ -42,28 +39,19 @@ Write-Debug "[$stackPath] - Start" $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - - if ([string]::IsNullOrEmpty($Owner)) { - $Owner = $Context.Owner - } - Write-Debug "Owner: [$Owner]" } process { - try { - $inputObject = @{ - Context = $Context - APIEndpoint = "/orgs/$Organization" - Method = 'DELETE' - } + $inputObject = @{ + Method = 'DELETE' + APIEndpoint = "/orgs/$Organization" + Context = $Context + } - if ($PSCmdlet.ShouldProcess("organization [$Organization]", 'Delete')) { - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } + if ($PSCmdlet.ShouldProcess("organization [$Organization]", 'DELETE')) { + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } - } catch { - throw $_ } } diff --git a/src/functions/public/Organization/Update-GitHubOrganization.ps1 b/src/functions/public/Organization/Update-GitHubOrganization.ps1 index b35e250f1..a3d6ecd55 100644 --- a/src/functions/public/Organization/Update-GitHubOrganization.ps1 +++ b/src/functions/public/Organization/Update-GitHubOrganization.ps1 @@ -14,9 +14,9 @@ .EXAMPLE $param = @{ - Organization = 'GitHub' - MembersCanCreatePublicRepositories = $true - MembersCanCreatePrivateRepositories = $true + Organization = 'GitHub' + MembersCanCreatePublicRepositories = $true + MembersCanCreatePrivateRepositories = $true MembersCanCreateInternalRepositories = $true } Update-GitHubOrganization @param @@ -40,9 +40,6 @@ ValueFromPipeline, ValueFromPipelineByPropertyName )] - [Alias('org')] - [Alias('owner')] - [Alias('login')] [string] $Organization, # Billing email address. This address is not publicized. @@ -176,56 +173,47 @@ Write-Debug "[$stackPath] - Start" $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - - if ([string]::IsNullOrEmpty($Owner)) { - $Owner = $Context.Owner - } - Write-Debug "Owner: [$Owner]" } process { - try { - $body = @{ - name = $Name - billing_email = $BillingEmail - blog = $Blog - company = $Company - description = $Description - email = $Email - location = $Location - twitter_username = $TwitterUsername - has_organization_projects = $PSBoundParameters.ContainsKey('HasOrganizationProjects') ? $HasOrganizationProjects : $null - has_repository_projects = $PSBoundParameters.ContainsKey('HasRepositoryProjects') ? $HasRepositoryProjects : $null - default_repository_permission = $PSBoundParameters.ContainsKey('DefaultRepositoryPermission') ? $DefaultRepositoryPermission : $null - members_can_create_repositories = $PSBoundParameters.ContainsKey('MembersCanCreateRepositories') ? $MembersCanCreateRepositories : $null - members_can_create_internal_repositories = $PSBoundParameters.ContainsKey('MembersCanCreateInternalRepositories') ? $MembersCanCreateInternalRepositories : $null - members_can_create_private_repositories = $PSBoundParameters.ContainsKey('MembersCanCreatePrivateRepositories') ? $MembersCanCreatePrivateRepositories : $null - members_can_create_public_repositories = $PSBoundParameters.ContainsKey('MembersCanCreatePublicRepositories') ? $MembersCanCreatePublicRepositories : $null - members_can_create_pages = $PSBoundParameters.ContainsKey('MembersCanCreatePages') ? $MembersCanCreatePages : $null - members_can_create_public_pages = $PSBoundParameters.ContainsKey('MembersCanCreatePublicPages') ? $MembersCanCreatePublicPages : $null - members_can_create_private_pages = $PSBoundParameters.ContainsKey('MembersCanCreatePrivatePages') ? $MembersCanCreatePrivatePages : $null - members_can_fork_private_repositories = $PSBoundParameters.ContainsKey('MembersCanForkPrivateRepositories') ? $MembersCanForkPrivateRepositories : $null - web_commit_signoff_required = $PSBoundParameters.ContainsKey('WebCommitSignoffRequired') ? $WebCommitSignoffRequired : $null - secret_scanning_push_protection_enabled_for_new_repositories = $PSBoundParameters.ContainsKey('SecretScanningPushProtectionEnabledForNewRepositories') ? $SecretScanningPushProtectionEnabledForNewRepositories : $null - secret_scanning_push_protection_custom_link_enabled = $PSBoundParameters.ContainsKey('SecretScanningPushProtectionCustomLinkEnabled') ? $SecretScanningPushProtectionCustomLinkEnabled : $null - secret_scanning_push_protection_custom_link = $PSBoundParameters.ContainsKey('SecretScanningPushProtectionCustomLink') ? $SecretScanningPushProtectionCustomLink : $null - } - $body | Remove-HashtableEntry -NullOrEmptyValues + $body = @{ + name = $Name + billing_email = $BillingEmail + blog = $Blog + company = $Company + description = $Description + email = $Email + location = $Location + twitter_username = $TwitterUsername + has_organization_projects = $PSBoundParameters.ContainsKey('HasOrganizationProjects') ? $HasOrganizationProjects : $null + has_repository_projects = $PSBoundParameters.ContainsKey('HasRepositoryProjects') ? $HasRepositoryProjects : $null + default_repository_permission = $PSBoundParameters.ContainsKey('DefaultRepositoryPermission') ? $DefaultRepositoryPermission : $null + members_can_create_repositories = $PSBoundParameters.ContainsKey('MembersCanCreateRepositories') ? $MembersCanCreateRepositories : $null + members_can_create_internal_repositories = $PSBoundParameters.ContainsKey('MembersCanCreateInternalRepositories') ? $MembersCanCreateInternalRepositories : $null + members_can_create_private_repositories = $PSBoundParameters.ContainsKey('MembersCanCreatePrivateRepositories') ? $MembersCanCreatePrivateRepositories : $null + members_can_create_public_repositories = $PSBoundParameters.ContainsKey('MembersCanCreatePublicRepositories') ? $MembersCanCreatePublicRepositories : $null + members_can_create_pages = $PSBoundParameters.ContainsKey('MembersCanCreatePages') ? $MembersCanCreatePages : $null + members_can_create_public_pages = $PSBoundParameters.ContainsKey('MembersCanCreatePublicPages') ? $MembersCanCreatePublicPages : $null + members_can_create_private_pages = $PSBoundParameters.ContainsKey('MembersCanCreatePrivatePages') ? $MembersCanCreatePrivatePages : $null + members_can_fork_private_repositories = $PSBoundParameters.ContainsKey('MembersCanForkPrivateRepositories') ? $MembersCanForkPrivateRepositories : $null + web_commit_signoff_required = $PSBoundParameters.ContainsKey('WebCommitSignoffRequired') ? $WebCommitSignoffRequired : $null + secret_scanning_push_protection_enabled_for_new_repositories = $PSBoundParameters.ContainsKey('SecretScanningPushProtectionEnabledForNewRepositories') ? $SecretScanningPushProtectionEnabledForNewRepositories : $null + secret_scanning_push_protection_custom_link_enabled = $PSBoundParameters.ContainsKey('SecretScanningPushProtectionCustomLinkEnabled') ? $SecretScanningPushProtectionCustomLinkEnabled : $null + secret_scanning_push_protection_custom_link = $PSBoundParameters.ContainsKey('SecretScanningPushProtectionCustomLink') ? $SecretScanningPushProtectionCustomLink : $null + } + $body | Remove-HashtableEntry -NullOrEmptyValues - $inputObject = @{ - Context = $Context - APIEndpoint = "/orgs/$Organization" - Method = 'PATCH' - Body = $body - } + $inputObject = @{ + Method = 'PATCH' + APIEndpoint = "/orgs/$Organization" + Body = $body + Context = $Context + } - if ($PSCmdlet.ShouldProcess("organization [$Organization]", 'Set')) { - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } + if ($PSCmdlet.ShouldProcess("organization [$Organization]", 'Set')) { + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } - } catch { - throw $_ } } diff --git a/src/functions/public/Organization/Update-GitHubOrganizationSecurityFeature.ps1 b/src/functions/public/Organization/Update-GitHubOrganizationSecurityFeature.ps1 index 44bd8682e..c087c6734 100644 --- a/src/functions/public/Organization/Update-GitHubOrganizationSecurityFeature.ps1 +++ b/src/functions/public/Organization/Update-GitHubOrganizationSecurityFeature.ps1 @@ -27,9 +27,6 @@ param( # The organization name. The name is not case sensitive. [Parameter(Mandatory)] - [Alias('org')] - [Alias('owner')] - [Alias('login')] [string] $Organization, # The security feature to enable or disable. @@ -79,33 +76,24 @@ Write-Debug "[$stackPath] - Start" $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - - if ([string]::IsNullOrEmpty($Owner)) { - $Owner = $Context.Owner - } - Write-Debug "Owner: [$Owner]" } process { - try { - $body = @{ - query_suite = $QuerySuite - } + $body = @{ + query_suite = $QuerySuite + } - $inputObject = @{ - Context = $Context - APIEndpoint = "/orgs/$Organization/$SecurityProduct/$Enablement" - Method = 'POST' - Body = $body - } + $inputObject = @{ + Method = 'POST' + APIEndpoint = "/orgs/$Organization/$SecurityProduct/$Enablement" + Body = $body + Context = $Context + } - if ($PSCmdlet.ShouldProcess("security feature [$SecurityProduct] on organization [$Organization]", 'Set')) { - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } + if ($PSCmdlet.ShouldProcess("security feature [$SecurityProduct] on organization [$Organization]", 'Set')) { + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } - } catch { - throw $_ } } diff --git a/src/functions/public/Rate-Limit/Get-GitHubRateLimit.ps1 b/src/functions/public/Rate-Limit/Get-GitHubRateLimit.ps1 index 4fbb270c2..de7da0229 100644 --- a/src/functions/public/Rate-Limit/Get-GitHubRateLimit.ps1 +++ b/src/functions/public/Rate-Limit/Get-GitHubRateLimit.ps1 @@ -48,18 +48,14 @@ } process { - try { - $inputObject = @{ - Context = $Context - APIEndpoint = '/rate_limit' - Method = 'GET' - } + $inputObject = @{ + Method = 'GET' + APIEndpoint = '/rate_limit' + Context = $Context + } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response.Resources - } - } catch { - throw $_ + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response.Resources } } diff --git a/src/functions/public/Releases/Assets/Add-GitHubReleaseAsset.ps1 b/src/functions/public/Releases/Assets/Add-GitHubReleaseAsset.ps1 index c488874d8..b52da2c5e 100644 --- a/src/functions/public/Releases/Assets/Add-GitHubReleaseAsset.ps1 +++ b/src/functions/public/Releases/Assets/Add-GitHubReleaseAsset.ps1 @@ -37,7 +37,7 @@ the old file before you can re-upload the new asset. .EXAMPLE - Add-GitHubReleaseAsset -Owner 'octocat' -Repo 'hello-world' -ID '7654321' -FilePath 'C:\Users\octocat\Downloads\hello-world.zip' + Add-GitHubReleaseAsset -Owner 'octocat' -Repository 'hello-world' -ID '7654321' -FilePath 'C:\Users\octocat\Downloads\hello-world.zip' Gets the release assets for the release with the ID '1234567' for the repository 'octocat/hello-world'. @@ -47,12 +47,14 @@ [CmdletBinding()] param( # The account owner of the repository. The name is not case sensitive. - [Parameter()] + [Parameter(Mandatory)] + [Alias('Organization')] + [Alias('User')] [string] $Owner, # The name of the repository without the .git extension. The name is not case sensitive. - [Parameter()] - [string] $Repo, + [Parameter(Mandatory)] + [string] $Repository, # The unique identifier of the release. [Parameter(Mandatory)] @@ -73,7 +75,7 @@ # The path to the asset file. [Parameter(Mandatory)] - [alias('fullname')] + [alias('FullName')] [string] $FilePath, # The context to run the command in. Used to get the details for the API call. @@ -87,70 +89,56 @@ Write-Debug "[$stackPath] - Start" $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - - if ([string]::IsNullOrEmpty($Owner)) { - $Owner = $Context.Owner - } - Write-Debug "Owner: [$Owner]" - - if ([string]::IsNullOrEmpty($Repo)) { - $Repo = $Context.Repo - } - Write-Debug "Repo: [$Repo]" } process { - try { - # If name is not provided, use the name of the file - if (!$Name) { - $Name = (Get-Item $FilePath).Name - } + # If name is not provided, use the name of the file + if (!$Name) { + $Name = (Get-Item $FilePath).Name + } - # If label is not provided, use the name of the file - if (!$Label) { - $Label = (Get-Item $FilePath).Name - } + # If label is not provided, use the name of the file + if (!$Label) { + $Label = (Get-Item $FilePath).Name + } - # If content type is not provided, use the file extension - if (!$ContentType) { - $ContentType = switch ((Get-Item $FilePath).Extension) { - '.zip' { 'application/zip' } - '.tar' { 'application/x-tar' } - '.gz' { 'application/gzip' } - '.bz2' { 'application/x-bzip2' } - '.xz' { 'application/x-xz' } - '.7z' { 'application/x-7z-compressed' } - '.rar' { 'application/vnd.rar' } - '.tar.gz' { 'application/gzip' } - '.tgz' { 'application/gzip' } - '.tar.bz2' { 'application/x-bzip2' } - '.tar.xz' { 'application/x-xz' } - '.tar.7z' { 'application/x-7z-compressed' } - '.tar.rar' { 'application/vnd.rar' } - '.png' { 'image/png' } - '.json' { 'application/json' } - '.txt' { 'text/plain' } - '.md' { 'text/markdown' } - '.html' { 'text/html' } - default { 'application/octet-stream' } - } + # If content type is not provided, use the file extension + if (!$ContentType) { + $ContentType = switch ((Get-Item $FilePath).Extension) { + '.zip' { 'application/zip' } + '.tar' { 'application/x-tar' } + '.gz' { 'application/gzip' } + '.bz2' { 'application/x-bzip2' } + '.xz' { 'application/x-xz' } + '.7z' { 'application/x-7z-compressed' } + '.rar' { 'application/vnd.rar' } + '.tar.gz' { 'application/gzip' } + '.tgz' { 'application/gzip' } + '.tar.bz2' { 'application/x-bzip2' } + '.tar.xz' { 'application/x-xz' } + '.tar.7z' { 'application/x-7z-compressed' } + '.tar.rar' { 'application/vnd.rar' } + '.png' { 'image/png' } + '.json' { 'application/json' } + '.txt' { 'text/plain' } + '.md' { 'text/markdown' } + '.html' { 'text/html' } + default { 'application/octet-stream' } } + } - $release = Get-GitHubRelease -Owner $Owner -Repo $Repo -ID $ID - $uploadURI = $release.upload_url -replace '{\?name,label}', "?name=$($Name)&label=$($Label)" + $release = Get-GitHubRelease -Owner $Owner -Repository $Repository -ID $ID + $uploadURI = $release.upload_url -replace '{\?name,label}', "?name=$($Name)&label=$($Label)" - $inputObject = @{ - URI = $uploadURI - Method = 'POST' - ContentType = $ContentType - UploadFilePath = $FilePath - } + $inputObject = @{ + Method = 'POST' + URI = $uploadURI + ContentType = $ContentType + UploadFilePath = $FilePath + } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } - } catch { - throw $_ + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } } diff --git a/src/functions/public/Releases/Assets/Get-GitHubReleaseAsset.ps1 b/src/functions/public/Releases/Assets/Get-GitHubReleaseAsset.ps1 index 227f7da3d..5106d462b 100644 --- a/src/functions/public/Releases/Assets/Get-GitHubReleaseAsset.ps1 +++ b/src/functions/public/Releases/Assets/Get-GitHubReleaseAsset.ps1 @@ -8,27 +8,29 @@ If a release ID is provided, all assets for the release are returned. .EXAMPLE - Get-GitHubReleaseAsset -Owner 'octocat' -Repo 'hello-world' -ID '1234567' + Get-GitHubReleaseAsset -Owner 'octocat' -Repository 'hello-world' -ID '1234567' Gets the release asset with the ID '1234567' for the repository 'octocat/hello-world'. .EXAMPLE - Get-GitHubReleaseAsset -Owner 'octocat' -Repo 'hello-world' -ReleaseID '7654321' + Get-GitHubReleaseAsset -Owner 'octocat' -Repository 'hello-world' -ReleaseID '7654321' Gets the release assets for the release with the ID '7654321' for the repository 'octocat/hello-world'. .NOTES [Get a release asset](https://docs.github.com/rest/releases/assets#get-a-release-asset) #> - [CmdletBinding()] + [CmdletBinding(DefaultParameterSetName = '__AllParameterSets')] param( # The account owner of the repository. The name is not case sensitive. - [Parameter()] + [Parameter(Mandatory)] + [Alias('Organization')] + [Alias('User')] [string] $Owner, # The name of the repository without the .git extension. The name is not case sensitive. - [Parameter()] - [string] $Repo, + [Parameter(Mandatory)] + [string] $Repository, # The unique identifier of the asset. [Parameter( @@ -57,28 +59,16 @@ Write-Debug "[$stackPath] - Start" $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - - if ([string]::IsNullOrEmpty($Owner)) { - $Owner = $Context.Owner - } - Write-Debug "Owner: [$Owner]" - - if ([string]::IsNullOrEmpty($Repo)) { - $Repo = $Context.Repo - } - Write-Debug "Repo: [$Repo]" } process { - try { - if ($ReleaseID) { - Get-GitHubReleaseAssetByReleaseID -Owner $Owner -Repo $Repo -ReleaseID $ReleaseID -Context $Context + switch ($PSCmdlet.ParameterSetName) { + 'ReleaseID' { + Get-GitHubReleaseAssetByReleaseID -Owner $Owner -Repository $Repository -ReleaseID $ReleaseID -Context $Context } - if ($ID) { - Get-GitHubReleaseAssetByID -Owner $Owner -Repo $Repo -ID $ID -Context $Context + 'ID' { + Get-GitHubReleaseAssetByID -Owner $Owner -Repository $Repository -ID $ID -Context $Context } - } catch { - throw $_ } } diff --git a/src/functions/public/Releases/Assets/Remove-GitHubReleaseAsset.ps1 b/src/functions/public/Releases/Assets/Remove-GitHubReleaseAsset.ps1 index 9caa5feed..b6eaecfe8 100644 --- a/src/functions/public/Releases/Assets/Remove-GitHubReleaseAsset.ps1 +++ b/src/functions/public/Releases/Assets/Remove-GitHubReleaseAsset.ps1 @@ -7,7 +7,7 @@ Delete a release asset .EXAMPLE - Remove-GitHubReleaseAsset -Owner 'octocat' -Repo 'hello-world' -ID '1234567' + Remove-GitHubReleaseAsset -Owner 'octocat' -Repository 'hello-world' -ID '1234567' Deletes the release asset with the ID '1234567' for the repository 'octocat/hello-world'. @@ -17,12 +17,14 @@ [CmdletBinding(SupportsShouldProcess)] param( # The account owner of the repository. The name is not case sensitive. - [Parameter()] + [Parameter(Mandatory)] + [Alias('Organization')] + [Alias('User')] [string] $Owner, # The name of the repository without the .git extension. The name is not case sensitive. - [Parameter()] - [string] $Repo, + [Parameter(Mandatory)] + [string] $Repository, # The unique identifier of the asset. [Parameter(Mandatory)] @@ -40,33 +42,19 @@ Write-Debug "[$stackPath] - Start" $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - - if ([string]::IsNullOrEmpty($Owner)) { - $Owner = $Context.Owner - } - Write-Debug "Owner: [$Owner]" - - if ([string]::IsNullOrEmpty($Repo)) { - $Repo = $Context.Repo - } - Write-Debug "Repo: [$Repo]" } process { - try { - $inputObject = @{ - Context = $Context - APIEndpoint = "/repos/$Owner/$Repo/releases/assets/$ID" - Method = 'DELETE' - } + $inputObject = @{ + Method = 'DELETE' + APIEndpoint = "/repos/$Owner/$Repository/releases/assets/$ID" + Context = $Context + } - if ($PSCmdlet.ShouldProcess("Asset with ID [$ID] in [$Owner/$Repo]", 'Delete')) { - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } + if ($PSCmdlet.ShouldProcess("Asset with ID [$ID] in [$Owner/$Repository]", 'DELETE')) { + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } - } catch { - throw $_ } } diff --git a/src/functions/public/Releases/Assets/Set-GitHubReleaseAsset.ps1 b/src/functions/public/Releases/Assets/Set-GitHubReleaseAsset.ps1 index 52ad07ce7..a5def48de 100644 --- a/src/functions/public/Releases/Assets/Set-GitHubReleaseAsset.ps1 +++ b/src/functions/public/Releases/Assets/Set-GitHubReleaseAsset.ps1 @@ -7,7 +7,7 @@ Users with push access to the repository can edit a release asset. .EXAMPLE - Set-GitHubReleaseAsset -Owner 'octocat' -Repo 'hello-world' -ID '1234567' -Name 'new_asset_name' -Label 'new_asset_label' + Set-GitHubReleaseAsset -Owner 'octocat' -Repository 'hello-world' -ID '1234567' -Name 'new_asset_name' -Label 'new_asset_label' Updates the release asset with the ID '1234567' for the repository 'octocat/hello-world' with the new name 'new_asset_name' and label 'new_asset_label'. @@ -18,12 +18,14 @@ [CmdletBinding(SupportsShouldProcess)] param( # The account owner of the repository. The name is not case sensitive. - [Parameter()] + [Parameter(Mandatory)] + [Alias('Organization')] + [Alias('User')] [string] $Owner, # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo, + [string] $Repository, # The unique identifier of the asset. [Parameter(Mandatory)] @@ -54,41 +56,27 @@ Write-Debug "[$stackPath] - Start" $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - - if ([string]::IsNullOrEmpty($Owner)) { - $Owner = $Context.Owner - } - Write-Debug "Owner: [$Owner]" - - if ([string]::IsNullOrEmpty($Repo)) { - $Repo = $Context.Repo - } - Write-Debug "Repo: [$Repo]" } process { - try { - $body = @{ - name = $Name - label = $Label - state = $State - } - $body | Remove-HashtableEntry -NullOrEmptyValues + $body = @{ + name = $Name + label = $Label + state = $State + } + $body | Remove-HashtableEntry -NullOrEmptyValues - $inputObject = @{ - Context = $Context - APIEndpoint = "/repos/$Owner/$Repo/releases/assets/$ID" - Method = 'PATCH' - Body = $body - } + $inputObject = @{ + Method = 'PATCH' + APIEndpoint = "/repos/$Owner/$Repository/releases/assets/$ID" + Body = $body + Context = $Context + } - if ($PSCmdlet.ShouldProcess("assets for release with ID [$ID] in [$Owner/$Repo]", 'Set')) { - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } + if ($PSCmdlet.ShouldProcess("assets for release with ID [$ID] in [$Owner/$Repository]", 'Set')) { + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } - } catch { - throw $_ } } diff --git a/src/functions/public/Releases/Releases/Get-GitHubRelease.ps1 b/src/functions/public/Releases/Releases/Get-GitHubRelease.ps1 index 7b228b075..ede7522d6 100644 --- a/src/functions/public/Releases/Releases/Get-GitHubRelease.ps1 +++ b/src/functions/public/Releases/Releases/Get-GitHubRelease.ps1 @@ -9,22 +9,22 @@ Information about published releases are available to everyone. Only users with push access will receive listings for draft releases. .EXAMPLE - Get-GitHubRelease -Owner 'octocat' -Repo 'hello-world' + Get-GitHubRelease -Owner 'octocat' -Repository 'hello-world' Gets the releases for the repository 'hello-world' owned by 'octocat'. .EXAMPLE - Get-GitHubRelease -Owner 'octocat' -Repo 'hello-world' -Latest + Get-GitHubRelease -Owner 'octocat' -Repository 'hello-world' -Latest Gets the latest releases for the repository 'hello-world' owned by 'octocat'. .EXAMPLE - Get-GitHubRelease -Owner 'octocat' -Repo 'hello-world' -Tag 'v1.0.0' + Get-GitHubRelease -Owner 'octocat' -Repository 'hello-world' -Tag 'v1.0.0' Gets the release with the tag 'v1.0.0' for the repository 'hello-world' owned by 'octocat'. .EXAMPLE - Get-GitHubRelease -Owner 'octocat' -Repo 'hello-world' -ID '1234567' + Get-GitHubRelease -Owner 'octocat' -Repository 'hello-world' -ID '1234567' Gets the release with the ID '1234567' for the repository 'hello-world' owned by 'octocat'. @@ -36,12 +36,14 @@ [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSReviewUnusedParameter', 'Latest', Justification = 'Required for parameter set')] param( # The account owner of the repository. The name is not case sensitive. - [Parameter()] + [Parameter(Mandatory)] + [Alias('Organization')] + [Alias('User')] [string] $Owner, # The name of the repository without the .git extension. The name is not case sensitive. - [Parameter()] - [string] $Repo, + [Parameter(Mandatory)] + [string] $Repository, # The number of results per page (max 100). [Parameter(ParameterSetName = 'All')] @@ -82,37 +84,24 @@ Write-Debug "[$stackPath] - Start" $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - - if ([string]::IsNullOrEmpty($Owner)) { - $Owner = $Context.Owner - } - Write-Debug "Owner: [$Owner]" - - if ([string]::IsNullOrEmpty($Repo)) { - $Repo = $Context.Repo - } - Write-Debug "Repo: [$Repo]" } process { - try { - switch ($PSCmdlet.ParameterSetName) { - 'All' { - Get-GitHubReleaseAll -Owner $Owner -Repo $Repo -PerPage $PerPage -Context $Context - } - 'Latest' { - Get-GitHubReleaseLatest -Owner $Owner -Repo $Repo -Context $Context - } - 'Tag' { - Get-GitHubReleaseByTagName -Owner $Owner -Repo $Repo -Tag $Tag -Context $Context - } - 'ID' { - Get-GitHubReleaseByID -Owner $Owner -Repo $Repo -ID $ID -Context $Context - } + switch ($PSCmdlet.ParameterSetName) { + 'All' { + Get-GitHubReleaseAll -Owner $Owner -Repository $Repository -PerPage $PerPage -Context $Context + } + 'Latest' { + Get-GitHubReleaseLatest -Owner $Owner -Repository $Repository -Context $Context + } + 'Tag' { + Get-GitHubReleaseByTagName -Owner $Owner -Repository $Repository -Tag $Tag -Context $Context + } + 'ID' { + Get-GitHubReleaseByID -Owner $Owner -Repository $Repository -ID $ID -Context $Context } - } catch { - throw $_ } + } end { diff --git a/src/functions/public/Releases/Releases/New-GitHubRelease.ps1 b/src/functions/public/Releases/Releases/New-GitHubRelease.ps1 index 7b73687c1..021a3900a 100644 --- a/src/functions/public/Releases/Releases/New-GitHubRelease.ps1 +++ b/src/functions/public/Releases/Releases/New-GitHubRelease.ps1 @@ -11,7 +11,7 @@ and "[Dealing with secondary rate limits](https://docs.github.com/rest/guides/best-practices-for-integrators#dealing-with-secondary-rate-limits)" for details. .EXAMPLE - New-GitHubRelease -Owner 'octocat' -Repo 'hello-world' -TagName 'v1.0.0' -TargetCommitish 'main' -Body 'Release notes' + New-GitHubRelease -Owner 'octocat' -Repository 'hello-world' -TagName 'v1.0.0' -TargetCommitish 'main' -Body 'Release notes' Creates a release for the repository 'octocat/hello-world' with the tag 'v1.0.0' and the target commitish 'main'. @@ -23,12 +23,14 @@ [CmdletBinding(SupportsShouldProcess)] param( # The account owner of the repository. The name is not case sensitive. - [Parameter()] + [Parameter(Mandatory)] + [Alias('Organization')] + [Alias('User')] [string] $Owner, # The name of the repository without the .git extension. The name is not case sensitive. - [Parameter()] - [string] $Repo, + [Parameter(Mandatory)] + [string] $Repository, # The name of the tag. [Parameter(Mandatory)] @@ -87,47 +89,33 @@ Write-Debug "[$stackPath] - Start" $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - - if ([string]::IsNullOrEmpty($Owner)) { - $Owner = $Context.Owner - } - Write-Debug "Owner: [$Owner]" - - if ([string]::IsNullOrEmpty($Repo)) { - $Repo = $Context.Repo - } - Write-Debug "Repo: [$Repo]" } process { - try { - $requestBody = @{ - tag_name = $TagName - target_commitish = $TargetCommitish - name = $Name - body = $Body - discussion_category_name = $DiscussionCategoryName - make_latest = $MakeLatest - generate_release_notes = $GenerateReleaseNotes - draft = $Draft - prerelease = $Prerelease - } - $requestBody | Remove-HashtableEntry -NullOrEmptyValues + $body = @{ + tag_name = $TagName + target_commitish = $TargetCommitish + name = $Name + body = $Body + discussion_category_name = $DiscussionCategoryName + make_latest = $MakeLatest + generate_release_notes = $GenerateReleaseNotes + draft = $Draft + prerelease = $Prerelease + } + $body | Remove-HashtableEntry -NullOrEmptyValues - $inputObject = @{ - Context = $Context - APIEndpoint = "/repos/$Owner/$Repo/releases" - Method = 'POST' - Body = $requestBody - } + $inputObject = @{ + Method = 'POST' + APIEndpoint = "/repos/$Owner/$Repository/releases" + Body = $body + Context = $Context + } - if ($PSCmdlet.ShouldProcess("$Owner/$Repo", 'Create a release')) { - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } + if ($PSCmdlet.ShouldProcess("$Owner/$Repository", 'Create a release')) { + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } - } catch { - throw $_ } } diff --git a/src/functions/public/Releases/Releases/New-GitHubReleaseNote.ps1 b/src/functions/public/Releases/Releases/New-GitHubReleaseNote.ps1 index 7b7c90a8c..a4ccd2d8f 100644 --- a/src/functions/public/Releases/Releases/New-GitHubReleaseNote.ps1 +++ b/src/functions/public/Releases/Releases/New-GitHubReleaseNote.ps1 @@ -57,12 +57,14 @@ [CmdletBinding(SupportsShouldProcess)] param( # The account owner of the repository. The name is not case sensitive. - [Parameter()] + [Parameter(Mandatory)] + [Alias('Organization')] + [Alias('User')] [string] $Owner, # The name of the repository without the .git extension. The name is not case sensitive. - [Parameter()] - [string] $Repo, + [Parameter(Mandatory)] + [string] $Repository, # The tag name for the release. This can be an existing tag or a new one. [Parameter(Mandatory)] @@ -101,41 +103,27 @@ Write-Debug "[$stackPath] - Start" $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - - if ([string]::IsNullOrEmpty($Owner)) { - $Owner = $Context.Owner - } - Write-Debug "Owner: [$Owner]" - - if ([string]::IsNullOrEmpty($Repo)) { - $Repo = $Context.Repo - } - Write-Debug "Repo: [$Repo]" } process { - try { - $requestBody = @{ - tag_name = $TagName - target_commitish = $TargetCommitish - previous_tag_name = $PreviousTagName - configuration_file_path = $ConfigurationFilePath - } - $requestBody | Remove-HashtableEntry -NullOrEmptyValues + $body = @{ + tag_name = $TagName + target_commitish = $TargetCommitish + previous_tag_name = $PreviousTagName + configuration_file_path = $ConfigurationFilePath + } + $body | Remove-HashtableEntry -NullOrEmptyValues - $inputObject = @{ - APIEndpoint = "/repos/$Owner/$Repo/releases/generate-notes" - Method = 'POST' - Body = $requestBody - } + $inputObject = @{ + Method = 'POST' + APIEndpoint = "/repos/$Owner/$Repository/releases/generate-notes" + Body = $body + } - if ($PSCmdlet.ShouldProcess("$Owner/$Repo", 'Create release notes')) { - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } + if ($PSCmdlet.ShouldProcess("$Owner/$Repository", 'Create release notes')) { + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } - } catch { - throw $_ } } diff --git a/src/functions/public/Releases/Releases/Remove-GitHubRelease.ps1 b/src/functions/public/Releases/Releases/Remove-GitHubRelease.ps1 index 6539d0dc3..1184c427e 100644 --- a/src/functions/public/Releases/Releases/Remove-GitHubRelease.ps1 +++ b/src/functions/public/Releases/Releases/Remove-GitHubRelease.ps1 @@ -7,7 +7,7 @@ Users with push access to the repository can delete a release. .EXAMPLE - Remove-GitHubRelease -Owner 'octocat' -Repo 'hello-world' -ID '1234567' + Remove-GitHubRelease -Owner 'octocat' -Repository 'hello-world' -ID '1234567' Deletes the release with the ID '1234567' for the repository 'octocat/hello-world'. @@ -18,12 +18,14 @@ [CmdletBinding(SupportsShouldProcess)] param( # The account owner of the repository. The name is not case sensitive. - [Parameter()] + [Parameter(Mandatory)] + [Alias('Organization')] + [Alias('User')] [string] $Owner, # The name of the repository without the .git extension. The name is not case sensitive. - [Parameter()] - [string] $Repo, + [Parameter(Mandatory)] + [string] $Repository, # The unique identifier of the release. [Parameter( @@ -43,33 +45,19 @@ Write-Debug "[$stackPath] - Start" $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - - if ([string]::IsNullOrEmpty($Owner)) { - $Owner = $Context.Owner - } - Write-Debug "Owner: [$Owner]" - - if ([string]::IsNullOrEmpty($Repo)) { - $Repo = $Context.Repo - } - Write-Debug "Repo: [$Repo]" } process { - try { - $inputObject = @{ - Context = $Context - APIEndpoint = "/repos/$Owner/$Repo/releases/$ID" - Method = 'DELETE' - } + $inputObject = @{ + Method = 'DELETE' + APIEndpoint = "/repos/$Owner/$Repository/releases/$ID" + Context = $Context + } - if ($PSCmdlet.ShouldProcess("Release with ID [$ID] in [$Owner/$Repo]", 'Delete')) { - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } + if ($PSCmdlet.ShouldProcess("Release with ID [$ID] in [$Owner/$Repository]", 'DELETE')) { + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } - } catch { - throw $_ } } diff --git a/src/functions/public/Releases/Releases/Set-GitHubRelease.ps1 b/src/functions/public/Releases/Releases/Set-GitHubRelease.ps1 index d2517ae57..1559ef234 100644 --- a/src/functions/public/Releases/Releases/Set-GitHubRelease.ps1 +++ b/src/functions/public/Releases/Releases/Set-GitHubRelease.ps1 @@ -7,7 +7,7 @@ Users with push access to the repository can edit a release. .EXAMPLE - Set-GitHubRelease -Owner 'octocat' -Repo 'hello-world' -ID '1234567' -Body 'Release notes' + Set-GitHubRelease -Owner 'octocat' -Repository 'hello-world' -ID '1234567' -Body 'Release notes' Updates the release with the ID '1234567' for the repository 'octocat/hello-world' with the body 'Release notes'. @@ -19,12 +19,14 @@ [CmdletBinding(SupportsShouldProcess)] param( # The account owner of the repository. The name is not case sensitive. - [Parameter()] + [Parameter(Mandatory)] + [Alias('Organization')] + [Alias('User')] [string] $Owner, # The name of the repository without the .git extension. The name is not case sensitive. - [Parameter()] - [string] $Repo, + [Parameter(Mandatory)] + [string] $Repository, # The unique identifier of the release. [Parameter(Mandatory)] @@ -85,46 +87,32 @@ Write-Debug "[$stackPath] - Start" $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - - if ([string]::IsNullOrEmpty($Owner)) { - $Owner = $Context.Owner - } - Write-Debug "Owner: [$Owner]" - - if ([string]::IsNullOrEmpty($Repo)) { - $Repo = $Context.Repo - } - Write-Debug "Repo: [$Repo]" } process { - try { - $requestBody = @{ - tag_name = $TagName - target_commitish = $TargetCommitish - name = $Name - body = $Body - discussion_category_name = $DiscussionCategoryName - make_latest = $MakeLatest - draft = $Draft - prerelease = $Prerelease - } - $requestBody | Remove-HashtableEntry -NullOrEmptyValues + $body = @{ + tag_name = $TagName + target_commitish = $TargetCommitish + name = $Name + body = $Body + discussion_category_name = $DiscussionCategoryName + make_latest = $MakeLatest + draft = $Draft + prerelease = $Prerelease + } + $body | Remove-HashtableEntry -NullOrEmptyValues - $inputObject = @{ - Context = $Context - APIEndpoint = "/repos/$Owner/$Repo/releases/$ID" - Method = 'PATCH' - Body = $requestBody - } + $inputObject = @{ + Method = 'PATCH' + APIEndpoint = "/repos/$Owner/$Repository/releases/$ID" + Body = $body + Context = $Context + } - if ($PSCmdlet.ShouldProcess("release with ID [$ID] in [$Owner/$Repo]", 'Update')) { - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } + if ($PSCmdlet.ShouldProcess("release with ID [$ID] in [$Owner/$Repository]", 'Update')) { + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } - } catch { - throw $_ } } diff --git a/src/functions/public/Repositories/Autolinks/Get-GitHubRepositoryAutolink.ps1 b/src/functions/public/Repositories/Autolinks/Get-GitHubRepositoryAutolink.ps1 index 8f97fa861..eb3d7b079 100644 --- a/src/functions/public/Repositories/Autolinks/Get-GitHubRepositoryAutolink.ps1 +++ b/src/functions/public/Repositories/Autolinks/Get-GitHubRepositoryAutolink.ps1 @@ -9,12 +9,12 @@ Information about autolinks are only available to repository administrators. .EXAMPLE - Get-GitHubRepositoryAutolink -Owner 'octocat' -Repo 'Hello-World' + Get-GitHubRepositoryAutolink -Owner 'octocat' -Repository 'Hello-World' Gets all autolinks for the repository 'Hello-World' owned by 'octocat'. .EXAMPLE - Get-GitHubRepositoryAutolink -Owner 'octocat' -Repo 'Hello-World' -ID 1 + Get-GitHubRepositoryAutolink -Owner 'octocat' -Repository 'Hello-World' -ID 1 Gets the autolink with the ID 1 for the repository 'Hello-World' owned by 'octocat'. @@ -22,25 +22,25 @@ [Get all autolinks of a repository](https://docs.github.com/rest/repos/autolinks#list-all-autolinks-of-a-repository) #> [Alias('Get-GitHubRepositoryAutolinks')] - [CmdletBinding(DefaultParameterSetName = 'Default')] + [CmdletBinding(DefaultParameterSetName = '__AllParameterSets')] param( # The account owner of the repository. The name is not case sensitive. - [Parameter()] - [Alias('org')] + [Parameter(Mandatory)] + [Alias('Organization')] + [Alias('User')] [string] $Owner, # The name of the repository without the .git extension. The name is not case sensitive. - [Parameter()] - [string] $Repo, + [Parameter(Mandatory)] + [string] $Repository, # The unique identifier of the autolink. [Parameter( Mandatory, ParameterSetName = 'ById' )] - [Alias('autolink_id')] - [Alias('ID')] - [int] $AutolinkId, + [Alias('autolink_id', 'AutolinkID')] + [int] $ID, # 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. @@ -53,30 +53,16 @@ Write-Debug "[$stackPath] - Start" $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - - if ([string]::IsNullOrEmpty($Owner)) { - $Owner = $Context.Owner - } - Write-Debug "Owner: [$Owner]" - - if ([string]::IsNullOrEmpty($Repo)) { - $Repo = $Context.Repo - } - Write-Debug "Repo: [$Repo]" } process { - try { - switch ($PSCmdlet.ParameterSetName) { - 'ById' { - Get-GitHubRepositoryAutolinkById -Owner $Owner -Repo $Repo -ID $AutolinkId -Context $Context - } - default { - Get-GitHubRepositoryAutolinkList -Owner $Owner -Repo $Repo -Context $Context - } + switch ($PSCmdlet.ParameterSetName) { + 'ById' { + Get-GitHubRepositoryAutolinkById -Owner $Owner -Repository $Repository -ID $ID -Context $Context + } + default { + Get-GitHubRepositoryAutolinkList -Owner $Owner -Repository $Repository -Context $Context } - } catch { - throw $_ } } diff --git a/src/functions/public/Repositories/Autolinks/New-GitHubRepositoryAutolink.ps1 b/src/functions/public/Repositories/Autolinks/New-GitHubRepositoryAutolink.ps1 index 82e09218f..4ba3ae2dd 100644 --- a/src/functions/public/Repositories/Autolinks/New-GitHubRepositoryAutolink.ps1 +++ b/src/functions/public/Repositories/Autolinks/New-GitHubRepositoryAutolink.ps1 @@ -7,7 +7,7 @@ Users with admin access to the repository can create an autolink. .EXAMPLE - New-GitHubRepositoryAutolink -Owner 'octocat' -Repo 'Hello-World' -KeyPrefix 'GH-' -UrlTemplate 'https://www.example.com/issue/' + New-GitHubRepositoryAutolink -Owner 'octocat' -Repository 'Hello-World' -KeyPrefix 'GH-' -UrlTemplate 'https://www.example.com/issue/' Creates an autolink for the repository 'Hello-World' owned by 'octocat' that links to when the prefix 'GH-' is found in an issue, pull request, or commit. @@ -20,11 +20,13 @@ param( # The account owner of the repository. The name is not case sensitive. [Parameter(Mandatory)] + [Alias('Organization')] + [Alias('User')] [string] $Owner, # The name of the repository without the .git extension. The name is not case sensitive. [Parameter(Mandatory)] - [string] $Repo, + [string] $Repository, # This prefix appended by certain characters will generate a link any time it is found in an issue, pull request, or commit. [Parameter(Mandatory)] @@ -53,40 +55,26 @@ Write-Debug "[$stackPath] - Start" $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - - if ([string]::IsNullOrEmpty($Owner)) { - $Owner = $Context.Owner - } - Write-Debug "Owner: [$Owner]" - - if ([string]::IsNullOrEmpty($Repo)) { - $Repo = $Context.Repo - } - Write-Debug "Repo: [$Repo]" } process { - try { - $body = @{ - key_prefix = $KeyPrefix - url_template = $UrlTemplate - is_alphanumeric = $IsAlphanumeric - } + $body = @{ + key_prefix = $KeyPrefix + url_template = $UrlTemplate + is_alphanumeric = $IsAlphanumeric + } - $inputObject = @{ - Context = $Context - APIEndpoint = "/repos/$Owner/$Repo/autolinks" - Method = 'POST' - Body = $body - } + $inputObject = @{ + Method = 'POST' + APIEndpoint = "/repos/$Owner/$Repository/autolinks" + Body = $body + Context = $Context + } - if ($PSCmdlet.ShouldProcess("Autolink for repository [$Owner/$Repo]", 'Create')) { - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } + if ($PSCmdlet.ShouldProcess("Autolink for repository [$Owner/$Repository]", 'Create')) { + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } - } catch { - throw $_ } } diff --git a/src/functions/public/Repositories/Autolinks/Remove-GitHubRepositoryAutolink.ps1 b/src/functions/public/Repositories/Autolinks/Remove-GitHubRepositoryAutolink.ps1 index 9e3070a34..61828136c 100644 --- a/src/functions/public/Repositories/Autolinks/Remove-GitHubRepositoryAutolink.ps1 +++ b/src/functions/public/Repositories/Autolinks/Remove-GitHubRepositoryAutolink.ps1 @@ -9,7 +9,7 @@ Information about autolinks are only available to repository administrators. .EXAMPLE - Remove-GitHubRepositoryAutolink -Owner 'octocat' -Repo 'Hello-World' -AutolinkId 1 + Remove-GitHubRepositoryAutolink -Owner 'octocat' -Repository 'Hello-World' -AutolinkId 1 Deletes the autolink with ID 1 for the repository 'Hello-World' owned by 'octocat'. @@ -21,17 +21,18 @@ param( # The account owner of the repository. The name is not case sensitive. [Parameter(Mandatory)] + [Alias('Organization')] + [Alias('User')] [string] $Owner, # The name of the repository without the .git extension. The name is not case sensitive. [Parameter(Mandatory)] - [string] $Repo, + [string] $Repository, # The unique identifier of the autolink. [Parameter(Mandatory)] - [Alias('autolink_id')] - [Alias('ID')] - [int] $AutolinkId, + [Alias('autolink_id', 'AutolinkID')] + [int] $ID, # 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. @@ -44,34 +45,20 @@ Write-Debug "[$stackPath] - Start" $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - - if ([string]::IsNullOrEmpty($Owner)) { - $Owner = $Context.Owner - } - Write-Debug "Owner: [$Owner]" - - if ([string]::IsNullOrEmpty($Repo)) { - $Repo = $Context.Repo - } - Write-Debug "Repo: [$Repo]" } process { - try { - $inputObject = @{ - Context = $Context - APIEndpoint = "/repos/$Owner/$Repo/autolinks/$AutolinkId" - Method = 'DELETE' - Body = $body - } + $inputObject = @{ + Method = 'DELETE' + APIEndpoint = "/repos/$Owner/$Repository/autolinks/$ID" + Body = $body + Context = $Context + } - if ($PSCmdlet.ShouldProcess("Autolink with ID [$AutolinkId] for repository [$Owner/$Repo]", 'Delete')) { - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } + if ($PSCmdlet.ShouldProcess("Autolink with ID [$ID] for repository [$Owner/$Repository]", 'DELETE')) { + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } - } catch { - throw $_ } } diff --git a/src/functions/public/Repositories/CustomProperties/Get-GitHubRepositoryCustomProperty.ps1 b/src/functions/public/Repositories/CustomProperties/Get-GitHubRepositoryCustomProperty.ps1 index 0e30677db..ca11ddcd2 100644 --- a/src/functions/public/Repositories/CustomProperties/Get-GitHubRepositoryCustomProperty.ps1 +++ b/src/functions/public/Repositories/CustomProperties/Get-GitHubRepositoryCustomProperty.ps1 @@ -8,7 +8,7 @@ Users with read access to the repository can use this endpoint. .EXAMPLE - Get-GitHubRepositoryCustomProperty -Owner 'octocat' -Repo 'hello-world' + Get-GitHubRepositoryCustomProperty -Owner 'octocat' -Repository 'hello-world' Gets all custom property values that are set for the 'hello-world' repository. @@ -21,13 +21,14 @@ [OutputType([pscustomobject])] param( # The account owner of the repository. The name is not case sensitive. - [Parameter()] - [Alias('org')] + [Parameter(Mandatory)] + [Alias('Organization')] + [Alias('User')] [string] $Owner, # The name of the repository without the .git extension. The name is not case sensitive. - [Parameter()] - [string] $Repo, + [Parameter(Mandatory)] + [string] $Repository, # 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. @@ -40,31 +41,17 @@ Write-Debug "[$stackPath] - Start" $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - - if ([string]::IsNullOrEmpty($Owner)) { - $Owner = $Context.Owner - } - Write-Debug "Owner: [$Owner]" - - if ([string]::IsNullOrEmpty($Repo)) { - $Repo = $Context.Repo - } - Write-Debug "Repo: [$Repo]" } process { - try { - $inputObject = @{ - Context = $Context - APIEndpoint = "/repos/$Owner/$Repo/properties/values" - Method = 'GET' - } + $inputObject = @{ + Method = 'GET' + APIEndpoint = "/repos/$Owner/$Repository/properties/values" + Context = $Context + } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } - } catch { - throw $_ + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } } diff --git a/src/functions/public/Repositories/Repositories/Disable-GitHubRepositoryPrivateVulnerabilityReporting.ps1 b/src/functions/public/Repositories/Repositories/Disable-GitHubRepositoryPrivateVulnerabilityReporting.ps1 index ce87b3528..b8550b69f 100644 --- a/src/functions/public/Repositories/Repositories/Disable-GitHubRepositoryPrivateVulnerabilityReporting.ps1 +++ b/src/functions/public/Repositories/Repositories/Disable-GitHubRepositoryPrivateVulnerabilityReporting.ps1 @@ -9,7 +9,7 @@ "[Privately reporting a security vulnerability](https://docs.github.com/code-security/security-advisories/guidance-on-reporting-and-writing/privately-reporting-a-security-vulnerability)". .EXAMPLE - Disable-GitHubRepositoryPrivateVulnerabilityReporting -Owner 'PSModule' -Repo 'GitHub' + Disable-GitHubRepositoryPrivateVulnerabilityReporting -Owner 'PSModule' -Repository 'GitHub' Disables private vulnerability reporting for the PSModule/GitHub repository. @@ -20,13 +20,14 @@ [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidLongLines', '', Justification = 'Long links')] param( # The account owner of the repository. The name is not case sensitive. - [Parameter()] - [Alias('org')] + [Parameter(Mandatory)] + [Alias('Organization')] + [Alias('User')] [string] $Owner, # The name of the repository without the .git extension. The name is not case sensitive. - [Parameter()] - [string] $Repo, + [Parameter(Mandatory)] + [string] $Repository, # 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. @@ -39,33 +40,19 @@ Write-Debug "[$stackPath] - Start" $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - - if ([string]::IsNullOrEmpty($Owner)) { - $Owner = $Context.Owner - } - Write-Debug "Owner: [$Owner]" - - if ([string]::IsNullOrEmpty($Repo)) { - $Repo = $Context.Repo - } - Write-Debug "Repo: [$Repo]" } process { - try { - $inputObject = @{ - Context = $Context - APIEndpoint = "/repos/$Owner/$Repo/private-vulnerability-reporting" - Method = 'DELETE' - } + $inputObject = @{ + Method = 'DELETE' + APIEndpoint = "/repos/$Owner/$Repository/private-vulnerability-reporting" + Context = $Context + } - if ($PSCmdlet.ShouldProcess("Private Vulnerability Reporting for [$Owner/$Repo]", 'Disable')) { - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } + if ($PSCmdlet.ShouldProcess("Private Vulnerability Reporting for [$Owner/$Repository]", 'Disable')) { + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } - } catch { - throw $_ } } diff --git a/src/functions/public/Repositories/Repositories/Disable-GitHubRepositorySecurityFix.ps1 b/src/functions/public/Repositories/Repositories/Disable-GitHubRepositorySecurityFix.ps1 index c390ff1b8..3c6c8879b 100644 --- a/src/functions/public/Repositories/Repositories/Disable-GitHubRepositorySecurityFix.ps1 +++ b/src/functions/public/Repositories/Repositories/Disable-GitHubRepositorySecurityFix.ps1 @@ -9,7 +9,7 @@ "[Configuring automated security fixes](https://docs.github.com/articles/configuring-automated-security-fixes)". .EXAMPLE - Disable-GitHubRepositorySecurityFix -Owner 'PSModule' -Repo 'GitHub' + Disable-GitHubRepositorySecurityFix -Owner 'PSModule' -Repository 'GitHub' Disables automated security fixes for the repository. @@ -20,13 +20,14 @@ [Alias('Disable-GitHubRepositorySecurityFixes')] param( # The account owner of the repository. The name is not case sensitive. - [Parameter()] - [Alias('org')] + [Parameter(Mandatory)] + [Alias('Organization')] + [Alias('User')] [string] $Owner, # The name of the repository without the .git extension. The name is not case sensitive. - [Parameter()] - [string] $Repo, + [Parameter(Mandatory)] + [string] $Repository, # 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. @@ -39,33 +40,19 @@ Write-Debug "[$stackPath] - Start" $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - - if ([string]::IsNullOrEmpty($Owner)) { - $Owner = $Context.Owner - } - Write-Debug "Owner: [$Owner]" - - if ([string]::IsNullOrEmpty($Repo)) { - $Repo = $Context.Repo - } - Write-Debug "Repo: [$Repo]" } process { - try { - $inputObject = @{ - Context = $Context - APIEndpoint = "/repos/$Owner/$Repo/automated-security-fixes" - Method = 'DELETE' - } + $inputObject = @{ + Method = 'DELETE' + APIEndpoint = "/repos/$Owner/$Repository/automated-security-fixes" + Context = $Context + } - if ($PSCmdlet.ShouldProcess("Security Fixes for [$Owner/$Repo]", 'Disable')) { - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } + if ($PSCmdlet.ShouldProcess("Security Fixes for [$Owner/$Repository]", 'Disable')) { + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } - } catch { - throw $_ } } diff --git a/src/functions/public/Repositories/Repositories/Disable-GitHubRepositoryVulnerabilityAlert.ps1 b/src/functions/public/Repositories/Repositories/Disable-GitHubRepositoryVulnerabilityAlert.ps1 index bc9690d9e..19b2a9128 100644 --- a/src/functions/public/Repositories/Repositories/Disable-GitHubRepositoryVulnerabilityAlert.ps1 +++ b/src/functions/public/Repositories/Repositories/Disable-GitHubRepositoryVulnerabilityAlert.ps1 @@ -9,7 +9,7 @@ "[About security alerts for vulnerable dependencies](https://docs.github.com/articles/about-security-alerts-for-vulnerable-dependencies)". .EXAMPLE - Disable-GitHubRepositoryVulnerabilityAlert -Owner 'octocat' -Repo 'hello-world' + Disable-GitHubRepositoryVulnerabilityAlert -Owner 'octocat' -Repository 'hello-world' Disables vulnerability alerts for the 'octocat/hello-world' repository. @@ -20,13 +20,14 @@ [Alias('Disable-GitHubRepositoryVulnerabilityAlerts')] param( # The account owner of the repository. The name is not case sensitive. - [Parameter()] - [Alias('org')] + [Parameter(Mandatory)] + [Alias('Organization')] + [Alias('User')] [string] $Owner, # The name of the repository without the .git extension. The name is not case sensitive. - [Parameter()] - [string] $Repo, + [Parameter(Mandatory)] + [string] $Repository, # 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. @@ -39,33 +40,19 @@ Write-Debug "[$stackPath] - Start" $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - - if ([string]::IsNullOrEmpty($Owner)) { - $Owner = $Context.Owner - } - Write-Debug "Owner: [$Owner]" - - if ([string]::IsNullOrEmpty($Repo)) { - $Repo = $Context.Repo - } - Write-Debug "Repo: [$Repo]" } process { - try { - $inputObject = @{ - Context = $Context - APIEndpoint = "/repos/$Owner/$Repo/vulnerability-alerts" - Method = 'DELETE' - } + $inputObject = @{ + Method = 'DELETE' + APIEndpoint = "/repos/$Owner/$Repository/vulnerability-alerts" + Context = $Context + } - if ($PSCmdlet.ShouldProcess("Vulnerability Alerts for [$Owner/$Repo]", 'Disable')) { - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } + if ($PSCmdlet.ShouldProcess("Vulnerability Alerts for [$Owner/$Repository]", 'Disable')) { + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } - } catch { - throw $_ } } diff --git a/src/functions/public/Repositories/Repositories/Enable-GitHubRepositoryPrivateVulnerabilityReporting.ps1 b/src/functions/public/Repositories/Repositories/Enable-GitHubRepositoryPrivateVulnerabilityReporting.ps1 index 2236d79fc..b7fa7fded 100644 --- a/src/functions/public/Repositories/Repositories/Enable-GitHubRepositoryPrivateVulnerabilityReporting.ps1 +++ b/src/functions/public/Repositories/Repositories/Enable-GitHubRepositoryPrivateVulnerabilityReporting.ps1 @@ -9,7 +9,7 @@ "[Privately reporting a security vulnerability](https://docs.github.com/code-security/security-advisories/guidance-on-reporting-and-writing/privately-reporting-a-security-vulnerability)." .EXAMPLE - Enable-GitHubRepositoryPrivateVulnerabilityReporting -Owner 'PSModule' -Repo 'GitHub' + Enable-GitHubRepositoryPrivateVulnerabilityReporting -Owner 'PSModule' -Repository 'GitHub' Enables private vulnerability reporting for the PSModule/GitHub repository. @@ -20,13 +20,14 @@ [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidLongLines', '', Justification = 'Long links')] param( # The account owner of the repository. The name is not case sensitive. - [Parameter()] - [Alias('org')] + [Parameter(Mandatory)] + [Alias('Organization')] + [Alias('User')] [string] $Owner, # The name of the repository without the .git extension. The name is not case sensitive. - [Parameter()] - [string] $Repo, + [Parameter(Mandatory)] + [string] $Repository, # 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. @@ -39,33 +40,19 @@ Write-Debug "[$stackPath] - Start" $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - - if ([string]::IsNullOrEmpty($Owner)) { - $Owner = $Context.Owner - } - Write-Debug "Owner: [$Owner]" - - if ([string]::IsNullOrEmpty($Repo)) { - $Repo = $Context.Repo - } - Write-Debug "Repo: [$Repo]" } process { - try { - $inputObject = @{ - Context = $Context - APIEndpoint = "/repos/$Owner/$Repo/private-vulnerability-reporting" - Method = 'PUT' - } + $inputObject = @{ + Method = 'PUT' + APIEndpoint = "/repos/$Owner/$Repository/private-vulnerability-reporting" + Context = $Context + } - if ($PSCmdlet.ShouldProcess("Private Vulnerability Reporting for [$Owner/$Repo]", 'Enable')) { - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } + if ($PSCmdlet.ShouldProcess("Private Vulnerability Reporting for [$Owner/$Repository]", 'Enable')) { + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } - } catch { - throw $_ } } diff --git a/src/functions/public/Repositories/Repositories/Enable-GitHubRepositorySecurityFix.ps1 b/src/functions/public/Repositories/Repositories/Enable-GitHubRepositorySecurityFix.ps1 index 47d8cf67e..c9ff4d15e 100644 --- a/src/functions/public/Repositories/Repositories/Enable-GitHubRepositorySecurityFix.ps1 +++ b/src/functions/public/Repositories/Repositories/Enable-GitHubRepositorySecurityFix.ps1 @@ -9,7 +9,7 @@ "[Configuring automated security fixes](https://docs.github.com/articles/configuring-automated-security-fixes)". .EXAMPLE - Enable-GitHubRepositorySecurityFix -Owner 'PSModule' -Repo 'GitHub' + Enable-GitHubRepositorySecurityFix -Owner 'PSModule' -Repository 'GitHub' Enables automated security fixes for the repository. @@ -20,13 +20,14 @@ [Alias('Enable-GitHubRepositorySecurityFixes')] param( # The account owner of the repository. The name is not case sensitive. - [Parameter()] - [Alias('org')] + [Parameter(Mandatory)] + [Alias('Organization')] + [Alias('User')] [string] $Owner, # The name of the repository without the .git extension. The name is not case sensitive. - [Parameter()] - [string] $Repo, + [Parameter(Mandatory)] + [string] $Repository, # 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. @@ -39,33 +40,19 @@ Write-Debug "[$stackPath] - Start" $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - - if ([string]::IsNullOrEmpty($Owner)) { - $Owner = $Context.Owner - } - Write-Debug "Owner: [$Owner]" - - if ([string]::IsNullOrEmpty($Repo)) { - $Repo = $Context.Repo - } - Write-Debug "Repo: [$Repo]" } process { - try { - $inputObject = @{ - Context = $Context - APIEndpoint = "/repos/$Owner/$Repo/automated-security-fixes" - Method = 'PUT' - } + $inputObject = @{ + Method = 'PUT' + APIEndpoint = "/repos/$Owner/$Repository/automated-security-fixes" + Context = $Context + } - if ($PSCmdlet.ShouldProcess("Security Fixes for [$Owner/$Repo]", 'Enable')) { - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } + if ($PSCmdlet.ShouldProcess("Security Fixes for [$Owner/$Repository]", 'Enable')) { + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } - } catch { - throw $_ } } diff --git a/src/functions/public/Repositories/Repositories/Enable-GitHubRepositoryVulnerabilityAlert.ps1 b/src/functions/public/Repositories/Repositories/Enable-GitHubRepositoryVulnerabilityAlert.ps1 index 7709b0937..b6b2ac79d 100644 --- a/src/functions/public/Repositories/Repositories/Enable-GitHubRepositoryVulnerabilityAlert.ps1 +++ b/src/functions/public/Repositories/Repositories/Enable-GitHubRepositoryVulnerabilityAlert.ps1 @@ -10,7 +10,7 @@ "[About security alerts for vulnerable dependencies](https://docs.github.com/articles/about-security-alerts-for-vulnerable-dependencies)". .EXAMPLE - Enable-GitHubRepositoryVulnerabilityAlert -Owner 'octocat' -Repo 'hello-world' + Enable-GitHubRepositoryVulnerabilityAlert -Owner 'octocat' -Repository 'hello-world' Enables vulnerability alerts for the 'octocat/hello-world' repository. @@ -21,13 +21,14 @@ [Alias('Enable-GitHubRepositoryVulnerabilityAlerts')] param( # The account owner of the repository. The name is not case sensitive. - [Parameter()] - [Alias('org')] + [Parameter(Mandatory)] + [Alias('Organization')] + [Alias('User')] [string] $Owner, # The name of the repository without the .git extension. The name is not case sensitive. - [Parameter()] - [string] $Repo, + [Parameter(Mandatory)] + [string] $Repository, # 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. @@ -40,33 +41,19 @@ Write-Debug "[$stackPath] - Start" $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - - if ([string]::IsNullOrEmpty($Owner)) { - $Owner = $Context.Owner - } - Write-Debug "Owner: [$Owner]" - - if ([string]::IsNullOrEmpty($Repo)) { - $Repo = $Context.Repo - } - Write-Debug "Repo: [$Repo]" } process { - try { - $inputObject = @{ - Context = $Context - APIEndpoint = "/repos/$Owner/$Repo/vulnerability-alerts" - Method = 'PUT' - } + $inputObject = @{ + Method = 'PUT' + APIEndpoint = "/repos/$Owner/$Repository/vulnerability-alerts" + Context = $Context + } - if ($PSCmdlet.ShouldProcess("Vulnerability Alerts for [$Owner/$Repo]", 'Enable')) { - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } + if ($PSCmdlet.ShouldProcess("Vulnerability Alerts for [$Owner/$Repository]", 'Enable')) { + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } - } catch { - throw $_ } } diff --git a/src/functions/public/Repositories/Repositories/Get-GitHubRepository.ps1 b/src/functions/public/Repositories/Repositories/Get-GitHubRepository.ps1 index 5fbd22311..487ffa468 100644 --- a/src/functions/public/Repositories/Repositories/Get-GitHubRepository.ps1 +++ b/src/functions/public/Repositories/Repositories/Get-GitHubRepository.ps1 @@ -37,7 +37,7 @@ filter Get-GitHubRepository { Gets the repositories with an ID equals and greater than 123456789. .EXAMPLE - Get-GitHubRepository -Owner 'github' -Repo 'octocat' + Get-GitHubRepository -Owner 'github' -Repository 'octocat' Gets the specified repository. @@ -89,7 +89,7 @@ filter Get-GitHubRepository { Mandatory, ParameterSetName = 'ByName' )] - [string] $Repo, + [string] $Repository, # The handle for the GitHub user account. [Parameter( @@ -166,100 +166,86 @@ filter Get-GitHubRepository { Write-Debug "[$stackPath] - Start" $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - - if ([string]::IsNullOrEmpty($Owner)) { - $Owner = $Context.Owner - } - Write-Debug "Owner: [$Owner]" - - if ([string]::IsNullOrEmpty($Repo)) { - $Repo = $Context.Repo - } - Write-Debug "Repo: [$Repo]" } process { - try { - $Type = $PSBoundParameters['Type'] - Write-Debug "ParamSet: [$($PSCmdlet.ParameterSetName)]" - switch ($PSCmdlet.ParameterSetName) { - 'MyRepos_Type' { - $params = @{ - Context = $Context - Type = $Type - Sort = $Sort - Direction = $Direction - PerPage = $PerPage - Since = $Since - Before = $Before - } - $params | Remove-HashtableEntry -NullOrEmptyValues - Write-Verbose ($params | Format-List | Out-String) - Get-GitHubMyRepositories @params + $Type = $PSBoundParameters['Type'] + Write-Debug "ParamSet: [$($PSCmdlet.ParameterSetName)]" + switch ($PSCmdlet.ParameterSetName) { + 'MyRepos_Type' { + $params = @{ + Context = $Context + Type = $Type + Sort = $Sort + Direction = $Direction + PerPage = $PerPage + Since = $Since + Before = $Before } - 'MyRepos_Aff-Vis' { - $params = @{ - Context = $Context - Visibility = $Visibility - Affiliation = $Affiliation - Sort = $Sort - Direction = $Direction - PerPage = $PerPage - Since = $Since - Before = $Before - } - $params | Remove-HashtableEntry -NullOrEmptyValues - Write-Verbose ($params | Format-List | Out-String) - Get-GitHubMyRepositories @params + $params | Remove-HashtableEntry -NullOrEmptyValues + Write-Verbose ($params | Format-List | Out-String) + Get-GitHubMyRepositories @params + } + 'MyRepos_Aff-Vis' { + $params = @{ + Context = $Context + Visibility = $Visibility + Affiliation = $Affiliation + Sort = $Sort + Direction = $Direction + PerPage = $PerPage + Since = $Since + Before = $Before } - 'ByName' { - $params = @{ - Context = $Context - Owner = $Owner - Repo = $Repo - } - $params | Remove-HashtableEntry -NullOrEmptyValues - Write-Verbose ($params | Format-List | Out-String) - Get-GitHubRepositoryByName @params + $params | Remove-HashtableEntry -NullOrEmptyValues + Write-Verbose ($params | Format-List | Out-String) + Get-GitHubMyRepositories @params + } + 'ByName' { + $params = @{ + Context = $Context + Owner = $Owner + Repository = $Repository } - 'ListByID' { - $params = @{ - Context = $Context - Since = $SinceID - } - $params | Remove-HashtableEntry -NullOrEmptyValues - Write-Verbose ($params | Format-List | Out-String) - Get-GitHubRepositoryListByID @params + $params | Remove-HashtableEntry -NullOrEmptyValues + Write-Verbose ($params | Format-List | Out-String) + Get-GitHubRepositoryByName @params + } + 'ListByID' { + $params = @{ + Context = $Context + Since = $SinceID } - 'ListByOrg' { - $params = @{ - Context = $Context - Owner = $Owner - Type = $Type - Sort = $Sort - Direction = $Direction - PerPage = $PerPage - } - $params | Remove-HashtableEntry -NullOrEmptyValues - Write-Verbose ($params | Format-List | Out-String) - Get-GitHubRepositoryListByOrg @params + $params | Remove-HashtableEntry -NullOrEmptyValues + Write-Verbose ($params | Format-List | Out-String) + Get-GitHubRepositoryListByID @params + } + 'ListByOrg' { + $params = @{ + Context = $Context + Owner = $Owner + Type = $Type + Sort = $Sort + Direction = $Direction + PerPage = $PerPage } - 'ListByUser' { - $params = @{ - Context = $Context - Username = $Username - Type = $Type - Sort = $Sort - Direction = $Direction - PerPage = $PerPage - } - $params | Remove-HashtableEntry -NullOrEmptyValues - Write-Verbose ($params | Format-List | Out-String) - Get-GitHubRepositoryListByUser @params + $params | Remove-HashtableEntry -NullOrEmptyValues + Write-Verbose ($params | Format-List | Out-String) + Get-GitHubRepositoryListByOrg @params + } + 'ListByUser' { + $params = @{ + Context = $Context + Username = $Username + Type = $Type + Sort = $Sort + Direction = $Direction + PerPage = $PerPage } + $params | Remove-HashtableEntry -NullOrEmptyValues + Write-Verbose ($params | Format-List | Out-String) + Get-GitHubRepositoryListByUser @params } - } catch { - throw $_ } } diff --git a/src/functions/public/Repositories/Repositories/Get-GitHubRepositoryActivity.ps1 b/src/functions/public/Repositories/Repositories/Get-GitHubRepositoryActivity.ps1 index 839b4be6f..ee99c5c17 100644 --- a/src/functions/public/Repositories/Repositories/Get-GitHubRepositoryActivity.ps1 +++ b/src/functions/public/Repositories/Repositories/Get-GitHubRepositoryActivity.ps1 @@ -11,25 +11,25 @@ see "[Viewing activity and data for your repository](https://docs.github.com/repositories/viewing-activity-and-data-for-your-repository)." .EXAMPLE - Get-GitHubRepositoryActivity -Owner 'PSModule' -Repo 'GitHub' + Get-GitHubRepositoryActivity -Owner 'PSModule' -Repository 'GitHub' .EXAMPLE - Get-GitHubRepositoryActivity -Owner 'PSModule' -Repo 'GitHub' -Direction 'asc' + Get-GitHubRepositoryActivity -Owner 'PSModule' -Repository 'GitHub' -Direction 'asc' .EXAMPLE - Get-GitHubRepositoryActivity -Owner 'PSModule' -Repo 'GitHub' -PerPage 100 + Get-GitHubRepositoryActivity -Owner 'PSModule' -Repository 'GitHub' -PerPage 100 .EXAMPLE - Get-GitHubRepositoryActivity -Owner 'PSModule' -Repo 'GitHub' -Before '2021-01-01T00:00:00Z' + Get-GitHubRepositoryActivity -Owner 'PSModule' -Repository 'GitHub' -Before '2021-01-01T00:00:00Z' .EXAMPLE - Get-GitHubRepositoryActivity -Owner 'PSModule' -Repo 'GitHub' -After '2021-01-01T00:00:00Z' + Get-GitHubRepositoryActivity -Owner 'PSModule' -Repository 'GitHub' -After '2021-01-01T00:00:00Z' .EXAMPLE - Get-GitHubRepositoryActivity -Owner 'PSModule' -Repo 'GitHub' -Ref 'refs/heads/main' + Get-GitHubRepositoryActivity -Owner 'PSModule' -Repository 'GitHub' -Ref 'refs/heads/main' .EXAMPLE - Get-GitHubRepositoryActivity -Owner 'PSModule' -Repo 'GitHub' -Actor 'octocat' + Get-GitHubRepositoryActivity -Owner 'PSModule' -Repository 'GitHub' -Actor 'octocat' .EXAMPLE $params = @{ @@ -43,21 +43,22 @@ Gets the activity for the past 24 hours and selects the actor, activity type, ref, and timestamp. .EXAMPLE - Get-GitHubRepositoryActivity -Owner 'PSModule' -Repo 'GitHub' -ActivityType 'push','force_push' + Get-GitHubRepositoryActivity -Owner 'PSModule' -Repository 'GitHub' -ActivityType 'push','force_push' .NOTES [List repository activities](https://docs.github.com/rest/repos/repos#list-repository-activities) #> - [CmdletBinding()] + [CmdletBinding(DefaultParameterSetName = '__AllParameterSets')] param( # The account owner of the repository. The name is not case sensitive. - [Parameter()] - [Alias('org')] + [Parameter(Mandatory)] + [Alias('Organization')] + [Alias('User')] [string] $Owner, # The name of the repository without the .git extension. The name is not case sensitive. - [Parameter()] - [string] $Repo, + [Parameter(Mandatory)] + [string] $Repository, # The direction to sort the results by. [Parameter()] @@ -112,44 +113,30 @@ Write-Debug "[$stackPath] - Start" $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT + } - if ([string]::IsNullOrEmpty($Owner)) { - $Owner = $Context.Owner + process { + $body = @{ + direction = $Direction + per_page = $PerPage + before = $Before + after = $After + ref = $Ref + actor = $Actor + time_period = $TimePeriod + activity_type = $ActivityType } - Write-Debug "Owner: [$Owner]" + $body | Remove-HashtableEntry -NullOrEmptyValues - if ([string]::IsNullOrEmpty($Repo)) { - $Repo = $Context.Repo + $inputObject = @{ + Method = 'GET' + APIEndpoint = "/repos/$Owner/$Repository/activity" + Body = $body + Context = $Context } - Write-Debug "Repo: [$Repo]" - } - process { - try { - $body = @{ - direction = $Direction - per_page = $PerPage - before = $Before - after = $After - ref = $Ref - actor = $Actor - time_period = $TimePeriod - activity_type = $ActivityType - } - $body | Remove-HashtableEntry -NullOrEmptyValues - - $inputObject = @{ - Context = $Context - APIEndpoint = "/repos/$Owner/$Repo/activity" - Method = 'GET' - Body = $body - } - - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } - } catch { - throw $_ + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } } diff --git a/src/functions/public/Repositories/Repositories/Get-GitHubRepositoryCodeownersError.ps1 b/src/functions/public/Repositories/Repositories/Get-GitHubRepositoryCodeownersError.ps1 index cbc4ebbaa..ee15aeafe 100644 --- a/src/functions/public/Repositories/Repositories/Get-GitHubRepositoryCodeownersError.ps1 +++ b/src/functions/public/Repositories/Repositories/Get-GitHubRepositoryCodeownersError.ps1 @@ -10,7 +10,7 @@ see "[About code owners](https://docs.github.com/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-code-owners)." .EXAMPLE - Get-GitHubRepositoryCodeownersError -Owner 'PSModule' -Repo 'GitHub' + Get-GitHubRepositoryCodeownersError -Owner 'PSModule' -Repository 'GitHub' Gets the CODEOWNERS errors for the repository. @@ -21,13 +21,14 @@ [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidLongLines', '', Justification = 'Contains a long link.')] param( # The account owner of the repository. The name is not case sensitive. - [Parameter()] - [Alias('org')] + [Parameter(Mandatory)] + [Alias('Organization')] + [Alias('User')] [string] $Owner, # The name of the repository without the .git extension. The name is not case sensitive. - [Parameter()] - [string] $Repo, + [Parameter(Mandatory)] + [string] $Repository, # A branch, tag or commit name used to determine which version of the CODEOWNERS file to use. # Default: the repository's default branch (e.g. main) @@ -45,37 +46,23 @@ Write-Debug "[$stackPath] - Start" $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - - if ([string]::IsNullOrEmpty($Owner)) { - $Owner = $Context.Owner - } - Write-Debug "Owner: [$Owner]" - - if ([string]::IsNullOrEmpty($Repo)) { - $Repo = $Context.Repo - } - Write-Debug "Repo: [$Repo]" } process { - try { - $body = @{ - ref = $Ref - } - $body | Remove-HashtableEntry -NullOrEmptyValues + $body = @{ + ref = $Ref + } + $body | Remove-HashtableEntry -NullOrEmptyValues - $inputObject = @{ - Context = $Context - APIEndpoint = "/repos/$Owner/$Repo/codeowners/errors" - Method = 'GET' - Body = $body - } + $inputObject = @{ + Method = 'GET' + APIEndpoint = "/repos/$Owner/$Repository/codeowners/errors" + Body = $body + Context = $Context + } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } - } catch { - throw $_ + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } } diff --git a/src/functions/public/Repositories/Repositories/Get-GitHubRepositoryContributor.ps1 b/src/functions/public/Repositories/Repositories/Get-GitHubRepositoryContributor.ps1 index f7562b5f6..b5023d916 100644 --- a/src/functions/public/Repositories/Repositories/Get-GitHubRepositoryContributor.ps1 +++ b/src/functions/public/Repositories/Repositories/Get-GitHubRepositoryContributor.ps1 @@ -12,7 +12,7 @@ in the repository link to GitHub users. The rest will appear as anonymous contributors without associated GitHub user information. .EXAMPLE - Get-GitHubRepositoryContributor -Owner 'PSModule' -Repo 'GitHub' + Get-GitHubRepositoryContributor -Owner 'PSModule' -Repository 'GitHub' Gets all contributors to the GitHub repository. @@ -22,13 +22,14 @@ [CmdletBinding()] param( # The account owner of the repository. The name is not case sensitive. - [Parameter()] - [Alias('org')] + [Parameter(Mandatory)] + [Alias('Organization')] + [Alias('User')] [string] $Owner, # The name of the repository without the .git extension. The name is not case sensitive. - [Parameter()] - [string] $Repo, + [Parameter(Mandatory)] + [string] $Repository, # Wether to include anonymous contributors in results. [Parameter()] @@ -50,38 +51,24 @@ Write-Debug "[$stackPath] - Start" $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - - if ([string]::IsNullOrEmpty($Owner)) { - $Owner = $Context.Owner - } - Write-Debug "Owner: [$Owner]" - - if ([string]::IsNullOrEmpty($Repo)) { - $Repo = $Context.Repo - } - Write-Debug "Repo: [$Repo]" } process { - try { - $body = @{ - anon = $Anon - per_page = $PerPage - } - $body | Remove-HashtableEntry -NullOrEmptyValues + $body = @{ + anon = $Anon + per_page = $PerPage + } + $body | Remove-HashtableEntry -NullOrEmptyValues - $inputObject = @{ - Context = $Context - APIEndpoint = "/repos/$Owner/$Repo/contributors" - Method = 'GET' - Body = $body - } + $inputObject = @{ + Method = 'GET' + APIEndpoint = "/repos/$Owner/$Repository/contributors" + Body = $body + Context = $Context + } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } - } catch { - throw $_ + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } } diff --git a/src/functions/public/Repositories/Repositories/Get-GitHubRepositoryFork.ps1 b/src/functions/public/Repositories/Repositories/Get-GitHubRepositoryFork.ps1 index 3986c856e..9ea73adda 100644 --- a/src/functions/public/Repositories/Repositories/Get-GitHubRepositoryFork.ps1 +++ b/src/functions/public/Repositories/Repositories/Get-GitHubRepositoryFork.ps1 @@ -7,7 +7,7 @@ List forks of a named repository. .EXAMPLE - Get-GitHubRepositoryFork -Owner 'octocat' -Repo 'Hello-World' + Get-GitHubRepositoryFork -Owner 'octocat' -Repository 'Hello-World' List forks of the 'Hello-World' repository owned by 'octocat'. @@ -17,13 +17,14 @@ [CmdletBinding()] param( # The account owner of the repository. The name is not case sensitive. - [Parameter()] - [Alias('org')] + [Parameter(Mandatory)] + [Alias('Organization')] + [Alias('User')] [string] $Owner, # The name of the repository without the .git extension. The name is not case sensitive. - [Parameter()] - [string] $Repo, + [Parameter(Mandatory)] + [string] $Repository, # The direction to sort the results by. [Parameter()] @@ -46,38 +47,24 @@ Write-Debug "[$stackPath] - Start" $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - - if ([string]::IsNullOrEmpty($Owner)) { - $Owner = $Context.Owner - } - Write-Debug "Owner: [$Owner]" - - if ([string]::IsNullOrEmpty($Repo)) { - $Repo = $Context.Repo - } - Write-Debug "Repo: [$Repo]" } process { - try { - $body = @{ - sort = $Sort - per_page = $PerPage - } - $body | Remove-HashtableEntry -NullOrEmptyValues + $body = @{ + sort = $Sort + per_page = $PerPage + } + $body | Remove-HashtableEntry -NullOrEmptyValues - $inputObject = @{ - Context = $Context - APIEndpoint = "/repos/$Owner/$Repo/forks" - Method = 'GET' - Body = $body - } + $inputObject = @{ + Method = 'GET' + APIEndpoint = "/repos/$Owner/$Repository/forks" + Body = $body + Context = $Context + } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } - } catch { - throw $_ + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } } diff --git a/src/functions/public/Repositories/Repositories/Get-GitHubRepositoryLanguage.ps1 b/src/functions/public/Repositories/Repositories/Get-GitHubRepositoryLanguage.ps1 index cbecbb6ff..4476bcc98 100644 --- a/src/functions/public/Repositories/Repositories/Get-GitHubRepositoryLanguage.ps1 +++ b/src/functions/public/Repositories/Repositories/Get-GitHubRepositoryLanguage.ps1 @@ -8,7 +8,7 @@ bytes of code written in that language. .EXAMPLE - Get-GitHubRepositoryLanguage -Owner 'octocat' -Repo 'hello-world' + Get-GitHubRepositoryLanguage -Owner 'octocat' -Repository 'hello-world' Gets the languages for the 'hello-world' repository owned by 'octocat'. @@ -19,13 +19,14 @@ [Alias('Get-GitHubRepositoryLanguages')] param( # The account owner of the repository. The name is not case sensitive. - [Parameter()] - [Alias('org')] + [Parameter(Mandatory)] + [Alias('Organization')] + [Alias('User')] [string] $Owner, # The name of the repository without the .git extension. The name is not case sensitive. - [Parameter()] - [string] $Repo, + [Parameter(Mandatory)] + [string] $Repository, # 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. @@ -38,31 +39,17 @@ Write-Debug "[$stackPath] - Start" $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - - if ([string]::IsNullOrEmpty($Owner)) { - $Owner = $Context.Owner - } - Write-Debug "Owner: [$Owner]" - - if ([string]::IsNullOrEmpty($Repo)) { - $Repo = $Context.Repo - } - Write-Debug "Repo: [$Repo]" } process { - try { - $inputObject = @{ - Context = $Context - APIEndpoint = "/repos/$Owner/$Repo/languages" - Method = 'GET' - } + $inputObject = @{ + Method = 'GET' + APIEndpoint = "/repos/$Owner/$Repository/languages" + Context = $Context + } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } - } catch { - throw $_ + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } } diff --git a/src/functions/public/Repositories/Repositories/Get-GitHubRepositorySecurityFix.ps1 b/src/functions/public/Repositories/Repositories/Get-GitHubRepositorySecurityFix.ps1 index c109b2f9d..5f6c671ae 100644 --- a/src/functions/public/Repositories/Repositories/Get-GitHubRepositorySecurityFix.ps1 +++ b/src/functions/public/Repositories/Repositories/Get-GitHubRepositorySecurityFix.ps1 @@ -9,7 +9,7 @@ "[Configuring automated security fixes](https://docs.github.com/articles/configuring-automated-security-fixes)". .EXAMPLE - Get-GitHubRepositorySecurityFix -Owner 'PSModule' -Repo 'GitHub' + Get-GitHubRepositorySecurityFix -Owner 'PSModule' -Repository 'GitHub' Gets the automated security fixes status for the GitHub repository. @@ -21,13 +21,14 @@ [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidLongLines', '', Justification = 'Contains a long link.')] param( # The account owner of the repository. The name is not case sensitive. - [Parameter()] - [Alias('org')] + [Parameter(Mandatory)] + [Alias('Organization')] + [Alias('User')] [string] $Owner, # The name of the repository without the .git extension. The name is not case sensitive. - [Parameter()] - [string] $Repo, + [Parameter(Mandatory)] + [string] $Repository, # 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. @@ -40,31 +41,17 @@ Write-Debug "[$stackPath] - Start" $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - - if ([string]::IsNullOrEmpty($Owner)) { - $Owner = $Context.Owner - } - Write-Debug "Owner: [$Owner]" - - if ([string]::IsNullOrEmpty($Repo)) { - $Repo = $Context.Repo - } - Write-Debug "Repo: [$Repo]" } process { - try { - $inputObject = @{ - Context = $Context - APIEndpoint = "/repos/$Owner/$Repo/automated-security-fixes" - Method = 'GET' - } + $inputObject = @{ + Method = 'GET' + APIEndpoint = "/repos/$Owner/$Repository/automated-security-fixes" + Context = $Context + } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } - } catch { - throw $_ + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } } diff --git a/src/functions/public/Repositories/Repositories/Get-GitHubRepositoryTag.ps1 b/src/functions/public/Repositories/Repositories/Get-GitHubRepositoryTag.ps1 index 0d5c31fbc..b6e883ae5 100644 --- a/src/functions/public/Repositories/Repositories/Get-GitHubRepositoryTag.ps1 +++ b/src/functions/public/Repositories/Repositories/Get-GitHubRepositoryTag.ps1 @@ -7,7 +7,7 @@ List repository tags .EXAMPLE - Get-GitHubRepositoryTag -Owner 'PSModule' -Repo 'GitHub' + Get-GitHubRepositoryTag -Owner 'PSModule' -Repository 'GitHub' Gets all tags of the GitHub repository. @@ -18,13 +18,14 @@ [Alias('Get-GitHubRepositoryTags')] param( # The account owner of the repository. The name is not case sensitive. - [Parameter()] - [Alias('org')] + [Parameter(Mandatory)] + [Alias('Organization')] + [Alias('User')] [string] $Owner, # The name of the repository without the .git extension. The name is not case sensitive. - [Parameter()] - [string] $Repo, + [Parameter(Mandatory)] + [string] $Repository, # The number of results per page (max 100). [Parameter()] @@ -42,36 +43,22 @@ Write-Debug "[$stackPath] - Start" $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - - if ([string]::IsNullOrEmpty($Owner)) { - $Owner = $Context.Owner - } - Write-Debug "Owner: [$Owner]" - - if ([string]::IsNullOrEmpty($Repo)) { - $Repo = $Context.Repo - } - Write-Debug "Repo: [$Repo]" } process { - try { - $body = @{ - per_page = $PerPage - } + $body = @{ + per_page = $PerPage + } - $inputObject = @{ - Context = $Context - APIEndpoint = "/repos/$Owner/$Repo/tags" - Method = 'GET' - Body = $body - } + $inputObject = @{ + Method = 'GET' + APIEndpoint = "/repos/$Owner/$Repository/tags" + Body = $body + Context = $Context + } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } - } catch { - throw $_ + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } } diff --git a/src/functions/public/Repositories/Repositories/Get-GitHubRepositoryTeam.ps1 b/src/functions/public/Repositories/Repositories/Get-GitHubRepositoryTeam.ps1 index b17f5777c..b2970e9df 100644 --- a/src/functions/public/Repositories/Repositories/Get-GitHubRepositoryTeam.ps1 +++ b/src/functions/public/Repositories/Repositories/Get-GitHubRepositoryTeam.ps1 @@ -15,7 +15,7 @@ This endpoint is not compatible with fine-grained personal access tokens. .EXAMPLE - Get-GitHubRepositoryTeam -Owner 'PSModule' -Repo 'GitHub' + Get-GitHubRepositoryTeam -Owner 'PSModule' -Repository 'GitHub' Lists the teams that have access to the specified repository and that are also visible to the authenticated user. @@ -26,13 +26,14 @@ [Alias('Get-GitHubRepositoryTeams')] param( # The account owner of the repository. The name is not case sensitive. - [Parameter()] - [Alias('org')] + [Parameter(Mandatory)] + [Alias('Organization')] + [Alias('User')] [string] $Owner, # The name of the repository without the .git extension. The name is not case sensitive. - [Parameter()] - [string] $Repo, + [Parameter(Mandatory)] + [string] $Repository, # The number of results per page (max 100). [Parameter()] @@ -50,36 +51,22 @@ Write-Debug "[$stackPath] - Start" $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT + } - if ([string]::IsNullOrEmpty($Owner)) { - $Owner = $Context.Owner + process { + $body = @{ + per_page = $PerPage } - Write-Debug "Owner: [$Owner]" - if ([string]::IsNullOrEmpty($Repo)) { - $Repo = $Context.Repo + $inputObject = @{ + Method = 'GET' + APIEndpoint = "/repos/$Owner/$Repository/teams" + Body = $body + Context = $Context } - Write-Debug "Repo: [$Repo]" - } - process { - try { - $body = @{ - per_page = $PerPage - } - - $inputObject = @{ - Context = $Context - APIEndpoint = "/repos/$Owner/$Repo/teams" - Method = 'GET' - Body = $body - } - - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } - } catch { - throw $_ + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } } diff --git a/src/functions/public/Repositories/Repositories/Get-GitHubRepositoryTopic.ps1 b/src/functions/public/Repositories/Repositories/Get-GitHubRepositoryTopic.ps1 index 83e414d77..7ed6016d6 100644 --- a/src/functions/public/Repositories/Repositories/Get-GitHubRepositoryTopic.ps1 +++ b/src/functions/public/Repositories/Repositories/Get-GitHubRepositoryTopic.ps1 @@ -14,13 +14,14 @@ [CmdletBinding()] param( # The account owner of the repository. The name is not case sensitive. - [Parameter()] - [Alias('org')] + [Parameter(Mandatory)] + [Alias('Organization')] + [Alias('User')] [string] $Owner, # The name of the repository without the .git extension. The name is not case sensitive. - [Parameter()] - [string] $Repo, + [Parameter(Mandatory)] + [string] $Repository, # The number of results per page (max 100). [Parameter()] @@ -38,36 +39,22 @@ Write-Debug "[$stackPath] - Start" $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - - if ([string]::IsNullOrEmpty($Owner)) { - $Owner = $Context.Owner - } - Write-Debug "Owner: [$Owner]" - - if ([string]::IsNullOrEmpty($Repo)) { - $Repo = $Context.Repo - } - Write-Debug "Repo: [$Repo]" } process { - try { - $body = @{ - per_page = $PerPage - } + $body = @{ + per_page = $PerPage + } - $inputObject = @{ - Context = $Context - APIEndpoint = "/repos/$Owner/$Repo/topics" - Method = 'GET' - Body = $body - } + $inputObject = @{ + Method = 'GET' + APIEndpoint = "/repos/$Owner/$Repository/topics" + Body = $body + Context = $Context + } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response.names - } - } catch { - throw $_ + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response.names } } diff --git a/src/functions/public/Repositories/Repositories/Move-GitHubRepository.ps1 b/src/functions/public/Repositories/Repositories/Move-GitHubRepository.ps1 index 038962e12..590ee728b 100644 --- a/src/functions/public/Repositories/Repositories/Move-GitHubRepository.ps1 +++ b/src/functions/public/Repositories/Repositories/Move-GitHubRepository.ps1 @@ -12,7 +12,7 @@ a fine-grained personal access token cannot be used because they are only granted access to a single account. .EXAMPLE - Move-GitHubRepository -Owner 'PSModule' -Repo 'GitHub' -NewOwner 'GitHub' -NewName 'PowerShell' + Move-GitHubRepository -Owner 'PSModule' -Repository 'GitHub' -NewOwner 'GitHub' -NewName 'PowerShell' Moves the GitHub repository to the PSModule organization and renames it to GitHub. @@ -22,13 +22,14 @@ [CmdletBinding()] param( # The account owner of the repository. The name is not case sensitive. - [Parameter()] - [Alias('org')] + [Parameter(Mandatory)] + [Alias('Organization')] + [Alias('User')] [string] $Owner, # The name of the repository without the .git extension. The name is not case sensitive. - [Parameter()] - [string] $Repo, + [Parameter(Mandatory)] + [string] $Repository, # The username or organization name the repository will be transferred to. [Parameter(Mandatory)] @@ -56,39 +57,25 @@ Write-Debug "[$stackPath] - Start" $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - - if ([string]::IsNullOrEmpty($Owner)) { - $Owner = $Context.Owner - } - Write-Debug "Owner: [$Owner]" - - if ([string]::IsNullOrEmpty($Repo)) { - $Repo = $Context.Repo - } - Write-Debug "Repo: [$Repo]" } process { - try { - $body = @{ - new_owner = $NewOwner - new_name = $NewName - team_ids = $TeamIds - } - $body | Remove-HashtableEntry -NullOrEmptyValues + $body = @{ + new_owner = $NewOwner + new_name = $NewName + team_ids = $TeamIds + } + $body | Remove-HashtableEntry -NullOrEmptyValues - $inputObject = @{ - Context = $Context - APIEndpoint = "/repos/$Owner/$Repo/transfer" - Method = 'POST' - Body = $body - } + $inputObject = @{ + Method = 'POST' + APIEndpoint = "/repos/$Owner/$Repository/transfer" + Body = $body + Context = $Context + } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } - } catch { - throw $_ + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } } diff --git a/src/functions/public/Repositories/Repositories/New-GitHubRepository.ps1 b/src/functions/public/Repositories/Repositories/New-GitHubRepository.ps1 index d773f3146..a01592a22 100644 --- a/src/functions/public/Repositories/Repositories/New-GitHubRepository.ps1 +++ b/src/functions/public/Repositories/Repositories/New-GitHubRepository.ps1 @@ -110,7 +110,8 @@ filter New-GitHubRepository { # The account owner of the repository. The name is not case sensitive. [Parameter(ParameterSetName = 'org')] [Parameter(ParameterSetName = 'fork')] - [Alias('org')] + [Alias('Organization')] + [Alias('User')] [string] $Owner, # The name of the repository. @@ -338,88 +339,85 @@ filter New-GitHubRepository { } process { - try { - $GitignoreTemplate = $PSBoundParameters['GitignoreTemplate'] - $LicenseTemplate = $PSBoundParameters['LicenseTemplate'] - if ($PSCmdlet.ParameterSetName -in 'user', 'org') { - $params = @{ - Context = $Context - Owner = $Owner - Name = $Name - Description = $Description - Homepage = $Homepage - Visibility = $Visibility - HasIssues = $HasIssues - HasProjects = $HasProjects - HasWiki = $HasWiki - HasDiscussions = $HasDiscussions - HasDownloads = $HasDownloads - IsTemplate = $IsTemplate - TeamId = $TeamId - AutoInit = $AutoInit - AllowSquashMerge = $AllowSquashMerge - AllowMergeCommit = $AllowMergeCommit - AllowRebaseMerge = $AllowRebaseMerge - AllowAutoMerge = $AllowAutoMerge - DeleteBranchOnMerge = $DeleteBranchOnMerge - SquashMergeCommitTitle = $SquashMergeCommitTitle - SquashMergeCommitMessage = $SquashMergeCommitMessage - MergeCommitTitle = $MergeCommitTitle - MergeCommitMessage = $MergeCommitMessage - GitignoreTemplate = $GitignoreTemplate - LicenseTemplate = $LicenseTemplate - } - Remove-HashtableEntry -Hashtable $params -NullOrEmptyValues + $GitignoreTemplate = $PSBoundParameters['GitignoreTemplate'] + $LicenseTemplate = $PSBoundParameters['LicenseTemplate'] + if ($PSCmdlet.ParameterSetName -in 'user', 'org') { + $params = @{ + Context = $Context + Owner = $Owner + Name = $Name + Description = $Description + Homepage = $Homepage + Visibility = $Visibility + HasIssues = $HasIssues + HasProjects = $HasProjects + HasWiki = $HasWiki + HasDiscussions = $HasDiscussions + HasDownloads = $HasDownloads + IsTemplate = $IsTemplate + TeamId = $TeamId + AutoInit = $AutoInit + AllowSquashMerge = $AllowSquashMerge + AllowMergeCommit = $AllowMergeCommit + AllowRebaseMerge = $AllowRebaseMerge + AllowAutoMerge = $AllowAutoMerge + DeleteBranchOnMerge = $DeleteBranchOnMerge + SquashMergeCommitTitle = $SquashMergeCommitTitle + SquashMergeCommitMessage = $SquashMergeCommitMessage + MergeCommitTitle = $MergeCommitTitle + MergeCommitMessage = $MergeCommitMessage + GitignoreTemplate = $GitignoreTemplate + LicenseTemplate = $LicenseTemplate } + Remove-HashtableEntry -Hashtable $params -NullOrEmptyValues + } - switch ($PSCmdlet.ParameterSetName) { - 'user' { - if ($PSCmdlet.ShouldProcess("repository for user [$Name]", 'Create')) { - New-GitHubRepositoryUser @params - } + switch ($PSCmdlet.ParameterSetName) { + 'user' { + if ($PSCmdlet.ShouldProcess("repository for user [$Name]", 'Create')) { + New-GitHubRepositoryUser @params } - 'org' { - if ($PSCmdlet.ShouldProcess("repository for organization [$Owner/$Name]", 'Create')) { - New-GitHubRepositoryOrg @params - } + } + 'org' { + if ($PSCmdlet.ShouldProcess("repository for organization [$Owner/$Name]", 'Create')) { + New-GitHubRepositoryOrg @params } - 'template' { - if ($PSCmdlet.ShouldProcess("repository [$Owner/$Name] from template [$TemplateOwner/$TemplateRepo]", 'Create')) { - $params = @{ - Context = $Context - TemplateOwner = $TemplateOwner - TemplateRepo = $TemplateRepo - Owner = $Owner - Name = $Name - IncludeAllBranches = $IncludeAllBranches - Description = $Description - Private = $Visibility -eq 'private' - } - Remove-HashtableEntry -Hashtable $params -NullOrEmptyValues - New-GitHubRepositoryFromTemplate @params + } + 'template' { + if ($PSCmdlet.ShouldProcess("repository [$Owner/$Name] from template [$TemplateOwner/$TemplateRepo]", 'Create')) { + $params = @{ + Context = $Context + TemplateOwner = $TemplateOwner + TemplateRepo = $TemplateRepo + Owner = $Owner + Name = $Name + IncludeAllBranches = $IncludeAllBranches + Description = $Description + Private = $Visibility -eq 'private' } + Remove-HashtableEntry -Hashtable $params -NullOrEmptyValues + New-GitHubRepositoryFromTemplate @params } - 'fork' { - if ([string]::IsNullorEmpty($Name)) { - $Name = $ForkRepo - } - if ($PSCmdlet.ShouldProcess("repository [$Owner/$Name] as fork from [$ForkOwner/$ForkRepo]", 'Create')) { - $params = @{ - Context = $Context - Owner = $ForkOwner - Repo = $ForkRepo - Organization = $Owner - Name = $Name - DefaultBranchOnly = $DefaultBranchOnly - } - Remove-HashtableEntry -Hashtable $params -NullOrEmptyValues - New-GitHubRepositoryAsFork @params + } + 'fork' { + if ([string]::IsNullorEmpty($Name)) { + $Name = $ForkRepo + } + if ($PSCmdlet.ShouldProcess("repository [$Owner/$Name] as fork from [$ForkOwner/$ForkRepo]", 'Create')) { + $params = @{ + Context = $Context + Owner = $ForkOwner + Repo = $ForkRepo + Organization = $Owner + Name = $Name + DefaultBranchOnly = $DefaultBranchOnly } + Remove-HashtableEntry -Hashtable $params -NullOrEmptyValues + New-GitHubRepositoryAsFork @params } } - } catch { - throw $_ } + } end { diff --git a/src/functions/public/Repositories/Repositories/Remove-GitHubRepository.ps1 b/src/functions/public/Repositories/Repositories/Remove-GitHubRepository.ps1 index da62375ad..4ce1579f6 100644 --- a/src/functions/public/Repositories/Repositories/Remove-GitHubRepository.ps1 +++ b/src/functions/public/Repositories/Repositories/Remove-GitHubRepository.ps1 @@ -10,25 +10,24 @@ repositories, you will get a `403 Forbidden` response. .EXAMPLE - Remove-GitHubRepository -Owner 'PSModule' -Repo 'Hello-World' + Remove-GitHubRepository -Owner 'PSModule' -Repository 'Hello-World' Deletes the repository `Hello-World` in the `PSModule` organization. .NOTES [Delete a repository](https://docs.github.com/rest/repos/repos#delete-a-repository) #> - #TODO: Set high impact - [CmdletBinding(SupportsShouldProcess)] + [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'High')] param( # The account owner of the repository. The name is not case sensitive. [Parameter(Mandatory)] - [Alias('org')] - [Alias('login')] + [Alias('Organization')] + [Alias('User')] [string] $Owner, # The name of the repository without the .git extension. The name is not case sensitive. [Parameter(Mandatory)] - [string] $Repo, + [string] $Repository, # 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. @@ -41,33 +40,19 @@ Write-Debug "[$stackPath] - Start" $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - - if ([string]::IsNullOrEmpty($Owner)) { - $Owner = $Context.Owner - } - Write-Debug "Owner: [$Owner]" - - if ([string]::IsNullOrEmpty($Repo)) { - $Repo = $Context.Repo - } - Write-Debug "Repo: [$Repo]" } process { - try { - $inputObject = @{ - Context = $Context - APIEndpoint = "/repos/$Owner/$Repo" - Method = 'DELETE' - } + $inputObject = @{ + Method = 'DELETE' + APIEndpoint = "/repos/$Owner/$Repository" + Context = $Context + } - if ($PSCmdlet.ShouldProcess("repo [$Owner/$Repo]", 'Delete')) { - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } + if ($PSCmdlet.ShouldProcess("repo [$Owner/$Repository]", 'DELETE')) { + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } - } catch { - throw $_ } } diff --git a/src/functions/public/Repositories/Repositories/Set-GitHubRepositoryTopic.ps1 b/src/functions/public/Repositories/Repositories/Set-GitHubRepositoryTopic.ps1 index 8bd672d00..e5ac86ce7 100644 --- a/src/functions/public/Repositories/Repositories/Set-GitHubRepositoryTopic.ps1 +++ b/src/functions/public/Repositories/Repositories/Set-GitHubRepositoryTopic.ps1 @@ -7,7 +7,7 @@ Replace all repository topics .EXAMPLE - Set-GitHubRepositoryTopic -Owner 'octocat' -Repo 'hello-world' -Names 'octocat', 'octo', 'octocat/hello-world' + Set-GitHubRepositoryTopic -Owner 'octocat' -Repository 'hello-world' -Names 'octocat', 'octo', 'octocat/hello-world' Replaces all topics for the repository 'octocat/hello-world' with the topics 'octocat', 'octo', 'octocat/hello-world'. @@ -17,13 +17,14 @@ [CmdletBinding(SupportsShouldProcess)] param( # The account owner of the repository. The name is not case sensitive. - [Parameter()] - [Alias('org')] + [Parameter(Mandatory)] + [Alias('Organization')] + [Alias('User')] [string] $Owner, # The name of the repository without the .git extension. The name is not case sensitive. - [Parameter()] - [string] $Repo, + [Parameter(Mandatory)] + [string] $Repository, # The number of results per page (max 100). [Parameter()] @@ -41,38 +42,24 @@ Write-Debug "[$stackPath] - Start" $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - - if ([string]::IsNullOrEmpty($Owner)) { - $Owner = $Context.Owner - } - Write-Debug "Owner: [$Owner]" - - if ([string]::IsNullOrEmpty($Repo)) { - $Repo = $Context.Repo - } - Write-Debug "Repo: [$Repo]" } process { - try { - $body = @{ - names = $Names | ForEach-Object { $_.ToLower() } - } + $body = @{ + names = $Names | ForEach-Object { $_.ToLower() } + } - $inputObject = @{ - Context = $Context - APIEndpoint = "/repos/$Owner/$Repo/topics" - Method = 'PUT' - Body = $body - } + $inputObject = @{ + Method = 'PUT' + APIEndpoint = "/repos/$Owner/$Repository/topics" + Body = $body + Context = $Context + } - if ($PSCmdlet.ShouldProcess("topics for repo [$Owner/$Repo]", 'Set')) { - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response.names - } + if ($PSCmdlet.ShouldProcess("topics for repo [$Owner/$Repository]", 'Set')) { + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response.names } - } catch { - throw $_ } } diff --git a/src/functions/public/Repositories/Repositories/Start-GitHubRepositoryEvent.ps1 b/src/functions/public/Repositories/Repositories/Start-GitHubRepositoryEvent.ps1 index 59694f66f..db4b33d32 100644 --- a/src/functions/public/Repositories/Repositories/Start-GitHubRepositoryEvent.ps1 +++ b/src/functions/public/Repositories/Repositories/Start-GitHubRepositoryEvent.ps1 @@ -43,13 +43,14 @@ [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidLongLines', '', Justification = 'Long links')] param( # The account owner of the repository. The name is not case sensitive. - [Parameter()] - [Alias('org')] + [Parameter(Mandatory)] + [Alias('Organization')] + [Alias('User')] [string] $Owner, # The name of the repository without the .git extension. The name is not case sensitive. - [Parameter()] - [string] $Repo, + [Parameter(Mandatory)] + [string] $Repository, # A custom webhook event name. Must be 100 characters or fewer. [Parameter(Mandatory)] @@ -73,38 +74,24 @@ Write-Debug "[$stackPath] - Start" $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - - if ([string]::IsNullOrEmpty($Owner)) { - $Owner = $Context.Owner - } - Write-Debug "Owner: [$Owner]" - - if ([string]::IsNullOrEmpty($Repo)) { - $Repo = $Context.Repo - } - Write-Debug "Repo: [$Repo]" } process { - try { - $body = @{ - event_type = $EventType - client_payload = $ClientPayload - } - $body | Remove-HashtableEntry -NullOrEmptyValues + $body = @{ + event_type = $EventType + client_payload = $ClientPayload + } + $body | Remove-HashtableEntry -NullOrEmptyValues - $inputObject = @{ - Context = $Context - APIEndpoint = "/repos/$Owner/$Repo/dispatches" - Method = 'POST' - Body = $body - } + $inputObject = @{ + Method = 'POST' + APIEndpoint = "/repos/$Owner/$Repository/dispatches" + Body = $body + Context = $Context + } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } - } catch { - throw $_ + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } } diff --git a/src/functions/public/Repositories/Repositories/Test-GitHubRepositoryVulnerabilityAlert.ps1 b/src/functions/public/Repositories/Repositories/Test-GitHubRepositoryVulnerabilityAlert.ps1 index ee3d67b7b..9e1f0ff0e 100644 --- a/src/functions/public/Repositories/Repositories/Test-GitHubRepositoryVulnerabilityAlert.ps1 +++ b/src/functions/public/Repositories/Repositories/Test-GitHubRepositoryVulnerabilityAlert.ps1 @@ -10,7 +10,7 @@ "[About security alerts for vulnerable dependencies](https://docs.github.com/articles/about-security-alerts-for-vulnerable-dependencies)". .EXAMPLE - Test-GitHubRepositoryVulnerabilityAlert -Owner 'PSModule' -Repo 'GitHub' + Test-GitHubRepositoryVulnerabilityAlert -Owner 'PSModule' -Repository 'GitHub' Checks if vulnerability alerts are enabled for the PSModule/GitHub repository. @@ -22,13 +22,14 @@ [Alias('Test-GitHubRepositoryVulnerabilityAlerts')] param( # The account owner of the repository. The name is not case sensitive. - [Parameter()] - [Alias('org')] + [Parameter(Mandatory)] + [Alias('Organization')] + [Alias('User')] [string] $Owner, # The name of the repository without the .git extension. The name is not case sensitive. - [Parameter()] - [string] $Repo, + [Parameter(Mandatory)] + [string] $Repository, # 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. @@ -41,34 +42,16 @@ Write-Debug "[$stackPath] - Start" $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - - if ([string]::IsNullOrEmpty($Owner)) { - $Owner = $Context.Owner - } - Write-Debug "Owner: [$Owner]" - - if ([string]::IsNullOrEmpty($Repo)) { - $Repo = $Context.Repo - } - Write-Debug "Repo: [$Repo]" } process { $inputObject = @{ - Context = $Context - APIEndpoint = "/repos/$Owner/$Repo/vulnerability-alerts" Method = 'GET' + APIEndpoint = "/repos/$Owner/$Repository/vulnerability-alerts" + Context = $Context } - try { - (Invoke-GitHubAPI @inputObject).StatusCode -eq 204 - } catch { - if ($_.Exception.Response.StatusCode.Value__ -eq 404) { - return $false - } else { - throw $_ - } - } + Invoke-GitHubAPI @inputObject } end { diff --git a/src/functions/public/Repositories/Repositories/Update-GitHubRepository.ps1 b/src/functions/public/Repositories/Repositories/Update-GitHubRepository.ps1 index 614c19f3c..d12467553 100644 --- a/src/functions/public/Repositories/Repositories/Update-GitHubRepository.ps1 +++ b/src/functions/public/Repositories/Repositories/Update-GitHubRepository.ps1 @@ -14,7 +14,7 @@ $params = @{ Owner = 'octocat' Repo = 'Hello-World' - name = 'Hello-World-Repo + name = 'Hello-World-Repository description = 'This is your first repository' homepage = 'https://github.com' } @@ -26,13 +26,14 @@ [CmdletBinding(SupportsShouldProcess)] param( # The account owner of the repository. The name is not case sensitive. - [Parameter()] - [Alias('org')] + [Parameter(Mandatory)] + [Alias('Organization')] + [Alias('User')] [string] $Owner, # The name of the repository without the .git extension. The name is not case sensitive. - [Parameter()] - [string] $Repo, + [Parameter(Mandatory)] + [string] $Repository, # The name of the repository. [Parameter()] @@ -182,70 +183,56 @@ Write-Debug "[$stackPath] - Start" $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - - if ([string]::IsNullOrEmpty($Owner)) { - $Owner = $Context.Owner - } - Write-Debug "Owner: [$Owner]" - - if ([string]::IsNullOrEmpty($Repo)) { - $Repo = $Context.Repo - } - Write-Debug "Repo: [$Repo]" } process { - try { - $body = @{ - name = $Name - description = $Description - homepage = $Homepage - visibility = $Visibility - private = $Visibility -eq 'private' - default_branch = $DefaultBranch - squash_merge_commit_title = $SquashMergeCommitTitle - squash_merge_commit_message = $SquashMergeCommitMessage - merge_commit_title = $MergeCommitTitle - merge_commit_message = $MergeCommitMessage - advanced_security = $EnableAdvancedSecurity ? @{ - status = $EnableAdvancedSecurity ? 'enabled' : 'disabled' - } : $null - secret_scanning = $EnableSecretScanning ? @{ - status = $EnableSecretScanning ? 'enabled' : 'disabled' - } : $null - secret_scanning_push_protection = $EnableSecretScanningPushProtection ? @{ - status = $EnableSecretScanningPushProtection ? 'enabled' : 'disabled' - } : $null - has_issues = $HasIssues ? $HasIssues : $null - has_projects = $HasProjects ? $HasProjects : $null - has_wiki = $HasWiki ? $HasWiki : $null - is_template = $IsTemplate ? $IsTemplate : $null - allow_squash_merge = $AllowSquashMerge ? $AllowSquashMerge : $null - allow_merge_commit = $AllowMergeCommit ? $AllowMergeCommit : $null - allow_rebase_merge = $AllowRebaseMerge ? $AllowRebaseMerge : $null - allow_auto_merge = $AllowAutoMerge ? $AllowAutoMerge : $null - allow_update_branch = $AllowUpdateMerge ? $AllowUpdateMerge : $null - delete_branch_on_merge = $DeleteBranchOnMerge ? $DeleteBranchOnMerge : $null - archived = $Archived ? $Archived : $null - allow_forking = $AllowForking ? $AllowForking : $null - web_commit_signoff_required = $WebCommitSignoffRequired ? $WebCommitSignoffRequired : $null - } - $body | Remove-HashtableEntry -NullOrEmptyValues + $body = @{ + name = $Name + description = $Description + homepage = $Homepage + visibility = $Visibility + private = $Visibility -eq 'private' + default_branch = $DefaultBranch + squash_merge_commit_title = $SquashMergeCommitTitle + squash_merge_commit_message = $SquashMergeCommitMessage + merge_commit_title = $MergeCommitTitle + merge_commit_message = $MergeCommitMessage + advanced_security = $EnableAdvancedSecurity ? @{ + status = $EnableAdvancedSecurity ? 'enabled' : 'disabled' + } : $null + secret_scanning = $EnableSecretScanning ? @{ + status = $EnableSecretScanning ? 'enabled' : 'disabled' + } : $null + secret_scanning_push_protection = $EnableSecretScanningPushProtection ? @{ + status = $EnableSecretScanningPushProtection ? 'enabled' : 'disabled' + } : $null + has_issues = $HasIssues ? $HasIssues : $null + has_projects = $HasProjects ? $HasProjects : $null + has_wiki = $HasWiki ? $HasWiki : $null + is_template = $IsTemplate ? $IsTemplate : $null + allow_squash_merge = $AllowSquashMerge ? $AllowSquashMerge : $null + allow_merge_commit = $AllowMergeCommit ? $AllowMergeCommit : $null + allow_rebase_merge = $AllowRebaseMerge ? $AllowRebaseMerge : $null + allow_auto_merge = $AllowAutoMerge ? $AllowAutoMerge : $null + allow_update_branch = $AllowUpdateMerge ? $AllowUpdateMerge : $null + delete_branch_on_merge = $DeleteBranchOnMerge ? $DeleteBranchOnMerge : $null + archived = $Archived ? $Archived : $null + allow_forking = $AllowForking ? $AllowForking : $null + web_commit_signoff_required = $WebCommitSignoffRequired ? $WebCommitSignoffRequired : $null + } + $body | Remove-HashtableEntry -NullOrEmptyValues - $inputObject = @{ - Context = $Context - APIEndpoint = "/repos/$Owner/$Repo" - Method = 'PATCH' - Body = $body - } + $inputObject = @{ + Method = 'PATCH' + APIEndpoint = "/repos/$Owner/$Repository" + Body = $body + Context = $Context + } - if ($PSCmdlet.ShouldProcess("Repository [$Owner/$Repo]", 'Update')) { - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } + if ($PSCmdlet.ShouldProcess("Repository [$Owner/$Repository]", 'Update')) { + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } - } catch { - throw $_ } } diff --git a/src/functions/public/Repositories/RuleSuite/Get-GitHubRepositoryRuleSuite.ps1 b/src/functions/public/Repositories/RuleSuite/Get-GitHubRepositoryRuleSuite.ps1 index ec1dddde2..a3a7214cb 100644 --- a/src/functions/public/Repositories/RuleSuite/Get-GitHubRepositoryRuleSuite.ps1 +++ b/src/functions/public/Repositories/RuleSuite/Get-GitHubRepositoryRuleSuite.ps1 @@ -22,7 +22,7 @@ Gets a list of rule suites for the main branch of the hello-world repository owned by octocat. .EXAMPLE - Get-GitHubRepositoryRuleSuite -Owner 'octocat' -Repo 'hello-world' -RuleSuiteId 123456789 + Get-GitHubRepositoryRuleSuite -Owner 'octocat' -Repository 'hello-world' -RuleSuiteId 123456789 Gets information about a suite of rule evaluations with ID 123456789 from within the octocat/hello-world repository. @@ -32,7 +32,7 @@ #> [OutputType([pscustomobject])] [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidLongLines', '', Justification = 'Long links')] - [CmdletBinding(DefaultParameterSetName = 'Default')] + [CmdletBinding(DefaultParameterSetName = '__AllParameterSets')] param( # The account owner of the repository. The name is not case sensitive. [Parameter()] @@ -40,8 +40,8 @@ [string] $Owner, # The name of the repository without the .git extension. The name is not case sensitive. - [Parameter()] - [string] $Repo, + [Parameter(Mandatory)] + [string] $Repository, # The name of the ref. Cannot contain wildcard characters. # When specified, only rule evaluations triggered for this ref will be returned. @@ -87,46 +87,32 @@ Write-Debug "[$stackPath] - Start" $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - - if ([string]::IsNullOrEmpty($Owner)) { - $Owner = $Context.Owner - } - Write-Debug "Owner: [$Owner]" - - if ([string]::IsNullOrEmpty($Repo)) { - $Repo = $Context.Repo - } - Write-Debug "Repo: [$Repo]" } process { - try { - $params = @{ - Context = $Context - Owner = $Owner - Repo = $Repo - } + $params = @{ + Context = $Context + Owner = $Owner + Repository = $Repository + } - switch ($PSCmdlet.ParameterSetName) { - 'Default' { - $params += @{ - Ref = $Ref - TimePeriod = $TimePeriod - ActorName = $ActorName - RuleSuiteResult = $RuleSuiteResult - PerPage = $PerPage - } - Get-GitHubRepositoryRuleSuiteList @params + switch ($PSCmdlet.ParameterSetName) { + 'ById' { + $params += @{ + RuleSuiteId = $RuleSuiteId } - 'ById' { - $params += @{ - RuleSuiteId = $RuleSuiteId - } - Get-GitHubRepositoryRuleSuiteById @params + Get-GitHubRepositoryRuleSuiteById @params + } + default { + $params += @{ + Ref = $Ref + TimePeriod = $TimePeriod + ActorName = $ActorName + RuleSuiteResult = $RuleSuiteResult + PerPage = $PerPage } + Get-GitHubRepositoryRuleSuiteList @params } - } catch { - throw $_ } } diff --git a/src/functions/public/Repositories/RuleSuite/Get-GitHubRepositoryRuleSuiteById.ps1 b/src/functions/public/Repositories/RuleSuite/Get-GitHubRepositoryRuleSuiteById.ps1 index a4b1dc3b6..ac524015b 100644 --- a/src/functions/public/Repositories/RuleSuite/Get-GitHubRepositoryRuleSuiteById.ps1 +++ b/src/functions/public/Repositories/RuleSuite/Get-GitHubRepositoryRuleSuiteById.ps1 @@ -8,7 +8,7 @@ For more information, see "[Managing rulesets for a repository](https://docs.github.com/repositories/configuring-branches-and-merges-in-your-repository/managing-rulesets/managing-rulesets-for-a-repository#viewing-insights-for-rulesets)." .EXAMPLE - Get-GitHubRepositoryRuleSuiteById -Owner 'octocat' -Repo 'hello-world' -RuleSuiteId 123456789 + Get-GitHubRepositoryRuleSuiteById -Owner 'octocat' -Repository 'hello-world' -RuleSuiteId 123456789 Gets information about a suite of rule evaluations with ID 123456789 from within the octocat/hello-world repository. @@ -20,17 +20,19 @@ [CmdletBinding()] param( # The account owner of the repository. The name is not case sensitive. - [Parameter()] - [Alias('org')] + [Parameter(Mandatory)] + [Alias('Organization')] + [Alias('User')] [string] $Owner, # The name of the repository without the .git extension. The name is not case sensitive. - [Parameter()] - [string] $Repo, + [Parameter(Mandatory)] + [string] $Repository, # The unique identifier of the rule suite result. To get this ID, you can use GET /repos/ { owner }/ { repo }/rulesets/rule-suites for repositories and GET /orgs/ { org }/rulesets/rule-suites for organizations. [Parameter(Mandatory)] - [int] $RuleSuiteId, + [Alias('RuleSuiteId')] + [int] $ID, # 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. @@ -43,31 +45,17 @@ Write-Debug "[$stackPath] - Start" $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - - if ([string]::IsNullOrEmpty($Owner)) { - $Owner = $Context.Owner - } - Write-Debug "Owner: [$Owner]" - - if ([string]::IsNullOrEmpty($Repo)) { - $Repo = $Context.Repo - } - Write-Debug "Repo: [$Repo]" } process { - try { - $inputObject = @{ - Context = $Context - APIEndpoint = "/repos/$Owner/$Repo/rulesets/rule-suites/$RuleSuiteId" - Method = 'GET' - } + $inputObject = @{ + Method = 'GET' + APIEndpoint = "/repos/$Owner/$Repository/rulesets/rule-suites/$ID" + Context = $Context + } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } - } catch { - throw $_ + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } } diff --git a/src/functions/public/Repositories/RuleSuite/Get-GitHubRepositoryRuleSuiteList.ps1 b/src/functions/public/Repositories/RuleSuite/Get-GitHubRepositoryRuleSuiteList.ps1 index cb18ef6f4..036147e51 100644 --- a/src/functions/public/Repositories/RuleSuite/Get-GitHubRepositoryRuleSuiteList.ps1 +++ b/src/functions/public/Repositories/RuleSuite/Get-GitHubRepositoryRuleSuiteList.ps1 @@ -28,13 +28,14 @@ [CmdletBinding()] param( # The account owner of the repository. The name is not case sensitive. - [Parameter()] - [Alias('org')] + [Parameter(Mandatory)] + [Alias('Organization')] + [Alias('User')] [string] $Owner, # The name of the repository without the .git extension. The name is not case sensitive. - [Parameter()] - [string] $Repo, + [Parameter(Mandatory)] + [string] $Repository, # The name of the ref. Cannot contain wildcard characters. # When specified, only rule evaluations triggered for this ref will be returned. @@ -73,41 +74,27 @@ Write-Debug "[$stackPath] - Start" $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT + } - if ([string]::IsNullOrEmpty($Owner)) { - $Owner = $Context.Owner + process { + $body = @{ + ref = $Ref + time_period = $TimePeriod + actor_name = $ActorName + rule_suite_result = $RuleSuiteResult + per_page = $PerPage } - Write-Debug "Owner: [$Owner]" + $body | Remove-HashtableEntry -NullOrEmptyValues - if ([string]::IsNullOrEmpty($Repo)) { - $Repo = $Context.Repo + $inputObject = @{ + Method = 'GET' + APIEndpoint = "/repos/$Owner/$Repository/rulesets/rule-suites" + Body = $body + Context = $Context } - Write-Debug "Repo: [$Repo]" - } - process { - try { - $body = @{ - ref = $Ref - time_period = $TimePeriod - actor_name = $ActorName - rule_suite_result = $RuleSuiteResult - per_page = $PerPage - } - $body | Remove-HashtableEntry -NullOrEmptyValues - - $inputObject = @{ - Context = $Context - APIEndpoint = "/repos/$Owner/$Repo/rulesets/rule-suites" - Method = 'GET' - Body = $body - } - - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } - } catch { - throw $_ + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } } diff --git a/src/functions/public/Repositories/Tags/Get-GitHubRepositoryTagProtection.ps1 b/src/functions/public/Repositories/Tags/Get-GitHubRepositoryTagProtection.ps1 index 69f68deb4..545058183 100644 --- a/src/functions/public/Repositories/Tags/Get-GitHubRepositoryTagProtection.ps1 +++ b/src/functions/public/Repositories/Tags/Get-GitHubRepositoryTagProtection.ps1 @@ -9,7 +9,7 @@ This information is only available to repository administrators. .EXAMPLE - Get-GitHubRepositoryTagProtection -Owner 'octocat' -Repo 'hello-world' + Get-GitHubRepositoryTagProtection -Owner 'octocat' -Repository 'hello-world' Gets the tag protection states of the 'hello-world' repository. @@ -20,13 +20,14 @@ [CmdletBinding()] param( # The account owner of the repository. The name is not case sensitive. - [Parameter()] - [Alias('org')] + [Parameter(Mandatory)] + [Alias('Organization')] + [Alias('User')] [string] $Owner, # The name of the repository without the .git extension. The name is not case sensitive. - [Parameter()] - [string] $Repo, + [Parameter(Mandatory)] + [string] $Repository, # 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. @@ -39,31 +40,17 @@ Write-Debug "[$stackPath] - Start" $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - - if ([string]::IsNullOrEmpty($Owner)) { - $Owner = $Context.Owner - } - Write-Debug "Owner: [$Owner]" - - if ([string]::IsNullOrEmpty($Repo)) { - $Repo = $Context.Repo - } - Write-Debug "Repo: [$Repo]" } process { - try { - $inputObject = @{ - Context = $Context - APIEndpoint = "/repos/$Owner/$Repo/tags/protection" - Method = 'GET' - } + $inputObject = @{ + Method = 'GET' + APIEndpoint = "/repos/$Owner/$Repository/tags/protection" + Context = $Context + } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } - } catch { - throw $_ + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } } diff --git a/src/functions/public/Repositories/Tags/New-GitHubRepositoryTagProtection.ps1 b/src/functions/public/Repositories/Tags/New-GitHubRepositoryTagProtection.ps1 index 66612fc1c..88fca8de4 100644 --- a/src/functions/public/Repositories/Tags/New-GitHubRepositoryTagProtection.ps1 +++ b/src/functions/public/Repositories/Tags/New-GitHubRepositoryTagProtection.ps1 @@ -8,7 +8,7 @@ This endpoint is only available to repository administrators. .EXAMPLE - New-GitHubRepositoryTagProtection -Owner 'octocat' -Repo 'hello-world' -Pattern 'v1.*' + New-GitHubRepositoryTagProtection -Owner 'octocat' -Repository 'hello-world' -Pattern 'v1.*' Creates a tag protection state for the 'hello-world' repository with the pattern 'v1.*'. @@ -19,13 +19,14 @@ [CmdletBinding(SupportsShouldProcess)] param( # The account owner of the repository. The name is not case sensitive. - [Parameter()] - [Alias('org')] + [Parameter(Mandatory)] + [Alias('Organization')] + [Alias('User')] [string] $Owner, # The name of the repository without the .git extension. The name is not case sensitive. - [Parameter()] - [string] $Repo, + [Parameter(Mandatory)] + [string] $Repository, # An optional glob pattern to match against when enforcing tag protection. [Parameter(Mandatory)] @@ -42,38 +43,24 @@ Write-Debug "[$stackPath] - Start" $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - - if ([string]::IsNullOrEmpty($Owner)) { - $Owner = $Context.Owner - } - Write-Debug "Owner: [$Owner]" - - if ([string]::IsNullOrEmpty($Repo)) { - $Repo = $Context.Repo - } - Write-Debug "Repo: [$Repo]" } process { - try { - $body = @{ - pattern = $Pattern - } + $body = @{ + pattern = $Pattern + } - $inputObject = @{ - Context = $Context - APIEndpoint = "/repos/$Owner/$Repo/tags/protection" - Method = 'POST' - Body = $body - } + $inputObject = @{ + Method = 'POST' + APIEndpoint = "/repos/$Owner/$Repository/tags/protection" + Body = $body + Context = $Context + } - if ($PSCmdlet.ShouldProcess("tag protection state on pattern [$Pattern] for repository [$Owner/$Repo]", 'Create')) { - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } + if ($PSCmdlet.ShouldProcess("tag protection state on pattern [$Pattern] for repository [$Owner/$Repository]", 'Create')) { + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } - } catch { - throw $_ } } diff --git a/src/functions/public/Repositories/Tags/Remove-GitHubRepositoryTagProtection.ps1 b/src/functions/public/Repositories/Tags/Remove-GitHubRepositoryTagProtection.ps1 index 54aab7946..9acfe1e77 100644 --- a/src/functions/public/Repositories/Tags/Remove-GitHubRepositoryTagProtection.ps1 +++ b/src/functions/public/Repositories/Tags/Remove-GitHubRepositoryTagProtection.ps1 @@ -8,7 +8,7 @@ This endpoint is only available to repository administrators. .EXAMPLE - Remove-GitHubRepositoryTagProtection -Owner 'octocat' -Repo 'hello-world' -TagProtectionId 1 + Remove-GitHubRepositoryTagProtection -Owner 'octocat' -Repository 'hello-world' -TagProtectionId 1 Deletes the tag protection state with the ID 1 for the 'hello-world' repository. @@ -19,13 +19,14 @@ [CmdletBinding(SupportsShouldProcess)] param( # The account owner of the repository. The name is not case sensitive. - [Parameter()] - [Alias('org')] + [Parameter(Mandatory)] + [Alias('Organization')] + [Alias('User')] [string] $Owner, # The name of the repository without the .git extension. The name is not case sensitive. - [Parameter()] - [string] $Repo, + [Parameter(Mandatory)] + [string] $Repository, # The unique identifier of the tag protection. [Parameter(Mandatory)] @@ -42,33 +43,19 @@ Write-Debug "[$stackPath] - Start" $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - - if ([string]::IsNullOrEmpty($Owner)) { - $Owner = $Context.Owner - } - Write-Debug "Owner: [$Owner]" - - if ([string]::IsNullOrEmpty($Repo)) { - $Repo = $Context.Repo - } - Write-Debug "Repo: [$Repo]" } process { - try { - $inputObject = @{ - Context = $Context - APIEndpoint = "/repos/$Owner/$Repo/tags/protection/$TagProtectionId" - Method = 'DELETE' - } + $inputObject = @{ + Method = 'DELETE' + APIEndpoint = "/repos/$Owner/$Repository/tags/protection/$TagProtectionId" + Context = $Context + } - if ($PSCmdlet.ShouldProcess("tag protection state with ID [$TagProtectionId] for repository [$Owner/$Repo]", 'Delete')) { - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } + if ($PSCmdlet.ShouldProcess("tag protection state with ID [$TagProtectionId] for repository [$Owner/$Repository]", 'DELETE')) { + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } - } catch { - throw $_ } } diff --git a/src/functions/public/Status/Get-GitHubScheduledMaintenance.ps1 b/src/functions/public/Status/Get-GitHubScheduledMaintenance.ps1 index 0afc4e02b..96f4c6237 100644 --- a/src/functions/public/Status/Get-GitHubScheduledMaintenance.ps1 +++ b/src/functions/public/Status/Get-GitHubScheduledMaintenance.ps1 @@ -55,29 +55,26 @@ } process { - try { - $baseURL = $script:StatusBaseURL[$Stamp] - - if ($Active) { - $APIURI = "$baseURL/api/v2/scheduled-maintenances/active.json" - $response = Invoke-RestMethod -Uri $APIURI -Method Get - $response.scheduled_maintenances - return - } - - if ($Upcoming) { - $APIURI = "$baseURL/api/v2/scheduled-maintenances/upcoming.json" - $response = Invoke-RestMethod -Uri $APIURI -Method Get - $response.scheduled_maintenances - return - } - - $APIURI = "$baseURL/api/v2/scheduled-maintenances.json" + $baseURL = $script:StatusBaseURL[$Stamp] + + if ($Active) { + $APIURI = "$baseURL/api/v2/scheduled-maintenances/active.json" $response = Invoke-RestMethod -Uri $APIURI -Method Get $response.scheduled_maintenances - } catch { - throw $_ + return } + + if ($Upcoming) { + $APIURI = "$baseURL/api/v2/scheduled-maintenances/upcoming.json" + $response = Invoke-RestMethod -Uri $APIURI -Method Get + $response.scheduled_maintenances + return + } + + $APIURI = "$baseURL/api/v2/scheduled-maintenances.json" + $response = Invoke-RestMethod -Uri $APIURI -Method Get + $response.scheduled_maintenances + } end { diff --git a/src/functions/public/Status/Get-GitHubStatus.ps1 b/src/functions/public/Status/Get-GitHubStatus.ps1 index f8ccb4652..1dada6a2a 100644 --- a/src/functions/public/Status/Get-GitHubStatus.ps1 +++ b/src/functions/public/Status/Get-GitHubStatus.ps1 @@ -44,22 +44,19 @@ } process { - try { - $baseURL = $script:StatusBaseURL[$Stamp] + $baseURL = $script:StatusBaseURL[$Stamp] - if ($Summary) { - $APIURI = "$baseURL/api/v2/summary.json" - $response = Invoke-RestMethod -Uri $APIURI -Method Get - $response - return - } - - $APIURI = "$baseURL/api/v2/status.json" + if ($Summary) { + $APIURI = "$baseURL/api/v2/summary.json" $response = Invoke-RestMethod -Uri $APIURI -Method Get - $response.status - } catch { - throw $_ + $response + return } + + $APIURI = "$baseURL/api/v2/status.json" + $response = Invoke-RestMethod -Uri $APIURI -Method Get + $response.status + } end { diff --git a/src/functions/public/Status/Get-GitHubStatusComponent.ps1 b/src/functions/public/Status/Get-GitHubStatusComponent.ps1 index a8a699740..5aaa7b06d 100644 --- a/src/functions/public/Status/Get-GitHubStatusComponent.ps1 +++ b/src/functions/public/Status/Get-GitHubStatusComponent.ps1 @@ -31,15 +31,11 @@ } process { - try { - $baseURL = $script:StatusBaseURL[$Stamp] - - $APIURI = "$baseURL/api/v2/components.json" - $response = Invoke-RestMethod -Uri $APIURI -Method Get - $response.components - } catch { - throw $_ - } + $baseURL = $script:StatusBaseURL[$Stamp] + + $APIURI = "$baseURL/api/v2/components.json" + $response = Invoke-RestMethod -Uri $APIURI -Method Get + $response.components } end { diff --git a/src/functions/public/Status/Get-GitHubStatusIncident.ps1 b/src/functions/public/Status/Get-GitHubStatusIncident.ps1 index 8710340b5..2bca48fc4 100644 --- a/src/functions/public/Status/Get-GitHubStatusIncident.ps1 +++ b/src/functions/public/Status/Get-GitHubStatusIncident.ps1 @@ -44,22 +44,18 @@ } process { - try { - $baseURL = $script:StatusBaseURL[$Stamp] + $baseURL = $script:StatusBaseURL[$Stamp] - if ($Unresolved) { - $APIURI = "$baseURL/api/v2/incidents/unresolved.json" - $response = Invoke-RestMethod -Uri $APIURI -Method Get - $response.incidents - return - } - - $APIURI = "$baseURL/api/v2/incidents.json" + if ($Unresolved) { + $APIURI = "$baseURL/api/v2/incidents/unresolved.json" $response = Invoke-RestMethod -Uri $APIURI -Method Get $response.incidents - } catch { - throw $_ + return } + + $APIURI = "$baseURL/api/v2/incidents.json" + $response = Invoke-RestMethod -Uri $APIURI -Method Get + $response.incidents } end { diff --git a/src/functions/public/Teams/Get-GitHubTeam.ps1 b/src/functions/public/Teams/Get-GitHubTeam.ps1 index 54862c043..6560786b1 100644 --- a/src/functions/public/Teams/Get-GitHubTeam.ps1 +++ b/src/functions/public/Teams/Get-GitHubTeam.ps1 @@ -32,7 +32,6 @@ # The organization name. The name is not case sensitive. # If not provided, the owner from the context will be used. [Parameter()] - [Alias('Org')] [string] $Organization, # The context to run the command in. Used to get the details for the API call. @@ -54,21 +53,17 @@ } process { - try { - $params = @{ - Organization = $Organization - Context = $Context + $params = @{ + Organization = $Organization + Context = $Context + } + switch ($PSCmdlet.ParameterSetName) { + 'BySlug' { + Get-GitHubTeamBySlug @params -Slug $Slug } - switch ($PSCmdlet.ParameterSetName) { - 'BySlug' { - Get-GitHubTeamBySlug @params -Slug $Slug - } - '__AllParameterSets' { - Get-GitHubTeamListByOrg @params - } + default { + Get-GitHubTeamListByOrg @params } - } catch { - throw $_ } } diff --git a/src/functions/public/Teams/New-GitHubTeam.ps1 b/src/functions/public/Teams/New-GitHubTeam.ps1 index b7163c226..8e8d5253e 100644 --- a/src/functions/public/Teams/New-GitHubTeam.ps1 +++ b/src/functions/public/Teams/New-GitHubTeam.ps1 @@ -36,8 +36,7 @@ # The organization name. The name is not case sensitive. # If not provided, the organization from the context is used. - [Parameter()] - [Alias('Org')] + [Parameter(Mandatory)] [string] $Organization, # The description of the team. @@ -91,61 +90,52 @@ $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - if ([string]::IsNullOrEmpty($Organization)) { - $Organization = $Context.Owner - } - Write-Debug "Organization: [$Organization]" - if (-not $Visible -and $ParentTeamID -gt 0) { throw 'A nested team cannot be secret (invisible).' } } process { - try { - $body = @{ - name = $Name - description = $Description - maintainers = $Maintainers - repo_names = $RepoNames - privacy = $Visible ? 'closed' : 'secret' - notification_setting = $Notifications ? 'notifications_enabled' : 'notifications_disabled' - permission = $Permission - parent_team_id = $ParentTeamID -eq 0 ? $null : $ParentTeamID - } - $body | Remove-HashtableEntry -NullOrEmptyValues + $body = @{ + name = $Name + description = $Description + maintainers = $Maintainers + repo_names = $RepoNames + privacy = $Visible ? 'closed' : 'secret' + notification_setting = $Notifications ? 'notifications_enabled' : 'notifications_disabled' + permission = $Permission + parent_team_id = $ParentTeamID -eq 0 ? $null : $ParentTeamID + } + $body | Remove-HashtableEntry -NullOrEmptyValues - $inputObject = @{ - Context = $Context - APIEndpoint = "/orgs/$Organization/teams" - Method = 'POST' - Body = $body - } + $inputObject = @{ + Method = 'POST' + APIEndpoint = "/orgs/$Organization/teams" + Body = $body + Context = $Context + } - if ($PSCmdlet.ShouldProcess("'$Name' in '$Organization'", 'Create team')) { - Invoke-GitHubAPI @inputObject | ForEach-Object { - $team = $_.Response - [GitHubTeam]( - @{ - Name = $team.name - Slug = $team.slug - NodeID = $team.node_id - CombinedSlug = $Organization + '/' + $team.slug - DatabaseId = $team.id - Description = $team.description - Notifications = $team.notification_setting -eq 'notifications_enabled' ? $true : $false - Visible = $team.privacy -eq 'closed' ? $true : $false - ParentTeam = $team.parent.slug - Organization = $team.organization.login - ChildTeams = @() - CreatedAt = $team.created_at - UpdatedAt = $team.updated_at - } - ) - } + if ($PSCmdlet.ShouldProcess("'$Name' in '$Organization'", 'Create team')) { + Invoke-GitHubAPI @inputObject | ForEach-Object { + $team = $_.Response + [GitHubTeam]( + @{ + Name = $team.name + Slug = $team.slug + NodeID = $team.node_id + CombinedSlug = $Organization + '/' + $team.slug + DatabaseId = $team.id + Description = $team.description + Notifications = $team.notification_setting -eq 'notifications_enabled' ? $true : $false + Visible = $team.privacy -eq 'closed' ? $true : $false + ParentTeam = $team.parent.slug + Organization = $team.organization.login + ChildTeams = @() + CreatedAt = $team.created_at + UpdatedAt = $team.updated_at + } + ) } - } catch { - throw $_ } } diff --git a/src/functions/public/Teams/Remove-GitHubTeam.ps1 b/src/functions/public/Teams/Remove-GitHubTeam.ps1 index 066df8804..4a7b4a022 100644 --- a/src/functions/public/Teams/Remove-GitHubTeam.ps1 +++ b/src/functions/public/Teams/Remove-GitHubTeam.ps1 @@ -21,15 +21,15 @@ Mandatory, ValueFromPipelineByPropertyName )] - [Alias('team_slug')] - [string] $Slug, + [Alias('team_slug', 'Slug')] + [string] $Name, # The organization name. The name is not case sensitive. # If not provided, the organization from the context is used. [Parameter( + Mandatory, ValueFromPipelineByPropertyName )] - [Alias('Org')] [string] $Organization, # The context to run the command in. Used to get the details for the API call. @@ -43,28 +43,19 @@ Write-Debug "[$stackPath] - Start" $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - - if ([string]::IsNullOrEmpty($Organization)) { - $Organization = $Context.Owner - } - Write-Debug "Organization: [$Organization]" } process { - try { - $inputObject = @{ - Context = $Context - Method = 'Delete' - APIEndpoint = "/orgs/$Organization/teams/$Slug" - } + $inputObject = @{ + Method = 'DELETE' + APIEndpoint = "/orgs/$Organization/teams/$Name" + Context = $Context + } - if ($PSCmdlet.ShouldProcess("$Organization/$Slug", 'Delete')) { - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } + if ($PSCmdlet.ShouldProcess("$Organization/$Name", 'DELETE')) { + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } - } catch { - throw $_ } } diff --git a/src/functions/public/Teams/Update-GitHubTeam.ps1 b/src/functions/public/Teams/Update-GitHubTeam.ps1 index 21b6b4f2f..843a038d5 100644 --- a/src/functions/public/Teams/Update-GitHubTeam.ps1 +++ b/src/functions/public/Teams/Update-GitHubTeam.ps1 @@ -30,19 +30,18 @@ param( # The slug of the team name. [Parameter(Mandatory)] - [Alias('team_slug')] - [string] $Slug, + [Alias('team_slug', 'Slug')] + [string] $Name, # The organization name. The name is not case sensitive. # If you do not provide this parameter, the command will use the organization from the context. - [Parameter()] - [Alias('Org')] + [Parameter(Mandatory)] [string] $Organization, # The new team name. [Parameter()] [Alias()] - [string] $Name, + [string] $NewName, # The description of the team. [Parameter()] @@ -86,57 +85,48 @@ Write-Debug "[$stackPath] - Start" $Context = Resolve-GitHubContext -Context $Context Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - - if ([string]::IsNullOrEmpty($Organization)) { - $Organization = $Context.Owner - } - Write-Debug "Organization: [$Organization]" } process { - try { - $body = @{ - name = $Name - description = $Description - privacy = $PSBoundParameters.ContainsKey('Visible') ? ($Visible ? 'closed' : 'secret') : $null - notification_setting = $PSBoundParameters.ContainsKey('Notifications') ? + $body = @{ + name = $NewName + description = $Description + privacy = $PSBoundParameters.ContainsKey('Visible') ? ($Visible ? 'closed' : 'secret') : $null + notification_setting = $PSBoundParameters.ContainsKey('Notifications') ? ($Notifications ? 'notifications_enabled' : 'notifications_disabled') : $null - permission = $Permission - parent_team_id = $ParentTeamID -eq 0 ? $null : $ParentTeamID - } - $body | Remove-HashtableEntry -NullOrEmptyValues + permission = $Permission + parent_team_id = $ParentTeamID -eq 0 ? $null : $ParentTeamID + } + $body | Remove-HashtableEntry -NullOrEmptyValues - $inputObject = @{ - Context = $Context - APIEndpoint = "/orgs/$Organization/teams/$Slug" - Method = 'Patch' - Body = $body - } + $inputObject = @{ + Method = 'PATCH' + APIEndpoint = "/orgs/$Organization/teams/$Name" + Body = $body + Context = $Context + } - if ($PSCmdlet.ShouldProcess("$Organization/$Slug", 'Update')) { - Invoke-GitHubAPI @inputObject | ForEach-Object { - $team = $_.Response - [GitHubTeam]( - @{ - Name = $team.name - Slug = $team.slug - NodeID = $team.node_id - CombinedSlug = $Organization + '/' + $team.slug - DatabaseId = $team.id - Description = $team.description - Notifications = $team.notification_setting -eq 'notifications_enabled' ? $true : $false - Visible = $team.privacy -eq 'closed' ? $true : $false - ParentTeam = $team.parent.slug - Organization = $team.organization.login - ChildTeams = @() - CreatedAt = $team.created_at - UpdatedAt = $team.updated_at - } - ) - } + if ($PSCmdlet.ShouldProcess("$Organization/$Name", 'Update')) { + Invoke-GitHubAPI @inputObject | ForEach-Object { + $team = $_.Response + [GitHubTeam]( + @{ + Name = $team.name + Slug = $team.slug + NodeID = $team.node_id + CombinedSlug = $Organization + '/' + $team.slug + DatabaseId = $team.id + Description = $team.description + Notifications = $team.notification_setting -eq 'notifications_enabled' ? $true : $false + Visible = $team.privacy -eq 'closed' ? $true : $false + ParentTeam = $team.parent.slug + Organization = $team.organization.login + ChildTeams = @() + CreatedAt = $team.created_at + UpdatedAt = $team.updated_at + } + ) } - } catch { - throw $_ } } diff --git a/src/functions/public/Users/Blocking/Block-GitHubUser.ps1 b/src/functions/public/Users/Blocking/Block-GitHubUser.ps1 index 822227907..4d4701ddb 100644 --- a/src/functions/public/Users/Blocking/Block-GitHubUser.ps1 +++ b/src/functions/public/Users/Blocking/Block-GitHubUser.ps1 @@ -41,8 +41,6 @@ [Parameter( ParameterSetName = '__AllParameterSets' )] - [Alias('org')] - [Alias('owner')] [string] $Organization, # The context to run the command in. Used to get the details for the API call. @@ -59,17 +57,13 @@ } process { - try { - switch ($PSCmdlet.ParameterSetName) { - 'Organization' { - Block-GitHubUserByOrganization -Organization $Organization -Username $Username -Context $Context - } - '__AllParameterSets' { - Block-GitHubUserByUser -Username $Username -Context $Context - } + switch ($PSCmdlet.ParameterSetName) { + 'Organization' { + Block-GitHubUserByOrganization -Organization $Organization -Username $Username -Context $Context + } + '__AllParameterSets' { + Block-GitHubUserByUser -Username $Username -Context $Context } - } catch { - throw $_ } } diff --git a/src/functions/public/Users/Blocking/Get-GitHubBlockedUser.ps1 b/src/functions/public/Users/Blocking/Get-GitHubBlockedUser.ps1 index a8628e148..a769e0e71 100644 --- a/src/functions/public/Users/Blocking/Get-GitHubBlockedUser.ps1 +++ b/src/functions/public/Users/Blocking/Get-GitHubBlockedUser.ps1 @@ -28,8 +28,6 @@ ValueFromPipeline, ValueFromPipelineByPropertyName )] - [Alias('org')] - [Alias('owner')] [Alias('login')] [string] $Organization, @@ -57,14 +55,10 @@ } process { - try { - if ($Organization) { - Get-GitHubBlockedUserByOrganization -Organization $Organization -PerPage $PerPage -Context $Context - } else { - Get-GitHubBlockedUserByUser -PerPage $PerPage -Context $Context - } - } catch { - throw $_ + if ($Organization) { + Get-GitHubBlockedUserByOrganization -Organization $Organization -PerPage $PerPage -Context $Context + } else { + Get-GitHubBlockedUserByUser -PerPage $PerPage -Context $Context } } diff --git a/src/functions/public/Users/Blocking/Test-GitHubBlockedUser.ps1 b/src/functions/public/Users/Blocking/Test-GitHubBlockedUser.ps1 index 7f9d06eb6..58f9f3dff 100644 --- a/src/functions/public/Users/Blocking/Test-GitHubBlockedUser.ps1 +++ b/src/functions/public/Users/Blocking/Test-GitHubBlockedUser.ps1 @@ -41,8 +41,6 @@ ValueFromPipeline, ValueFromPipelineByPropertyName )] - [Alias('org')] - [Alias('owner')] [string] $Organization, # The number of results per page (max 100). @@ -69,14 +67,10 @@ } process { - try { - if ($Organization) { - Test-GitHubBlockedUserByOrganization -Organization $Organization -Username $Username -PerPage $PerPage -Context $Context - } else { - Test-GitHubBlockedUserByUser -Username $Username -PerPage $PerPage -Context $Context - } - } catch { - throw $_ + if ($Organization) { + Test-GitHubBlockedUserByOrganization -Organization $Organization -Username $Username -PerPage $PerPage -Context $Context + } else { + Test-GitHubBlockedUserByUser -Username $Username -PerPage $PerPage -Context $Context } } diff --git a/src/functions/public/Users/Blocking/Unblock-GitHubUser.ps1 b/src/functions/public/Users/Blocking/Unblock-GitHubUser.ps1 index c7f602f45..a61c784d3 100644 --- a/src/functions/public/Users/Blocking/Unblock-GitHubUser.ps1 +++ b/src/functions/public/Users/Blocking/Unblock-GitHubUser.ps1 @@ -39,8 +39,6 @@ ValueFromPipeline, ValueFromPipelineByPropertyName )] - [Alias('org')] - [Alias('owner')] [string] $Organization, # The context to run the command in. Used to get the details for the API call. @@ -62,14 +60,10 @@ } process { - try { - if ($Organization) { - Unblock-GitHubUserByOrganization -Organization $Organization -Username $Username -Context $Context - } else { - Unblock-GitHubUserByUser -Username $Username -Context $Context - } - } catch { - throw $_ + if ($Organization) { + Unblock-GitHubUserByOrganization -Organization $Organization -Username $Username -Context $Context + } else { + Unblock-GitHubUserByUser -Username $Username -Context $Context } } diff --git a/src/functions/public/Users/Emails/Add-GitHubUserEmail.ps1 b/src/functions/public/Users/Emails/Add-GitHubUserEmail.ps1 index 3a2587561..64bcc2e42 100644 --- a/src/functions/public/Users/Emails/Add-GitHubUserEmail.ps1 +++ b/src/functions/public/Users/Emails/Add-GitHubUserEmail.ps1 @@ -7,7 +7,7 @@ This endpoint is accessible with the `user` scope. .EXAMPLE - Add-GitHubUserEmail -Emails 'octocat@github.com','firstname.lastname@work.com' + Add-GitHubUserEmail -Email 'octocat@github.com','firstname.lastname@work.com' Adds the email addresses `octocat@github.com` and `firstname.lastname@work.com` to the authenticated user's account. @@ -26,7 +26,7 @@ ValueFromPipeline, ValueFromPipelineByPropertyName )] - [string[]] $Emails, + [string[]] $Email, # 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. @@ -42,23 +42,19 @@ } process { - try { - $body = @{ - emails = $Emails - } + $body = @{ + emails = $Email + } - $inputObject = @{ - Context = $Context - APIEndpoint = '/user/emails' - Method = 'POST' - Body = $body - } + $inputObject = @{ + Method = 'POST' + APIEndpoint = '/user/emails' + Body = $body + Context = $Context + } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } - } catch { - throw $_ + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } } diff --git a/src/functions/public/Users/Emails/Get-GitHubUserEmail.ps1 b/src/functions/public/Users/Emails/Get-GitHubUserEmail.ps1 index ed591a3a7..da5f510a6 100644 --- a/src/functions/public/Users/Emails/Get-GitHubUserEmail.ps1 +++ b/src/functions/public/Users/Emails/Get-GitHubUserEmail.ps1 @@ -48,14 +48,10 @@ } process { - try { - if ($Public) { - Get-GitHubUserPublicEmail -PerPage $PerPage -Context $Context - } else { - Get-GitHubUserAllEmail -PerPage $PerPage -Context $Context - } - } catch { - throw $_ + if ($Public) { + Get-GitHubUserPublicEmail -PerPage $PerPage -Context $Context + } else { + Get-GitHubUserAllEmail -PerPage $PerPage -Context $Context } } diff --git a/src/functions/public/Users/Emails/Remove-GitHubUserEmail.ps1 b/src/functions/public/Users/Emails/Remove-GitHubUserEmail.ps1 index 643e053af..e797bc277 100644 --- a/src/functions/public/Users/Emails/Remove-GitHubUserEmail.ps1 +++ b/src/functions/public/Users/Emails/Remove-GitHubUserEmail.ps1 @@ -24,7 +24,7 @@ ValueFromPipeline, ValueFromPipelineByPropertyName )] - [string[]] $Emails, + [string[]] $Email, # 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. @@ -40,25 +40,21 @@ } process { - try { - $body = @{ - emails = $Emails - } + $body = @{ + emails = $Email + } - $inputObject = @{ - Context = $Context - APIEndpoint = '/user/emails' - Method = 'DELETE' - Body = $body - } + $inputObject = @{ + Method = 'DELETE' + APIEndpoint = '/user/emails' + Body = $body + Context = $Context + } - if ($PSCmdlet.ShouldProcess("Email addresses [$($Emails -join ', ')]", 'Delete')) { - $null = Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } + if ($PSCmdlet.ShouldProcess("Email addresses [$($Email -join ', ')]", 'DELETE')) { + $null = Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } - } catch { - throw $_ } } diff --git a/src/functions/public/Users/Emails/Update-GitHubUserEmailVisibility.ps1 b/src/functions/public/Users/Emails/Update-GitHubUserEmailVisibility.ps1 index 8436e6067..ce0a4ca91 100644 --- a/src/functions/public/Users/Emails/Update-GitHubUserEmailVisibility.ps1 +++ b/src/functions/public/Users/Emails/Update-GitHubUserEmailVisibility.ps1 @@ -46,25 +46,21 @@ } process { - try { - $body = @{ - visibility = $Visibility - } + $body = @{ + visibility = $Visibility + } - $inputObject = @{ - Context = $Context - APIEndpoint = '/user/email/visibility' - Method = 'PATCH' - Body = $body - } + $inputObject = @{ + Method = 'PATCH' + APIEndpoint = '/user/email/visibility' + Body = $body + Context = $Context + } - if ($PSCmdlet.ShouldProcess("Email visibility [$Visibility]", 'Set')) { - $null = Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } + if ($PSCmdlet.ShouldProcess("Email visibility [$Visibility]", 'Set')) { + $null = Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } - } catch { - throw $_ } } diff --git a/src/functions/public/Users/Followers/Add-GitHubUserFollowing.ps1 b/src/functions/public/Users/Followers/Add-GitHubUserFollowing.ps1 index 7ff3a5afc..6937844b7 100644 --- a/src/functions/public/Users/Followers/Add-GitHubUserFollowing.ps1 +++ b/src/functions/public/Users/Followers/Add-GitHubUserFollowing.ps1 @@ -42,19 +42,13 @@ } process { - try { - $inputObject = @{ - Context = $Context - APIEndpoint = "/user/following/$Username" - Method = 'PUT' - } - - $null = Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } - } catch { - throw $_ + $inputObject = @{ + Method = 'PUT' + APIEndpoint = "/user/following/$Username" + Context = $Context } + + Invoke-GitHubAPI @inputObject } end { diff --git a/src/functions/public/Users/Followers/Get-GitHubUserFollower.ps1 b/src/functions/public/Users/Followers/Get-GitHubUserFollower.ps1 index 90ffb73a7..65cf93c6b 100644 --- a/src/functions/public/Users/Followers/Get-GitHubUserFollower.ps1 +++ b/src/functions/public/Users/Followers/Get-GitHubUserFollower.ps1 @@ -50,14 +50,10 @@ } process { - try { - if ($Username) { - Get-GitHubUserFollowersOfUser -Username $Username -PerPage $PerPage -Context $Context - } else { - Get-GitHubUserMyFollowers -PerPage $PerPage -Context $Context - } - } catch { - throw $_ + if ($Username) { + Get-GitHubUserFollowersOfUser -Username $Username -PerPage $PerPage -Context $Context + } else { + Get-GitHubUserMyFollowers -PerPage $PerPage -Context $Context } } diff --git a/src/functions/public/Users/Followers/Get-GitHubUserFollowing.ps1 b/src/functions/public/Users/Followers/Get-GitHubUserFollowing.ps1 index af0f38800..8dd082767 100644 --- a/src/functions/public/Users/Followers/Get-GitHubUserFollowing.ps1 +++ b/src/functions/public/Users/Followers/Get-GitHubUserFollowing.ps1 @@ -50,14 +50,10 @@ } process { - try { - if ($Username) { - Get-GitHubUserFollowingUser -Username $Username -PerPage $PerPage -Context $Context - } else { - Get-GitHubUserFollowingMe -PerPage $PerPage -Context $Context - } - } catch { - throw $_ + if ($Username) { + Get-GitHubUserFollowingUser -Username $Username -PerPage $PerPage -Context $Context + } else { + Get-GitHubUserFollowingMe -PerPage $PerPage -Context $Context } } diff --git a/src/functions/public/Users/Followers/Remove-GitHubUserFollowing.ps1 b/src/functions/public/Users/Followers/Remove-GitHubUserFollowing.ps1 index c337a6e36..50c05bdcf 100644 --- a/src/functions/public/Users/Followers/Remove-GitHubUserFollowing.ps1 +++ b/src/functions/public/Users/Followers/Remove-GitHubUserFollowing.ps1 @@ -40,20 +40,14 @@ } process { - try { - $inputObject = @{ - Context = $Context - APIEndpoint = "/user/following/$Username" - Method = 'DELETE' - } + $inputObject = @{ + Method = 'DELETE' + APIEndpoint = "/user/following/$Username" + Context = $Context + } - if ($PSCmdlet.ShouldProcess("User [$Username]", 'Unfollow')) { - $null = Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } - } - } catch { - throw $_ + if ($PSCmdlet.ShouldProcess("User [$Username]", 'Unfollow')) { + Invoke-GitHubAPI @inputObject } } diff --git a/src/functions/public/Users/Followers/Test-GitHubUserFollowing.ps1 b/src/functions/public/Users/Followers/Test-GitHubUserFollowing.ps1 index 2ae70b097..c3293f3a1 100644 --- a/src/functions/public/Users/Followers/Test-GitHubUserFollowing.ps1 +++ b/src/functions/public/Users/Followers/Test-GitHubUserFollowing.ps1 @@ -56,14 +56,10 @@ } process { - try { - if ($Username) { - Test-GitHubUserFollowedByUser -Username $Username -Follows $Follows -Context $Context - } else { - Test-GitHubUserFollowedByMe -Username $Follows -Context $Context - } - } catch { - throw $_ + if ($Username) { + Test-GitHubUserFollowedByUser -Username $Username -Follows $Follows -Context $Context + } else { + Test-GitHubUserFollowedByMe -Username $Follows -Context $Context } } diff --git a/src/functions/public/Users/GPG-Keys/Add-GitHubUserGpgKey.ps1 b/src/functions/public/Users/GPG-Keys/Add-GitHubUserGpgKey.ps1 index 230fff1fe..7666ed9f5 100644 --- a/src/functions/public/Users/GPG-Keys/Add-GitHubUserGpgKey.ps1 +++ b/src/functions/public/Users/GPG-Keys/Add-GitHubUserGpgKey.ps1 @@ -24,7 +24,7 @@ #> [OutputType([pscustomobject])] [CmdletBinding()] - param( + param ( # A descriptive name for the new key. [Parameter( Mandatory, @@ -55,24 +55,20 @@ } process { - try { - $body = @{ - name = $Name - armored_public_key = $ArmoredPublicKey - } + $body = @{ + name = $Name + armored_public_key = $ArmoredPublicKey + } - $inputObject = @{ - Context = $Context - APIEndpoint = '/user/gpg_keys' - Method = 'POST' - Body = $body - } + $inputObject = @{ + Method = 'POST' + APIEndpoint = '/user/gpg_keys' + Body = $body + Context = $Context + } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } - } catch { - throw $_ + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } } diff --git a/src/functions/public/Users/GPG-Keys/Get-GitHubUserGpgKey.ps1 b/src/functions/public/Users/GPG-Keys/Get-GitHubUserGpgKey.ps1 index 6ae2abc8c..8887e7599 100644 --- a/src/functions/public/Users/GPG-Keys/Get-GitHubUserGpgKey.ps1 +++ b/src/functions/public/Users/GPG-Keys/Get-GitHubUserGpgKey.ps1 @@ -25,7 +25,7 @@ [List GPG keys for the authenticated user](https://docs.github.com/rest/users/gpg-keys#list-gpg-keys-for-the-authenticated-user) #> [OutputType([pscustomobject])] - [CmdletBinding()] + [CmdletBinding(DefaultParameterSetName = '__AllParameterSets')] param( # The handle for the GitHub user account. [Parameter( @@ -62,18 +62,16 @@ } process { - try { - if ($Username) { + switch ($PSCmdlet.ParameterSetName) { + 'Username' { Get-GitHubUserGpgKeyForUser -Username $Username -PerPage $PerPage -Context $Context - } else { - if ($ID) { - Get-GitHubUserMyGpgKeyById -ID $ID -Context $Context - } else { - Get-GitHubUserMyGpgKey -PerPage $PerPage -Context $Context - } } - } catch { - throw $_ + 'Me' { + Get-GitHubUserMyGpgKeyById -ID $ID -Context $Context + } + default { + Get-GitHubUserMyGpgKey -PerPage $PerPage -Context $Context + } } } diff --git a/src/functions/public/Users/GPG-Keys/Remove-GitHubUserGpgKey.ps1 b/src/functions/public/Users/GPG-Keys/Remove-GitHubUserGpgKey.ps1 index 5f1449afd..6dd0d0c59 100644 --- a/src/functions/public/Users/GPG-Keys/Remove-GitHubUserGpgKey.ps1 +++ b/src/functions/public/Users/GPG-Keys/Remove-GitHubUserGpgKey.ps1 @@ -40,20 +40,14 @@ } process { - try { - $inputObject = @{ - Context = $Context - APIEndpoint = "/user/gpg_keys/$ID" - Method = 'DELETE' - } + $inputObject = @{ + Method = 'DELETE' + APIEndpoint = "/user/gpg_keys/$ID" + Context = $Context + } - if ($PSCmdlet.ShouldProcess("GPG key with ID [$ID]", 'Delete')) { - $null = Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } - } - } catch { - throw $_ + if ($PSCmdlet.ShouldProcess("GPG key with ID [$ID]", 'DELETE')) { + Invoke-GitHubAPI @inputObject } } diff --git a/src/functions/public/Users/Get-GitHubUser.ps1 b/src/functions/public/Users/Get-GitHubUser.ps1 index 0744f87e4..5bd094a89 100644 --- a/src/functions/public/Users/Get-GitHubUser.ps1 +++ b/src/functions/public/Users/Get-GitHubUser.ps1 @@ -72,26 +72,22 @@ } process { - try { - switch ($PSCmdlet.ParameterSetName) { - '__AllParameterSets' { - $user = Get-GitHubMyUser -Context $Context - $social_accounts = Get-GitHubMyUserSocials -Context $Context - $user | Add-Member -MemberType NoteProperty -Name 'social_accounts' -Value $social_accounts -Force - $user - } - 'NamedUser' { - $user = Get-GitHubUserByName -Username $Username -Context $Context - $social_accounts = Get-GitHubUserSocialsByName -Username $Username -Context $Context - $user | Add-Member -MemberType NoteProperty -Name 'social_accounts' -Value $social_accounts -Force - $user - } - 'AllUsers' { - Get-GitHubAllUser -Since $Since -PerPage $PerPage -Context $Context - } + switch ($PSCmdlet.ParameterSetName) { + 'NamedUser' { + $user = Get-GitHubUserByName -Username $Username -Context $Context + $social_accounts = Get-GitHubUserSocialsByName -Username $Username -Context $Context + $user | Add-Member -MemberType NoteProperty -Name 'social_accounts' -Value $social_accounts -Force + $user + } + 'AllUsers' { + Get-GitHubAllUser -Since $Since -PerPage $PerPage -Context $Context + } + default { + $user = Get-GitHubMyUser -Context $Context + $social_accounts = Get-GitHubMyUserSocials -Context $Context + $user | Add-Member -MemberType NoteProperty -Name 'social_accounts' -Value $social_accounts -Force + $user } - } catch { - throw $_ } } diff --git a/src/functions/public/Users/Keys/Add-GitHubUserKey.ps1 b/src/functions/public/Users/Keys/Add-GitHubUserKey.ps1 index 914060868..de8375a50 100644 --- a/src/functions/public/Users/Keys/Add-GitHubUserKey.ps1 +++ b/src/functions/public/Users/Keys/Add-GitHubUserKey.ps1 @@ -49,24 +49,20 @@ } process { - try { - $body = @{ - title = $Title - key = $Key - } + $body = @{ + title = $Title + key = $Key + } - $inputObject = @{ - Context = $Context - APIEndpoint = '/user/keys' - Method = 'POST' - Body = $body - } + $inputObject = @{ + Method = 'POST' + APIEndpoint = '/user/keys' + Body = $body + Context = $Context + } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } - } catch { - throw $_ + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } } diff --git a/src/functions/public/Users/Keys/Get-GitHubUserKey.ps1 b/src/functions/public/Users/Keys/Get-GitHubUserKey.ps1 index f339c742b..cb0d4e6cd 100644 --- a/src/functions/public/Users/Keys/Get-GitHubUserKey.ps1 +++ b/src/functions/public/Users/Keys/Get-GitHubUserKey.ps1 @@ -28,7 +28,7 @@ [List GPG keys for the authenticated user](https://docs.github.com/rest/users/gpg-keys#list-gpg-keys-for-the-authenticated-user) #> [OutputType([pscustomobject])] - [CmdletBinding()] + [CmdletBinding(DefaultParameterSetName = '__AllParameterSets')] param( # The handle for the GitHub user account. [Parameter( @@ -65,18 +65,16 @@ } process { - try { - if ($Username) { + switch ($PSCmdlet.ParameterSetName) { + 'Username' { Get-GitHubUserKeyForUser -Username $Username -PerPage $PerPage -Context $Context - } else { - if ($ID) { - Get-GitHubUserMyKeyById -ID $ID -Context $Context - } else { - Get-GitHubUserMyKey -PerPage $PerPage -Context $Context - } } - } catch { - throw $_ + 'Me' { + Get-GitHubUserMyKeyById -ID $ID -Context $Context + } + default { + Get-GitHubUserMyKey -PerPage $PerPage -Context $Context + } } } diff --git a/src/functions/public/Users/Keys/Remove-GitHubUserKey.ps1 b/src/functions/public/Users/Keys/Remove-GitHubUserKey.ps1 index 917b3bc99..21eb19876 100644 --- a/src/functions/public/Users/Keys/Remove-GitHubUserKey.ps1 +++ b/src/functions/public/Users/Keys/Remove-GitHubUserKey.ps1 @@ -41,20 +41,14 @@ } process { - try { - $inputObject = @{ - Context = $Context - APIEndpoint = "/user/keys/$ID" - Method = 'DELETE' - } + $inputObject = @{ + Method = 'DELETE' + APIEndpoint = "/user/keys/$ID" + Context = $Context + } - if ($PSCmdlet.ShouldProcess("Key with ID [$ID]", 'Delete')) { - $null = Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } - } - } catch { - throw $_ + if ($PSCmdlet.ShouldProcess("Key with ID [$ID]", 'DELETE')) { + Invoke-GitHubAPI @inputObject } } diff --git a/src/functions/public/Users/SSH-Signing-Keys/Add-GitHubUserSigningKey.ps1 b/src/functions/public/Users/SSH-Signing-Keys/Add-GitHubUserSigningKey.ps1 index 7484e2f7d..0a3e252f6 100644 --- a/src/functions/public/Users/SSH-Signing-Keys/Add-GitHubUserSigningKey.ps1 +++ b/src/functions/public/Users/SSH-Signing-Keys/Add-GitHubUserSigningKey.ps1 @@ -51,24 +51,20 @@ } process { - try { - $body = @{ - title = $Title - key = $Key - } + $body = @{ + title = $Title + key = $Key + } - $inputObject = @{ - Context = $Context - APIEndpoint = '/user/ssh_signing_keys' - Method = 'POST' - Body = $body - } + $inputObject = @{ + Method = 'POST' + APIEndpoint = '/user/ssh_signing_keys' + Body = $body + Context = $Context + } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } - } catch { - throw $_ + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } } diff --git a/src/functions/public/Users/SSH-Signing-Keys/Get-GitHubUserSigningKey.ps1 b/src/functions/public/Users/SSH-Signing-Keys/Get-GitHubUserSigningKey.ps1 index 3d3418627..afb7d54db 100644 --- a/src/functions/public/Users/SSH-Signing-Keys/Get-GitHubUserSigningKey.ps1 +++ b/src/functions/public/Users/SSH-Signing-Keys/Get-GitHubUserSigningKey.ps1 @@ -28,7 +28,7 @@ #> [OutputType([pscustomobject])] [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidLongLines', '', Justification = 'Contains a long link.')] - [CmdletBinding()] + [CmdletBinding(DefaultParameterSetName = '__AllParameterSets')] param( # The handle for the GitHub user account. [Parameter( @@ -65,18 +65,16 @@ } process { - try { - if ($Username) { + switch ($PSCmdlet.ParameterSetName) { + 'Username' { Get-GitHubUserSigningKeyForUser -Username $Username -PerPage $PerPage -Context $Context - } else { - if ($ID) { - Get-GitHubUserMySigningKeyById -ID $ID -Context $Context - } else { - Get-GitHubUserMySigningKey -PerPage $PerPage -Context $Context - } } - } catch { - throw $_ + 'Me' { + Get-GitHubUserMySigningKeyById -ID $ID -Context $Context + } + default { + Get-GitHubUserMySigningKey -PerPage $PerPage -Context $Context + } } } diff --git a/src/functions/public/Users/SSH-Signing-Keys/Remove-GitHubUserSigningKey.ps1 b/src/functions/public/Users/SSH-Signing-Keys/Remove-GitHubUserSigningKey.ps1 index 41704ce8f..7b30b078d 100644 --- a/src/functions/public/Users/SSH-Signing-Keys/Remove-GitHubUserSigningKey.ps1 +++ b/src/functions/public/Users/SSH-Signing-Keys/Remove-GitHubUserSigningKey.ps1 @@ -42,20 +42,14 @@ } process { - try { - $inputObject = @{ - Context = $Context - APIEndpoint = "/user/ssh_signing_keys/$ID" - Method = 'DELETE' - } + $inputObject = @{ + Method = 'DELETE' + APIEndpoint = "/user/ssh_signing_keys/$ID" + Context = $Context + } - if ($PSCmdlet.ShouldProcess("SSH signing key with ID [$ID]", 'Delete')) { - $null = Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } - } - } catch { - throw $_ + if ($PSCmdlet.ShouldProcess("SSH signing key with ID [$ID]", 'DELETE')) { + Invoke-GitHubAPI @inputObject } } diff --git a/src/functions/public/Users/Social-Accounts/Add-GitHubUserSocial.ps1 b/src/functions/public/Users/Social-Accounts/Add-GitHubUserSocial.ps1 index 363aad47d..c3099981b 100644 --- a/src/functions/public/Users/Social-Accounts/Add-GitHubUserSocial.ps1 +++ b/src/functions/public/Users/Social-Accounts/Add-GitHubUserSocial.ps1 @@ -21,8 +21,8 @@ param( # Full URLs for the social media profiles to add. [Parameter(Mandatory)] - [Alias('account_urls')] - [string[]] $AccountUrls, + [Alias('account_urls', 'social_accounts', 'AccountUrls')] + [string[]] $URL, # 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. @@ -38,23 +38,19 @@ } process { - try { - $body = @{ - account_urls = $AccountUrls - } + $body = @{ + account_urls = $URL + } - $inputObject = @{ - Context = $Context - APIEndpoint = '/user/social_accounts' - Body = $body - Method = 'POST' - } + $inputObject = @{ + Method = 'POST' + APIEndpoint = '/user/social_accounts' + Body = $body + Context = $Context + } - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } - } catch { - throw $_ + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } } diff --git a/src/functions/public/Users/Social-Accounts/Remove-GitHubUserSocial.ps1 b/src/functions/public/Users/Social-Accounts/Remove-GitHubUserSocial.ps1 index dcc0e3816..3a62449c1 100644 --- a/src/functions/public/Users/Social-Accounts/Remove-GitHubUserSocial.ps1 +++ b/src/functions/public/Users/Social-Accounts/Remove-GitHubUserSocial.ps1 @@ -22,8 +22,8 @@ param( # Full URLs for the social media profiles to add. [Parameter(Mandatory)] - [Alias('account_urls')] - [string[]] $AccountUrls, + [Alias('account_urls', 'social_accounts', 'AccountUrls')] + [string[]] $URL, # 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. @@ -39,25 +39,19 @@ } process { - try { - $body = @{ - account_urls = $AccountUrls - } + $body = @{ + account_urls = $URL + } - $inputObject = @{ - Context = $Context - APIEndpoint = '/user/social_accounts' - Body = $body - Method = 'DELETE' - } + $inputObject = @{ + Method = 'DELETE' + APIEndpoint = '/user/social_accounts' + Body = $body + Context = $Context + } - if ($PSCmdlet.ShouldProcess("Social accounts [$($AccountUrls -join ', ')]", 'Delete')) { - $null = Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } - } - } catch { - throw $_ + if ($PSCmdlet.ShouldProcess("Social accounts [$($URL -join ', ')]", 'DELETE')) { + Invoke-GitHubAPI @inputObject } } diff --git a/src/functions/public/Users/Update-GitHubUser.ps1 b/src/functions/public/Users/Update-GitHubUser.ps1 index 6d8a4ed33..32f4f0d68 100644 --- a/src/functions/public/Users/Update-GitHubUser.ps1 +++ b/src/functions/public/Users/Update-GitHubUser.ps1 @@ -75,33 +75,29 @@ } process { - try { - $body = @{ - name = $Name - email = $Email - blog = $Blog - twitter_username = $TwitterUsername - company = $Company - location = $Location - hireable = $Hireable - bio = $Bio - } - $body | Remove-HashtableEntry -NullOrEmptyValues + $body = @{ + name = $Name + email = $Email + blog = $Blog + twitter_username = $TwitterUsername + company = $Company + location = $Location + hireable = $Hireable + bio = $Bio + } + $body | Remove-HashtableEntry -NullOrEmptyValues - $inputObject = @{ - Context = $Context - APIEndpoint = '/user' - Method = 'PATCH' - Body = $body - } + $inputObject = @{ + Method = 'PATCH' + APIEndpoint = '/user' + Body = $body + Context = $Context + } - if ($PSCmdlet.ShouldProcess('authenticated user', 'Set')) { - Invoke-GitHubAPI @inputObject | ForEach-Object { - Write-Output $_.Response - } + if ($PSCmdlet.ShouldProcess('authenticated user', 'Set')) { + Invoke-GitHubAPI @inputObject | ForEach-Object { + Write-Output $_.Response } - } catch { - throw $_ } } diff --git a/tests/GitHub.Tests.ps1 b/tests/GitHub.Tests.ps1 index d657262cd..5fa4a693b 100644 --- a/tests/GitHub.Tests.ps1 +++ b/tests/GitHub.Tests.ps1 @@ -1,4 +1,7 @@ -[Diagnostics.CodeAnalysis.SuppressMessageAttribute( +#Requires -Modules @{ ModuleName = 'Microsoft.PowerShell.SecretManagement'; RequiredVersion = '1.1.2' } +#Requires -Modules @{ ModuleName = 'Pester'; RequiredVersion = '5.7.1' } + +[Diagnostics.CodeAnalysis.SuppressMessageAttribute( 'PSUseDeclaredVarsMoreThanAssignments', '', Justification = 'Pester grouping syntax: known issue.' )] @@ -437,7 +440,7 @@ Describe 'As a user - Fine-grained PAT token - user account access (USER_FG_PAT) { Get-GitHubLicense -Name 'mit' } | Should -Not -Throw } It 'Get-GitHubLicense - Gets a license from a repository (USER_FG_PAT)' { - { Get-GitHubLicense -Owner 'PSModule' -Repo 'GitHub' } | Should -Not -Throw + { Get-GitHubLicense -Owner 'PSModule' -Repository 'GitHub' } | Should -Not -Throw } } Context 'Emoji' { @@ -445,7 +448,7 @@ Describe 'As a user - Fine-grained PAT token - user account access (USER_FG_PAT) { Get-GitHubEmoji } | Should -Not -Throw } It 'Get-GitHubEmoji - Downloads all emojis (USER_FG_PAT)' { - { Get-GitHubEmoji -Destination $Home } | Should -Not -Throw + { Get-GitHubEmoji -Path $Home } | Should -Not -Throw } } Context 'Repository' { @@ -459,7 +462,7 @@ Describe 'As a user - Fine-grained PAT token - user account access (USER_FG_PAT) { Get-GitHubRepository -Visibility 'public' -Affiliation 'owner' } | Should -Not -Throw } It 'Get-GitHubRepository - Gets a specific repository (USER_FG_PAT)' { - { Get-GitHubRepository -Owner 'PSModule' -Repo 'GitHub' } | Should -Not -Throw + { Get-GitHubRepository -Owner 'PSModule' -Repository 'GitHub' } | Should -Not -Throw } It 'Get-GitHubRepository - Gets all repositories from a organization (USER_FG_PAT)' { { Get-GitHubRepository -Owner 'PSModule' } | Should -Not -Throw @@ -499,14 +502,14 @@ Describe 'As a user - Fine-grained PAT token - user account access (USER_FG_PAT) $user = Get-GitHubUser { Update-GitHubUser -Name 'Octocat' } | Should -Not -Throw { Update-GitHubUser -Blog 'https://psmodule.io' } | Should -Not -Throw - { Update-GitHubUser -TwitterUsername $guid } | Should -Not -Throw + { Update-GitHubUser -TwitterUsername 'PSModule' } | Should -Not -Throw { Update-GitHubUser -Company 'PSModule' } | Should -Not -Throw { Update-GitHubUser -Location 'USA' } | Should -Not -Throw { Update-GitHubUser -Bio 'I love programming' } | Should -Not -Throw $tmpUser = Get-GitHubUser $tmpUser.name | Should -Be 'Octocat' $tmpUser.blog | Should -Be 'https://psmodule.io' - $tmpUser.twitter_username | Should -Be $guid + $tmpUser.twitter_username | Should -Be 'PSModule' $tmpUser.company | Should -Be 'PSModule' $tmpUser.location | Should -Be 'USA' $tmpUser.bio | Should -Be 'I love programming' @@ -517,9 +520,9 @@ Describe 'As a user - Fine-grained PAT token - user account access (USER_FG_PAT) } It 'Add/Remove-GitHubUserEmail - Adds and removes an email to the authenticated user (USER_FG_PAT)' { $email = (New-Guid).Guid + '@psmodule.io' - { Add-GitHubUserEmail -Emails $email } | Should -Not -Throw + { Add-GitHubUserEmail -Email $email } | Should -Not -Throw (Get-GitHubUserEmail).email | Should -Contain $email - { Remove-GitHubUserEmail -Emails $email } | Should -Not -Throw + { Remove-GitHubUserEmail -Email $email } | Should -Not -Throw (Get-GitHubUserEmail).email | Should -Not -Contain $email } } @@ -594,7 +597,7 @@ Describe 'As a user - Fine-grained PAT token - organization account access (ORG_ { Get-GitHubLicense -Name 'mit' } | Should -Not -Throw } It 'Get-GitHubLicense - Gets a license from a repository (ORG_FG_PAT)' { - { Get-GitHubLicense -Owner 'PSModule' -Repo 'GitHub' } | Should -Not -Throw + { Get-GitHubLicense -Owner 'PSModule' -Repository 'GitHub' } | Should -Not -Throw } } Context 'Emoji' { @@ -602,7 +605,7 @@ Describe 'As a user - Fine-grained PAT token - organization account access (ORG_ { Get-GitHubEmoji } | Should -Not -Throw } It 'Get-GitHubEmoji - Downloads all emojis (ORG_FG_PAT)' { - { Get-GitHubEmoji -Destination $Home } | Should -Not -Throw + { Get-GitHubEmoji -Path $Home } | Should -Not -Throw } } Context 'Repository' { @@ -616,7 +619,7 @@ Describe 'As a user - Fine-grained PAT token - organization account access (ORG_ { Get-GitHubRepository -Visibility 'public' -Affiliation 'owner' } | Should -Not -Throw } It 'Get-GitHubRepository - Gets a specific repository (ORG_FG_PAT)' { - { Get-GitHubRepository -Owner 'PSModule' -Repo 'GitHub' } | Should -Not -Throw + { Get-GitHubRepository -Owner 'PSModule' -Repository 'GitHub' } | Should -Not -Throw } It 'Get-GitHubRepository - Gets all repositories from a organization (ORG_FG_PAT)' { { Get-GitHubRepository -Owner 'PSModule' } | Should -Not -Throw @@ -677,8 +680,7 @@ Describe 'As a user - Fine-grained PAT token - organization account access (ORG_ Update-GitHubOrganization -Organization 'psmodule-test-org2' -Email $email } | Should -Not -Throw { - $guid = (New-Guid).Guid - Update-GitHubOrganization -Organization 'psmodule-test-org2' -TwitterUsername $guid + Update-GitHubOrganization -Organization 'psmodule-test-org2' -TwitterUsername 'PSModule' } | Should -Not -Throw { Update-GitHubOrganization -Organization 'psmodule-test-org2' -Location 'USA' } | Should -Not -Throw { Update-GitHubOrganization -Organization 'psmodule-test-org2' -Description 'Test Organization' } | Should -Not -Throw @@ -774,7 +776,7 @@ Describe 'As a user - Classic PAT token (PAT)' { { Get-GitHubLicense -Name 'mit' } | Should -Not -Throw } It 'Get-GitHubLicense - Gets a license from a repository (PAT)' { - { Get-GitHubLicense -Owner 'PSModule' -Repo 'GitHub' } | Should -Not -Throw + { Get-GitHubLicense -Owner 'PSModule' -Repository 'GitHub' } | Should -Not -Throw } } Context 'Emoji' { @@ -782,7 +784,7 @@ Describe 'As a user - Classic PAT token (PAT)' { { Get-GitHubEmoji } | Should -Not -Throw } It 'Get-GitHubEmoji - Downloads all emojis (PAT)' { - { Get-GitHubEmoji -Destination $Home } | Should -Not -Throw + { Get-GitHubEmoji -Path $Home } | Should -Not -Throw } } Context 'GitIgnore' { @@ -816,14 +818,14 @@ Describe 'As a user - Classic PAT token (PAT)' { $user = Get-GitHubUser { Update-GitHubUser -Name 'Octocat' } | Should -Not -Throw { Update-GitHubUser -Blog 'https://psmodule.io' } | Should -Not -Throw - { Update-GitHubUser -TwitterUsername $guid } | Should -Not -Throw + { Update-GitHubUser -TwitterUsername 'PSModule' } | Should -Not -Throw { Update-GitHubUser -Company 'PSModule' } | Should -Not -Throw { Update-GitHubUser -Location 'USA' } | Should -Not -Throw { Update-GitHubUser -Bio 'I love programming' } | Should -Not -Throw $tmpUser = Get-GitHubUser $tmpUser.name | Should -Be 'Octocat' $tmpUser.blog | Should -Be 'https://psmodule.io' - $tmpUser.twitter_username | Should -Be $guid + $tmpUser.twitter_username | Should -Be 'PSModule' $tmpUser.company | Should -Be 'PSModule' $tmpUser.location | Should -Be 'USA' $tmpUser.bio | Should -Be 'I love programming' @@ -834,9 +836,9 @@ Describe 'As a user - Classic PAT token (PAT)' { } It 'Add/Remove-GitHubUserEmail - Adds and removes an email to the authenticated user (PAT)' { $email = (New-Guid).Guid + '@psmodule.io' - { Add-GitHubUserEmail -Emails $email } | Should -Not -Throw + { Add-GitHubUserEmail -Email $email } | Should -Not -Throw (Get-GitHubUserEmail).email | Should -Contain $email - { Remove-GitHubUserEmail -Emails $email } | Should -Not -Throw + { Remove-GitHubUserEmail -Email $email } | Should -Not -Throw (Get-GitHubUserEmail).email | Should -Not -Contain $email } } @@ -953,7 +955,7 @@ Describe 'As GitHub Actions (GHA)' { { Get-GitHubLicense -Name 'mit' } | Should -Not -Throw } It 'Get-GitHubLicense - Gets a license from a repository (GHA)' { - { Get-GitHubLicense -Owner 'PSModule' -Repo 'GitHub' } | Should -Not -Throw + { Get-GitHubLicense -Owner 'PSModule' -Repository 'GitHub' } | Should -Not -Throw } } Context 'Emoji' { @@ -961,7 +963,7 @@ Describe 'As GitHub Actions (GHA)' { { Get-GitHubEmoji } | Should -Not -Throw } It 'Get-GitHubEmoji - Downloads all emojis (GHA)' { - { Get-GitHubEmoji -Destination $Home } | Should -Not -Throw + { Get-GitHubEmoji -Path $Home } | Should -Not -Throw } } Context 'GitIgnore' { @@ -1030,8 +1032,8 @@ Describe 'As a GitHub App - Enterprise (APP_ENT)' { It 'Get-GitHubOrganization - Gets a specific organization (APP_ENT)' { { Get-GitHubOrganization -Organization 'psmodule-test-org3' } | Should -Not -Throw } - It 'Get-GitHubOrganizationAppInstallation - Gets the GitHub App installations on the organization (APP_ENT)' { - $installations = Get-GitHubOrganizationAppInstallation -Organization 'psmodule-test-org3' + It 'Get-GitHubAppInstallation - Gets the GitHub App installations on the organization (APP_ENT)' { + $installations = Get-GitHubAppInstallation -Organization 'psmodule-test-org3' Write-Verbose ($installations | Format-Table | Out-String) -Verbose $installations | Should -Not -BeNullOrEmpty } @@ -1050,8 +1052,7 @@ Describe 'As a GitHub App - Enterprise (APP_ENT)' { Update-GitHubOrganization -Organization 'psmodule-test-org3' -Email $email } | Should -Not -Throw { - $guid = (New-Guid).Guid - Update-GitHubOrganization -Organization 'psmodule-test-org3' -TwitterUsername $guid + Update-GitHubOrganization -Organization 'psmodule-test-org3' -TwitterUsername 'PSModule' } | Should -Not -Throw { Update-GitHubOrganization -Organization 'psmodule-test-org3' -Location 'USA' } | Should -Not -Throw { Update-GitHubOrganization -Organization 'psmodule-test-org3' -Description 'Test Organization' } | Should -Not -Throw @@ -1150,8 +1151,8 @@ Describe 'As a GitHub App - Organization (APP_ORG)' { It 'Get-GitHubOrganization - Gets a specific organization (APP_ORG)' { { Get-GitHubOrganization -Organization 'psmodule-test-org' } | Should -Not -Throw } - It 'Get-GitHubOrganizationAppInstallation - Gets the GitHub App installations on the organization (APP_ORG)' { - $installations = Get-GitHubOrganizationAppInstallation -Organization 'psmodule-test-org' + It 'Get-GitHubAppInstallation - Gets the GitHub App installations on the organization (APP_ORG)' { + $installations = Get-GitHubAppInstallation -Organization 'psmodule-test-org' Write-Verbose ($installations | Format-Table | Out-String) -Verbose $installations | Should -Not -BeNullOrEmpty } @@ -1170,8 +1171,7 @@ Describe 'As a GitHub App - Organization (APP_ORG)' { Update-GitHubOrganization -Organization 'psmodule-test-org' -Email $email } | Should -Not -Throw { - $guid = (New-Guid).Guid - Update-GitHubOrganization -Organization 'psmodule-test-org' -TwitterUsername $guid + Update-GitHubOrganization -Organization 'psmodule-test-org' -TwitterUsername 'PSModule' } | Should -Not -Throw { Update-GitHubOrganization -Organization 'psmodule-test-org' -Location 'USA' } | Should -Not -Throw { Update-GitHubOrganization -Organization 'psmodule-test-org' -Description 'Test Organization' } | Should -Not -Throw diff --git a/tools/utilities/GetDefaultsFromContext.ps1 b/tools/utilities/GetDefaultsFromContext.ps1 new file mode 100644 index 000000000..4f258e58b --- /dev/null +++ b/tools/utilities/GetDefaultsFromContext.ps1 @@ -0,0 +1,21 @@ +if ([string]::IsNullOrEmpty($Enterprise)) { + $Enterprise = $Context.Enterprise +} +Write-Debug "Enterprise: [$Enterprise]" + +if ([string]::IsNullOrEmpty($Organization)) { + $Organization = $Context.Organization +} +Write-Debug "Organization: [$Organization]" + +if ([string]::IsNullOrEmpty($Owner)) { + $Owner = $Context.Owner +} +Write-Debug "Owner: [$Owner]" + +if ([string]::IsNullOrEmpty($Repo)) { + $Repo = $Context.Repo +} +Write-Debug "Repo: [$Repo]" + +# What about "Name", "Login", "Username" diff --git a/tools/utilities/GetFunctionChanges.ps1 b/tools/utilities/GetFunctionChanges.ps1 new file mode 100644 index 000000000..b4a22ac23 --- /dev/null +++ b/tools/utilities/GetFunctionChanges.ps1 @@ -0,0 +1,33 @@ +function Get-GitBranchFileContent { + [CmdletBinding()] + param( + # The path of the file in the repository + [Parameter(Mandatory)] + [ValidateScript({ Test-Path $_ })] + [string] $Path, + + # The branch to get file content from + [Parameter()] + [string] $Branch = 'main' + ) + + $filePaths = git ls-tree -r $Branch --name-only $Path + $content = @() + foreach ($filePath in $filePaths) { + # Retrieve file content from the first reference + $tmp = git show "$Branch`:$filePath" + $tmp = $tmp -replace '∩╗┐' + $content += $tmp + } + + return $content +} + +$main = Get-GitBranchFileContent -Path 'C:\Repos\GitHub\PSModule\Module\GitHub\src' -Branch 'main' +$head = Get-GitBranchFileContent -Path 'C:\Repos\GitHub\PSModule\Module\GitHub\src' -Branch 'HEAD' + +$main | Out-File -FilePath 'C:\Repos\GitHub\PSModule\Module\GitHub\src\main.txt' +$head | Out-File -FilePath 'C:\Repos\GitHub\PSModule\Module\GitHub\src\head.txt' + + + diff --git a/tools/utilities/GetFunctionMissingDefaultParamSet.ps1 b/tools/utilities/GetFunctionMissingDefaultParamSet.ps1 new file mode 100644 index 000000000..94e831390 --- /dev/null +++ b/tools/utilities/GetFunctionMissingDefaultParamSet.ps1 @@ -0,0 +1,92 @@ +function Get-FunctionsMissingDefaultParameterSet { + param ( + [string]$Path = 'C:\Repos\GitHub\PSModule\Module\GitHub\src', + [switch]$Fix = $true + ) + + function Get-IntFunctionsMissingDefaultParameterSet { + param ( + [string]$ScriptPath + ) + + $scriptContent = Get-Content -Raw -Path $ScriptPath + + try { + $ast = [System.Management.Automation.Language.Parser]::ParseInput($scriptContent, [ref]$null, [ref]$null) + } catch { + Write-Warning "Failed to parse $ScriptPath" + return + } + + $functions = $ast.FindAll({ param ($node) $node -is [System.Management.Automation.Language.FunctionDefinitionAst] }, $true) + + $fixesNeeded = @() + + foreach ($function in $functions) { + $cmdletBinding = $function.Body.ParamBlock?.Attributes | Where-Object { $_.TypeName.Name -eq 'CmdletBinding' } + + if ($cmdletBinding) { + $hasParameterSets = $function.Body.ParamBlock.Parameters | Where-Object { $_.Attributes.NamedArguments -match 'ParameterSetName' } + + if ($hasParameterSets) { + $defaultParamSet = $cmdletBinding.NamedArguments | Where-Object { $_.ArgumentName -eq 'DefaultParameterSetName' } + + if (-not $defaultParamSet) { + $fixesNeeded += [PSCustomObject]@{ + FilePath = $ScriptPath + Function = $function.Name + LineNumber = $function.Extent.StartLineNumber + Extent = $function.Extent + } + } + } + } + } + + return $fixesNeeded + } + + function Fix-Script { + param ( + [string]$ScriptPath, + [System.Management.Automation.Language.IScriptExtent]$FunctionExtent + ) + + $scriptContent = Get-Content -Raw -Path $ScriptPath + + # Ensure the correct format for the `[CmdletBinding()]` attribute + $updatedContent = $scriptContent -replace '(?<=\[CmdletBinding\(\s*)\)', "DefaultParameterSetName = '__AllParameterSets')" + + if ($updatedContent -ne $scriptContent) { + Set-Content -Path $ScriptPath -Value $updatedContent + Write-Host "Updated: $ScriptPath -> Added DefaultParameterSetName to function at line $($FunctionExtent.StartLineNumber)" + } + } + + $results = @() + $files = Get-ChildItem -Path $Path -Filter *.ps1 -Recurse + $files += Get-ChildItem -Path $Path -Filter *.psm1 -Recurse + + foreach ($file in $files) { + $missingDefaults = Get-IntFunctionsMissingDefaultParameterSet -ScriptPath $file.FullName + if ($missingDefaults) { + $results += $missingDefaults + + if ($Fix) { + foreach ($item in $missingDefaults) { + Fix-Script -ScriptPath $item.FilePath -FunctionExtent $item.Extent + } + } + } + } + + if (-not $Fix) { + if ($results) { + $results | Format-Table -AutoSize + } else { + Write-Host 'No issues found.' + } + } else { + Write-Host 'Fix applied where necessary.' + } +} diff --git a/tools/utilities/GitHubAPI.ps1 b/tools/utilities/GitHubAPI.ps1 index bff1706b6..820c3ce40 100644 --- a/tools/utilities/GitHubAPI.ps1 +++ b/tools/utilities/GitHubAPI.ps1 @@ -1,4 +1,4 @@ -# https://github.com/github/rest-api-description +# https://github.com/github/rest-api-description $APIDocURI = 'https://raw.githubusercontent.com/github/rest-api-description/main' $Bundled = '/descriptions/api.github.com/api.github.com.json' # $Dereferenced = 'descriptions/api.github.com/dereferenced/api.github.com.deref.json' @@ -94,4 +94,3 @@ $schema.title $schema.properties.action.enum $schema.required - diff --git a/tools/utilities/Local-Testing.ps1 b/tools/utilities/Local-Testing.ps1 index d5eab535e..fbdbf708a 100644 --- a/tools/utilities/Local-Testing.ps1 +++ b/tools/utilities/Local-Testing.ps1 @@ -1,4 +1,6 @@ -##### +#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 diff --git a/tools/utilities/New-Function.ps1 b/tools/utilities/New-Function.ps1 index e7a79fde3..8c1955e05 100644 --- a/tools/utilities/New-Function.ps1 +++ b/tools/utilities/New-Function.ps1 @@ -1,5 +1,4 @@ - -function New-Function { +function New-Function { <# .SYNOPSIS Short description diff --git a/tools/utilities/StopWorkflowsCustom.ps1 b/tools/utilities/StopWorkflowsCustom.ps1 index ea7c787e3..599655573 100644 --- a/tools/utilities/StopWorkflowsCustom.ps1 +++ b/tools/utilities/StopWorkflowsCustom.ps1 @@ -30,8 +30,6 @@ Get-GitHubWorkflow | Disable-GitHubWorkflow # Cancel all started workflows Get-GitHubWorkflowRun | Where-Object status -NE completed | Stop-GitHubWorkflowRun -Get-GitHubRepoTeams - (Get-GitHubWorkflow).count