From 20307adf94803bcdab0631e55c333a5ab7b9aa46 Mon Sep 17 00:00:00 2001 From: Carly Gundy Date: Mon, 9 Dec 2024 14:54:15 +0100 Subject: [PATCH] wip --- reusable_workflows/check_cla/check_cla_pr.py | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/reusable_workflows/check_cla/check_cla_pr.py b/reusable_workflows/check_cla/check_cla_pr.py index f474046..f09ca94 100644 --- a/reusable_workflows/check_cla/check_cla_pr.py +++ b/reusable_workflows/check_cla/check_cla_pr.py @@ -12,33 +12,30 @@ APPROVED_LABEL = "cla:agreed" GH_WORKFLOW_LABEL = "cla:gh-wf-pending" -# keep all old bot names for backwards compatibility -CLA_BOT_NAMES = ["cla-idx-bot[bot]", "sa-github-api", "dfinity-droid-prod[bot]"] - class CLAHandler: def __init__(self, gh: github3.login) -> None: self.cla_repo = gh.repository(owner="dfinity", repository="cla") self.cla_link = f"{self.cla_repo.html_url}/blob/main/CLA.md" + @staticmethod def check_comment_already_exists( - self, comments: github3.structs.GitHubIterator + search_comment: str, comments: github3.structs.GitHubIterator ) -> bool: for comment in comments: - if comment.user.login in CLA_BOT_NAMES: + if search_comment == comment.body: return True return False - def comment_on_issue(self, issue: GHIssue): + 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() - bot_comment = self.check_comment_already_exists(issue_comments) - if not bot_comment: + if not self.check_comment_already_exists(messages.FAILED_COMMENT, issue_comments): issue.create_comment(messages.FAILED_COMMENT) - def comment_on_pr(self, pr: GHPullRequest, pr_comment): - bot_comment = self.check_comment_already_exists(pr.issue_comments()) - if not bot_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): pr.create_comment(pr_comment) def check_if_cla_signed(self, issue: GHIssue, user: str) -> bool: