diff --git a/scripts/github_bounty_claimer.py b/scripts/github_bounty_claimer.py index d8df176..aab67d8 100644 --- a/scripts/github_bounty_claimer.py +++ b/scripts/github_bounty_claimer.py @@ -199,6 +199,21 @@ def claim_comment_by_us(comments: list[dict[str, Any]], login: str) -> dict[str, return None +def is_algora_bounty_instruction_comment(comment: dict[str, Any]) -> bool: + user = comment.get("user") if isinstance(comment.get("user"), dict) else {} + author = str(user.get("login") or "").lower() + user_type = str(user.get("type") or "").lower() + if author != "algora-pbc[bot]" and user_type != "bot": + return False + body = str(comment.get("body") or "").lower() + return ( + "steps to solve" in body + and "create a pull request" in body + and "/claim" in body + and "algora.io" in body + ) + + def blocking_competition_in_comments(comments: list[dict[str, Any]], login: str) -> str: pattern = re.compile( r"\b(opened|submitted|raised)\s+(?:a\s+)?(?:focused\s+)?(?:fix\s+)?(?:pr|pull request)\b" @@ -212,6 +227,8 @@ def blocking_competition_in_comments(comments: list[dict[str, Any]], login: str) author = str(user.get("login") or "") if author.lower() == login.lower(): continue + if is_algora_bounty_instruction_comment(comment): + continue if pattern.search(str(comment.get("body") or "")): return f"strong active attempt/comment by {author or 'another user'}" return "" diff --git a/tests/test_github_bounty_claimer.py b/tests/test_github_bounty_claimer.py new file mode 100644 index 0000000..73a69a6 --- /dev/null +++ b/tests/test_github_bounty_claimer.py @@ -0,0 +1,43 @@ +import sys +import unittest +from pathlib import Path + + +sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "scripts")) + +from github_bounty_claimer import blocking_competition_in_comments + + +class BlockingCompetitionTests(unittest.TestCase): + def test_algora_bounty_instruction_comment_is_not_competition(self) -> None: + comments = [ + { + "user": {"login": "algora-pbc[bot]", "type": "Bot"}, + "body": ( + "## $50 bounty\n\n" + "### Steps to solve:\n" + "1. **Submit work**: Create a pull request including `/claim #1985` " + "in the PR body to claim the bounty\n\n" + "**[Add a bounty](https://algora.io)**" + ), + } + ] + + self.assertEqual(blocking_competition_in_comments(comments, "asaadnashed"), "") + + def test_human_attempt_comment_still_blocks(self) -> None: + comments = [ + { + "user": {"login": "other-contributor", "type": "User"}, + "body": "/attempt #1985", + } + ] + + self.assertEqual( + blocking_competition_in_comments(comments, "asaadnashed"), + "strong active attempt/comment by other-contributor", + ) + + +if __name__ == "__main__": + unittest.main()