diff options
author | Douglas Barbosa Alexandre <dbalexandre@gmail.com> | 2017-07-17 20:19:22 -0300 |
---|---|---|
committer | Douglas Barbosa Alexandre <dbalexandre@gmail.com> | 2017-08-07 13:06:12 -0300 |
commit | a7363d4a54e95dcd417ca1a75ab65265d069e164 (patch) | |
tree | 32f36d057a6a2f7d7a12dbe8a069fcd59e54edb2 /lib/github | |
parent | 51186e72c5b06e144960bd0caf9684dbc387920c (diff) | |
download | gitlab-ce-a7363d4a54e95dcd417ca1a75ab65265d069e164.tar.gz |
Move GitHub root endpoint methods to Github::Client
Diffstat (limited to 'lib/github')
-rw-r--r-- | lib/github/client.rb | 19 | ||||
-rw-r--r-- | lib/github/import.rb | 17 |
2 files changed, 19 insertions, 17 deletions
diff --git a/lib/github/client.rb b/lib/github/client.rb index e65d908d232..ac4e3a739f9 100644 --- a/lib/github/client.rb +++ b/lib/github/client.rb @@ -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 diff --git a/lib/github/import.rb b/lib/github/import.rb index 69bc5f08d9a..8ca7b678633 100644 --- a/lib/github/import.rb +++ b/lib/github/import.rb @@ -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 |