diff options
author | Aleks Kissinger <aleks0@gmail.com> | 2019-01-13 18:13:29 +0100 |
---|---|---|
committer | Aleks Kissinger <aleks0@gmail.com> | 2019-01-13 18:13:29 +0100 |
commit | cfd6ae88b194d69d2a2c365d4a8a78644ba9079b (patch) | |
tree | 55fb550e78ee4da583a484f1129e798cce88e0dd /scripts/gh.py | |
parent | d49cde5d0b948f24aa7b3bd9ad9b3b63333f2281 (diff) |
added github AUTO deploy scripts
Diffstat (limited to 'scripts/gh.py')
-rw-r--r-- | scripts/gh.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/scripts/gh.py b/scripts/gh.py new file mode 100644 index 0000000..13a8880 --- /dev/null +++ b/scripts/gh.py @@ -0,0 +1,29 @@ +import sys, os, json +from subprocess import Popen, PIPE + +api_url = 'https://api.github.com/repos/tikzit/tikzit' + +tok = os.getenv('GITHUB_TOKEN', '') + +if tok == '': + print("Must set GITHUB_TOKEN environment variable.") + sys.exit(1) + +# pretty-print JSON responses +def pr(j): print(json.dumps(j, indent=2)) + +# call GitHub API with curl +def gh(s, args=[]): + cmd = (["curl", "-s"] + args + + ["-H", "Authorization: token " + tok] + + [s if 'https://' in s else api_url + '/' + s]) + # ONLY UN-COMMENT FOR TESTING: + # print(' '.join(cmd)) + p = Popen(cmd, stdout=PIPE) + resp = p.stdout.read() + return json.loads(resp if resp else '{}') + +def get_release(n): + rs = [r for r in gh('releases') if r['name'] == n] + if len(rs) > 0: return rs[0] + else: return None |