Skip to content

Commit 078912a

Browse files
Rename mention decorator kwarg from mention to context
Updates the kwarg passed to mention handlers from "mention" to "context" to better reflect that it contains a MentionContext object with comment, triggered_by, and scope fields. Also removes unused _mention_permission attribute from MentionHandlerBase protocol. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent ae6238a commit 078912a

File tree

2 files changed

+16
-17
lines changed

2 files changed

+16
-17
lines changed

src/django_github_app/routing.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232

3333
class MentionHandlerBase(Protocol):
3434
_mention_pattern: str | re.Pattern[str] | None
35-
_mention_permission: str | None
3635
_mention_scope: MentionScope | None
3736
_mention_username: str | re.Pattern[str] | None
3837

@@ -103,7 +102,7 @@ async def async_wrapper(
103102
continue
104103
mention.match = match
105104

106-
kwargs["mention"] = MentionContext(
105+
kwargs["context"] = MentionContext(
107106
comment=comment,
108107
triggered_by=mention,
109108
scope=event_scope,
@@ -133,7 +132,7 @@ def sync_wrapper(
133132
continue
134133
mention.match = match
135134

136-
kwargs["mention"] = MentionContext(
135+
kwargs["context"] = MentionContext(
137136
comment=comment,
138137
triggered_by=mention,
139138
scope=event_scope,

tests/test_routing.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ def test_multiple_decorators_on_same_function(
246246
@router.mention(pattern="help")
247247
def help_handler_help(event, *args, **kwargs):
248248
call_tracker.append("help decorator")
249-
mention = kwargs.get("mention")
249+
mention = kwargs.get("context")
250250
if mention and mention.triggered_by:
251251
text = mention.triggered_by.text.strip()
252252
if text in call_counts:
@@ -255,7 +255,7 @@ def help_handler_help(event, *args, **kwargs):
255255
@router.mention(pattern="h")
256256
def help_handler_h(event, *args, **kwargs):
257257
call_tracker.append("h decorator")
258-
mention = kwargs.get("mention")
258+
mention = kwargs.get("context")
259259
if mention and mention.triggered_by:
260260
text = mention.triggered_by.text.strip()
261261
if text in call_counts:
@@ -264,7 +264,7 @@ def help_handler_h(event, *args, **kwargs):
264264
@router.mention(pattern="?")
265265
def help_handler_q(event, *args, **kwargs):
266266
call_tracker.append("? decorator")
267-
mention = kwargs.get("mention")
267+
mention = kwargs.get("context")
268268
if mention and mention.triggered_by:
269269
text = mention.triggered_by.text.strip()
270270
if text in call_counts:
@@ -573,8 +573,8 @@ def deploy_handler(event, *args, **kwargs):
573573
test_router.dispatch(event, mock_gh)
574574

575575
assert handler_called
576-
assert "mention" in captured_kwargs
577-
mention = captured_kwargs["mention"]
576+
assert "context" in captured_kwargs
577+
mention = captured_kwargs["context"]
578578
# Check the new structure
579579
assert mention.comment.body == "@bot deploy"
580580
assert mention.triggered_by.text == "deploy"
@@ -593,7 +593,7 @@ def test_mention_context_structure(self, test_router, get_mock_github_api_sync):
593593
def test_handler(event, *args, **kwargs):
594594
nonlocal handler_called, captured_mention
595595
handler_called = True
596-
captured_mention = kwargs.get("mention")
596+
captured_mention = kwargs.get("context")
597597

598598
event = sansio.Event(
599599
{
@@ -647,7 +647,7 @@ def test_multiple_mentions_triggered_by(
647647
def deploy_handler(event, *args, **kwargs):
648648
nonlocal handler_called, captured_mention
649649
handler_called = True
650-
captured_mention = kwargs.get("mention")
650+
captured_mention = kwargs.get("context")
651651

652652
event = sansio.Event(
653653
{
@@ -693,7 +693,7 @@ def test_mention_without_pattern(self, test_router, get_mock_github_api_sync):
693693
def general_handler(event, *args, **kwargs):
694694
nonlocal handler_called, captured_mention
695695
handler_called = True
696-
captured_mention = kwargs.get("mention")
696+
captured_mention = kwargs.get("context")
697697

698698
event = sansio.Event(
699699
{
@@ -733,7 +733,7 @@ async def test_async_mention_context_structure(
733733
async def async_handler(event, *args, **kwargs):
734734
nonlocal handler_called, captured_mention
735735
handler_called = True
736-
captured_mention = kwargs.get("mention")
736+
captured_mention = kwargs.get("context")
737737

738738
event = sansio.Event(
739739
{
@@ -774,7 +774,7 @@ def test_pattern_parameter_string(self, test_router, get_mock_github_api_sync):
774774
def deploy_handler(event, *args, **kwargs):
775775
nonlocal handler_called, captured_mention
776776
handler_called = True
777-
captured_mention = kwargs.get("mention")
777+
captured_mention = kwargs.get("context")
778778

779779
# Should match
780780
event = sansio.Event(
@@ -812,7 +812,7 @@ def test_pattern_parameter_regex(self, test_router, get_mock_github_api_sync):
812812
def deploy_env_handler(event, *args, **kwargs):
813813
nonlocal handler_called, captured_mention
814814
handler_called = True
815-
captured_mention = kwargs.get("mention")
815+
captured_mention = kwargs.get("context")
816816

817817
event = sansio.Event(
818818
{
@@ -895,7 +895,7 @@ def test_username_all_mentions(self, test_router, get_mock_github_api_sync):
895895

896896
@test_router.mention(username=re.compile(r".*"))
897897
def all_mentions_handler(event, *args, **kwargs):
898-
mention = kwargs.get("mention")
898+
mention = kwargs.get("context")
899899
mentions_seen.append(mention.triggered_by.username)
900900

901901
event = sansio.Event(
@@ -987,7 +987,7 @@ def test_multiple_decorators_different_patterns(
987987
@test_router.mention(pattern=re.compile(r"ship"))
988988
@test_router.mention(pattern=re.compile(r"release"))
989989
def deploy_handler(event, *args, **kwargs):
990-
mention = kwargs.get("mention")
990+
mention = kwargs.get("context")
991991
patterns_matched.append(mention.triggered_by.text.split()[0])
992992

993993
event = sansio.Event(
@@ -1011,7 +1011,7 @@ def test_question_pattern(self, test_router, get_mock_github_api_sync):
10111011

10121012
@test_router.mention(pattern=re.compile(r".*\?$"))
10131013
def question_handler(event, *args, **kwargs):
1014-
mention = kwargs.get("mention")
1014+
mention = kwargs.get("context")
10151015
questions_received.append(mention.triggered_by.text)
10161016

10171017
event = sansio.Event(

0 commit comments

Comments
 (0)