Skip to content

Commit 7083819

Browse files
authored
✨ Feature: allow parsing webhook with event name of type str (#123)
1 parent 4f2e025 commit 7083819

File tree

3 files changed

+40
-6
lines changed

3 files changed

+40
-6
lines changed

codegen/templates/webhooks/_namespace.py.jinja

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,13 @@ class WebhookNamespace:
6161
def parse(name: EventNameType, payload: Union[str, bytes]) -> "WebhookEvent":
6262
...
6363

64+
@overload
6465
@staticmethod
65-
def parse(name: EventNameType, payload: Union[str, bytes]) -> "WebhookEvent":
66+
def parse(name: str, payload: Union[str, bytes]) -> "WebhookEvent":
67+
...
68+
69+
@staticmethod
70+
def parse(name: Union[EventNameType, str], payload: Union[str, bytes]) -> "WebhookEvent":
6671
"""Parse the webhook payload with event name.
6772

6873
Args:
@@ -105,8 +110,13 @@ class WebhookNamespace:
105110
def parse_obj(name: EventNameType, payload: Dict[str, Any]) -> "WebhookEvent":
106111
...
107112

113+
@overload
108114
@staticmethod
109-
def parse_obj(name: EventNameType, payload: Dict[str, Any]) -> "WebhookEvent":
115+
def parse_obj(name: str, payload: Dict[str, Any]) -> "WebhookEvent":
116+
...
117+
118+
@staticmethod
119+
def parse_obj(name: Union[EventNameType, str], payload: Dict[str, Any]) -> "WebhookEvent":
110120
"""Parse the webhook payload dict with event name.
111121

112122
Args:

githubkit/versions/ghec_v2022_11_28/webhooks/_namespace.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -616,8 +616,14 @@ def parse(
616616
@staticmethod
617617
def parse(name: EventNameType, payload: Union[str, bytes]) -> "WebhookEvent": ...
618618

619+
@overload
620+
@staticmethod
621+
def parse(name: str, payload: Union[str, bytes]) -> "WebhookEvent": ...
622+
619623
@staticmethod
620-
def parse(name: EventNameType, payload: Union[str, bytes]) -> "WebhookEvent":
624+
def parse(
625+
name: Union[EventNameType, str], payload: Union[str, bytes]
626+
) -> "WebhookEvent":
621627
"""Parse the webhook payload with event name.
622628
623629
Args:
@@ -1007,8 +1013,14 @@ def parse_obj(
10071013
@staticmethod
10081014
def parse_obj(name: EventNameType, payload: Dict[str, Any]) -> "WebhookEvent": ...
10091015

1016+
@overload
1017+
@staticmethod
1018+
def parse_obj(name: str, payload: Dict[str, Any]) -> "WebhookEvent": ...
1019+
10101020
@staticmethod
1011-
def parse_obj(name: EventNameType, payload: Dict[str, Any]) -> "WebhookEvent":
1021+
def parse_obj(
1022+
name: Union[EventNameType, str], payload: Dict[str, Any]
1023+
) -> "WebhookEvent":
10121024
"""Parse the webhook payload dict with event name.
10131025
10141026
Args:

githubkit/versions/v2022_11_28/webhooks/_namespace.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -600,8 +600,14 @@ def parse(
600600
@staticmethod
601601
def parse(name: EventNameType, payload: Union[str, bytes]) -> "WebhookEvent": ...
602602

603+
@overload
604+
@staticmethod
605+
def parse(name: str, payload: Union[str, bytes]) -> "WebhookEvent": ...
606+
603607
@staticmethod
604-
def parse(name: EventNameType, payload: Union[str, bytes]) -> "WebhookEvent":
608+
def parse(
609+
name: Union[EventNameType, str], payload: Union[str, bytes]
610+
) -> "WebhookEvent":
605611
"""Parse the webhook payload with event name.
606612
607613
Args:
@@ -981,8 +987,14 @@ def parse_obj(
981987
@staticmethod
982988
def parse_obj(name: EventNameType, payload: Dict[str, Any]) -> "WebhookEvent": ...
983989

990+
@overload
991+
@staticmethod
992+
def parse_obj(name: str, payload: Dict[str, Any]) -> "WebhookEvent": ...
993+
984994
@staticmethod
985-
def parse_obj(name: EventNameType, payload: Dict[str, Any]) -> "WebhookEvent":
995+
def parse_obj(
996+
name: Union[EventNameType, str], payload: Dict[str, Any]
997+
) -> "WebhookEvent":
986998
"""Parse the webhook payload dict with event name.
987999
9881000
Args:

0 commit comments

Comments
 (0)