-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.py
40 lines (27 loc) · 971 Bytes
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from configparser import ConfigParser
import requests
from fastapi import FastAPI
# Environment Variables
config_file = "env.ini"
config = ConfigParser()
config.read(config_file)
secret_key = config.get('secrets', 'key')
GITHUB_TOKEN = config.get('secrets', 'github_token')
owner = config.get('secrets', 'owner')
repository = config.get('secrets', 'repository')
app = FastAPI()
@app.get("/")
def home():
return {'message': "Hello World"}
@app.post("/do")
def action(event_type: str, secret: str):
if secret == secret_key:
headers = {
'Accept': 'application/vnd.github.everest-preview+json',
'Authorization': f'token {GITHUB_TOKEN}'
}
url = f'https://api.github.com/repos/{owner}/{repository}/dispatches'
data = '{"event_type":"' + event_type + '"}'
res = requests.post(url, headers=headers, data=data)
return {'status': res.status_code}
return {'status': 'Unauthenticated'}