From 51186e72c5b06e144960bd0caf9684dbc387920c Mon Sep 17 00:00:00 2001 From: Douglas Barbosa Alexandre Date: Fri, 14 Jul 2017 13:43:25 -0300 Subject: [PATCH] Use a custom root endpoint if defined on GH ominiauth provider settings --- lib/github/import.rb | 17 ++++++++++++++++- lib/tasks/import.rake | 2 +- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/github/import.rb b/lib/github/import.rb index fd4059c612e..69bc5f08d9a 100644 --- a/lib/github/import.rb +++ b/lib/github/import.rb @@ -48,9 +48,9 @@ module Github @project = project @repository = project.repository @repo = project.import_source - @options = options @repo_url = project.import_url @wiki_url = project.import_url.sub(/\.git\z/, '.wiki.git') + @options = options.reverse_merge(url: root_endpoint) @verbose = options.fetch(:verbose, false) @cached = Hash.new { |hash, key| hash[key] = Hash.new } @errors = [] @@ -383,5 +383,20 @@ 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 diff --git a/lib/tasks/import.rake b/lib/tasks/import.rake index 75ccd7af793..90792dfe51d 100644 --- a/lib/tasks/import.rake +++ b/lib/tasks/import.rake @@ -7,7 +7,7 @@ class GithubImport end def initialize(token, gitlab_username, project_path, extras) - @options = { url: 'https://api.github.com', token: token, verbose: true } + @options = { token: token, verbose: true } @project_path = project_path @current_user = User.find_by_username(gitlab_username) @github_repo = extras.empty? ? nil : extras.first