Import API

Tier: Free, Premium, Ultimate Offering: GitLab.com, Self-Managed형, GitLab Dedicated

GitHub 또는 Bitbucket Server에서 리포지터리를 가져오기 위해 Import API를 사용합니다.

GitHub에서 리포지터리 가져오기

  • GitLab 15.8에서 도입되었으며, GitLab은 target_namespace에 지정된 네임스페이스나 그룹 이름이 없으면 더 이상 자동으로 네임스페이스 또는 그룹을 생성하지 않습니다. GitLab도 네임스페이스 또는 그룹 이름이 사용 중이거나 target_namespace이 비어 있을 경우 사용자의 개인 네임스페이스를 대체로 사용하지 않습니다.
  • GitLab 16.0에서 Maintainer 역할이 도입되었으며, GitLab 15.11.1 및 GitLab 15.10.5로 백포트되었습니다.
  • optional_stagescollaborators_import 키는 GitLab 16.0에서 도입되었습니다.
  • Feature 플래그 github_import_extended_events는 GitLab 16.8에서 도입되었습니다. 기본적으로 비활성화되어 있으며 수행 속도를 향상시키지만 single_endpoint_issue_events_import 선택 사항 단계를 비활성화합니다.
  • Feature 플래그 github_import_extended_events는 GitLab 16.9에서 GitLab.com 및 Self-Managed형에서 활성화되었습니다.
  • 향상된 가져오기 성능이 GitLab 16.11에서 일반적으로 사용 가능하게 되었습니다. Feature 플래그 github_import_extended_events가 제거되었습니다.

GitHub에서 프로젝트를 GitLab으로 가져오려면 API를 사용합니다.

전제 조건:

  • GitHub 가져오기기에 필요한 사전 조건.
  • target_namespace에 설정된 네임스페이스가 있어야 합니다.
  • 네임스페이스는 사용자 네임스페이스이거나 적어도 Maintainer 역할이 있는 기존 그룹일 수 있습니다.
POST /import/github
속성 유형 필수 설명
personal_access_token string GitHub 개인 액세스 토큰
repo_id integer GitHub 리포지터리 ID
new_name string 아니오 새 프로젝트의 이름. 새 경로로도 사용되므로 특수 문자로 시작하거나 끝나서는 안 되며 연속된 특수 문자를 포함해서도 안 됩니다.
target_namespace string 가져올 리포지터리의 네임스페이스. /namespace/subgroup와 같이 하위 그룹을 지원합니다. GitLab 15.8 이후로는 비어 있을 수 없습니다.
github_hostname string 아니요 사용자 정의 GitHub Enterprise 호스트 이름입니다. GitHub.com의 경우 설정하지 마십시오.
optional_stages object 아니요 추가로 가져올 항목. GitLab 15.5에서 도입됨
timeout_strategy string 아니요 가져오기 시간 초과 처리 전략입니다. optimistic (가져오기의 다음 단계로 진행) 또는 pessimistic (즉시 실패) 중 유효한 값입니다. 기본값은 pessimistic입니다. GitLab 16.5에서 도입되었습니다.
curl --request POST \
  --url "https://gitlab.example.com/api/v4/import/github" \
  --header "content-type: application/json" \
  --header "Authorization: Bearer <your_access_token>" \
  --data '{
    "personal_access_token": "aBc123abC12aBc123abC12abC123+_A/c123",
    "repo_id": "12345",
    "target_namespace": "group/subgroup",
    "new_name": "NEW-NAME",
    "github_hostname": "https://github.example.com",
    "optional_stages": {
      "single_endpoint_notes_import": true,
      "attachments_import": true,
      "collaborators_import": true
    }
}'

