Skip to content

Commit

Permalink
Added get repo CODEOWNERS errors
Browse files Browse the repository at this point in the history
  • Loading branch information
MariusStorhaug committed Oct 12, 2023
1 parent 23dd302 commit 6564da8
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
filter Get-GitHubRepositoryCodeownersError {
<#
.SYNOPSIS
List CODEOWNERS errors
.DESCRIPTION
List any syntax errors that are detected in the CODEOWNERS file.
For more information about the correct CODEOWNERS syntax,
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'
Gets the CODEOWNERS errors for the repository.
.NOTES
https://docs.github.com/rest/repos/repos#list-codeowners-errors
#>
[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),

# 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)
[Parameter()]
[string] $Ref
)

$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-HashtableEntries -Hashtable $body -RemoveNames 'Owner','Repo' -RemoveTypes 'SwitchParameter'

$inputObject = @{
APIEndpoint = "/repos/$Owner/$Repo/codeowners/errors"
Method = 'GET'
Body = $body
}

Invoke-GitHubAPI @inputObject | ForEach-Object {
Write-Output $_.Response
}
}
2 changes: 1 addition & 1 deletion tools/utilities/GitHubAPI.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ $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}/teams'
$path = '/repos/{owner}/{repo}/codeowners/errors'
$method = 'get'
$response.paths.$path.$method
$response.paths.$path.$method.tags | clip # -> Namespace/foldername
Expand Down
4 changes: 2 additions & 2 deletions tools/utilities/Local-Testing.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Get-SecretInfo
Get-Module -Name GitHub -ListAvailable
$VerbosePreference = 'Continue'

Find-Module -Name GitHub
Install-Module -Name GitHub -Force -Verbose -AllowPrerelease
Get-Module -Name GitHub -ListAvailable
# $env:PSModulePath += ';C:\Repos\GitHub\PSModule\Modules\GitHub\outputs'
Expand Down Expand Up @@ -125,9 +126,9 @@ $params = @{
DeleteBranchOnMerge = $true
}
New-GitHubRepositoryOrg @params -GitignoreTemplate VisualStudio -LicenseTemplate mit

Remove-GitHubRepository -Owner PSModule -Repo 'Hello-world' -Verbose


$params = @{
Verbose = $true
Name = 'Hello-world'
Expand All @@ -154,7 +155,6 @@ $params = @{
DeleteBranchOnMerge = $true
}
New-GitHubRepositoryUser @params -GitignoreTemplate VisualStudio -LicenseTemplate gpl-3.0

Remove-GitHubRepository -Owner MariusStorhaug -Repo 'Hello-world' -Verbose


Expand Down

0 comments on commit 6564da8

Please sign in to comment.