解决从 GitHub 导入项目到 GitLab 的问题
- Tier: Free, Premium, Ultimate
- Offering: GitLab.com, GitLab Self-Managed, GitLab Dedicated
当从 GitHub 导入项目到 GitLab 时,您可能会遇到以下问题。
手动继续之前失败的导入过程
在某些情况下,GitHub 导入过程可能无法导入仓库。这会导致 GitLab 中止项目导入过程,并需要手动导入仓库。管理员可以为失败的导入过程手动导入仓库:
-
打开 Rails 控制台。
-
在控制台中运行以下命令序列:
project_id = <PROJECT_ID> github_access_token = <GITHUB_ACCESS_TOKEN> github_repository_path = '<GROUP>/<REPOSITORY>' github_repository_url = "https://#{github_access_token}@github.com/#{github_repository_path}.git" # Find project by ID project = Project.find(project_id) # Set import URL and credentials project.import_url = github_repository_url project.import_type = 'github' project.import_source = github_repository_path project.save! # Create an import state if the project was created manually and not from a failed import project.create_import_state if project.import_state.blank? # Set state to start project.import_state.force_start # Optional: If your import had certain optional stages selected or a timeout strategy # set, you can reset them here. Below is an example. # The params follow the format documented in the API: # https://docs.gitlab.com/ee/api/import.html#import-repository-from-github Gitlab::GithubImport::Settings .new(project) .write( timeout_strategy: "optimistic", optional_stages: { single_endpoint_issue_events_import: true, single_endpoint_notes_import: true, attachments_import: true, collaborators_import: true } ) # Trigger import from second step Gitlab::GithubImport::Stage::ImportRepositoryWorker.perform_async(project.id)
因缺少前缀导致导入失败
在 GitLab 16.5 及更高版本中,您可能会收到一个错误消息,显示"由于 GitHub 错误导致导入失败:(HTTP 406)"。
此问题发生是因为在 GitLab 16.5 中,路径前缀 api/v3 已从 GitHub 导入器中移除。这是因为导入器停止使用 Gitlab::LegacyGithubImport::Client。该客户端在从 GitHub Enterprise URL 导入时会自动添加 api/v3 前缀。
要解决此错误,在从 GitHub Enterprise URL 导入时,添加 api/v3 前缀。
导入大型项目时的错误
GitHub 导入器在导入大型项目时可能会遇到一些错误。
缺少评论
GitHub API 有一个限制,防止导入超过约 30,000 个注释或差异注释。当达到此限制时,GitHub API 会返回以下错误:
In order to keep the API fast for everyone, pagination is limited for this resource. Check the rel=last link relation in the Link response header to see how far back you can traverse.在导入包含大量评论的 GitHub 项目时,选择使用替代评论导入方法 additional item to import 复选框。此设置会使导入过程花费更长时间,因为它增加了执行导入所需的网络请求数量。
GitLab 实例无法连接到 GitHub
运行 GitLab 15.10 或更早版本且位于代理后面的 GitLab Self-Managed 实例,无法解析 github.com 或 api.github.com 的 DNS。在导入过程中,GitLab 实例无法连接到 GitHub,您必须在本地请求允许列表中添加 github.com 和 api.github.com 条目。