将所有存储库从 GitHub 组织迁移到另一个 GitHub 组织(同一实例)

问题描述 投票:0回答:2

寻找将所有存储库从 GitHub 组织迁移/转移到同一 GitHub 实例中的另一个 GitHub 组织。有人以前尝试过这个吗?

  • 列出组织中的所有存储库(可以是 10 或 1000+)
  • 将它们移动到另一个组织,转移包括 - 存储库的所有功能 - 代码历史记录、PR、问题、操作(秘密/环境)、分支保护规则

请提出建议。谢谢

git github migration
2个回答
1
投票

您可以使用 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"}

0
投票

根据 @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."
© www.soinside.com 2019 - 2024. All rights reserved.