Skip to content

Instantly share code, notes, and snippets.

@jsnape
Created January 10, 2023 21:18
Show Gist options
  • Save jsnape/9748732668d5eff98a5ef7263517067a to your computer and use it in GitHub Desktop.
Save jsnape/9748732668d5eff98a5ef7263517067a to your computer and use it in GitHub Desktop.
<#
.SYNOPSIS
Configures the repo permissions to restrict branch names.
.DESCRIPTION
Branches should be master, release/, hotfix/, feature/ etc
This script ensures that they are.
#>
[CmdletBinding(PositionalBinding)]
param(
[Parameter()]
[string]
# The repository to configure
$repo,
[Parameter()]
[string]
# The project to configure
$project,
[Parameter()]
[string]
# The project collection to configure
$collection
)
$script:collectionUri = "https://dev.azure.com/$collection/"
$projectAdmins = "[$project]\Project Administrators"
$releaseAdmins = "[$project]\Release Administrators"
$contributors = "[$project]\Contributors"
function Grant-BranchCreate {
param($group, $branch)
tf.exe git permission /allow:CreateBranch /group:$group /collection:$collectionUri /teamproject:$project /repository:$repo /branch:$branch
}
tf.exe git permission /deny:CreateBranch /group:$contributors /collection:$collectionUri /teamproject:$project /repository:$repo
$topicBranches = @('feature', 'user', 'hotfix', 'bugfix')
$topicBranches | ForEach-Object {
Grant-BranchCreate $contributors $_
}
Grant-BranchCreate $releaseAdmins 'release'
Grant-BranchCreate $projectAdmins 'master'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment