Skip to content

Commit fec42f4

Browse files
authored
✨ split events into single files
1 parent 0baeb3c commit fec42f4

File tree

269 files changed

+2435
-2150
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

269 files changed

+2435
-2150
lines changed

codegen/__init__.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ class Data:
3333
payload_types: list[str]
3434

3535

36+
def module_name(event: str, action: Data) -> str:
37+
return f"{event}_{action.action}" if action.action else event
38+
39+
3640
def pascal_case(*names: str) -> str:
3741
words = chain.from_iterable(name.split("_") for name in names)
3842
return "".join(word if word.isupper() else word.capitalize() for word in words)
@@ -82,6 +86,7 @@ def build_event():
8286
output_dir.mkdir(parents=True, exist_ok=True)
8387

8488
env = Environment(loader=PackageLoader("codegen"))
89+
env.globals["filename"] = module_name
8590

8691
# generate base model
8792
template = env.get_template("_base.py.jinja")
@@ -96,13 +101,13 @@ def build_event():
96101
# generate event models
97102
template = env.get_template("event.py.jinja")
98103
for event, actions in event_types.items():
99-
event_text = template.render(
100-
event=event,
101-
actions=actions,
102-
message_events=MESSAGE_EVENTS,
103-
has_message_events=HAS_MESSAGE_EVENTS,
104-
)
105-
(output_dir / f"{event}.py").write_text(event_text)
104+
for action in actions:
105+
event_text = template.render(
106+
action=action,
107+
message_events=MESSAGE_EVENTS,
108+
has_message_events=HAS_MESSAGE_EVENTS,
109+
)
110+
(output_dir / f"{module_name(event, action)}.py").write_text(event_text)
106111

107112
# generate init file
108113
template = env.get_template("__init__.py.jinja")

codegen/templates/__init__.py.jinja

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@ if TYPE_CHECKING:
55
from ._types import events as events
66
{% for event, actions in types.items() %}
77
{% for action in actions %}
8-
from .{{ event }} import {{ action.class_name }} as {{ action.class_name }}
8+
from .{{ filename(event, action) }} import {{ action.class_name }} as {{ action.class_name }}
99
{% endfor %}
1010
{% endfor %}
1111
else:
1212
__lazy_vars__ = {
1313
{% for event, actions in types.items() %}
14-
".{{ event }}": (
15-
{% for action in actions %}
14+
{% for action in actions %}
15+
".{{ filename(event, action) }}": (
1616
"{{ action.class_name }}",
17-
{% endfor %}
1817
),
1918
{% endfor %}
19+
{% endfor %}
2020
"._base": (
2121
"Event",
2222
),

codegen/templates/event.py.jinja

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,14 @@ from typing import Union
22
from functools import cached_property
33
from typing_extensions import override
44

5-
{% for action in actions %}
65
{% for model in action.payload_types %}
76
from githubkit.versions.latest.models import {{ model }}
87
{% endfor %}
9-
{% endfor %}
108

119
from ..message import Message
1210

1311
from ._base import Event
1412

15-
{% for action in actions %}
16-
1713
class {{ action.class_name }}(Event):
1814
{% if action.payload_types | length > 1 %}
1915
payload: Union[{{ action.payload_types | join(", ") }}]
@@ -40,4 +36,3 @@ class {{ action.class_name }}(Event):
4036
keep_untouched = (cached_property,)
4137

4238
{% endif %}
43-
{% endfor %}

nonebot/adapters/github/event/__init__.py

Lines changed: 560 additions & 554 deletions
Large diffs are not rendered by default.

nonebot/adapters/github/event/branch_protection_configuration.py renamed to nonebot/adapters/github/event/branch_protection_configuration_disabled.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from githubkit.versions.latest.models import (
2-
WebhookBranchProtectionConfigurationEnabled,
32
WebhookBranchProtectionConfigurationDisabled,
43
)
54

@@ -9,8 +8,3 @@
98
class BranchProtectionConfigurationDisabled(Event):
109

1110
payload: WebhookBranchProtectionConfigurationDisabled
12-
13-
14-
class BranchProtectionConfigurationEnabled(Event):
15-
16-
payload: WebhookBranchProtectionConfigurationEnabled
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from githubkit.versions.latest.models import WebhookBranchProtectionConfigurationEnabled
2+
3+
from ._base import Event
4+
5+
6+
class BranchProtectionConfigurationEnabled(Event):
7+
8+
payload: WebhookBranchProtectionConfigurationEnabled

nonebot/adapters/github/event/branch_protection_rule.py

Lines changed: 0 additions & 22 deletions
This file was deleted.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from githubkit.versions.latest.models import WebhookBranchProtectionRuleCreated
2+
3+
from ._base import Event
4+
5+
6+
class BranchProtectionRuleCreated(Event):
7+
8+
payload: WebhookBranchProtectionRuleCreated
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from githubkit.versions.latest.models import WebhookBranchProtectionRuleDeleted
2+
3+
from ._base import Event
4+
5+
6+
class BranchProtectionRuleDeleted(Event):
7+
8+
payload: WebhookBranchProtectionRuleDeleted
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from githubkit.versions.latest.models import WebhookBranchProtectionRuleEdited
2+
3+
from ._base import Event
4+
5+
6+
class BranchProtectionRuleEdited(Event):
7+
8+
payload: WebhookBranchProtectionRuleEdited

0 commit comments

Comments
 (0)