Skip to content

Instantly share code, notes, and snippets.

@garlandkr
Forked from narze/gh-add-repos-to-team.sh
Created October 26, 2022 18:30
Show Gist options
  • Save garlandkr/11f0fdfcfcc379368b649c6fd650c2ae to your computer and use it in GitHub Desktop.
Save garlandkr/11f0fdfcfcc379368b649c6fd650c2ae 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`
REPOS=(
"orgname/reponame"
)
for REPO in "${REPOS[@]}"; do
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