Skip to content

Instantly share code, notes, and snippets.

@carloscarucce
Forked from narze/gh-add-repos-to-team.sh
Last active June 12, 2024 18:56
Show Gist options
  • Save carloscarucce/e3428dcc2055cb9a66fc205cee577fc1 to your computer and use it in GitHub Desktop.
Save carloscarucce/e3428dcc2055cb9a66fc205cee577fc1 to your computer and use it in GitHub Desktop.
Add repos to team with gh
#!/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