Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix github_api to consider commits without checks as passing #12

Merged
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
5 changes: 4 additions & 1 deletion tubular/github_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,8 +591,11 @@ def _poll_commit(self, sha):
)
def _run():
result = self._is_commit_successful(sha)
if result[0] == False: # No Checks found against the Commit
# Returning any string other than '' will set the commit status to succeed.
# Returning 'success' to avoid breaking pipeline checks in case no actions are found
return ("success", None)
return (result[2], result[1])

return _run()

def poll_pull_request_test_status(self, pr_number):
Expand Down
26 changes: 17 additions & 9 deletions tubular/tests/test_github.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,21 +303,29 @@ def test_check_combined_status_commit(
self.repo_mock.get_commit.assert_called_with(sha)

@ddt.data(
('passed', True),
('failed', False)
('', 'success', None), # Case where no actions are found
('passed', 'passed', True), # Case where actions are found and succeed
('failed', 'failed', False), # Case where actions are found and fail
)
@ddt.unpack
def test_poll_commit(self, end_status, successful):
def test_poll_commit(self, initial_status, end_status, successful):
url_dict = {'TravisCI': 'some url'}
with patch.object(self.api, '_is_commit_successful', side_effect=[
(False, url_dict, 'pending'),
side_effects = [
(False, url_dict, initial_status) if initial_status == '' else (True, url_dict, initial_status),
(successful, url_dict, end_status),
]):
]

with patch.object(self.api, '_is_commit_successful', side_effect=side_effects) as mock_is_commit_successful:
result = self.api._poll_commit('some sha') # pylint: disable=protected-access

assert self.api._is_commit_successful.call_count == 2 # pylint: disable=protected-access
assert result[0] == end_status
assert result[1] == url_dict
if initial_status == '':
# We expect the function to return immediately after the first call
assert result[0] == 'success'
assert result[1] is None
else:
# Ensure the function processes both calls
assert result[0] == end_status
assert result[1] == url_dict

@ddt.data(
(
Expand Down
Loading