Skip to content

Commit

Permalink
Add Test-RepoVulnerabiltyAlerts
Browse files Browse the repository at this point in the history
  • Loading branch information
MariusStorhaug committed Oct 30, 2023
1 parent 1fc123e commit 9e7a3c7
Showing 1 changed file with 49 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
filter Test-GitHubRepositoryVulnerabilityAlert {
<#
.SYNOPSIS
Check if vulnerability alerts are enabled for a repository
.DESCRIPTION
Shows whether dependency alerts are enabled or disabled for a repository.
The authenticated user must have admin read access to the repository.
For more information, see
"[About security alerts for vulnerable dependencies](https://docs.github.com/articles/about-security-alerts-for-vulnerable-dependencies)".
.EXAMPLE
Test-GitHubRepositoryVulnerabilityAlert -Owner 'PSModule' -Repo 'GitHub'
Checks if vulnerability alerts are enabled for the PSModule/GitHub repository.
.NOTES
https://docs.github.com/rest/repos/repos#list-repository-tags
#>
[OutputType([bool])]
[CmdletBinding()]
[Alias('Test-GitHubRepositoryVulnerabilityAlerts')]
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)
)

$inputObject = @{
APIEndpoint = "/repos/$Owner/$Repo/vulnerability-alerts"
Method = 'GET'
}

try {
(Invoke-GitHubAPI @inputObject).StatusCode -eq 204
} catch {
if ($_.Exception.Response.StatusCode.Value__ -eq 404) {
return $false
} else {
throw $_
}
}
}

0 comments on commit 9e7a3c7

Please sign in to comment.