File tree 3 files changed +36
-0
lines changed
3 files changed +36
-0
lines changed Original file line number Diff line number Diff line change
1
+ .vscode
2
+ config.ini
Original file line number Diff line number Diff line change
1
+ import configparser
2
+ import requests
3
+ from flask import Flask , request
4
+
5
+ config : configparser .ConfigParser = configparser .ConfigParser ()
6
+ config .read ("./config.ini" )
7
+
8
+ POST_URL = config ["constants" ]["discord_webhook_url" ]
9
+
10
+ app = Flask (__name__ )
11
+
12
+
13
+ @app .route ("/" , methods = ["post" , "get" ])
14
+ def requestHandler ():
15
+ if request .method == "POST" :
16
+ recieved_data = request .get_json ()
17
+ if recieved_data .get ("ref" ) != None :
18
+ request_body = {
19
+ "content" : "New commit added!\r " + recieved_data ["repository" ]["html_url" ] + "/commit/" + recieved_data ["after" ]
20
+ }
21
+ requests .post (POST_URL , json = request_body )
22
+ return ("OK!" , 200 )
23
+ if recieved_data .get ("issue" ) != None and recieved_data .get ("action" ) == "opened" :
24
+ request_body = {
25
+ "content" : "New issue opened!\r " + recieved_data ["issue" ]["html_url" ]
26
+ }
27
+ requests .post (POST_URL , json = request_body )
28
+ return ("OK!" , 200 )
29
+ else :
30
+ return ("<p>Only POST requests accepted!</p>" , 405 )
31
+
32
+
33
+ app .run (host = "0.0.0.0" , port = config ["constants" ]["flask_port" ])
Original file line number Diff line number Diff line change
1
+ Flask == 2.2.2
You can’t perform that action at this time.
0 commit comments