3
3
"""
4
4
5
5
from dataclasses import dataclass
6
- from core .models import Webhook
7
6
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
10
13
from django .conf import settings
11
14
15
+
12
16
@dataclass
13
17
class DiscordChannel :
14
18
channel_id : int
15
19
channel_name : str
16
20
17
21
18
-
19
22
dont_send_it = DiscordChannel (channel_id = 0 , channel_name = "/dev/null" )
20
23
24
+
21
25
class Channels :
22
26
test_channel = DiscordChannel (
23
27
channel_id = settings .DISCORD_TEST_CHANNEL_ID ,
24
28
channel_name = settings .DISCORD_TEST_CHANNEL_NAME ,
25
29
)
26
30
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
+ )
32
51
33
52
34
53
def discord_channel_router (wh : Webhook ) -> DiscordChannel :
35
-
36
54
if wh .source == "github" :
37
55
return github_router (wh )
38
56
@@ -43,20 +61,19 @@ def discord_channel_router(wh: Webhook) -> DiscordChannel:
43
61
44
62
45
63
def github_router (wh : Webhook ) -> DiscordChannel :
46
-
47
- gwh = GithubWebhook .from_webhook (wh )
64
+ gwh = parse_github_webhook (wh )
48
65
project = gwh .get_project ()
49
66
repository = gwh .get_repository ()
50
67
51
68
# We have three github projects, that we want to route to three different
52
69
# 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 :
54
71
return Channels .board_channel
55
72
56
- elif project == GithubProjects .ep2025_project :
73
+ elif project . id == GithubProjects .ep2025_project :
57
74
return Channels .ep2025_channel
58
75
59
- elif project == GithubProjects .em_project :
76
+ elif project . id == GithubProjects .em_project :
60
77
return Channels .em_channel
61
78
62
79
else :
0 commit comments