Move GitHub root endpoint methods to Github::Client

parent 51186e72
......@@ -3,7 +3,7 @@ module Github
attr_reader :connection, :rate_limit
def initialize(options)
@connection = Faraday.new(url: options.fetch(:url)) do |faraday|
@connection = Faraday.new(url: options.fetch(:url, root_endpoint)) do |faraday|
faraday.options.open_timeout = options.fetch(:timeout, 60)
faraday.options.timeout = options.fetch(:timeout, 60)
faraday.authorization 'token', options.fetch(:token)
......@@ -19,5 +19,22 @@ module Github
Github::Response.new(connection.get(url, query))
end
private
def root_endpoint
custom_endpoint || githup_endpoint
end
def custom_endpoint
Gitlab.config.omniauth.providers
.find { |provider| provider.name == 'github' }
.to_h
.dig('args', 'client_options', 'site')
end
def github_endpoint
OmniAuth::Strategies::GitHub.default_options[:client_options][:site]
end
end
end
......@@ -50,7 +50,7 @@ module Github
@repo = project.import_source
@repo_url = project.import_url
@wiki_url = project.import_url.sub(/\.git\z/, '.wiki.git')
@options = options.reverse_merge(url: root_endpoint)
@options = options
@verbose = options.fetch(:verbose, false)
@cached = Hash.new { |hash, key| hash[key] = Hash.new }
@errors = []
......@@ -383,20 +383,5 @@ module Github
def error(type, url, message)
errors << { type: type, url: Gitlab::UrlSanitizer.sanitize(url), error: message }
end
def root_endpoint
@root_endpoint ||= custom_endpoint || githup_endpoint
end
def custom_endpoint
Gitlab.config.omniauth.providers
.find { |provider| provider.name == 'github' }
.to_h
.dig('args', 'client_options', 'site')
end
def github_endpoint
OmniAuth::Strategies::GitHub.default_options[:client_options][:site]
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment