Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: retry rate limit error #21

Merged
merged 3 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 0 additions & 34 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,37 +20,3 @@ jobs:
- name: build github3api ${{ matrix.version }} image
run:
docker image build --target build-image --build-arg PYTHON_VERSION=${{ matrix.version }} -t github3api:${{ matrix.version }} .
- name: save github3api ${{ matrix.version }} image
if: ${{ matrix.version == '3.9' }}
run: |
mkdir -p images
docker save --output images/github3api-${{ matrix.version }}.tar github3api:${{ matrix.version }}
- name: upload github3api ${{ matrix.version }} image artifact
if: ${{ matrix.version == '3.9' }}
uses: actions/upload-artifact@v2
with:
name: image
path: images/github3api-${{ matrix.version }}.tar
coverage:
name: Publish Code Coverage Report
needs: build-images
runs-on: ubuntu-20.04
steps:
- name: download image artifact
uses: actions/download-artifact@v2
with:
name: image
path: images/
- name: load image
run:
docker load --input images/github3api-3.9.tar
- name: prepare report
run: |
ID=$(docker create github3api:3.9)
docker cp $ID:/code/target/reports/github3api_coverage.xml github3api_coverage.xml
sed -i -e 's,filename="github3api/,filename="src/main/python/github3api/,g' github3api_coverage.xml
- name: upload report
uses: codecov/codecov-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: github3api_coverage.xml
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# github3api
[![GitHub Workflow Status](https://github.com/soda480/github3api/workflows/build/badge.svg)](https://github.com/soda480/github3api/actions)
[![Code Coverage](https://codecov.io/gh/soda480/github3api/branch/master/graph/badge.svg)](https://codecov.io/gh/soda480/github3api)
[![coverage](https://img.shields.io/badge/coverage-100%25-brightgreen)](https://pybuilder.io/)
[![complexity](https://img.shields.io/badge/complexity-A-brightgreen)](https://radon.readthedocs.io/en/latest/api.html#module-radon.complexity)
[![vulnerabilities](https://img.shields.io/badge/vulnerabilities-None-brightgreen)](https://pypi.org/project/bandit/)
[![PyPI version](https://badge.fury.io/py/github3api.svg)](https://app.codiga.io/public/project/13337/github3api/dashboard)
[![python](https://img.shields.io/badge/python-3.7%20%7C%203.8%20%7C%203.9%20%7C%203.10-teal)](https://www.python.org/downloads/)
Expand Down
3 changes: 1 addition & 2 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
authors = [Author('Emilio Reyes', 'emilio.reyes@intel.com')]
summary = 'An advanced REST client for the GitHub API'
url = 'https://github.com/soda480/github3api'
version = '0.3.1'
version = '0.3.2'
default_task = [
'clean',
'analyze',
Expand Down Expand Up @@ -76,4 +76,3 @@ def set_properties(project):
project.set_property('radon_break_build_average_complexity_threshold', 3.6)
project.set_property('radon_break_build_complexity_threshold', 14)
project.set_property('bandit_break_build', True)
project.set_property('anybadge_exclude', 'coverage, complexity')
3 changes: 2 additions & 1 deletion src/main/python/github3api/githubapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ def retry_ratelimit_error(exception):
"""
logger.debug(f"checking if '{type(exception).__name__}' exception is a ratelimit error")
if isinstance(exception, HTTPError):
if exception.response.status_code == 403:
logger.debug(exception.response.reason)
if exception.response.status_code == 403 and 'rate limit exceeded' in exception.response.reason.lower():
logger.info('ratelimit error encountered - retrying request in 60 seconds')
return True
logger.debug(f'exception is not a ratelimit error: {exception}')
Expand Down
10 changes: 8 additions & 2 deletions src/unittest/python/test_githubapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,18 +109,24 @@ def test__retry_ratelimit_error_Should_Return_False_When_NotHttpError(self, *pat

self.assertFalse(GitHubAPI.retry_ratelimit_error(Exception('test')))

def test__retry_ratelimit_error_Should_Return_True_When_HttpErrorNoStatusCodeMatch(self, *patches):
def test__retry_ratelimit_error_Should_Return_False_When_HttpErrorNoStatusCodeMatch(self, *patches):
response_mock = Mock(status_code=404)
http_error_mock = HTTPError(Mock())
http_error_mock.response = response_mock
self.assertFalse(GitHubAPI.retry_ratelimit_error(http_error_mock))

def test__retry_ratelimit_error_Should_Return_True_When_Match(self, *patches):
response_mock = Mock(status_code=403)
response_mock = Mock(status_code=403, reason='API Rate Limit Exceeded')
http_error_mock = HTTPError(Mock())
http_error_mock.response = response_mock
self.assertTrue(GitHubAPI.retry_ratelimit_error(http_error_mock))

def test__retry_ratelimit_error_Should_Return_False_When_403NotRateLimit(self, *patches):
response_mock = Mock(status_code=403, reason='Forbidden')
http_error_mock = HTTPError(Mock())
http_error_mock.response = response_mock
self.assertFalse(GitHubAPI.retry_ratelimit_error(http_error_mock))

@patch('github3api.githubapi.GitHubAPI.log_ratelimit')
@patch('github3api.githubapi.GitHubAPI.get_ratelimit')
def test__get_response_Should_CallExpected_When_RateLimit(self, get_ratelimit_patch, log_ratelimit_patch, *patches):
Expand Down
Loading