I am writing a code in powershell to update the teams who can push to matching branches So when i write the below code in this way it works but i only want to update the teams and i dont want to update any other branch protection rules. How can i achieve that?
Code which works and which also updates the whole branch protection rule if i keep the below json body into
$jsonBody = '
{
"required_pull_request_reviews": {
"dismiss_stale_reviews": false,
"require_code_owner_reviews": false,
"required_approving_review_count": 2
},
"enforce_admins": false,
"required_status_checks" : null,
"restrictions": {
"users": [],
"teams": ["test"],
"apps": []
}
}'
$response = Invoke-WebRequest -Uri "https://github.source.internal/api/v3/$repos/cds/Api.testbpr/branches/master/protection" -Method Put -Body $body -ContentType "application/json" `
-Headers @{"Authorization"=$headerString; `
"Accept"="application/vnd.github.luke-cage-preview+json" } `
-TimeoutSec 300 -UseBasicParsing
The above code works and updates the whole branch protection rule but what i need to achieve is that i just want to add a team under restrictions and i tried the below code but it throws error
$response = Invoke-WebRequest -Uri "https://github.source.internal/api/v3/$repos/cds/Api.testbpr/branches/master/protection/restrictions/teams" -Method Put -Body '{"teams":["test"]}' -ContentType "application/json" `
-Headers @{"Authorization"=$headerString; `
"Accept"="application/vnd.github.luke-cage-preview+json" } `
-TimeoutSec 300 -UseBasicParsing
Error : Invoke-WebRequest : {"message":"Invalid request.\n\nFor 'links/9/schema', {\"teams\"=>[\"teams\"]} is not an
array.","documentation_url":"https://docs.github.com/enterprise/3.5/rest/reference/repos#add-team-access-restrictions"}