-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathhacktobot.py
47 lines (34 loc) · 1.08 KB
/
hacktobot.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
41
42
43
44
45
46
47
"""
Server to listen to pull requests using GitHub webhooks.
Outer shell to co-ordinate between all other actions
"""
from flask import Flask, request, abort
from json import dump
import hmac
import hashlib
import os
from pr_judge import pr_judge
app = Flask(__name__)
GITHUB_SECRET = os.environ['GITHUB_SECRET']
@app.route("/")
def home():
return "Webhook is up and running!"
@app.route('/webhook', methods=['POST'])
def webhook():
if request.method == 'POST':
# Extract signature header
signature = request.headers.get("X-Hub-Signature")
if not signature or not signature.startswith("sha1="):
abort(400, "X-Hub-Signature required")
# Create local hash of payload
digest = hmac.new(GITHUB_SECRET.encode(), request.data, hashlib.sha1).hexdigest()
# Verify signature
if not hmac.compare_digest(signature, "sha1=" + digest):
abort(400, "Invalid signature")
if(request.json['action'] == 'opened'):
pr_judge(int(request.json["number"]))
# TODO: Check for the files
# TODO: Execute and send the output on discord
return 'success', 200
else:
abort(400)