Import API

Tier: Free, Premium, Ultimate Offering: GitLab.com, 자체 관리, GitLab Dedicated

GitHub 또는 Bitbucket Server에서 저장소를 가져오기 위해 Import API를 사용합니다.

GitHub에서 저장소 가져오기

  • GitLab 15.8에서 도입되었으며, 이제 더 이상 GitLab은 target_namespace에서 지정한 네임스페이스 또는 그룹이 없는 경우 자동으로 생성하지 않습니다. 그리고 네임스페이스 또는 그룹 이름이 사용 중이거나 target_namespace이 비어 있는 경우 더 이상 사용자의 개인적인 네임스페이스를 사용하지 않습니다.
  • GitLab 16.0에서 Maintainer 역할을 도입하고 이를 GitLab 15.11.1 및 GitLab 15.10.5로 역방향 이관했습니다.
  • optional_stagescollaborators_import 키는 GitLab 16.0에서 도입되었습니다.
  • Feature flag github_import_extended_events는 GitLab 16.8에서 도입되었습니다. 기본적으로 비활성화되어 있습니다. 이 플래그는 가져오기의 성능을 향상시키지만 single_endpoint_issue_events_import 옵션 단계를 비활성화합니다.
  • Feature flag github_import_extended_events는 GitLab 16.9에서 GitLab.com과 자체 관리에서 활성화되었습니다.

API를 사용하여 GitHub의 프로젝트를 GitLab으로 가져옵니다.

Prerequisites:

  • GitHub Importer 사전 요구 사항.
  • target_namespace에 설정된 네임스페이스가 있어야 합니다.
  • 네임스페이스는 사용자의 네임스페이스이거나 최소한 Maintainer 역할을 가진 기존 그룹이어야 합니다.
POST /import/github
속성 유형 필수 설명
personal_access_token string yes GitHub 개인 액세스 토큰
repo_id integer yes GitHub 저장소 ID
new_name string no 새 프로젝트의 이름. 새 경로로도 사용되므로 특수 문자로 시작하거나 끝나거나 연속된 특수 문자를 포함해서는 안 됩니다.
target_namespace string yes 저장소를 가져올 네임스페이스. /namespace/subgroup와 같이 하위 그룹을 지원합니다. GitLab 15.8 이상에서는 비어 있을 수 없습니다.
github_hostname string no 사용자 정의 GitHub Enterprise 호스트명. GitHub.com의 경우 설정하지 마십시오.
optional_stages object no 추가 가져오기 항목을 지원합니다. GitLab 15.5에서 도입되었습니다
timeout_strategy string no 가져오기 시간 초과 처리 전략입니다. 유효한 값은 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_issue_events_import": true,
      "single_endpoint_notes_import": true,
      "attachments_import": true,
      "collaborators_import": true
    }
}'

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

  • single_endpoint_issue_events_import: 이슈 및 풀 리퀘스트 이벤트 가져오기를 위함입니다. github_import_extended_events 기능 플래그가 활성화된 경우, 이 옵션 단계를 사용할 수 없습니다.
  • single_endpoint_notes_import: 대안 및 철저한 코멘트 가져오기를 위함입니다.
  • attachments_import: 마크다운 첨부 파일 가져오기를 위함입니다.
  • 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로 프로젝트를 API를 통해 그룹 액세스 토큰을 이용하여 가져올 때:

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

GitHub 프로젝트 가져오기 취소

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

POST /import/github/cancel
속성 유형 필수 설명
project_id 정수 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 Gists를 GitLab 스니펫으로 가져오기

  • GitLab 15.8에서 플래그 github_import_gists와 함께 도입됨. 기본적으로 비활성화되어 있으며 GitLab.com에서 활성화됨.
  • GitLab 15.10에서 자체 호스팅 활성화.
  • GitLab 15.11에서 일반 사용 가능해짐. 기능 플래그 github_import_gists 제거됨.

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

가져오기에 실패한 경우, 가져오지 못한 Gists 목록이 포함된 이메일이 전송됩니다.

POST /import/github/gists
속성 유형 필수 설명
personal_access_token 문자열 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: Gists 가져오기가 시작됩니다.
  • 401 Unauthorized: 사용자의 GitHub 개인 액세스 토큰이 잘못되었습니다.
  • 422 Unprocessable Entity: Gists 가져오기가 이미 진행 중입니다.
  • 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 문자열 Bitbucket Server URL
bitbucket_server_username 문자열 Bitbucket Server 사용자명
personal_access_token 문자열 Bitbucket Server 개인 액세스 토큰/비밀번호
bitbucket_server_project 문자열 Bitbucket 프로젝트 키
bitbucket_server_repo 문자열 Bitbucket 리포지토리 이름
new_name 문자열 아니요 새 프로젝트 이름. 새 경로로도 사용되므로 특수 문자로 시작하거나 끝날 수 없으며 연속된 특수 문자가 포함되어서는 안 됩니다. GitLab 15.1에서 16.9사이에서는 프로젝트 경로가 Bitbucket에서 복사되었습니다. GitLab 16.10에서는 원래 동작으로 변경되었습니다.
target_namespace 문자열 아니요 리포지토리를 가져올 네임스페이스. /namespace/subgroup와 같은 서브그룹을 지원합니다.
timeout_strategy 문자열 아니요 가져오기 시간 초과 처리 전략. 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"
}'

관련 주제