optional_stages에 대해 다음 키를 사용할 수 있습니다:

  • single_endpoint_issue_events_import, 이슈 및 풀 리퀘스트 이벤트 가져오기용입니다. 이 선택 사항 단계는 GitLab 16.9에서 제거되었습니다.
  • single_endpoint_notes_import, 대안적이고 철저한 코멘트 가져오기용입니다.
  • attachments_import, Markdown 첨부 파일 가져오기용입니다.
  • collaborators_import, 외부 협력자가 아닌 직접적인 리포지터리 공동 작업자 가져오기용입니다.

자세한 정보는 추가로 가져올 항목 선택을 참조하세요.

예시 응답:

{
    "id": 27,
    "name": "my-repo",
    "full_path": "/root/my-repo",
    "full_name": "Administrator / my-repo",
    "refs_url": "/root/my-repo/refs",
    "import_source": "my-github/repo",
    "import_status": "scheduled",
    "human_import_status_name": "scheduled",
    "provider_link": "/my-github/repo",
    "relation_type": null,
    "import_warning": null
}

그룹 액세스 토큰을 사용하여 API를 통해 공개 프로젝트 가져오기

  • GitLab 15.7에서 도입되었으며, 프로젝트는 어떠한 상황에서도 봇 사용자의 네임스페이스로 가져오지 않습니다. 봇 사용자의 네임스페이스로 가져온 프로젝트는 유효한 토큰이 있는 사용자에 의해 삭제할 수 없어 사용자에게 보안 위험을 표현했습니다.

그룹 액세스 토큰을 사용하여 GitHub에서 GitLab으로 프로젝트를 가져올 때:

  • GitLab 프로젝트는 원래 프로젝트의 가시성 설정을 상속합니다. 그 결과, 원래 프로젝트가 공개 상태인 경우 프로젝트도 공개적으로 접근할 수 있습니다.
  • path 또는 target_namespace이 존재하지 않으면 프로젝트 가져오기가 실패합니다.

GitHub 프로젝트 가져오기 취소

API를 사용하여 진행 중인 GitHub 프로젝트 가져오기를 취소합니다.

POST /import/github/cancel
속성 유형 필수 설명
project_id integer GitLab 프로젝트 ID
curl --request POST \
  --url "https://gitlab.example.com/api/v4/import/github/cancel" \
  --header "content-type: application/json" \
  --header "PRIVATE-TOKEN: <your_access_token>" \
  --data '{
    "project_id": 12345
}'

예시 응답:

{
    "id": 160,
    "name": "my-repo",
    "full_path": "/root/my-repo",
    "full_name": "Administrator / my-repo",
    "import_source": "source/source-repo",
    "import_status": "canceled",
    "human_import_status_name": "canceled",
    "provider_link": "/source/source-repo"
}

다음 상태 코드를 반환합니다:

  • 200 OK: 프로젝트 가져오기가 취소되고 있습니다.
  • 400 Bad Request: 프로젝트 가져오기를 취소할 수 없습니다.
  • 404 Not Found: project_id와 관련된 프로젝트가 존재하지 않습니다.

GitHub gist를 GitLab 스니펫으로 가져오기

GitLab API를 사용하여 최대 10개의 파일이 있는 개인 GitHub gist를 개인 GitLab 스니펫으로 가져올 수 있습니다. 10개 이상의 파일이 있는 GitHub gist는 건너뜁니다. 이러한 GitHub gist는 매뉴얼으로 마이그레이션해야 합니다.

가져올 수 없는 gist가 있다면 해당하는 gist 디렉터리이 포함된 이메일이 전송됩니다.

POST /import/github/gists
속성 유형 필수 설명
personal_access_token string GitHub 개인 액세스 토큰
curl --request POST \
  --url "https://gitlab.example.com/api/v4/import/github/gists" \
  --header "content-type: application/json" \
  --header "PRIVATE-TOKEN: <your_gitlab_access_token>" \
  --data '{
    "personal_access_token": "<your_github_personal_access_token>"
}'

