Skip to content

Instantly share code, notes, and snippets.

@Richard-Barrett
Last active February 20, 2025 23:16
Show Gist options
  • Select an option

  • Save Richard-Barrett/e0f994c05611f6b5430f5d7f8d0699f8 to your computer and use it in GitHub Desktop.

Select an option

Save Richard-Barrett/e0f994c05611f6b5430f5d7f8d0699f8 to your computer and use it in GitHub Desktop.
GitHub Migration Script Using A Flat Text File with Org Names
#!/bin/bash
# Define the source file containing the list of SOURCE_ORG names
SOURCE_FILE="orgs.txt"
TARGET_ENTERPRISE=$TARGET_ENTERPRISE
# Number of parallel jobs (adjust as needed)
PARALLEL_JOBS=5
DRY_RUN=false
# Parse command-line arguments
while [[ "$#" -gt 0 ]]; do
case "$1" in
--dry-run) DRY_RUN=true ;;
*) echo "Unknown option: $1"; exit 1 ;;
esac
shift
done
# Function to migrate an organization
migrate_org() {
local SOURCE_ORG="$1"
local TARGET_ORG="${SOURCE_ORG}-new"
if [ "$DRY_RUN" = true ]; then
echo "[Dry Run] Would migrate: $SOURCE_ORG -> $TARGET_ORG"
else
echo "Migrating from $SOURCE_ORG to $TARGET_ORG..."
gh gei migrate-org --github-source-org "$SOURCE_ORG" --github-target-org "$TARGET_ORG" --github-target-enterprise "$TARGET_ENTERPRISE"
fi
}
export -f migrate_org
export TARGET_ENTERPRISE DRY_RUN
# Read the orgs file and process them in parallel
if [ "$DRY_RUN" = true ]; then
while IFS= read -r ORG; do
migrate_org "$ORG"
done < "$SOURCE_FILE"
else
cat "$SOURCE_FILE" | xargs -I {} -P "$PARALLEL_JOBS" bash -c 'migrate_org "$@"' _ {}
fi
echo "All migrations completed."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment