Skip to content

Commit

Permalink
Merge pull request #4312 from nickmango/feature/bot-comment-edit
Browse files Browse the repository at this point in the history
[#4195] Feature/bot comment edit
  • Loading branch information
nickmango authored May 7, 2024
2 parents 98ea56b + c5cbbde commit a4154e1
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 9 deletions.
8 changes: 4 additions & 4 deletions cla-backend/cla/models/github_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
47 changes: 42 additions & 5 deletions cla-backend/cla/tests/unit/test_github.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:"
Expand Down Expand Up @@ -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
Expand All @@ -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):
Expand Down
1 change: 1 addition & 0 deletions cla-backend/cla/tests/unit/test_github_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@
#
# if __name__ == '__main__':
# unittest.main()
import unittest
from unittest import TestCase
from unittest.mock import MagicMock, Mock, patch

Expand Down
2 changes: 2 additions & 0 deletions cla-backend/cla/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 += '</ul>'

committers_comment += '<!-- Date Modified: ' + str(datetime.datetime.now()) + ' -->'

if len(signed) > 0 and len(missing) == 0:
text = "The committers listed above are authorized under a signed CLA."

Expand Down

0 comments on commit a4154e1

Please sign in to comment.