File tree 4 files changed +55
-5
lines changed
4 files changed +55
-5
lines changed Original file line number Diff line number Diff line change 1
1
from aiohttp import web
2
2
3
- from .. import settings
4
- from .views import routes # , on_oauth2_login
3
+ from .views import routes
5
4
6
5
7
6
async def app_factory () -> web .Application :
@@ -10,10 +9,7 @@ async def app_factory() -> web.Application:
10
9
client_session = None , # populated via parent app signal
11
10
redis = None , # populated via parent app signal
12
11
scheduler = None , # populated via parent app signal
13
- slack_invite_token = settings .SLACK_INVITE_TOKEN ,
14
- slack_token = settings .SLACK_TOKEN ,
15
12
)
16
13
17
14
sirbot .add_routes (routes )
18
-
19
15
return sirbot
Original file line number Diff line number Diff line change
1
+ import os
2
+
3
+ # production
4
+ READTHEDOCS_NOTIFICATION_CHANNEL = "community_projects"
5
+
6
+ # Development
7
+ if os .environ .get ("PLATFORM_BRANCH" ) != "master" :
8
+ READTHEDOCS_NOTIFICATION_CHANNEL = "general"
Original file line number Diff line number Diff line change 1
1
import logging
2
2
3
3
from aiohttp import web
4
+ from slack import methods
5
+ from slack .events import Message
4
6
5
7
from pyslackersweb .util .log import ContextAwareLoggerAdapter
6
8
9
+ from . import settings
7
10
8
11
logger = ContextAwareLoggerAdapter (logging .getLogger (__name__ ))
9
12
10
13
routes = web .RouteTableDef ()
14
+
15
+
16
+ @routes .view ("/readthedocs" , name = "readthedocs" )
17
+ class ReadTheDocsView (web .View ):
18
+ async def post (self ):
19
+ payload = await self .request .json ()
20
+
21
+ project = payload .get ("name" )
22
+ if not project :
23
+ return web .Response (status = 400 )
24
+
25
+ logger .debug ("Incoming readthedocs notification: %s" , payload )
26
+
27
+ msg = Message ()
28
+ msg ["channel" ] = settings .READTHEDOCS_NOTIFICATION_CHANNEL
29
+ msg ["text" ] = f"""Building of { project } documentation failed ! :cry:"""
30
+ await self .request .app ["slack_client" ].query (methods .CHAT_POST_MESSAGE , data = msg )
31
+
32
+ return web .Response (status = 200 )
Original file line number Diff line number Diff line change
1
+ from slack import methods
2
+
3
+ from pyslackersweb .sirbot import settings
4
+
5
+
6
+ async def test_readthedocs_notification (client ):
7
+ r = await client .post ("/bot/readthedocs" , json = {"name" : "pyslackers/website" })
8
+ assert r .status == 200
9
+
10
+ # Assert we send a message to slack
11
+ client .app ["slack_client" ]._request .assert_called_once ()
12
+ assert methods .CHAT_POST_MESSAGE .value [0 ] in client .app ["slack_client" ]._request .call_args .args
13
+ assert (
14
+ settings .READTHEDOCS_NOTIFICATION_CHANNEL
15
+ in client .app ["slack_client" ]._request .call_args .args [3 ]
16
+ )
17
+
18
+
19
+ async def test_readthedocs_notification_missing_name (client ):
20
+ r = await client .post ("/bot/readthedocs" , json = {})
21
+ assert r .status == 400
22
+
23
+ # Assert we did not send a message to slack
24
+ assert not client .app ["slack_client" ]._request .called
You can’t perform that action at this time.
0 commit comments