-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #224 from gm3dmo/addrepostate
Adding user team permission scripts
- Loading branch information
Showing
4 changed files
with
71 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
. ./.gh-api-examples.conf | ||
|
||
|
||
# run this script after create-teams-for-repository-permission.sh | ||
# | ||
# | ||
|
||
declare -A permission_to_user | ||
permissions=("pull" "triage" "push" "maintain" "admin") | ||
team_members_array=($team_members) | ||
|
||
for i in "${!permissions[@]}"; do | ||
permission_to_user["${permissions[i]}"]="${team_members_array[i]}" | ||
done | ||
|
||
|
||
prefix=pwr | ||
|
||
for team_permission in "${permissions[@]}"; | ||
|
||
do | ||
team_name=${prefix}-team-${team_permission} | ||
team_slug=${team_name} | ||
team_id=$(curl ${curl_custom_flags} -H "Authorization: Bearer ${GITHUB_TOKEN}" ${GITHUB_API_BASE_URL}/orgs/${org}/teams/$team_slug | jq '.id') | ||
team_member="${permission_to_user[$team_permission]}" | ||
|
||
curl ${curl_custom_flags} \ | ||
-X PUT \ | ||
-H "Accept: application/vnd.github.v3+json" \ | ||
-H "Authorization: Bearer ${GITHUB_TOKEN}" \ | ||
"${GITHUB_API_BASE_URL}/teams/${team_id}/memberships/${team_member}" | ||
done |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
. ./.gh-api-examples.conf | ||
|
||
# https://docs.github.com/en/enterprise-cloud@latest/rest/teams/teams?apiVersion=2022-11-28#create-a-team | ||
# POST /orgs/{org}/teams | ||
|
||
# Permissions for teams are from: | ||
# https://docs.github.com/en/enterprise-cloud@latest/rest/teams/teams?apiVersion=2022-11-28#add-or-update-team-repository-permissions | ||
|
||
for team_type in pull triage push maintain admin | ||
do | ||
|
||
prefix=pwr-team | ||
team_name="${prefix}-${team_type}" | ||
team=$team_name | ||
privacy="closed" | ||
#privacy="secret" | ||
json_file=tmp/team-permission-data.json | ||
|
||
jq -n \ | ||
--arg name "${team}" \ | ||
--arg description "${team} is a ${privacy} team. See: https://docs.github.com/en/enterprise-cloud@latest/rest/teams/teams?apiVersion=2022-11-28#add-or-update-team-repository-permissions" \ | ||
--arg privacy "$privacy" \ | ||
'{name: $name, description: $description, privacy: $privacy }' > ${json_file} | ||
|
||
cat $json_file | jq -r | ||
|
||
curl ${curl_custom_flags} \ | ||
-H "Accept: application/vnd.github.v3+json" \ | ||
-H "Authorization: Bearer ${GITHUB_TOKEN}" \ | ||
"${GITHUB_API_BASE_URL}/orgs/${org}/teams" --data @${json_file} | ||
|
||
done |
This file contains 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