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,41 @@
filter Get-GitHubRepositoryTagProtection {
<#
.SYNOPSIS
List tag protection states for a repository

.DESCRIPTION
This returns the tag protection states of a repository.

This information is only available to repository administrators.

.EXAMPLE
Get-GitHubRepositoryTagProtection -Owner 'octocat' -Repo 'hello-world'

Gets the tag protection states of the 'hello-world' repository.

.NOTES
https://docs.github.com/rest/repos/tags#list-tag-protection-states-for-a-repository

#>
[OutputType([pscustomobject])]
[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)
)

$inputObject = @{
APIEndpoint = "/repos/$Owner/$Repo/tags/protection"
Method = 'GET'
}

Invoke-GitHubAPI @inputObject | ForEach-Object {
Write-Output $_.Response
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
filter New-GitHubRepositoryTagProtection {
<#
.SYNOPSIS
Create a tag protection state for a repository

.DESCRIPTION
This creates a tag protection state for a repository.
This endpoint is only available to repository administrators.

.EXAMPLE
New-GitHubRepositoryTagProtection -Owner 'octocat' -Repo 'hello-world' -Pattern 'v1.*'

Creates a tag protection state for the 'hello-world' repository with the pattern 'v1.*'.

.NOTES
https://docs.github.com/rest/repos/tags#create-a-tag-protection-state-for-a-repository

#>
[OutputType([pscustomobject])]
[CmdletBinding(SupportsShouldProcess)]
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),

# An optional glob pattern to match against when enforcing tag protection.
[Parameter(Mandatory)]
[string] $Pattern
)

$body['pattern'] = $Pattern

$inputObject = @{
APIEndpoint = "/repos/$Owner/$Repo/tags/protection"
Method = 'POST'
Body = $body
}

if ($PSCmdlet.ShouldProcess("tag protection state on pattern [$Pattern] for repository [$Owner/$Repo]", 'Create')) {
Invoke-GitHubAPI @inputObject | ForEach-Object {
Write-Output $_.Response
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
filter Remove-GitHubRepositoryTagProtection {
<#
.SYNOPSIS
Delete a tag protection state for a repository

.DESCRIPTION
This deletes a tag protection state for a repository.
This endpoint is only available to repository administrators.

.EXAMPLE
Remove-GitHubRepositoryTagProtection -Owner 'octocat' -Repo 'hello-world' -TagProtectionId 1

Deletes the tag protection state with the id 1 for the 'hello-world' repository.

.NOTES
https://docs.github.com/rest/repos/tags#delete-a-tag-protection-state-for-a-repository

#>
[OutputType([pscustomobject])]
[CmdletBinding(SupportsShouldProcess)]
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 tag protection.
[Parameter(Mandatory)]
[int] $TagProtectionId
)

$inputObject = @{
APIEndpoint = "/repos/$Owner/$Repo/tags/protection/$TagProtectionId"
Method = 'DELETE'
}

if ($PSCmdlet.ShouldProcess("tag protection state with ID [$TagProtectionId] for repository [$Owner/$Repo]", 'Delete')) {
Invoke-GitHubAPI @inputObject | ForEach-Object {
Write-Output $_.Response
}
}
}
12 changes: 6 additions & 6 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}/properties/values'
$method = 'get'
$path = '/repos/{owner}/{repo}/tags/protection/{tag_protection_id}'
$method = 'delete'
$response.paths.$path.$method
$response.paths.$path.$method.tags | clip # -> Namespace/foldername
$response.paths.$path.$method.operationId | clip # -> FunctionName
Expand All @@ -42,11 +42,11 @@ $response.paths.$path.$method.responses.'200'.content.'application/json'.schema.

$response.components.schemas.PSobject.Properties | ForEach-Object {
[pscustomobject]@{
Name = $_.Name
Title = $_.Value.title
Type = $_.Value.type
Name ame
Titlee.title
Typelype
Properties = $_.Value.properties
Required = $_.Value.required
Requiredlue.required
}
}

Expand Down