forked from tensorflow/build
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsubmit.py
executable file
·61 lines (45 loc) · 1.14 KB
/
submit.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
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env python3
import requests
import hashlib
import hmac
import os
import sys
from pprint import pprint
# forward to listener with:
# kubectl port-forward svc/el-build-listener 7070:8080 --namespace=sig-build
HOOKURL = 'https://tfbuild.perfinion.com/webhook/'
HEADERS = {
'X-GitHub-Event': 'push',
}
DATA = {
"head_commit":
{
"id": "master"
},
"repository":
{
"name": "build",
"full_name": "perfinion/build",
"owner":
{
"name": "perfinion",
},
}
}
############################################
secret = os.environ.get('GITHUB_SECRET', '')
if len(secret) < 1:
print('Set env var GITHUB_SECRET')
sys.exit(1)
secret = secret.encode('utf-8')
request = requests.Request('POST', HOOKURL, headers=HEADERS, json=DATA)
prepped = request.prepare()
sig = hmac.new(secret, prepped.body, hashlib.sha1)
prepped.headers['X-Hub-Signature'] = "sha1=%s" % sig.hexdigest()
with requests.Session() as session:
r = session.send(prepped)
print("Response status code:", r.status_code)
print("Response headers:")
pprint(r.headers)
print("\nResponse text:")
print(r.text)