Use a custom root endpoint if defined on GH ominiauth provider settings

This commit is contained in:
Douglas Barbosa Alexandre 2017-07-14 13:43:25 -03:00
parent 81995317f9
commit 51186e72c5
2 changed files with 17 additions and 2 deletions

View File

@ -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

View File

@ -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