寻找将所有存储库从 GitHub 组织迁移/转移到同一 GitHub 实例中的另一个 GitHub 组织。有人以前尝试过这个吗?
请提出建议。谢谢
您可以使用 Transfer 自动将存储库从一个组织转移到另一个组织。有一些 API 可以使用脚本来执行此操作,而不是手动执行。
curl -L \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>"\
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/orgs/ORG/repos
转移仓库:
curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>"\
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/OWNER/REPO/transfer \
-d '{"new_owner":"github","new_name":"octorepo"}
根据 @jessehouwing 的回答,我创建了一个 bash 脚本,将 100 多个存储库从一个组织移动到另一个组织,并且效果非常好。每次都移动30个repos,我不知道为什么,也懒得去调试。
#!/bin/bash
# Set variables
OLD_ORG="" # Source organization
NEW_ORG="" # Destination organization
GITHUB_TOKEN="" # GitHub token with admin repo permissions
API_VERSION="2022-11-28" # GitHub API version
# Get the list of all repositories in the old organization
repos=$(curl -s -L \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
-H "X-GitHub-Api-Version: ${API_VERSION}" \
https://api.github.com/orgs/${OLD_ORG}/repos | jq -r '.[].name')
# Check if jq is installed
if ! command -v jq &> /dev/null; then
echo "The 'jq' command is required but not installed. Please install 'jq' and try again."
exit 1
fi
# Loop through each repository and transfer it to the new organization
for repo in $repos; do
echo "Transferring repo: ${repo} to ${NEW_ORG}"
# API call to transfer the repository
curl -s -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
-H "X-GitHub-Api-Version: ${API_VERSION}" \
https://api.github.com/repos/${OLD_ORG}/${repo}/transfer \
-d "{\"new_owner\":\"${NEW_ORG}\"}"
echo "Transfer request for repo: ${repo} sent."
done
echo "All transfer requests completed."