Skip to content

Commit e2f9ec4

Browse files
committed
fix: webhook factory to work in classes
1 parent 2bd8ef3 commit e2f9ec4

File tree

4 files changed

+14
-16
lines changed

4 files changed

+14
-16
lines changed

app/components/github_integration/webhooks/core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
from app.config import WebhookFeedType
2525

2626
type EmbedColor = Literal["green", "red", "purple", "gray", "orange", "blue"]
27-
type SubhookStore[E] = dict[str, Callable[[E], Awaitable[None]]]
27+
type SubhookStore[C, E] = dict[str, Callable[[C, E], Awaitable[None]]]
2828

2929
EMBED_COLORS: dict[EmbedColor, int] = {
3030
"green": 0x3FB950,

app/components/github_integration/webhooks/discussions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
from app.bot import GhosttyBot
3636
from app.components.github_integration.emoji import EmojiName
3737

38-
discussion_subhooks: SubhookStore[DiscussionEvent] = {}
38+
discussion_subhooks: SubhookStore[Discussions, DiscussionEvent] = {}
3939

4040
register_discussion_subhook = make_subhook_registrar(discussion_subhooks)
4141

@@ -88,7 +88,7 @@ async def _(event: DiscussionCommentEvent) -> None:
8888
async def _(event: DiscussionEvent) -> None:
8989
if subhook := discussion_subhooks.get(event.action):
9090
with reraise_with_payload(event):
91-
await subhook(event)
91+
await subhook(self, event)
9292

9393
@register_discussion_subhook("created")
9494
async def handle_created_discussion(self, event: WebhookDiscussionCreated) -> None:

app/components/github_integration/webhooks/issues.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
from app.bot import GhosttyBot
3636
from app.components.github_integration.emoji import EmojiName
3737

38-
issue_subhooks: SubhookStore[IssuesEvent] = {}
38+
issue_subhooks: SubhookStore[Issues, IssuesEvent] = {}
3939

4040
register_issue_subhook = make_subhook_registrar(issue_subhooks)
4141

@@ -105,7 +105,7 @@ async def _(event: IssueCommentEvent) -> None:
105105
async def _(event: IssuesEvent) -> None:
106106
if subhook := issue_subhooks.get(event.action):
107107
with reraise_with_payload(event):
108-
await subhook(event)
108+
await subhook(self, event)
109109

110110
@register_issue_subhook("opened")
111111
async def handle_opened_issue(self, event: WebhookIssuesOpened) -> None:

app/components/github_integration/webhooks/prs.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
EmbedContent,
2121
Footer,
2222
SubhookStore,
23-
client,
2423
make_subhook_registrar,
2524
reraise_with_payload,
2625
send_embed,
@@ -64,8 +63,8 @@
6463

6564
HUNK_CODEBLOCK_OVERHEAD = len("```diff\n\n```\n")
6665

67-
pr_subhooks: SubhookStore[PullRequestEvent] = {}
68-
pr_review_subhooks: SubhookStore[PullRequestReviewEvent] = {}
66+
pr_subhooks: SubhookStore[PRHook, PullRequestEvent] = {}
67+
pr_review_subhooks: SubhookStore[PRHook, PullRequestReviewEvent] = {}
6968

7069
register_pr_subhook = make_subhook_registrar(pr_subhooks)
7170
register_pr_review_subhook = make_subhook_registrar(pr_review_subhooks)
@@ -98,13 +97,6 @@ def pr_embed_content(
9897
return EmbedContent(template.format(f"PR #{pr.number}"), pr.html_url, body)
9998

10099

101-
@client.on("pull_request")
102-
async def handle_pr_event(event: PullRequestEvent) -> None:
103-
if subhook := pr_subhooks.get(event.action):
104-
with reraise_with_payload(event):
105-
await subhook(event)
106-
107-
108100
@final
109101
class PRHook(commands.Cog):
110102
def __init__(self, bot: GhosttyBot, monalisten_client: Monalisten) -> None:
@@ -123,7 +115,13 @@ async def _(event: PullRequestReviewCommentEvent) -> None:
123115
async def _(event: PullRequestReviewEvent) -> None:
124116
if subhook := pr_review_subhooks.get(event.action):
125117
with reraise_with_payload(event):
126-
await subhook(event)
118+
await subhook(self, event)
119+
120+
@self.monalisten_client.on("pull_request")
121+
async def _(event: PullRequestEvent) -> None:
122+
if subhook := pr_subhooks.get(event.action):
123+
with reraise_with_payload(event):
124+
await subhook(self, event)
127125

128126
@register_pr_subhook("opened")
129127
async def handle_opened_pr(self, event: WebhookPullRequestOpened) -> None:

0 commit comments

Comments
 (0)