Commit eac0433f authored by Douwe Maan's avatar Douwe Maan

Merge branch 'fix-gh-rate-limit' into 'master'

Fix GitHub client requests when rate limit is disabled

## What does this MR do?

GitHub Rate Limit API returns 404 when the rate limit is disabled. In this case we just want to return gracefully instead of spitting out an error.

## Are there points in the code the reviewer needs to double check?

No.

## Why was this MR needed?

GitHub importer fails when rate limit is disabled in GitHub Enterprise.

## What are the relevant issue numbers?

https://gitlab.com/gitlab-org/gitlab-ee/issues/697

## Does this MR meet the acceptance criteria?

- [X] [CHANGELOG](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/CHANGELOG) entry added
- Tests
  - [X] Added for this feature/bug
  - [x] All builds are passing
- [x] Conform by the [style guides](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/CONTRIBUTING.md#style-guides)
- [ ] Branch has no merge conflicts with `master` (if you do - rebase it please)
- [ ] [Squashed related commits together](https://git-scm.com/book/en/Git-Tools-Rewriting-History#Squashing-Commits)

See merge request !5191
parents 7ed103b4 78a5de99
...@@ -80,6 +80,7 @@ v 8.10.0 (unreleased) ...@@ -80,6 +80,7 @@ v 8.10.0 (unreleased)
- Add reminder to not paste private SSH keys !4399 (Ingo Blechschmidt) - Add reminder to not paste private SSH keys !4399 (Ingo Blechschmidt)
- Remove duplicate `description` field in `MergeRequest` entities (Ben Boeckel) - Remove duplicate `description` field in `MergeRequest` entities (Ben Boeckel)
- Style of import project buttons were fixed in the new project page. !5183 (rdemirbay) - Style of import project buttons were fixed in the new project page. !5183 (rdemirbay)
- Fix GitHub client requests when rate limit is disabled
v 8.9.6 (unreleased) v 8.9.6 (unreleased)
- Fix importing of events under notes for GitLab projects - Fix importing of events under notes for GitLab projects
......
...@@ -78,10 +78,21 @@ module Gitlab ...@@ -78,10 +78,21 @@ module Gitlab
def rate_limit def rate_limit
api.rate_limit! api.rate_limit!
# GitHub Rate Limit API returns 404 when the rate limit is
# disabled. In this case we just want to return gracefully
# instead of spitting out an error.
rescue Octokit::NotFound
nil
end
def has_rate_limit?
return @has_rate_limit if defined?(@has_rate_limit)
@has_rate_limit = rate_limit.present?
end end
def rate_limit_exceed? def rate_limit_exceed?
rate_limit.remaining <= GITHUB_SAFE_REMAINING_REQUESTS has_rate_limit? && rate_limit.remaining <= GITHUB_SAFE_REMAINING_REQUESTS
end end
def rate_limit_sleep_time def rate_limit_sleep_time
......
...@@ -61,4 +61,11 @@ describe Gitlab::GithubImport::Client, lib: true do ...@@ -61,4 +61,11 @@ describe Gitlab::GithubImport::Client, lib: true do
expect(client.api.api_endpoint).to eq 'https://github.company.com/' expect(client.api.api_endpoint).to eq 'https://github.company.com/'
end end
end end
it 'does not raise error when rate limit is disabled' do
stub_request(:get, /api.github.com/)
allow(client.api).to receive(:rate_limit!).and_raise(Octokit::NotFound)
expect { client.issues }.not_to raise_error
end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment