Skip to content

Commit 58fc33e

Browse files
committed
first semi-working version of the discord channel router
1 parent 76be383 commit 58fc33e

File tree

15 files changed

+804
-135
lines changed

15 files changed

+804
-135
lines changed

intbot/conftest.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import json
2+
3+
import pytest
4+
from django.conf import settings
5+
6+
7+
@pytest.fixture(scope="session")
8+
def gh_data():
9+
base_path = settings.BASE_DIR / "tests" / "test_integrations" / "github"
10+
11+
return {
12+
"project_v2_item.edited": json.load(
13+
open(base_path / "project_v2_item.edited.json"),
14+
),
15+
"query_result": json.load(
16+
open(base_path / "query_result.json"),
17+
)["data"]["node"],
18+
}

intbot/core/bot/channel_router.py

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,54 @@
33
"""
44

55
from dataclasses import dataclass
6-
from core.models import Webhook
76

8-
from core.integrations.github import GithubProjects, GithubRepositories
9-
from core.integrations.github import GithubWebhook
7+
from core.integrations.github import (
8+
GithubProjects,
9+
GithubRepositories,
10+
parse_github_webhook,
11+
)
12+
from core.models import Webhook
1013
from django.conf import settings
1114

15+
1216
@dataclass
1317
class DiscordChannel:
1418
channel_id: int
1519
channel_name: str
1620

1721

18-
1922
dont_send_it = DiscordChannel(channel_id=0, channel_name="/dev/null")
2023

24+
2125
class Channels:
2226
test_channel = DiscordChannel(
2327
channel_id=settings.DISCORD_TEST_CHANNEL_ID,
2428
channel_name=settings.DISCORD_TEST_CHANNEL_NAME,
2529
)
2630

27-
board_channel = DiscordChannel(channel_id=..., channel_name=...)
28-
ep2025_channel = DiscordChannel(channel_id=..., channel_name=...)
29-
em_channel = DiscordChannel(channel_id=..., channel_name=...)
30-
website_channel = DiscordChannel(channel_id=..., channel_name=...)
31-
bot_channel = DiscordChannel(channel_id=..., channel_name=...)
31+
board_channel = DiscordChannel(
32+
channel_id=settings.DISCORD_BOARD_CHANNEL_ID,
33+
channel_name=settings.DISCORD_BOARD_CHANNEL_NAME,
34+
)
35+
ep2025_channel = DiscordChannel(
36+
channel_id=settings.DISCORD_EP2025_CHANNEL_ID,
37+
channel_name=settings.DISCORD_EP2025_CHANNEL_NAME,
38+
)
39+
em_channel = DiscordChannel(
40+
channel_id=settings.DISCORD_EM_CHANNEL_ID,
41+
channel_name=settings.DISCORD_EM_CHANNEL_NAME,
42+
)
43+
website_channel = DiscordChannel(
44+
channel_id=settings.DISCORD_WEBSITE_CHANNEL_ID,
45+
channel_name=settings.DISCORD_WEBSITE_CHANNEL_NAME,
46+
)
47+
bot_channel = DiscordChannel(
48+
channel_id=settings.DISCORD_BOT_CHANNEL_ID,
49+
channel_name=settings.DISCORD_BOT_CHANNEL_NAME,
50+
)
3251

3352

3453
def discord_channel_router(wh: Webhook) -> DiscordChannel:
35-
3654
if wh.source == "github":
3755
return github_router(wh)
3856

@@ -43,20 +61,19 @@ def discord_channel_router(wh: Webhook) -> DiscordChannel:
4361

4462

4563
def github_router(wh: Webhook) -> DiscordChannel:
46-
47-
gwh = GithubWebhook.from_webhook(wh)
64+
gwh = parse_github_webhook(wh)
4865
project = gwh.get_project()
4966
repository = gwh.get_repository()
5067

5168
# We have three github projects, that we want to route to three different
5269
# channels - one for ep2025, one for EM, and one for the board.
53-
if project == GithubProjects.board_project:
70+
if project.id == GithubProjects.board_project:
5471
return Channels.board_channel
5572

56-
elif project == GithubProjects.ep2025_project:
73+
elif project.id == GithubProjects.ep2025_project:
5774
return Channels.ep2025_channel
5875

59-
elif project == GithubProjects.em_project:
76+
elif project.id == GithubProjects.em_project:
6077
return Channels.em_channel
6178

6279
else:

0 commit comments

Comments
 (0)