-
-
Save carloscarucce/e3428dcc2055cb9a66fc205cee577fc1 to your computer and use it in GitHub Desktop.
Add repos to team with gh
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
#!/bin/bash | |
PERMISSION="push" # Can be one of: pull, push, admin, maintain, triage | |
ORG="orgname" | |
TEAM_SLUG="your-team-slug" | |
# Get names with `gh repo list orgname` | |
# Change "limit" if necessary | |
gh repo list $ORG --limit 1000 --json name --json owner -q '.[] | "\(.owner.login)/\(.name)"' | while read -r REPO; do | |
echo "Repo: ${REPO}\r\n" | |
echo "Adding repo ${REPO} to Org:$ORG Team:$TEAM_SLUG" | |
# https://docs.github.com/en/rest/teams/teams#add-or-update-team-repository-permissions | |
# (needs admin:org scope) | |
# --silent added to make it less noisy | |
gh api \ | |
--method PUT \ | |
-H "Accept: application/vnd.github+json" \ | |
--silent \ | |
"/orgs/$ORG/teams/$TEAM_SLUG/repos/$REPO" \ | |
-f permission="$PERMISSION" && echo 'Added' || echo 'Failed' | |
echo "\n============================================================\n" | |
done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment