debian-mirror-gitlab/lib/gitlab/github_import.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

47 lines
1.4 KiB
Ruby
Raw Normal View History

2018-12-13 13:39:08 +05:30
# frozen_string_literal: true
2018-03-17 18:26:18 +05:30
module Gitlab
module GithubImport
def self.refmap
[:heads, :tags, '+refs/pull/*/head:refs/merge-requests/*/head']
end
2021-01-29 00:20:46 +05:30
def self.new_client_for(project, token: nil, host: nil, parallel: true)
2018-03-17 18:26:18 +05:30
token_to_use = token || project.import_data&.credentials&.fetch(:user)
2021-01-29 00:20:46 +05:30
Client.new(
token_to_use,
host: host.presence || self.formatted_import_url(project),
2021-11-11 11:23:49 +05:30
per_page: self.per_page(project),
2021-01-29 00:20:46 +05:30
parallel: parallel
)
2018-03-17 18:26:18 +05:30
end
# Returns the ID of the ghost user.
def self.ghost_user_id
key = 'github-import/ghost-user-id'
2020-04-08 14:13:33 +05:30
Gitlab::Cache::Import::Caching.read_integer(key) || Gitlab::Cache::Import::Caching.write(key, User.select(:id).ghost.id)
2018-03-17 18:26:18 +05:30
end
2021-01-29 00:20:46 +05:30
# 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-11-11 11:23:49 +05:30
def self.per_page(project)
if project.group.present? && Feature.enabled?(:github_importer_lower_per_page_limit, project.group, type: :ops, default_enabled: :yaml)
Gitlab::GithubImport::Client::LOWER_PER_PAGE
else
Gitlab::GithubImport::Client::DEFAULT_PER_PAGE
end
end
2018-03-17 18:26:18 +05:30
end
end