diff --git a/app/hook_details/labeled_hook_details.py b/app/hook_details/labeled_hook_details.py index f6d6273..4da917c 100644 --- a/app/hook_details/labeled_hook_details.py +++ b/app/hook_details/labeled_hook_details.py @@ -53,8 +53,8 @@ def setup_final_param_values(self, registration_cursor: RegistrationCursor) -> N pass async def should_trigger(self, cursor: RegistrationCursor, github_client: GithubClient) -> bool: - if cursor.file_restrictions and not await github_client.are_files_in_repo(self.repository, - self.sha, - cursor.file_restrictions): + if cursor.file_restrictions and not await github_client.are_files_in_repo(self.repository, self.sha, cursor.file_restrictions): + return False + if cursor.branch_restrictions and self.branch not in cursor.branch_restrictions: return False return True diff --git a/tests/hook_details/test_labeled_hook_details.py b/tests/hook_details/test_labeled_hook_details.py index cb30ba0..2651fa1 100644 --- a/tests/hook_details/test_labeled_hook_details.py +++ b/tests/hook_details/test_labeled_hook_details.py @@ -34,19 +34,27 @@ async def test__setup_final_params(self): async def test__should_trigger(self): github_client = mock(spec=GithubClient, strict=True) - registration_cursor = mock({'file_restrictions': []}, spec=RegistrationCursor, strict=True) + registration_cursor = mock({'file_restrictions': [], 'branch_restrictions': []}, spec=RegistrationCursor, strict=True) assert await LabeledHookDetails('repo', 'master', '123321', 'custom', 'karolgil', 'https://pr.url')\ .should_trigger(registration_cursor, github_client) - registration_cursor = mock({'file_restrictions': ['README.md']}, spec=RegistrationCursor, strict=True) + registration_cursor = mock({'file_restrictions': ['README.md'], 'branch_restrictions': []}, spec=RegistrationCursor, strict=True) expect(github_client).are_files_in_repo('repo', '123321', ['README.md']).thenReturn(async_value(False)) assert not await LabeledHookDetails('repo', 'master', '123321', 'custom', 'karolgil', 'https://pr.url')\ .should_trigger(registration_cursor, github_client) - registration_cursor = mock({'file_restrictions': ['README.md']}, spec=RegistrationCursor, strict=True) + registration_cursor = mock({'file_restrictions': ['README.md'], 'branch_restrictions': []}, spec=RegistrationCursor, strict=True) expect(github_client).are_files_in_repo('repo', '123321', ['README.md']).thenReturn(async_value(True)) assert await LabeledHookDetails('repo', 'master', '123321', 'custom', 'karolgil', 'https://pr.url')\ .should_trigger(registration_cursor, github_client) + registration_cursor = mock({'file_restrictions': [], 'branch_restrictions': ['master']}, spec=RegistrationCursor, strict=True) + assert await LabeledHookDetails('repo', 'master', '123321', 'custom', 'karolgil', 'https://pr.url')\ + .should_trigger(registration_cursor, github_client) + + registration_cursor = mock({'file_restrictions': [], 'branch_restrictions': ['feature']}, spec=RegistrationCursor, strict=True) + assert not await LabeledHookDetails('repo', 'master', '123321', 'custom', 'karolgil', 'https://pr.url')\ + .should_trigger(registration_cursor, github_client) + async def test__get_event_type(self): assert LabeledHookDetails('repo', 'master', '123321', 'custom', 'karolgil', 'https://pr.url').get_event_type() == EventType.PR_LABELED