다음 상태 코드를 반환합니다:

  • 202 Accepted: gist 가져오기가 시작되었습니다.
  • 401 Unauthorized: 사용자의 GitHub 개인 액세스 토큰이 잘못되었습니다.
  • 422 Unprocessable Entity: gist 가져오기가 이미 진행 중입니다.
  • 429 Too Many Requests: 사용자가 GitHub의 요율 제한을 초과했습니다.

Bitbucket Server에서 리포지터리 가져오기

API를 사용하여 Bitbucket Server에서 프로젝트를 GitLab으로 가져옵니다.

Bitbucket 프로젝트 키는 Bitbucket에서 리포지터리를 찾을 때만 사용됩니다. GitLab 그룹에 리포지터리를 가져오려면 target_namespace를 지정해야 합니다. target_namespace를 지정하지 않으면 프로젝트가 개인 사용자 네임스페이스에 가져오게 됩니다.

사전 요구 사항:

POST /import/bitbucket_server
속성 유형 필수 설명
bitbucket_server_url string yes Bitbucket Server URL
bitbucket_server_username string yes Bitbucket Server 사용자 이름
personal_access_token string yes Bitbucket Server 개인 액세스 토큰/비밀번호
bitbucket_server_project string yes Bitbucket Project Key
bitbucket_server_repo string yes Bitbucket Repository Name
new_name string no 새 프로젝트의 이름. 또한 새 경로로 사용되므로 특수 문자로 시작하거나 끝나서는 안 되며 연속된 특수 문자를 포함해서도 안 됩니다. GitLab 15.1부터 GitLab 16.9까지 프로젝트 경로가 Bitbucket에서 복사되었습니다. GitLab 16.10에서는 원래 동작으로 돌아갔습니다.
target_namespace string no 리포지터리를 가져올 네임스페이스. /namespace/subgroup와 같이 하위 그룹을 지원합니다.
timeout_strategy string no 가져오기 시간 초과 처리 전략. 유효한 값은 optimistic(가져오기의 다음 단계로 계속) 또는 pessimistic(즉시 실패)입니다. 기본값은 pessimistic입니다. GitLab 16.5에서 도입되었습니다.
curl --request POST \
  --url "https://gitlab.example.com/api/v4/import/bitbucket_server" \
  --header "content-type: application/json" \
  --header "PRIVATE-TOKEN: <your_access_token>" \
  --data '{
    "bitbucket_server_url": "http://bitbucket.example.com",
    "bitbucket_server_username": "root",
    "personal_access_token": "Nzk4MDcxODY4MDAyOiP8y410zF3tGAyLnHRv/E0+3xYs",
    "bitbucket_server_project": "NEW",
    "bitbucket_server_repo": "my-repo",
    "new_name": "NEW-NAME"
}'

Bitbucket Cloud에서 리포지터리 가져오기

API를 사용하여 Bitbucket Cloud에서 프로젝트를 GitLab으로 가져옵니다.

사전 요구 사항:

POST /import/bitbucket
속성 유형 필수 설명
bitbucket_username string yes Bitbucket Cloud 사용자 이름
bitbucket_app_password string yes Bitbucket Cloud 앱 패스워드
repo_path string yes 리포지터리 경로
target_namespace string yes 리포지터리를 가져올 네임스페이스. /namespace/subgroup을 지원합니다.
new_name string no 새 프로젝트의 이름. 또한 새 경로로 사용되므로 특수 문자로 시작하거나 끝나서는 안 되며 연속된 특수 문자를 포함해서도 안 됩니다.
curl --request POST \
  --url "https://gitlab.example.com/api/v4/import/bitbucket" \
  --header "content-type: application/json" \
  --header "PRIVATE-TOKEN: <your_access_token>" \
  --data '{
    "bitbucket_username": "bitbucket_username",
    "bitbucket_app_password": "bitbucket_app_password",
    "repo_path": "username/my_project"
    "target_namespace": "my_group/my_subgroup"
    "new_name": "new_project_name"
}'

관련 주제