-
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 #226 from gm3dmo/issue225
Adding permissions demo
- Loading branch information
Showing
10 changed files
with
201 additions
and
15 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,39 @@ | ||
. ./.gh-api-examples.conf | ||
|
||
# https://docs.github.com/en/rest/reference/teams#add-or-update-team-membership-for-a-user | ||
# PUT /orgs/:org/teams/:team_slug/memberships/:username | ||
|
||
# https://docs.github.com/en/enterprise-cloud@latest/rest/teams/teams?apiVersion=2022-11-28#add-or-update-team-repository-permissions | ||
# PUT /orgs/{org}/teams/{team_slug}/repos/{owner}/{repo} | ||
|
||
if [ -z "$1" ] | ||
then | ||
repo=$repo | ||
else | ||
repo=$1 | ||
fi | ||
|
||
declare -A permission_to_user | ||
permissions=("pull" "triage" "push" "maintain" "admin") | ||
|
||
prefix=pwr | ||
|
||
for team_permission in "${permissions[@]}" | ||
do | ||
team_name=${prefix}-team-${team_permission} | ||
team_slug=${team_name} | ||
team_id=$(curl --silent -H "Authorization: Bearer ${GITHUB_TOKEN}" ${GITHUB_API_BASE_URL}/orgs/${org}/teams/$team_slug | jq '.id') | ||
|
||
json_file=tmp/add-or-update-team-repository-permissions.json | ||
jq -n \ | ||
--arg permission "${team_permission}" \ | ||
'{ | ||
permission: $permission, | ||
}' > ${json_file} | ||
|
||
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}/repos/${org}/${repo}" --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
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,86 @@ | ||
normal=$(tput sgr0) | ||
highlight=$(tput setaf 2) | ||
|
||
printf "$highlight" | ||
|
||
cat << EOF | ||
|
||
________ ____ | ||
/_ __/ /_ ___ / __ \____ _ _____ _____ | ||
/ / / __ \/ _ \ / /_/ / __ \ | /| / / _ \/ ___/ | ||
/ / / / / / __/ / ____/ /_/ / |/ |/ / __/ / | ||
/_/ /_/ /_/\___/ /_/ \____/|__/|__/\___/_/ | ||
|
||
EOF | ||
|
||
printf "${normal}" | ||
|
||
printf "${highlight} - Creating repo: ${normal}" | ||
./create-repo-testrepo.sh | jq -r '.name' | ||
printf "${highlight} - Creating webhook: ${normal}" | ||
./create-webhook.sh | jq -r '.id' | ||
sleep 5 | ||
|
||
printf "${highlight} - Clean the slate and delete teams (if they exist): ${normal}" | ||
echo | ||
echo | ||
./delete-teams-for-permissions.sh | ||
echo | ||
|
||
printf "${highlight} - Create the teams named based on permissions: ${normal}" | ||
echo | ||
echo | ||
./create-teams-for-repository-permission.sh | ||
echo | ||
|
||
printf "${highlight} - Add users to teams: ${normal}" | ||
echo | ||
echo | ||
./add-users-to-teams-for-repository-permission.sh | ||
echo | ||
|
||
printf "${highlight} - Add repo to teams: ${normal}" | ||
echo | ||
echo | ||
./add-repo-to-permissions-teams.sh | ||
echo | ||
printf "${highlight} - Delete team_admin user from created teams: ${normal}" | ||
echo | ||
echo | ||
./delete-admin-from-teams-for-permissions.sh | ||
echo | ||
|
||
printf "${highlight} - Add/Invite repo_collaborator user to repo: ${normal}" | ||
./add-collaborator-to-repo.sh | jq -r '.invitee.login' | ||
|
||
printf "${highlight} - Creating docs/README.md: ${normal}" | ||
./create-commit-readme.sh | jq -r ".content.html_url" | ||
printf "${highlight} - Creating CODEOWNERS: ${normal}" | ||
./create-commit-codeowners.sh| jq -r ".content.html_url" | ||
printf "${highlight} - Creating requirements.txt: ${normal}" | ||
./create-commit-python-pip.sh| jq -r ".content.html_url" | ||
sleep 2 | ||
printf "${highlight} - Creating new branch: ${normal}" | ||
./create-branch-newbranch.sh | jq -r '.url' | ||
printf "${highlight} - Creating a commit on the new branch: ${normal}" | ||
./create-commit-on-new-branch.sh | jq -r ".content.html_url" | ||
printf "${highlight} - Creating an update commit to docs/README.md: ${normal}" | ||
./create-commit-update-readme.sh | jq -r ".content.html_url" | ||
printf "${highlight} - Creating an issue: ${normal}" | ||
./create-an-issue.sh | jq -r '.html_url' | ||
printf "${highlight} - Creating a pull request: ${normal}" | ||
./create-pull-request.sh | jq -r '.html_url' | ||
# set the branch protection rules for main | ||
printf "${highlight} - Setting branch protection rules on default branch: ${normal}" | ||
./set-branch-protection.sh | jq -r '.url' | ||
|
||
printf "${highlight} - Creating a release: ${normal}" | ||
./create-release.sh | jq -r '.html_url' | ||
printf "${highlight} - Adding a .gitattributes file to new branch: ${normal}" | ||
./create-commit-gitattributes.sh | jq -r ".content.html_url" | ||
echo | ||
|
||
|
||
# If you have the appropriate token set in `pr_approver_token` | ||
# then you can provide an approving review: | ||
# ./create-approving-review-for-a-pull-request.sh |
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
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,21 @@ | ||
. ./.gh-api-examples.conf | ||
|
||
# https://docs.github.com/en/rest/reference/teams#remove-team-membership-for-a-user | ||
# DELETE /orgs/{org}/teams/{team_slug}/memberships/{username} | ||
|
||
team_member=${team_admin} | ||
prefix=pwr | ||
|
||
for team_permission in ${available_team_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') | ||
echo "${team_member} delete ----X> from ${team_name}" | ||
|
||
curl ${curl_custom_flags} \ | ||
-X DELETE \ | ||
-H "Authorization: Bearer ${GITHUB_TOKEN}" \ | ||
"${GITHUB_API_BASE_URL}/orgs/${org}/teams/${team_slug}/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,17 @@ | ||
. ./.gh-api-examples.conf | ||
|
||
|
||
|
||
|
||
|
||
for permission in ${available_team_permissions} | ||
do | ||
team_name="${team_permission_prefix}-team-${permission}" | ||
team_slug=${team_name} | ||
echo deleting ${team_slug} >&2 | ||
|
||
curl ${curl_custom_flags} \ | ||
-X DELETE \ | ||
-H "Authorization: Bearer ${GITHUB_TOKEN}" \ | ||
"${GITHUB_API_BASE_URL}/orgs/${org}/teams/${team_slug}" | ||
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