From 33da633c587083a126e6126f6ac5813c6cb854f8 Mon Sep 17 00:00:00 2001 From: kaosx5s <> Date: Thu, 5 Oct 2023 10:13:50 -0700 Subject: [PATCH 1/2] Add support for setting a path on get_files Signed-off-by: kaosx5s --- CHANGELOG.md | 4 ++++ gordian/repo.py | 4 ++-- setup.py | 2 +- tests/test_repo.py | 10 ++++++++++ 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7afbf2a..102cac4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com), and this project adheres to [Semantic Versioning](https://semver.org). +## [3.6.0] - 2023-05-16 +### Added +- Added support to pass in a path when calling get_files(), resolves issue #34 + ## [3.5.0] - 2023-05-16 ### Added - Added support to pass in a github token, username and password as named parameters diff --git a/gordian/repo.py b/gordian/repo.py index ace55db..d2f4be2 100644 --- a/gordian/repo.py +++ b/gordian/repo.py @@ -77,9 +77,9 @@ def get_objects(self, filename, klass=None): return PlainTextFile(file, self) - def get_files(self): + def get_files(self, path=''): if not self.files: - contents = self._get_repo_contents('') + contents = self._get_repo_contents(path) while contents: file = contents.pop(0) diff --git a/setup.py b/setup.py index f274213..ec35914 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ setup_reqs = ["pytest", "pytest-cov", "pytest-runner", "flake8"] setuptools.setup( name="gordian", - version="3.5.0", + version="3.6.0", author="Intuit", author_email="cg-sre@intuit.com", description="A tool to search and replace files in a Git repo", diff --git a/tests/test_repo.py b/tests/test_repo.py index 95aa639..d35c418 100644 --- a/tests/test_repo.py +++ b/tests/test_repo.py @@ -191,6 +191,16 @@ def test_delete_file(self, mock_git): repo._source_repo.delete_file.assert_called_once() self.assertTrue(repo.dirty) + def test_get_files_with_path(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 = [[MagicMock(path='directory', type='dir')],[repository_file]] + self.repo.get_files('test') + self.repo._source_repo.get_contents.assert_has_calls([call('test', 'refs/heads/target'), call('directory', 'refs/heads/target')]) + self.assertEquals(self.repo.files, [repository_file]) + def test__get_github_client(self): repo = Repo('test_repo', branch='', github=self.mock_git) From d617a6b7f603f3113035a78c79f69c5f93c9b046 Mon Sep 17 00:00:00 2001 From: kaosx5s <> Date: Wed, 18 Oct 2023 09:54:06 -0700 Subject: [PATCH 2/2] fix repo test after target change in 3.6.0 Signed-off-by: kaosx5s <> --- tests/test_repo.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_repo.py b/tests/test_repo.py index c3c982b..a341ea1 100644 --- a/tests/test_repo.py +++ b/tests/test_repo.py @@ -198,7 +198,7 @@ def test_get_files_with_path(self): repository_file = MagicMock(path='test/afile.txt', type='not_dir') self.repo._source_repo.get_contents.side_effect = [[MagicMock(path='directory', type='dir')],[repository_file]] self.repo.get_files('test') - self.repo._source_repo.get_contents.assert_has_calls([call('test', 'refs/heads/target'), call('directory', 'refs/heads/target')]) + self.repo._source_repo.get_contents.assert_has_calls([call('test', 'target'), call('directory', 'target')]) self.assertEquals(self.repo.files, [repository_file]) def test__get_github_client(self):