Restore Enterprise support in the GH importer

This was removed by accident as the old GitHub importer handled this
deep down the codebase, making it easy to miss.
This commit is contained in:
Yorick Peterse 2017-11-08 18:06:03 +01:00
parent 07ab4ad60a
commit 2b886a7815
No known key found for this signature in database
GPG key ID: EDD30D2BEB691AC9
2 changed files with 119 additions and 14 deletions

View file

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

View file

@ -260,27 +260,106 @@ describe Gitlab::GithubImport::Client do
end
end
describe '#method_missing' do
it 'delegates missing methods to the request method' do
client = described_class.new('foo')
describe '#api_endpoint' do
let(:client) { described_class.new('foo') }
expect(client).to receive(:milestones).with(state: 'all')
context 'without a custom endpoint configured in Omniauth' do
it 'returns the default API endpoint' do
expect(client)
.to receive(:custom_api_endpoint)
.and_return(nil)
client.milestones(state: 'all')
expect(client.api_endpoint).to eq('https://api.github.com')
end
end
context 'with a custom endpoint configured in Omniauth' do
it 'returns the custom endpoint' do
endpoint = 'https://github.kittens.com'
expect(client)
.to receive(:custom_api_endpoint)
.and_return(endpoint)
expect(client.api_endpoint).to eq(endpoint)
end
end
end
describe '#respond_to_missing?' do
it 'returns true for methods supported by Octokit' do
client = described_class.new('foo')
describe '#custom_api_endpoint' do
let(:client) { described_class.new('foo') }
expect(client.respond_to?(:milestones)).to eq(true)
context 'without a custom endpoint' do
it 'returns nil' do
expect(client)
.to receive(:github_omniauth_provider)
.and_return({})
expect(client.custom_api_endpoint).to be_nil
end
end
it 'returns false for methods not supported by Octokit' do
context 'with a custom endpoint' do
it 'returns the API endpoint' do
endpoint = 'https://github.kittens.com'
expect(client)
.to receive(:github_omniauth_provider)
.and_return({ 'args' => { 'client_options' => { 'site' => endpoint } } })
expect(client.custom_api_endpoint).to eq(endpoint)
end
end
end
describe '#default_api_endpoint' do
it 'returns the default API endpoint' do
client = described_class.new('foo')
expect(client.respond_to?(:kittens)).to eq(false)
expect(client.default_api_endpoint).to eq('https://api.github.com')
end
end
describe '#verify_ssl' do
let(:client) { described_class.new('foo') }
context 'without a custom configuration' do
it 'returns true' do
expect(client)
.to receive(:github_omniauth_provider)
.and_return({})
expect(client.verify_ssl).to eq(true)
end
end
context 'with a custom configuration' do
it 'returns the configured value' do
expect(client.verify_ssl).to eq(false)
end
end
end
describe '#github_omniauth_provider' do
let(:client) { described_class.new('foo') }
context 'without a configured provider' do
it 'returns an empty Hash' do
expect(Gitlab.config.omniauth)
.to receive(:providers)
.and_return([])
expect(client.github_omniauth_provider).to eq({})
end
end
context 'with a configured provider' do
it 'returns the provider details as a Hash' do
hash = client.github_omniauth_provider
expect(hash['name']).to eq('github')
expect(hash['url']).to eq('https://github.com/')
end
end
end
end