Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
cgundy committed Dec 9, 2024
1 parent 20307ad commit f6a16c1
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 16 deletions.
2 changes: 1 addition & 1 deletion reusable_workflows/check_cla/check_cla_issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def main() -> None:

cla_signed = cla.check_if_cla_signed(issue, user)
if not cla_signed:
cla.comment_on_issue(issue)
cla.leave_failed_comment_on_issue(issue)
else:
cla.handle_cla_signed(issue, user)

Expand Down
8 changes: 4 additions & 4 deletions reusable_workflows/check_cla/check_cla_pr.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def __init__(self, gh: github3.login) -> None:
self.cla_link = f"{self.cla_repo.html_url}/blob/main/CLA.md"

@staticmethod
def check_comment_already_exists(
def check_if_comment_already_exists(
search_comment: str, comments: github3.structs.GitHubIterator
) -> bool:
for comment in comments:
Expand All @@ -30,12 +30,12 @@ def check_comment_already_exists(
def leave_failed_comment_on_issue(self, issue: GHIssue) -> None:
# check if bot has already left a message to avoid spam
issue_comments = issue.comments()
if not self.check_comment_already_exists(messages.FAILED_COMMENT, issue_comments):
if not self.check_if_comment_already_exists(messages.FAILED_COMMENT, issue_comments):
issue.create_comment(messages.FAILED_COMMENT)

def comment_on_pr(self, pr: GHPullRequest, pr_comment: str) -> None:
pr_comments = pr.comments()
if not self.check_comment_already_exists(pr_comment, pr_comments):
if not self.check_if_comment_already_exists(pr_comment, pr_comments):
pr.create_comment(pr_comment)

def check_if_cla_signed(self, issue: GHIssue, user: str) -> bool:
Expand All @@ -53,7 +53,7 @@ def check_if_cla_signed(self, issue: GHIssue, user: str) -> bool:

def get_cla_issue(self, user: str) -> Optional[GHIssue]:
for issue in self.cla_repo.issues():
if issue.title == f"cla: @{user}" and issue.user.login in CLA_BOT_NAMES:
if issue.title == f"cla: @{user}":
return issue
print(f"No CLA issue for {user}")
return None # to make linter happy
Expand Down
4 changes: 2 additions & 2 deletions reusable_workflows/tests/test_cla_issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def test_end_to_end_cla_signed(cla_mock, gh_login_mock):
main()

cla.check_if_cla_signed.assert_called_with(issue, "username")
cla.comment_on_issue.assert_not_called()
cla.leave_failed_comment_on_issue.assert_not_called()
cla.handle_cla_signed.assert_called_once()


Expand All @@ -56,7 +56,7 @@ def test_end_to_end_cla_not_signed(cla_mock, gh_login_mock):
main()

cla.check_if_cla_signed.assert_called_with(issue, "username")
cla.comment_on_issue.assert_called_once()
cla.leave_failed_comment_on_issue.assert_called_once()
cla.handle_cla_signed.assert_not_called()


Expand Down
16 changes: 7 additions & 9 deletions reusable_workflows/tests/test_cla_pr.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,14 @@ def test_bot_comment_exists():
cla = CLAHandler(mock.Mock())
comments_iterator = mock.Mock()
comment1 = mock.Mock()
comment1.user.login = "username"
comment1.body = "comment1"
comment2 = mock.Mock()
comment2.user.login = "sa-github-api"
comment2.body = "comment2"
comments_iterator.__iter__ = mock.Mock(
return_value=iter([comment1, comment2, comment1])
return_value=iter([comment1, comment2])
)
# comments_iterator.return_value = [comment1, comment2, comment1]

bot_comment = cla.check_comment_already_exists(comments_iterator)
bot_comment = cla.check_if_comment_already_exists("comment1", comments_iterator)

assert bot_comment is True

Expand All @@ -45,10 +44,10 @@ def test_no_bot_comment():
cla = CLAHandler(mock.Mock())
issue_comments = mock.Mock()
comment1 = mock.Mock()
comment1.user.login = "username"
issue_comments.__iter__ = mock.Mock(return_value=iter([comment1, comment1]))
comment1.body = "comment"
issue_comments.__iter__ = mock.Mock(return_value=iter([comment1]))

bot_comment = cla.check_comment_already_exists(issue_comments)
bot_comment = cla.check_if_comment_already_exists("comment2", issue_comments)

assert bot_comment is False

Expand Down Expand Up @@ -103,7 +102,6 @@ def test_get_cla_issue_success():
cla_repo = mock.Mock()
issue = mock.Mock()
issue.title = "cla: @username"
issue.user.login = "sa-github-api"
cla_repo.issues.return_value = [mock.Mock(), issue]
cla.cla_repo = cla_repo

Expand Down

0 comments on commit f6a16c1

Please sign in to comment.