Skip to content

Instantly share code, notes, and snippets.

@anderssonjohan
Last active May 10, 2023 14:27
Show Gist options
  • Save anderssonjohan/738ccf7beb01bfbadb94da21e05d0d6a to your computer and use it in GitHub Desktop.
Save anderssonjohan/738ccf7beb01bfbadb94da21e05d0d6a to your computer and use it in GitHub Desktop.
Get and delete deployments for a github repository
param(
$owner,
$repository_name,
$databaseid
)
gh api --method DELETE -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" /repos/$owner/$repository_name/deployments/$databaseid
param(
[parameter(mandatory, valuefrompipelinebypropertyname)]
[string] $owner,
[parameter(mandatory, valuefrompipelinebypropertyname)]
[string] $name
)
begin {
function getDeploymentsQuery($owner, $name) {
@"
{
repository(name: "$name", owner: "$owner") {
id
deployments(first: 10, orderBy: {field: CREATED_AT, direction: DESC}, environments: "production") {
nodes {
environment
state
databaseId
createdAt
}
}
}
}
"@
}
}
process {
$query = getDeploymentsQuery $owner $name
$result = ./execute-graphql.ps1 $query
$result | % repository | % deployments | % nodes `
| add-member -PassThru -Name repository_name -Value $name -MemberType NoteProperty `
| add-member -PassThru -Name owner -Value $owner -MemberType NoteProperty
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment