2018-10-22 03:00:50 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-10-13 12:50:36 -04:00
|
|
|
module Gitlab
|
|
|
|
module GithubImport
|
2017-11-23 10:51:55 -05:00
|
|
|
def self.refmap
|
2017-11-15 10:46:08 -05:00
|
|
|
[:heads, :tags, '+refs/pull/*/head:refs/merge-requests/*/head']
|
|
|
|
end
|
|
|
|
|
2020-10-27 23:08:41 -04:00
|
|
|
def self.new_client_for(project, token: nil, host: nil, parallel: true)
|
2017-10-13 12:50:36 -04:00
|
|
|
token_to_use = token || project.import_data&.credentials&.fetch(:user)
|
2020-10-27 23:08:41 -04:00
|
|
|
Client.new(
|
|
|
|
token_to_use,
|
|
|
|
host: host.presence || self.formatted_import_url(project),
|
2021-08-19 14:10:32 -04:00
|
|
|
per_page: self.per_page(project),
|
2020-10-27 23:08:41 -04:00
|
|
|
parallel: parallel
|
|
|
|
)
|
2017-10-13 12:50:36 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
# Returns the ID of the ghost user.
|
|
|
|
def self.ghost_user_id
|
|
|
|
key = 'github-import/ghost-user-id'
|
|
|
|
|
2020-03-13 20:09:30 -04:00
|
|
|
Gitlab::Cache::Import::Caching.read_integer(key) || Gitlab::Cache::Import::Caching.write(key, User.select(:id).ghost.id)
|
2017-10-13 12:50:36 -04:00
|
|
|
end
|
2020-10-27 23:08:41 -04:00
|
|
|
|
|
|
|
# Get formatted GitHub import URL. If github.com is in the import URL, this will return nil and octokit will use the default github.com API URL
|
|
|
|
def self.formatted_import_url(project)
|
|
|
|
url = URI.parse(project.import_url)
|
|
|
|
|
|
|
|
unless url.host == 'github.com'
|
|
|
|
url.user = nil
|
|
|
|
url.password = nil
|
|
|
|
url.path = "/api/v3"
|
|
|
|
url.to_s
|
|
|
|
end
|
|
|
|
end
|
2021-08-19 14:10:32 -04:00
|
|
|
|
|
|
|
def self.per_page(project)
|
2022-05-06 11:09:03 -04:00
|
|
|
if project.group.present? && Feature.enabled?(:github_importer_lower_per_page_limit, project.group, type: :ops)
|
2021-08-19 14:10:32 -04:00
|
|
|
Gitlab::GithubImport::Client::LOWER_PER_PAGE
|
|
|
|
else
|
|
|
|
Gitlab::GithubImport::Client::DEFAULT_PER_PAGE
|
|
|
|
end
|
|
|
|
end
|
2017-10-13 12:50:36 -04:00
|
|
|
end
|
|
|
|
end
|