Skip to content
This repository has been archived by the owner on Feb 4, 2020. It is now read-only.

Commit

Permalink
Enable branch restrictions for labeled triggers
Browse files Browse the repository at this point in the history
  • Loading branch information
karolgil authored and karolgil committed Jun 21, 2019
1 parent 8195bb0 commit 27f0f08
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
6 changes: 3 additions & 3 deletions app/hook_details/labeled_hook_details.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 11 additions & 3 deletions tests/hook_details/test_labeled_hook_details.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 27f0f08

Please sign in to comment.