Skip to content

Commit eb67cb2

Browse files
Rename commands module to mentions and CommandScope to MentionScope
1 parent 4181c4c commit eb67cb2

File tree

4 files changed

+39
-39
lines changed

4 files changed

+39
-39
lines changed

src/django_github_app/commands.py renamed to src/django_github_app/mentions.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,24 @@ class EventAction(NamedTuple):
1212
action: str
1313

1414

15-
class CommandScope(str, Enum):
15+
class MentionScope(str, Enum):
1616
COMMIT = "commit"
1717
ISSUE = "issue"
1818
PR = "pr"
1919

2020
def get_events(self) -> list[EventAction]:
2121
match self:
22-
case CommandScope.ISSUE:
22+
case MentionScope.ISSUE:
2323
return [
2424
EventAction("issue_comment", "created"),
2525
]
26-
case CommandScope.PR:
26+
case MentionScope.PR:
2727
return [
2828
EventAction("issue_comment", "created"),
2929
EventAction("pull_request_review_comment", "created"),
3030
EventAction("pull_request_review", "submitted"),
3131
]
32-
case CommandScope.COMMIT:
32+
case MentionScope.COMMIT:
3333
return [
3434
EventAction("commit_comment", "created"),
3535
]
@@ -92,7 +92,7 @@ def check_event_for_mention(
9292
return any(mention.command == command.lower() for mention in mentions)
9393

9494

95-
def check_event_scope(event: sansio.Event, scope: CommandScope | None) -> bool:
95+
def check_event_scope(event: sansio.Event, scope: MentionScope | None) -> bool:
9696
if scope is None:
9797
return True
9898

@@ -102,10 +102,10 @@ def check_event_scope(event: sansio.Event, scope: CommandScope | None) -> bool:
102102
is_pull_request = "pull_request" in issue and issue["pull_request"] is not None
103103

104104
# If scope is ISSUE, we only want actual issues (not PRs)
105-
if scope == CommandScope.ISSUE:
105+
if scope == MentionScope.ISSUE:
106106
return not is_pull_request
107107
# If scope is PR, we only want pull requests
108-
elif scope == CommandScope.PR:
108+
elif scope == MentionScope.PR:
109109
return is_pull_request
110110

111111
scope_events = scope.get_events()

src/django_github_app/routing.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
from gidgethub.routing import Router as GidgetHubRouter
1515

1616
from ._typing import override
17-
from .commands import CommandScope
18-
from .commands import check_event_for_mention
19-
from .commands import check_event_scope
17+
from .mentions import MentionScope
18+
from .mentions import check_event_for_mention
19+
from .mentions import check_event_scope
2020

2121
AsyncCallback = Callable[..., Awaitable[None]]
2222
SyncCallback = Callable[..., None]
@@ -26,7 +26,7 @@
2626

2727
class MentionHandlerBase(Protocol):
2828
_mention_command: str | None
29-
_mention_scope: CommandScope | None
29+
_mention_scope: MentionScope | None
3030
_mention_permission: str | None
3131

3232

@@ -116,7 +116,7 @@ def sync_wrapper(
116116
wrapper._mention_scope = scope
117117
wrapper._mention_permission = permission
118118

119-
events = scope.get_events() if scope else CommandScope.all_events()
119+
events = scope.get_events() if scope else MentionScope.all_events()
120120
for event_action in events:
121121
self.add(
122122
wrapper, event_action.event, action=event_action.action, **kwargs

tests/test_commands.py renamed to tests/test_mentions.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
from gidgethub import sansio
44

5-
from django_github_app.commands import CommandScope
6-
from django_github_app.commands import check_event_for_mention
7-
from django_github_app.commands import check_event_scope
8-
from django_github_app.commands import parse_mentions
5+
from django_github_app.mentions import MentionScope
6+
from django_github_app.mentions import check_event_for_mention
7+
from django_github_app.mentions import check_event_scope
8+
from django_github_app.mentions import parse_mentions
99

1010

1111
class TestParseMentions:
@@ -231,65 +231,65 @@ def test_issue_scope_on_issue_comment(self):
231231
issue_event = sansio.Event(
232232
{"issue": {"title": "Bug report"}}, event="issue_comment", delivery_id="1"
233233
)
234-
assert check_event_scope(issue_event, CommandScope.ISSUE) is True
234+
assert check_event_scope(issue_event, MentionScope.ISSUE) is True
235235

236236
# Issue comment on a pull request (has pull_request field)
237237
pr_event = sansio.Event(
238238
{"issue": {"title": "PR title", "pull_request": {"url": "..."}}},
239239
event="issue_comment",
240240
delivery_id="2",
241241
)
242-
assert check_event_scope(pr_event, CommandScope.ISSUE) is False
242+
assert check_event_scope(pr_event, MentionScope.ISSUE) is False
243243

244244
def test_pr_scope_on_issue_comment(self):
245245
# Issue comment on an actual issue (no pull_request field)
246246
issue_event = sansio.Event(
247247
{"issue": {"title": "Bug report"}}, event="issue_comment", delivery_id="1"
248248
)
249-
assert check_event_scope(issue_event, CommandScope.PR) is False
249+
assert check_event_scope(issue_event, MentionScope.PR) is False
250250

251251
# Issue comment on a pull request (has pull_request field)
252252
pr_event = sansio.Event(
253253
{"issue": {"title": "PR title", "pull_request": {"url": "..."}}},
254254
event="issue_comment",
255255
delivery_id="2",
256256
)
257-
assert check_event_scope(pr_event, CommandScope.PR) is True
257+
assert check_event_scope(pr_event, MentionScope.PR) is True
258258

259259
def test_pr_scope_allows_pr_specific_events(self):
260260
# PR scope should allow pull_request_review_comment
261261
event1 = sansio.Event({}, event="pull_request_review_comment", delivery_id="1")
262-
assert check_event_scope(event1, CommandScope.PR) is True
262+
assert check_event_scope(event1, MentionScope.PR) is True
263263

264264
# PR scope should allow pull_request_review
265265
event2 = sansio.Event({}, event="pull_request_review", delivery_id="2")
266-
assert check_event_scope(event2, CommandScope.PR) is True
266+
assert check_event_scope(event2, MentionScope.PR) is True
267267

268268
# PR scope should not allow commit_comment
269269
event3 = sansio.Event({}, event="commit_comment", delivery_id="3")
270-
assert check_event_scope(event3, CommandScope.PR) is False
270+
assert check_event_scope(event3, MentionScope.PR) is False
271271

272272
def test_commit_scope_allows_commit_comment_only(self):
273273
# Commit scope should allow commit_comment
274274
event1 = sansio.Event({}, event="commit_comment", delivery_id="1")
275-
assert check_event_scope(event1, CommandScope.COMMIT) is True
275+
assert check_event_scope(event1, MentionScope.COMMIT) is True
276276

277277
# Commit scope should not allow issue_comment
278278
event2 = sansio.Event({"issue": {}}, event="issue_comment", delivery_id="2")
279-
assert check_event_scope(event2, CommandScope.COMMIT) is False
279+
assert check_event_scope(event2, MentionScope.COMMIT) is False
280280

281281
# Commit scope should not allow PR events
282282
event3 = sansio.Event({}, event="pull_request_review_comment", delivery_id="3")
283-
assert check_event_scope(event3, CommandScope.COMMIT) is False
283+
assert check_event_scope(event3, MentionScope.COMMIT) is False
284284

285285
def test_issue_scope_disallows_non_issue_events(self):
286286
# Issue scope should not allow pull_request_review_comment
287287
event1 = sansio.Event({}, event="pull_request_review_comment", delivery_id="1")
288-
assert check_event_scope(event1, CommandScope.ISSUE) is False
288+
assert check_event_scope(event1, MentionScope.ISSUE) is False
289289

290290
# Issue scope should not allow commit_comment
291291
event2 = sansio.Event({}, event="commit_comment", delivery_id="2")
292-
assert check_event_scope(event2, CommandScope.ISSUE) is False
292+
assert check_event_scope(event2, MentionScope.ISSUE) is False
293293

294294
def test_pull_request_field_none_treated_as_issue(self):
295295
# If pull_request field exists but is None, treat as issue
@@ -298,11 +298,11 @@ def test_pull_request_field_none_treated_as_issue(self):
298298
event="issue_comment",
299299
delivery_id="1",
300300
)
301-
assert check_event_scope(event, CommandScope.ISSUE) is True
302-
assert check_event_scope(event, CommandScope.PR) is False
301+
assert check_event_scope(event, MentionScope.ISSUE) is True
302+
assert check_event_scope(event, MentionScope.PR) is False
303303

304304
def test_missing_issue_data(self):
305305
# If issue data is missing entirely, default behavior
306306
event = sansio.Event({}, event="issue_comment", delivery_id="1")
307-
assert check_event_scope(event, CommandScope.ISSUE) is True
308-
assert check_event_scope(event, CommandScope.PR) is False
307+
assert check_event_scope(event, MentionScope.ISSUE) is True
308+
assert check_event_scope(event, MentionScope.PR) is False

tests/test_routing.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from django.http import JsonResponse
88
from gidgethub import sansio
99

10-
from django_github_app.commands import CommandScope
10+
from django_github_app.mentions import MentionScope
1111
from django_github_app.github import SyncGitHubAPI
1212
from django_github_app.routing import GitHubRouter
1313
from django_github_app.views import BaseWebhookView
@@ -157,7 +157,7 @@ def help_command(event, *args, **kwargs):
157157
def test_mention_with_scope(self, test_router):
158158
pr_handler_called = False
159159

160-
@test_router.mention(command="deploy", scope=CommandScope.PR)
160+
@test_router.mention(command="deploy", scope=MentionScope.PR)
161161
def deploy_command(event, *args, **kwargs):
162162
nonlocal pr_handler_called
163163
pr_handler_called = True
@@ -278,7 +278,7 @@ def test_scope_validation_issue_comment_on_issue(self, test_router):
278278
"""Test that ISSUE scope works for actual issues."""
279279
handler_called = False
280280

281-
@test_router.mention(command="issue-only", scope=CommandScope.ISSUE)
281+
@test_router.mention(command="issue-only", scope=MentionScope.ISSUE)
282282
def issue_handler(event, *args, **kwargs):
283283
nonlocal handler_called
284284
handler_called = True
@@ -301,7 +301,7 @@ def test_scope_validation_issue_comment_on_pr(self, test_router):
301301
"""Test that ISSUE scope rejects PR comments."""
302302
handler_called = False
303303

304-
@test_router.mention(command="issue-only", scope=CommandScope.ISSUE)
304+
@test_router.mention(command="issue-only", scope=MentionScope.ISSUE)
305305
def issue_handler(event, *args, **kwargs):
306306
nonlocal handler_called
307307
handler_called = True
@@ -328,7 +328,7 @@ def test_scope_validation_pr_scope_on_pr(self, test_router):
328328
"""Test that PR scope works for pull requests."""
329329
handler_called = False
330330

331-
@test_router.mention(command="pr-only", scope=CommandScope.PR)
331+
@test_router.mention(command="pr-only", scope=MentionScope.PR)
332332
def pr_handler(event, *args, **kwargs):
333333
nonlocal handler_called
334334
handler_called = True
@@ -355,7 +355,7 @@ def test_scope_validation_pr_scope_on_issue(self, test_router):
355355
"""Test that PR scope rejects issue comments."""
356356
handler_called = False
357357

358-
@test_router.mention(command="pr-only", scope=CommandScope.PR)
358+
@test_router.mention(command="pr-only", scope=MentionScope.PR)
359359
def pr_handler(event, *args, **kwargs):
360360
nonlocal handler_called
361361
handler_called = True
@@ -378,7 +378,7 @@ def test_scope_validation_commit_scope(self, test_router):
378378
"""Test that COMMIT scope works for commit comments."""
379379
handler_called = False
380380

381-
@test_router.mention(command="commit-only", scope=CommandScope.COMMIT)
381+
@test_router.mention(command="commit-only", scope=MentionScope.COMMIT)
382382
def commit_handler(event, *args, **kwargs):
383383
nonlocal handler_called
384384
handler_called = True

0 commit comments

Comments
 (0)