diff --git a/highfive/newpr.py b/highfive/newpr.py index ba068a39..3d441f1f 100644 --- a/highfive/newpr.py +++ b/highfive/newpr.py @@ -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 @@ -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: diff --git a/highfive/tests/test_newpr.py b/highfive/tests/test_newpr.py index 9cc45bd1..d8d6808e 100644 --- a/highfive/tests/test_newpr.py +++ b/highfive/tests/test_newpr.py @@ -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') @@ -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):