Skip to content

Instantly share code, notes, and snippets.

@drewfreyling
Last active July 15, 2019 05:51
Show Gist options
  • Save drewfreyling/941be380c309cdcc4a7161ea44351e5b to your computer and use it in GitHub Desktop.
Save drewfreyling/941be380c309cdcc4a7161ea44351e5b to your computer and use it in GitHub Desktop.
Update Builds and Approvers for all repos
$Credential = Get-Credential
$uri = 'https://stash.globalx.com.au/rest/api/1.0/projects?limit=100'
$projects = Invoke-RestMethod -uri $uri -Authentication Basic -Credential $Credential
ForEach ($project in $projects.values)
{
$key = $project.key
$uri = "https://stash.globalx.com.au/rest/api/1.0/projects/$key/repos?limit=500"
$repos = Invoke-RestMethod -uri $uri -Authentication Basic -Credential $Credential
ForEach ($repo in $repos.values)
{
$name = $repo.name
$name = $name -replace '\s','-'
$uri = "https://stash.globalx.com.au/rest/api/1.0/projects/$key/repos/$name/settings/pull-requests"
$prSettings = Invoke-RestMethod -uri $uri -Authentication Basic -Credential $Credential
If ($prSettings.requiredApprovers -eq 0) {
$prSettings.requiredApprovers = 1
$prSettings.requiredSuccessfulBuilds = 1
$prSettingsJson = $prSettings | convertto-json
Write-Host "Updating $name with 1 approver and 1 sucessful build"
Invoke-RestMethod -Method POST -uri $uri -Authentication Basic -Credential $Credential -Body $prSettingsJson -ContentType 'application/json'
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment