Created
January 10, 2023 21:18
-
-
Save jsnape/9748732668d5eff98a5ef7263517067a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.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