Skip to content

Instantly share code, notes, and snippets.

@Hitokun
Created December 30, 2024 22:58
Show Gist options
  • Save Hitokun/4b1e6d63c295c06620ffa87d5c612924 to your computer and use it in GitHub Desktop.
Save Hitokun/4b1e6d63c295c06620ffa87d5c612924 to your computer and use it in GitHub Desktop.
How to import repositories from Self-Managed GitHub Enterprise instances into GitLab
# Import Project from GitHub Enterprise Self Managed to Gitlab.
# More info: https://docs.gitlab.com/ee/user/project/import/github.html#use-the-api
#
# Usage ./github_import.sh repo_id <Repo name>
# To find repo_id and name of the repos, do something like:
# curl -L \
# -H "Accept: application/vnd.github+json" \
# -H "Authorization: Bearer <YOUR-TOKEN>" \
# -H "X-GitHub-Api-Version: 2022-11-28" \
# https://some.enterprise.com/api/v3/orgs/ORG/repos \
# | jq -c '.[] | [.id, .name]'
# See more details at https://docs.github.com/en/enterprise-server/rest/repos/repos
#!/bin/bash
personal_access_token=GITHUB_TOKEN
gl_personal_token=GITLAB_TOKEN
target_namespace=namespace/subgroup
github_hostname=some.enterprise.com
echo repo_id: $1
echo repo name: $2
curl --request POST \
--url "https://gitlab.com/api/v4/import/github" \
--header "content-type: application/json" \
--header "Authorization: Bearer $gl_personal_token" \
--data '{
"personal_access_token": "'$personal_access_token'",
"repo_id": "'$1'",
"target_namespace": "'$target_namespace'",
"new_name": "'$2'",
"github_hostname": "https://'$github_hostname'",
"optional_stages": {
"single_endpoint_notes_import": true,
"attachments_import": true,
"collaborators_import": true
}
}'
echo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment