Skip to content

Commit

Permalink
Allow path define on get files (#42)
Browse files Browse the repository at this point in the history
* Add support for setting a path on get_files

Signed-off-by: kaosx5s <[email protected]>

* fix repo test after target change in 3.6.0

Signed-off-by: kaosx5s <>

---------

Signed-off-by: kaosx5s <[email protected]>
Signed-off-by: kaosx5s <>
Co-authored-by: kaosx5s <>
  • Loading branch information
kaosx5s authored Oct 24, 2023
1 parent 5924837 commit 02e70bc
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ 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.7.0] - 2023-10-18
### Added
- Added support to pass in a path when calling get_files(), resolves issue #34

## [3.6.0] - 2023-10-06
### Fix
- Fetch repo content from target branch
Expand Down
4 changes: 2 additions & 2 deletions gordian/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions tests/test_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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', 'target'), call('directory', 'target')])
self.assertEquals(self.repo.files, [repository_file])

def test__get_github_client(self):
repo = Repo('test_repo', branch='', github=self.mock_git)

Expand Down

0 comments on commit 02e70bc

Please sign in to comment.