-
Notifications
You must be signed in to change notification settings - Fork 0
/
Create-OrganisationTeam.ps1
29 lines (20 loc) · 1.05 KB
/
Create-OrganisationTeam.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
param (
[string] $TeamName,
[string] $OrganizationName
)
$Header = GetBasicAuthenticationHeader
$CreateRepoGithubUri = "https://api.github.com/orgs/$OrganizationName/teams";
$Body = @{
name = $TeamName
}
$TeamResponse = Invoke-RestMethod -Uri $CreateRepoGithubUri -Headers @{Authorization = $Header} -ContentType "application/json" -Method Post -Body (ConvertTo-Json $Body)
$AzureGroupsUri = "https://api.github.com/orgs/$OrganizationName/team-sync/groups";
$Response = Invoke-RestMethod -Uri $AzureGroupsUri -Headers @{Authorization = $Header} -ContentType "application/json" -Method Get
$AzureGroup = @($Response.groups | Where-Object {$_.group_name -eq $TeamName})
$TeamSlug = $TeamResponse.slug
$GroupMappingUri = "https://api.github.com/orgs/$OrganizationName/teams/$TeamSlug/team-sync/group-mappings";
$GroupsMappingBody = @{
groups = $AzureGroup
}
$Response = Invoke-RestMethod -Uri $GroupMappingUri -Headers @{Authorization = $Header} -ContentType "application/json" -Method Patch -Body (ConvertTo-Json $GroupsMappingBody)
return $TeamResponse