diff options
author | Douwe Maan <douwe@gitlab.com> | 2017-11-09 08:37:41 +0000 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2017-11-09 08:37:41 +0000 |
commit | 760b2c75ef9d2c6acb655860dceae4c04cd8e5a7 (patch) | |
tree | e0d1154cdb4fcdf7474adbe39e9d07c8da84f379 /lib | |
parent | 20ac30a705f4edd22efd934ecf68b58557f868db (diff) | |
parent | f37fe2edc80b83513cb9d30b6c97e85c9ccca29c (diff) | |
download | gitlab-ce-760b2c75ef9d2c6acb655860dceae4c04cd8e5a7.tar.gz |
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
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/github_import/client.rb | 6 | ||||
-rw-r--r-- | lib/tasks/import.rake | 6 |
2 files changed, 9 insertions, 3 deletions
diff --git a/lib/gitlab/github_import/client.rb b/lib/gitlab/github_import/client.rb index c1c338487a7..5da9befa08e 100644 --- a/lib/gitlab/github_import/client.rb +++ b/lib/gitlab/github_import/client.rb @@ -129,6 +129,8 @@ module Gitlab # whether we are running in parallel mode or not. For more information see # `#rate_or_wait_for_rate_limit`. def with_rate_limit + return yield unless rate_limiting_enabled? + request_count_counter.increment raise_or_wait_for_rate_limit unless requests_remaining? @@ -170,6 +172,10 @@ module Gitlab octokit.rate_limit.resets_in + 5 end + def rate_limiting_enabled? + @rate_limiting_enabled ||= api_endpoint.include?('.github.com') + end + def api_endpoint custom_api_endpoint || default_api_endpoint end diff --git a/lib/tasks/import.rake b/lib/tasks/import.rake index 943cbe6d80c..aafbe52e5f8 100644 --- a/lib/tasks/import.rake +++ b/lib/tasks/import.rake @@ -101,8 +101,8 @@ end class GithubRepos def initialize(token, current_user, github_repo) - @client = Octokit::Client - .new(access_token: token, auto_paginate: true, per_page: 100) + @client = Gitlab::GithubImport::Client.new(token) + @client.octokit.auto_paginate = true @current_user = current_user @github_repo = github_repo @@ -130,7 +130,7 @@ class GithubRepos end def repos - @client.list_repositories + @client.octokit.list_repositories end end |