提交 760b2c75 编写于 作者: D Douwe Maan

Merge branch 'github-rake-task-rate-limiting' into 'master'

Add GitHub enterprise support to the GitHub Rake task and better handle rate limiting being disabled

See merge request gitlab-org/gitlab-ce!15284
...@@ -129,6 +129,8 @@ module Gitlab ...@@ -129,6 +129,8 @@ module Gitlab
# whether we are running in parallel mode or not. For more information see # whether we are running in parallel mode or not. For more information see
# `#rate_or_wait_for_rate_limit`. # `#rate_or_wait_for_rate_limit`.
def with_rate_limit def with_rate_limit
return yield unless rate_limiting_enabled?
request_count_counter.increment request_count_counter.increment
raise_or_wait_for_rate_limit unless requests_remaining? raise_or_wait_for_rate_limit unless requests_remaining?
...@@ -170,6 +172,10 @@ module Gitlab ...@@ -170,6 +172,10 @@ module Gitlab
octokit.rate_limit.resets_in + 5 octokit.rate_limit.resets_in + 5
end end
def rate_limiting_enabled?
@rate_limiting_enabled ||= api_endpoint.include?('.github.com')
end
def api_endpoint def api_endpoint
custom_api_endpoint || default_api_endpoint custom_api_endpoint || default_api_endpoint
end end
......
...@@ -101,8 +101,8 @@ end ...@@ -101,8 +101,8 @@ end
class GithubRepos class GithubRepos
def initialize(token, current_user, github_repo) def initialize(token, current_user, github_repo)
@client = Octokit::Client @client = Gitlab::GithubImport::Client.new(token)
.new(access_token: token, auto_paginate: true, per_page: 100) @client.octokit.auto_paginate = true
@current_user = current_user @current_user = current_user
@github_repo = github_repo @github_repo = github_repo
...@@ -130,7 +130,7 @@ class GithubRepos ...@@ -130,7 +130,7 @@ class GithubRepos
end end
def repos def repos
@client.list_repositories @client.octokit.list_repositories
end end
end end
......
...@@ -185,6 +185,17 @@ describe Gitlab::GithubImport::Client do ...@@ -185,6 +185,17 @@ describe Gitlab::GithubImport::Client do
client.with_rate_limit { } client.with_rate_limit { }
end end
it 'ignores rate limiting when disabled' do
expect(client)
.to receive(:rate_limiting_enabled?)
.and_return(false)
expect(client)
.not_to receive(:requests_remaining?)
expect(client.with_rate_limit { 10 }).to eq(10)
end
end end
describe '#requests_remaining?' do describe '#requests_remaining?' do
...@@ -362,4 +373,20 @@ describe Gitlab::GithubImport::Client do ...@@ -362,4 +373,20 @@ describe Gitlab::GithubImport::Client do
end end
end end
end end
describe '#rate_limiting_enabled?' do
let(:client) { described_class.new('foo') }
it 'returns true when using GitHub.com' do
expect(client.rate_limiting_enabled?).to eq(true)
end
it 'returns false for GitHub enterprise installations' do
expect(client)
.to receive(:api_endpoint)
.and_return('https://github.kittens.com/')
expect(client.rate_limiting_enabled?).to eq(false)
end
end
end end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册