{{< details >}}

  • Tier: 基础版, 专业版, 旗舰版
  • Offering: JihuLab.com, 私有化部署

{{< /details >}}

使用 Import API 从 GitHub 或 Bitbucket Server 导入代码库。

{{< alert type=”note” >}}

当您导入项目到个人命名空间时,不支持用户贡献映射。当您导入到个人命名空间时,所有贡献都分配给一个名为 Import User 的非功能性用户,并且无法重新分配。

{{< /alert >}}

从 GitHub 导入代码库

{{< history >}}

  • 在 极狐GitLab 15.8 中引入,极狐GitLab 不再自动创建命名空间或群组,如果 target_namespace 中指定的命名空间或群组名称不存在。极狐GitLab 也不再回退到使用用户的个人命名空间,如果命名空间或群组名称已被占用或 target_namespace 为空。
  • 在 极狐GitLab 16.0 中引入了对 Maintainer 角色的要求,并向后移植到 极狐GitLab 15.11.1 和 极狐GitLab 15.10.5。
  • 在 极狐GitLab 16.0 中,optional_stages 中的 collaborators_import 键被引入。
  • 在 极狐GitLab 16.8 中引入了特性标志 github_import_extended_events。默认情况下禁用。此标志提高了导入性能,但禁用了 single_endpoint_issue_events_import 可选阶段。
  • 在 极狐GitLab 16.9 中,在 JihuLab.com 和 极狐GitLab 私有化部署上启用了特性标志 github_import_extended_events
  • 在 极狐GitLab 16.11 中,改进导入性能 GA。移除了特性标志 github_import_extended_events

{{< /history >}}

使用 API 将您的项目从 GitHub 导入到 极狐GitLab。

前提条件:

  • 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 设置。从 极狐GitLab 16.5 到 极狐GitLab 17.1,您必须包含路径 /api/v3
optional_stages object 额外导入的项目。在 极狐GitLab 15.5 中引入
timeout_strategy string 处理导入超时的策略。有效值为 optimistic(继续到导入的下一个阶段)或 pessimistic(立即失败)。默认值为 pessimistic。在 极狐GitLab 16.5 中引入
pagination_limit integer 每次 GitHub API 请求检索的项目数。默认值为每页 100 个项目。对于大型仓库的项目导入,将此值降低到较小的数字可以降低 GitHub API 端点返回 500502 错误的风险。然而,减少页面大小将导致更长的迁移时间。
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 导入公共项目

{{< history >}}

  • 在 极狐GitLab 15.7 中引入,项目在任何情况下都不会被导入到机器人用户的命名空间中。导入到机器人用户命名空间的项目无法被持有有效令牌的用户删除,这代表了安全风险。

{{< /history >}}

当您使用群组访问令牌通过 API 从 GitHub 导入项目时:

  • 极狐GitLab 项目继承原始项目的可见性设置。因此,如果原始项目是公共的,则项目是公开访问的。
  • 如果 pathtarget_namespace 不存在,项目导入将失败。

取消 GitHub 项目导入

{{< history >}}

  • 在 极狐GitLab 15.5 中引入。

{{< /history >}}

使用 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 gists 导入到极狐GitLab 代码片段

{{< history >}}

  • 在 极狐GitLab 15.8 中引入,使用名为 github_import_gists功能标志。默认禁用。在 JihuLab.com 上启用。
  • 在 极狐GitLab 15.10 中,在极狐GitLab 私有化部署上启用。
  • 在 极狐GitLab 15.11 中 GA。移除了特性标志 github_import_gists

{{< /history >}}

您可以使用 极狐GitLab API 将个人 GitHub gists(最多 10 个文件)导入到个人极狐GitLab 代码片段。含有超过 10 个文件的 GitHub gists 会被跳过。您应该手动迁移这些 GitHub gists。

如果有任何 gists 无法导入,会发送一封电子邮件,列出未导入的 gists。

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: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 string Bitbucket Server URL
bitbucket_server_username string Bitbucket Server 用户名
personal_access_token string Bitbucket Server 个人访问令牌/密码
bitbucket_server_project string Bitbucket 项目密钥
bitbucket_server_repo string Bitbucket 仓库名称
new_name string 新项目的名称。也用作新路径,因此不得以特殊字符开头或结尾,并且不得包含连续的特殊字符。在 极狐GitLab 15.1 到 极狐GitLab 16.9 之间,项目路径从 Bitbucket 复制。在 极狐GitLab 16.10 中,行为被改回原始行为。
target_namespace string 要导入仓库的命名空间。支持像 /namespace/subgroup 这样的子群组
timeout_strategy string 处理导入超时的策略。有效值为 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 导入代码库

{{< history >}}

  • 在 极狐GitLab 17.0 中引入。

{{< /history >}}

通过 API 将您的项目从 Bitbucket Cloud 导入到 极狐GitLab。

前提条件:

POST /import/bitbucket
属性 类型 必需 描述
bitbucket_username string Bitbucket Cloud 用户名
bitbucket_app_password string Bitbucket Cloud 应用密码
repo_path string 仓库路径
target_namespace string 要导入仓库的命名空间。支持像 /namespace/subgroup 这样的子群组
new_name string 新项目的名称。也用作新路径,因此不得以特殊字符开头或结尾,并且不得包含连续的特殊字符。
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"
}'

相关主题