Skip to content

Commit bfb0875

Browse files
committed
feat: support retry_transient_errors through config
1 parent 0698abf commit bfb0875

File tree

3 files changed

+87
-0
lines changed

3 files changed

+87
-0
lines changed

gitlab/client.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ def from_config(
250250
pagination=config.pagination,
251251
order_by=config.order_by,
252252
user_agent=config.user_agent,
253+
retry_transient_errors=config.retry_transient_errors,
253254
)
254255

255256
def auth(self) -> None:

gitlab/config.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,20 @@ def __init__(
206206
except Exception:
207207
pass
208208

209+
self.retry_transient_errors = False
210+
try:
211+
self.retry_transient_errors = self._config.get(
212+
"global", "retry_transient_errors"
213+
)
214+
except Exception:
215+
pass
216+
try:
217+
self.retry_transient_errors = self._config.get(
218+
self.gitlab_id, "retry_transient_errors"
219+
)
220+
except Exception:
221+
pass
222+
209223
def _get_values_from_helper(self) -> None:
210224
"""Update attributes that may get values from an external helper program"""
211225
for attr in HELPER_ATTRIBUTES:

tests/unit/test_config.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,33 @@
8686
"""
8787

8888

89+
def global_retry_transient_errors(value: bool) -> str:
90+
return u"""[global]
91+
default = one
92+
retry_transient_errors={}
93+
94+
[one]
95+
url = http://one.url
96+
private_token = ABCDEF""".format(
97+
value
98+
)
99+
100+
101+
def global_and_gitlab_retry_transient_errors(
102+
global_value: bool, gitlab_value: bool
103+
) -> str:
104+
return u"""[global]
105+
default = one
106+
retry_transient_errors={global_value}
107+
108+
[one]
109+
url = http://one.url
110+
private_token = ABCDEF
111+
retry_transient_errors={gitlab_value}""".format(
112+
global_value=global_value, gitlab_value=gitlab_value
113+
)
114+
115+
89116
@mock.patch.dict(os.environ, {"PYTHON_GITLAB_CFG": "/some/path"})
90117
def test_env_config_present():
91118
assert ["/some/path"] == config._env_config()
@@ -245,3 +272,48 @@ def test_config_user_agent(m_open, path_exists, config_string, expected_agent):
245272

246273
cp = config.GitlabConfigParser()
247274
assert cp.user_agent == expected_agent
275+
276+
277+
@mock.patch("os.path.exists")
278+
@mock.patch("builtins.open")
279+
@pytest.mark.parametrize(
280+
"config_string,expected",
281+
[
282+
pytest.param(valid_config, False, id="default_value"),
283+
pytest.param(
284+
global_retry_transient_errors(True), "True", id="global_config_true"
285+
),
286+
pytest.param(
287+
global_retry_transient_errors(False), "False", id="global_config_false"
288+
),
289+
pytest.param(
290+
global_and_gitlab_retry_transient_errors(False, True),
291+
"True",
292+
id="gitlab_overrides_global_true",
293+
),
294+
pytest.param(
295+
global_and_gitlab_retry_transient_errors(True, False),
296+
"False",
297+
id="gitlab_overrides_global_false",
298+
),
299+
pytest.param(
300+
global_and_gitlab_retry_transient_errors(True, True),
301+
"True",
302+
id="gitlab_equals_global_true",
303+
),
304+
pytest.param(
305+
global_and_gitlab_retry_transient_errors(False, False),
306+
"False",
307+
id="gitlab_equals_global_false",
308+
),
309+
],
310+
)
311+
def test_config_retry_transient_errors_when_global_config_is_set(
312+
m_open, path_exists, config_string, expected
313+
):
314+
fd = io.StringIO(config_string)
315+
fd.close = mock.Mock(return_value=None)
316+
m_open.return_value = fd
317+
318+
cp = config.GitlabConfigParser()
319+
assert cp.retry_transient_errors == expected

0 commit comments

Comments
 (0)