Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions scripts/github_bounty_claimer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 ""
Expand Down
43 changes: 43 additions & 0 deletions tests/test_github_bounty_claimer.py
Original file line number Diff line number Diff line change
@@ -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()