Skip to content

Commit 0a18fb7

Browse files
authored
fix: retry rate limit error (#21)
* build: update build version * fix: retry rate limit error * ci: use pyb code coverage --------- Signed-off-by: Emilio Reyes <soda480@gmail.com>
1 parent 398c812 commit 0a18fb7

File tree

5 files changed

+13
-40
lines changed

5 files changed

+13
-40
lines changed

.github/workflows/main.yml

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -20,37 +20,3 @@ jobs:
2020
- name: build github3api ${{ matrix.version }} image
2121
run:
2222
docker image build --target build-image --build-arg PYTHON_VERSION=${{ matrix.version }} -t github3api:${{ matrix.version }} .
23-
- name: save github3api ${{ matrix.version }} image
24-
if: ${{ matrix.version == '3.9' }}
25-
run: |
26-
mkdir -p images
27-
docker save --output images/github3api-${{ matrix.version }}.tar github3api:${{ matrix.version }}
28-
- name: upload github3api ${{ matrix.version }} image artifact
29-
if: ${{ matrix.version == '3.9' }}
30-
uses: actions/upload-artifact@v2
31-
with:
32-
name: image
33-
path: images/github3api-${{ matrix.version }}.tar
34-
coverage:
35-
name: Publish Code Coverage Report
36-
needs: build-images
37-
runs-on: ubuntu-20.04
38-
steps:
39-
- name: download image artifact
40-
uses: actions/download-artifact@v2
41-
with:
42-
name: image
43-
path: images/
44-
- name: load image
45-
run:
46-
docker load --input images/github3api-3.9.tar
47-
- name: prepare report
48-
run: |
49-
ID=$(docker create github3api:3.9)
50-
docker cp $ID:/code/target/reports/github3api_coverage.xml github3api_coverage.xml
51-
sed -i -e 's,filename="github3api/,filename="src/main/python/github3api/,g' github3api_coverage.xml
52-
- name: upload report
53-
uses: codecov/codecov-action@v1
54-
with:
55-
token: ${{ secrets.CODECOV_TOKEN }}
56-
file: github3api_coverage.xml

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# github3api
22
[![GitHub Workflow Status](https://github.com/soda480/github3api/workflows/build/badge.svg)](https://github.com/soda480/github3api/actions)
3-
[![Code Coverage](https://codecov.io/gh/soda480/github3api/branch/master/graph/badge.svg)](https://codecov.io/gh/soda480/github3api)
3+
[![coverage](https://img.shields.io/badge/coverage-100%25-brightgreen)](https://pybuilder.io/)
4+
[![complexity](https://img.shields.io/badge/complexity-A-brightgreen)](https://radon.readthedocs.io/en/latest/api.html#module-radon.complexity)
45
[![vulnerabilities](https://img.shields.io/badge/vulnerabilities-None-brightgreen)](https://pypi.org/project/bandit/)
56
[![PyPI version](https://badge.fury.io/py/github3api.svg)](https://app.codiga.io/public/project/13337/github3api/dashboard)
67
[![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/)

build.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
authors = [Author('Emilio Reyes', 'emilio.reyes@intel.com')]
3131
summary = 'An advanced REST client for the GitHub API'
3232
url = 'https://github.com/soda480/github3api'
33-
version = '0.3.1'
33+
version = '0.3.2'
3434
default_task = [
3535
'clean',
3636
'analyze',
@@ -76,4 +76,3 @@ def set_properties(project):
7676
project.set_property('radon_break_build_average_complexity_threshold', 3.6)
7777
project.set_property('radon_break_build_complexity_threshold', 14)
7878
project.set_property('bandit_break_build', True)
79-
project.set_property('anybadge_exclude', 'coverage, complexity')

src/main/python/github3api/githubapi.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,8 @@ def retry_ratelimit_error(exception):
153153
"""
154154
logger.debug(f"checking if '{type(exception).__name__}' exception is a ratelimit error")
155155
if isinstance(exception, HTTPError):
156-
if exception.response.status_code == 403:
156+
logger.debug(exception.response.reason)
157+
if exception.response.status_code == 403 and 'rate limit exceeded' in exception.response.reason.lower():
157158
logger.info('ratelimit error encountered - retrying request in 60 seconds')
158159
return True
159160
logger.debug(f'exception is not a ratelimit error: {exception}')

src/unittest/python/test_githubapi.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,18 +109,24 @@ def test__retry_ratelimit_error_Should_Return_False_When_NotHttpError(self, *pat
109109

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

112-
def test__retry_ratelimit_error_Should_Return_True_When_HttpErrorNoStatusCodeMatch(self, *patches):
112+
def test__retry_ratelimit_error_Should_Return_False_When_HttpErrorNoStatusCodeMatch(self, *patches):
113113
response_mock = Mock(status_code=404)
114114
http_error_mock = HTTPError(Mock())
115115
http_error_mock.response = response_mock
116116
self.assertFalse(GitHubAPI.retry_ratelimit_error(http_error_mock))
117117

118118
def test__retry_ratelimit_error_Should_Return_True_When_Match(self, *patches):
119-
response_mock = Mock(status_code=403)
119+
response_mock = Mock(status_code=403, reason='API Rate Limit Exceeded')
120120
http_error_mock = HTTPError(Mock())
121121
http_error_mock.response = response_mock
122122
self.assertTrue(GitHubAPI.retry_ratelimit_error(http_error_mock))
123123

124+
def test__retry_ratelimit_error_Should_Return_False_When_403NotRateLimit(self, *patches):
125+
response_mock = Mock(status_code=403, reason='Forbidden')
126+
http_error_mock = HTTPError(Mock())
127+
http_error_mock.response = response_mock
128+
self.assertFalse(GitHubAPI.retry_ratelimit_error(http_error_mock))
129+
124130
@patch('github3api.githubapi.GitHubAPI.log_ratelimit')
125131
@patch('github3api.githubapi.GitHubAPI.get_ratelimit')
126132
def test__get_response_Should_CallExpected_When_RateLimit(self, get_ratelimit_patch, log_ratelimit_patch, *patches):

0 commit comments

Comments
 (0)