diff --git a/README.md b/README.md index 492245b..9783d48 100644 --- a/README.md +++ b/README.md @@ -162,7 +162,7 @@ The simplest way to hit the ground running if you want to contribute with code i Launch a python container ```shell -localhost$ docker run --rm -it -v $(pwd):$(pwd) -w $(pwd) python:3.7-stretch bash +localhost$ docker run --rm -it -v $(pwd):$(pwd) -w $(pwd) python:3.11-slim-bullseye bash ``` Install the project and test dependencies in developer mode diff --git a/gordian/repo.py b/gordian/repo.py index 0c53a0b..bd6e5f1 100644 --- a/gordian/repo.py +++ b/gordian/repo.py @@ -126,7 +126,7 @@ def _set_target_branch(self, target_branch, source_branch=None): self.branch_name = f"refs/heads/{datetime.datetime.now().strftime('%Y-%m-%d-%H%M%S.%f')}" self.source_branch = self.target_ref - @retry(GithubException, tries=3, delay=1, backoff=2) + @retry((GithubException, TimeoutError), tries=3, delay=1, backoff=2) def _get_repo_contents(self, path): try: logger.debug(f'Fetching repo contents {path}...') @@ -135,6 +135,9 @@ def _get_repo_contents(self, path): if e.status == 404: raise e logger.info(f'Error fetching repo contents: {e}') + except TimeoutError as e: + logger.info(f'Error fetching repo contents: {e}') + raise e @retry(GithubException, tries=3, delay=1, backoff=2) def _make_branch(self): @@ -248,6 +251,6 @@ def _get_new_version(self): elif self.semver_label == 'patch': patch = str(int(patch) + 1) self.new_version = '.'.join([major, minor, patch]) - + def get_github_client(self): return self._github diff --git a/tests/test_repo.py b/tests/test_repo.py index a341ea1..33b7183 100644 --- a/tests/test_repo.py +++ b/tests/test_repo.py @@ -206,3 +206,23 @@ def test__get_github_client(self): self.assertIsNotNone(repo.get_github_client()) self.assertEqual(repo.get_github_client(), self.mock_git) + + def test_get_repo_contents_timeout_error(self): + self.repo._set_target_branch('target') + self.repo.files = [] + self.repo._source_repo = MagicMock() + self.repo._source_repo.get_contents.side_effect = TimeoutError('Read Timeout') + with pytest.raises(Exception) as context: + self.repo._get_repo_contents(path='test/afile.txt') + assert "Read Timeout" in str(context.value) + self.repo._source_repo.get_contents.assert_has_calls([call('test/afile.txt', 'target'), call('test/afile.txt', 'target'), call('test/afile.txt', 'target')]) + + + def test_get_repo_contents(self): + self.repo._set_target_branch('target') + self.repo.files = [] + self.repo._source_repo = MagicMock() + repository_file = MagicMock(path='test/afile.txt', type='not_dir') + self.repo._source_repo.get_contents.side_effect = [repository_file] + self.repo._get_repo_contents(path='test/afile.txt') + self.repo._source_repo.get_contents.assert_has_calls([call('test/afile.txt', 'target')])