diff options
author | Douglas Barbosa Alexandre <dbalexandre@gmail.com> | 2017-07-14 13:43:25 -0300 |
---|---|---|
committer | Douglas Barbosa Alexandre <dbalexandre@gmail.com> | 2017-08-07 13:06:12 -0300 |
commit | 51186e72c5b06e144960bd0caf9684dbc387920c (patch) | |
tree | 67c7cbba93f5b3a9c8c763ff530ec91402134d12 | |
parent | 81995317f99550a0cd5c76e9b15fd91364665d1f (diff) | |
download | gitlab-ce-51186e72c5b06e144960bd0caf9684dbc387920c.tar.gz |
Use a custom root endpoint if defined on GH ominiauth provider settings
-rw-r--r-- | lib/github/import.rb | 17 | ||||
-rw-r--r-- | 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 |