diff --git a/cla-backend/cla/models/github_models.py b/cla-backend/cla/models/github_models.py index 647492252..6bbbb5792 100644 --- a/cla-backend/cla/models/github_models.py +++ b/cla-backend/cla/models/github_models.py @@ -742,8 +742,8 @@ def update_change_request(self, installation_id, github_repository_id, change_re cla.log.debug(f'{fn} - PR: {pull_request.number} for user: {user_commit_summary}') futures.append(executor.submit(handle_commit_from_user, project,user_commit_summary,signed,missing)) - #Wait for all threads to be finished before mobing on - executor.shutdown(wait=True) + #Wait for all threads to be finished before moving on + executor.shutdown(wait=True) for future in concurrent.futures.as_completed(futures): cla.log.debug(f'{fn} - ThreadClosed for handle_commit_from_user') @@ -1407,7 +1407,7 @@ def get_co_author_commits(co_author,commit,pr,installation_id): def has_check_previously_passed_or_failed(pull_request: PullRequest): """ - Review the status updates in the PR. Identify 1 or more previous failed + Review the status updates in the PR. Identify 1 or more previous failed|passed updates from the EasyCLA bot. If we fine one, return True with the comment, otherwise return False, None @@ -1505,7 +1505,7 @@ def update_pull_request(installation_id, github_repository_id, pull_request, rep # After Issue #167 wsa in place, they decided via Issue #289 that we # DO want to update the comment, but only after we've previously failed if previously_pass_or_failed: - cla.log.debug(f'{fn} - Found previously failed checks - updating CLA comment in PR.') + cla.log.debug(f'{fn} - Found previously passed or failed checks - updating CLA comment in PR.') comment.edit(body) cla.log.debug(f'{fn} - EasyCLA App checks pass for PR: {pull_request.number} with authors: {signed}') else: diff --git a/cla-backend/cla/tests/unit/test_github.py b/cla-backend/cla/tests/unit/test_github.py index 64be36d4a..1d4229cd4 100644 --- a/cla-backend/cla/tests/unit/test_github.py +++ b/cla-backend/cla/tests/unit/test_github.py @@ -2,10 +2,11 @@ # SPDX-License-Identifier: MIT import unittest +from unittest.mock import MagicMock import cla -from cla.controllers.github import (webhook_secret_failed_email_content, - webhook_secret_validation) +from cla.controllers.github import webhook_secret_failed_email_content, webhook_secret_validation +from cla.models.github_models import has_check_previously_passed_or_failed from cla.utils import get_comment_badge SUCCESS = ":white_check_mark:" @@ -119,6 +120,42 @@ def test_comment_badge_with_missing_whitelisted_user(): assert confirmation_needed_badge in response +def test_has_check_previously_passed_or_failed_failed_status(): + # Create a mock PullRequest object + pull_request = MagicMock() + # Create mock comments + comments = [ + MagicMock(body="This is a comment that does not match any failure or pass condition"), + ] + # Set the return value of get_issue_comments to the mock comments + pull_request.get_issue_comments.return_value = comments + + # Test the function + result, comment = has_check_previously_passed_or_failed(pull_request) + + assert result == False + assert comment is None + + +def test_has_check_previously_passed_or_failed_passed_status(): + # Create a mock PullRequest object + pull_request = MagicMock() + # Create mock comments + comments = [ + MagicMock(body="This is a comment that does not match any failure or pass condition"), + MagicMock(body="The committers listed above are authorized under a signed CLA."), + ] + # Set the return value of get_issue_comments to the mock comments + pull_request.get_issue_comments.return_value = comments + + # Test the function + result, comment = has_check_previously_passed_or_failed(pull_request) + + # Assert that the function returns True and the correct comment + assert result + assert comment == comments[1] + + class TestWebhookSecretValidation(unittest.TestCase): def setUp(self) -> None: self.old_email = cla.config.EMAIL_SERVICE @@ -134,21 +171,21 @@ def test_webhook_secret_validation_empty(self): """ cla.config.GITHUB_APP_WEBHOOK_SECRET = "" with self.assertRaises(RuntimeError) as ex: - _ = webhook_secret_validation("secret", b'') + _ = webhook_secret_validation("secret", b"") def test_webhook_secret_validation_failed(self): """ Tests the webhook_secret_validation method """ cla.config.GITHUB_APP_WEBHOOK_SECRET = "secret" - assert not webhook_secret_validation("sha1=secret", ''.encode()) + assert not webhook_secret_validation("sha1=secret", "".encode()) def test_webhook_secret_validation_success(self): """ Tests the webhook_secret_validation method """ cla.config.GITHUB_APP_WEBHOOK_SECRET = "secret" - input_data = 'data'.encode('utf-8') + input_data = "data".encode("utf-8") assert webhook_secret_validation("sha1=9818e3306ba5ac267b5f2679fe4abd37e6cd7b54", input_data) # def test_webhook_secret_failed_email(self): diff --git a/cla-backend/cla/tests/unit/test_github_models.py b/cla-backend/cla/tests/unit/test_github_models.py index 6e68aa3ef..833d4d329 100644 --- a/cla-backend/cla/tests/unit/test_github_models.py +++ b/cla-backend/cla/tests/unit/test_github_models.py @@ -246,6 +246,7 @@ # # if __name__ == '__main__': # unittest.main() +import unittest from unittest import TestCase from unittest.mock import MagicMock, Mock, patch diff --git a/cla-backend/cla/utils.py b/cla-backend/cla/utils.py index d21100b8e..de6b28dd5 100644 --- a/cla-backend/cla/utils.py +++ b/cla-backend/cla/utils.py @@ -1078,6 +1078,8 @@ def get_comment_body(repository_type, sign_url, signed: List[UserCommitSummary], if len(signed) > 0 or len(missing) > 0: committers_comment += '' + committers_comment += '' + if len(signed) > 0 and len(missing) == 0: text = "The committers listed above are authorized under a signed CLA."