forked from github/ghas-jira-integration
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.py
39 lines (26 loc) · 766 Bytes
/
util.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
import hashlib
import os.path
import json
REQUEST_TIMEOUT = 10
def state_from_json(s):
j = json.loads(s)
if "version" not in j:
return {}
return j["states"]
def state_to_json(state):
final = {"version": 2, "states": state}
return json.dumps(final, indent=2, sort_keys=True)
def state_from_file(fpath):
if os.path.isfile(fpath):
with open(fpath, "r") as f:
return state_from_json(f.read())
return {}
def state_to_file(fpath, state):
with open(fpath, "w") as f:
f.write(state_to_json(state))
def make_key(s):
sha_3 = hashlib.sha3_256()
sha_3.update(s.encode("utf-8"))
return sha_3.hexdigest()
def json_accept_header():
return {"Accept": "application/vnd.github.v3+json"}