Skip to content
This repository was archived by the owner on Mar 14, 2023. It is now read-only.

Fix exception when loading the global config #201

Merged
merged 1 commit into from
Mar 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions highfive/newpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,14 @@ def __init__(self, payload, config, config_dir=None):
self.integration_user = config.github_username
self.integration_token = config.github_token

self.repo_config = self.load_repo_config(config_dir)
self.config_dir = config_dir
self.repo_config = self.load_repo_config()

def load_repo_config(self, config_dir=None):
def load_repo_config(self):
'''Load the repository configuration.'''
(org, repo) = self.payload['repository', 'full_name'].split('/')
try:
return self._load_json_file(os.path.join(org, repo) + '.json', config_dir)
return self._load_json_file(os.path.join(org, repo) + '.json')
except IOError:
raise UnsupportedRepoError

Expand All @@ -75,8 +76,9 @@ def run(self, event):
else:
return 'Unsupported webhook event.\n'

def _load_json_file(self, name, config_dir=None):
if not config_dir:
def _load_json_file(self, name):
config_dir = self.config_dir
if not self.config_dir:
config_dir = os.path.join(os.path.dirname(__file__), 'configs')

with open(os.path.join(config_dir, name)) as config:
Expand Down
4 changes: 2 additions & 2 deletions highfive/tests/test_newpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def test_load_repo_config_supported(self, mock_load_json_file):
m.stop_patchers()
assert m.handler.load_repo_config() == {'a': 'config!'}
mock_load_json_file.assert_called_once_with(
os.path.join('foo', 'blah.json'), None,
os.path.join('foo', 'blah.json'),
)

@mock.patch('highfive.newpr.HighfiveHandler._load_json_file')
Expand All @@ -99,7 +99,7 @@ def test_load_repo_config_unsupported(self, mock_load_json_file):
with pytest.raises(newpr.UnsupportedRepoError):
m.handler.load_repo_config()
mock_load_json_file.assert_called_once_with(
os.path.join('foo', 'blah.json'), None
os.path.join('foo', 'blah.json'),
)

class TestNewPRGeneral(TestNewPR):
Expand Down