Last active
June 12, 2024 22:45
-
-
Save lionello/a7e4ad3ba72c117a35de05f6735551d7 to your computer and use it in GitHub Desktop.
Shell script to bulk-transfer repositories from one org to another
This file contains hidden or 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
#!/usr/bin/env bash | |
set -e # Exit on error | |
ORG=DefangLabs | |
OWNER=$ORG | |
NEW_OWNER=DefangSamples | |
TOKEN=ghp_… # REPLACE | |
repos=$(curl -sL \ | |
-H "Accept: application/vnd.github+json" \ | |
-H "Authorization: Bearer $TOKEN" \ | |
-H "X-GitHub-Api-Version: 2022-11-28" \ | |
"https://api.github.com/orgs/$ORG/repos?type=public&per_page=100" | jq -r '.[] | select(.is_template == true) | .name') | |
for REPO in $repos; do | |
echo "Moving $REPO to $NEW_OWNER" | |
curl -sL \ | |
-X POST \ | |
-H "Accept: application/vnd.github+json" \ | |
-H "Authorization: Bearer $TOKEN" \ | |
-H "X-GitHub-Api-Version: 2022-11-28" \ | |
https://api.github.com/repos/$OWNER/$REPO/transfer \ | |
-d "{\"new_owner\":\"$NEW_OWNER\"}" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment