Skip to content

Commit

Permalink
Fetch repo content from target branch (#47)
Browse files Browse the repository at this point in the history
* Fetch repo content from target branch

The source branch of the PR may not exist at that point in time when you try to request content from it.

Signed-off-by: Jean Remond <[email protected]>

* Fixed test

Signed-off-by: Corey Caverly <[email protected]>

---------

Signed-off-by: Jean Remond <[email protected]>
Signed-off-by: Corey Caverly <[email protected]>
Co-authored-by: Corey Caverly <[email protected]>
  • Loading branch information
jremond and coreycaverly authored Oct 5, 2023
1 parent e8dd5ad commit 0265753
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion gordian/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def _set_target_branch(self, target_branch, source_branch=None):
def _get_repo_contents(self, path):
try:
logger.debug(f'Fetching repo contents {path}...')
return self._source_repo.get_contents(path, self.source_branch)
return self._source_repo.get_contents(path, self.target_branch)
except GithubException as e:
if e.status == 404:
raise e
Expand Down
2 changes: 1 addition & 1 deletion tests/test_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def test_get_files(self):
repository_file = MagicMock(path='afile.txt', type='not_dir')
self.repo._source_repo.get_contents.side_effect = [[MagicMock(path='directory', type='dir')],[repository_file]]
self.repo.get_files()
self.repo._source_repo.get_contents.assert_has_calls([call('', 'refs/heads/target'), call('directory', 'refs/heads/target')])
self.repo._source_repo.get_contents.assert_has_calls([call('', 'target'), call('directory', 'target')])
self.assertEquals(self.repo.files, [repository_file])

def test_set_target_branch(self):
Expand Down

0 comments on commit 0265753

Please sign in to comment.