Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
filter Get-GitHubRepositoryRuleSuite {
<#
.SYNOPSIS
List repository rule suites or a rule suite by id.

.DESCRIPTION
Lists suites of rule evaluations at the repository level.
If an ID is specified, gets information about a suite of rule evaluations from within a repository.
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
$params = @{
Owner = 'octocat'
Repo = 'hello-world'
Ref = 'main'
TimePeriod = 'day'
ActorName = 'octocat'
RuleSuiteResult = 'all'
}
Get-GitHubRepositoryRuleSuite @params

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

Gets information about a suite of rule evaluations with id 123456789 from within the octocat/hello-world repository.

.NOTES
https://docs.github.com/rest/repos/rule-suites#list-repository-rule-suites
https://docs.github.com/rest/repos/rule-suites#get-a-repository-rule-suite

#>
[OutputType([pscustomobject])]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidLongLines', '', Justification = 'Long links')]
[CmdletBinding(DefaultParameterSetName = 'Default')]
param (
# The account owner of the repository. The name is not case sensitive.
[Parameter()]
[Alias('org')]
[string] $Owner = (Get-GitHubConfig -Name Owner),

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

# The name of the ref. Cannot contain wildcard characters.
# When specified, only rule evaluations triggered for this ref will be returned.
[Parameter()]
[string] $Ref,

# The time period to filter by.
# For example,day will filter for rule suites that occurred in the past 24 hours,
# and week will filter for insights that occurred in the past 7 days (168 hours).
[Parameter()]
[ValidateSet('hour', 'day', 'week', 'month')]
[string] $TimePeriod = 'day',

# The handle for the GitHub user account to filter on. When specified, only rule evaluations triggered by this actor will be returned.
[Parameter()]
[string] $ActorName,

# The rule results to filter on. When specified, only suites with this result will be returned.
[Parameter()]
[ValidateSet('pass', 'fail', 'bypass', 'all')]
[string] $RuleSuiteResult = 'all',

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

# 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,
ParameterSetName = 'ById'
)]
[int] $RuleSuiteId
)

switch ($PSCmdlet.ParameterSetName) {
'Default' {
$params = @{
Owner = $Owner
Repo = $Repo
Ref = $Ref
TimePeriod = $TimePeriod
ActorName = $ActorName
RuleSuiteResult = $RuleSuiteResult
PerPage = $PerPage
}
Get-GitHubRepositoryRuleSuiteList @params
}
'ById' {
$params = @{
Owner = $Owner
Repo = $Repo
RuleSuiteId = $RuleSuiteId
}
Get-GitHubRepositoryRuleSuiteById @params
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
filter Get-GitHubRepositoryRuleSuiteById {
<#
.SYNOPSIS
Get a repository rule suite

.DESCRIPTION
Gets information about a suite of rule evaluations from within a repository.
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

Gets information about a suite of rule evaluations with id 123456789 from within the octocat/hello-world repository.

.NOTES
https://docs.github.com/rest/repos/rule-suites#get-a-repository-rule-suite

#>
[OutputType([pscustomobject])]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidLongLines', '', Justification = 'Long links')]
[CmdletBinding()]
param (
# The account owner of the repository. The name is not case sensitive.
[Parameter()]
[Alias('org')]
[string] $Owner = (Get-GitHubConfig -Name Owner),

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

# 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

)

$inputObject = @{
APIEndpoint = "/repos/$Owner/$Repo/rulesets/rule-suites/$RuleSuiteId"
Method = 'GET'
}

Invoke-GitHubAPI @inputObject | ForEach-Object {
Write-Output $_.Response
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
filter Get-GitHubRepositoryRuleSuiteList {
<#
.SYNOPSIS
List repository rule suites

.DESCRIPTION
Lists suites of rule evaluations at the repository level.
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
$params = @{
Owner = 'octocat'
Repo = 'hello-world'
Ref = 'main'
TimePeriod = 'day'
ActorName = 'octocat'
RuleSuiteResult = 'all'
}
Get-GitHubRepositoryRuleSuiteList @params

Gets a list of rule suites for the main branch of the hello-world repository owned by octocat.

.NOTES
https://docs.github.com/rest/repos/rule-suites#list-repository-rule-suites

#>
[OutputType([pscustomobject])]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidLongLines', '', Justification = 'Long links')]
[CmdletBinding()]
param (
# The account owner of the repository. The name is not case sensitive.
[Parameter()]
[Alias('org')]
[string] $Owner = (Get-GitHubConfig -Name Owner),

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

# The name of the ref. Cannot contain wildcard characters.
# When specified, only rule evaluations triggered for this ref will be returned.
[Parameter()]
[string] $Ref,

# The time period to filter by.
# For example,day will filter for rule suites that occurred in the past 24 hours,
# and week will filter for insights that occurred in the past 7 days (168 hours).
[Parameter()]
[ValidateSet('hour', 'day', 'week', 'month')]
[string] $TimePeriod = 'day',

# The handle for the GitHub user account to filter on. When specified, only rule evaluations triggered by this actor will be returned.
[Parameter()]
[string] $ActorName,

# The rule results to filter on. When specified, only suites with this result will be returned.
[Parameter()]
[ValidateSet('pass', 'fail', 'bypass', 'all')]
[string] $RuleSuiteResult = 'all',

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

$PSCmdlet.MyInvocation.MyCommand.Parameters.GetEnumerator() | ForEach-Object {
$paramName = $_.Key
$paramDefaultValue = Get-Variable -Name $paramName -ValueOnly -ErrorAction SilentlyContinue
$providedValue = $PSBoundParameters[$paramName]
Write-Verbose "[$paramName]"
Write-Verbose " - Default: [$paramDefaultValue]"
Write-Verbose " - Provided: [$providedValue]"
if (-not $PSBoundParameters.ContainsKey($paramName) -and ($null -ne $paramDefaultValue)) {
Write-Verbose ' - Using default value'
$PSBoundParameters[$paramName] = $paramDefaultValue
} else {
Write-Verbose ' - Using provided value'
}
}

$body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case
Remove-HashtableEntry -Hashtable $body -RemoveNames 'Owner', 'Repo' -RemoveTypes 'SwitchParameter'


$inputObject = @{
APIEndpoint = "/repos/$Owner/$Repo/rulesets/rule-suites"
Method = 'GET'
Body = $body
}

Invoke-GitHubAPI @inputObject | ForEach-Object {
Write-Output $_.Response
}
}
4 changes: 2 additions & 2 deletions tools/utilities/GitHubAPI.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ $response = Invoke-RestMethod -Uri $APIDocURI -Method Get
# @{n = 'PUT'; e = { (($_.value.psobject.Properties.Name) -contains 'PUT') } }, `
# @{n = 'PATCH'; e = { (($_.value.psobject.Properties.Name) -contains 'PATCH') } } | Format-Table

$path = '/repos/{owner}/{repo}/tags/protection/{tag_protection_id}'
$method = 'delete'
$path = '/repos/{owner}/{repo}/rulesets/rule-suites/{rule_suite_id}'
$method = 'get'
$response.paths.$path.$method
$response.paths.$path.$method.tags | clip # -> Namespace/foldername
$response.paths.$path.$method.operationId | clip # -> FunctionName
Expand Down