summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2017-11-08 18:06:01 +0000
committerDouwe Maan <douwe@gitlab.com>2017-11-08 18:06:01 +0000
commit1d7e2a961aec86e50f3159ad3b82524e86b007c2 (patch)
tree81cd9728e70ce1824306168834c6570ba9c0332d /lib
parentfec66bf7a163e14980f11d2f0370ce9c3630862b (diff)
parentff082a003d103736cef8a4d58213f8366f45bdcd (diff)
downloadgitlab-ce-1d7e2a961aec86e50f3159ad3b82524e86b007c2.tar.gz
Merge branch 'github-enterprise-support-importer' into 'master'
Github enterprise support importer Closes #39931 See merge request gitlab-org/gitlab-ce!15281
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/github_import/client.rb32
-rw-r--r--lib/tasks/import.rake32
2 files changed, 47 insertions, 17 deletions
diff --git a/lib/gitlab/github_import/client.rb b/lib/gitlab/github_import/client.rb
index 844530b1ea7..c1c338487a7 100644
--- a/lib/gitlab/github_import/client.rb
+++ b/lib/gitlab/github_import/client.rb
@@ -38,7 +38,14 @@ module Gitlab
# otherwise hitting the rate limit will result in a thread
# being blocked in a `sleep()` call for up to an hour.
def initialize(token, per_page: 100, parallel: true)
- @octokit = Octokit::Client.new(access_token: token, per_page: per_page)
+ @octokit = Octokit::Client.new(
+ access_token: token,
+ per_page: per_page,
+ api_endpoint: api_endpoint
+ )
+
+ @octokit.connection_options[:ssl] = { verify: verify_ssl }
+
@parallel = parallel
end
@@ -163,8 +170,27 @@ module Gitlab
octokit.rate_limit.resets_in + 5
end
- def respond_to_missing?(method, include_private = false)
- octokit.respond_to?(method, include_private)
+ def api_endpoint
+ custom_api_endpoint || default_api_endpoint
+ end
+
+ def custom_api_endpoint
+ github_omniauth_provider.dig('args', 'client_options', 'site')
+ end
+
+ def default_api_endpoint
+ OmniAuth::Strategies::GitHub.default_options[:client_options][:site]
+ end
+
+ def verify_ssl
+ github_omniauth_provider.fetch('verify_ssl', true)
+ end
+
+ def github_omniauth_provider
+ @github_omniauth_provider ||=
+ Gitlab.config.omniauth.providers
+ .find { |provider| provider.name == 'github' }
+ .to_h
end
def rate_limit_counter
diff --git a/lib/tasks/import.rake b/lib/tasks/import.rake
index 8e9aef49e89..943cbe6d80c 100644
--- a/lib/tasks/import.rake
+++ b/lib/tasks/import.rake
@@ -14,7 +14,9 @@ class GithubImport
end
def run!
- @repo = GithubRepos.new(@options, @current_user, @github_repo).choose_one!
+ @repo = GithubRepos
+ .new(@options[:token], @current_user, @github_repo)
+ .choose_one!
raise 'No repo found!' unless @repo
@@ -28,7 +30,7 @@ class GithubImport
private
def show_warning!
- puts "This will import GitHub #{@repo['full_name'].bright} into GitLab #{@project_path.bright} as #{@current_user.name}"
+ puts "This will import GitHub #{@repo.full_name.bright} into GitLab #{@project_path.bright} as #{@current_user.name}"
puts "Permission checks are ignored. Press any key to continue.".color(:red)
STDIN.getch
@@ -65,16 +67,16 @@ class GithubImport
@current_user,
name: name,
path: name,
- description: @repo['description'],
+ description: @repo.description,
namespace_id: namespace.id,
visibility_level: visibility_level,
- skip_wiki: @repo['has_wiki']
+ skip_wiki: @repo.has_wiki
).execute
project.update!(
import_type: 'github',
- import_source: @repo['full_name'],
- import_url: @repo['clone_url'].sub('://', "://#{@options[:token]}@")
+ import_source: @repo.full_name,
+ import_url: @repo.clone_url.sub('://', "://#{@options[:token]}@")
)
project
@@ -93,13 +95,15 @@ class GithubImport
end
def visibility_level
- @repo['private'] ? Gitlab::VisibilityLevel::PRIVATE : Gitlab::CurrentSettings.current_application_settings.default_project_visibility
+ @repo.private ? Gitlab::VisibilityLevel::PRIVATE : Gitlab::CurrentSettings.current_application_settings.default_project_visibility
end
end
class GithubRepos
- def initialize(options, current_user, github_repo)
- @options = options
+ def initialize(token, current_user, github_repo)
+ @client = Octokit::Client
+ .new(access_token: token, auto_paginate: true, per_page: 100)
+
@current_user = current_user
@github_repo = github_repo
end
@@ -108,17 +112,17 @@ class GithubRepos
return found_github_repo if @github_repo
repos.each do |repo|
- print "ID: #{repo['id'].to_s.bright}".color(:green)
- print "\tName: #{repo['full_name']}\n".color(:green)
+ print "ID: #{repo.id.to_s.bright}".color(:green)
+ print "\tName: #{repo.full_name}\n".color(:green)
end
print 'ID? '.bright
- repos.find { |repo| repo['id'] == repo_id }
+ repos.find { |repo| repo.id == repo_id }
end
def found_github_repo
- repos.find { |repo| repo['full_name'] == @github_repo }
+ repos.find { |repo| repo.full_name == @github_repo }
end
def repo_id
@@ -126,7 +130,7 @@ class GithubRepos
end
def repos
- Github::Repositories.new(@options).fetch
+ @client.list_repositories
end
end