Created
August 24, 2023 11:56
-
-
Save dinkelspiel/83b0679a15f3145e94c06483d330c233 to your computer and use it in GitHub Desktop.
Import all projects from a GitHub account into a GitLab account
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
#!/bin/bash | |
# GitHub & GitLab personal access tokens | |
GITHUB_TOKEN=<Github PAT Token> | |
GITLAB_TOKEN=<Gitlab PAT Token> | |
# Usernames for GitHub & GitLab | |
GITHUB_USERNAME=<Github Username> | |
GITLAB_NAMESPACE=<Gitlab username> | |
# URL of your GitLab instance (default is gitlab.com) | |
GITLAB_URL="https://gitlab.com" | |
# Fetch all repos from GitHub | |
repos=$(curl -s -H "Authorization: token $GITHUB_TOKEN" "https://api.github.com/users/$GITHUB_USERNAME/repos?per_page=100" | jq -c '.[] | {name: .name, id: .id}') | |
for repo_info in $repos; do | |
repo_name=$(echo "$repo_info" | jq -r '.name') | |
repo_id=$(echo "$repo_info" | jq -r '.id') | |
echo "Importing $repo_name from GitHub to GitLab..." | |
# Trigger the import process using GitLab's API | |
curl -s --header "PRIVATE-TOKEN: $GITLAB_TOKEN" \ | |
--data "personal_access_token=$GITHUB_TOKEN" \ | |
--data "repo_id=$repo_id" \ | |
--data "target_namespace=$GITLAB_NAMESPACE" \ | |
"$GITLAB_URL/api/v4/import/github" | |
sleep 2 # A slight delay to not overwhelm the API, can be adjusted | |
done | |
echo "All repos imported or import triggered. Check GitLab for status." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment