-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathb12_application.py
More file actions
72 lines (59 loc) · 1.64 KB
/
b12_application.py
File metadata and controls
72 lines (59 loc) · 1.64 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
import json
import hmac
import hashlib
import os
from datetime import datetime, timezone
import requests
ENDPOINT = "https://b12.io/apply/submission"
SIGNING_SECRET = b"hello-there-from-b12"
def iso8601_timestamp():
return (
datetime.now(timezone.utc)
.isoformat(timespec="milliseconds")
.replace("+00:00", "Z")
)
def main():
action_run_id = os.environ["GITHUB_RUN_ID"]
repository = os.environ["GITHUB_REPOSITORY"]
server_url = os.environ["GITHUB_SERVER_URL"]
email = os.environ["APPLICANT_EMAIL"]
resume_link = os.environ["APPLICANT_RESUME_LINK"]
name = os.environ["APPLICANT_NAME"]
payload = {
"action_run_link": f"{server_url}/{repository}/actions/runs/{action_run_id}",
"repository_link": f"{server_url}/{repository}",
"name": name,
"email": email,
"resume_link": resume_link,
"timestamp": iso8601_timestamp(),
}
body = json.dumps(
payload,
sort_keys=True,
separators=(",", ":"),
ensure_ascii=False,
).encode("utf-8")
digest = hmac.new(
SIGNING_SECRET,
body,
hashlib.sha256,
).hexdigest()
headers = {
"Content-Type": "application/json",
"X-Signature-256": f"sha256={digest}",
}
response = requests.post(
ENDPOINT,
data=body,
headers=headers,
timeout=30,
)
response.raise_for_status()
result = response.json()
receipt = result.get("receipt")
if receipt:
print("Submission receipt:", receipt)
else:
raise RuntimeError("No receipt returned")
if __name__ == "__main__":
main()