summaryrefslogtreecommitdiff
path: root/scripts/gh.py
diff options
context:
space:
mode:
authorGard Spreemann <gspreemann@gmail.com>2019-01-14 17:45:44 +0100
committerGard Spreemann <gspreemann@gmail.com>2019-01-14 17:45:44 +0100
commit8074365997835ec3e93ee2aa1eadb3a794437066 (patch)
tree6f87d32435c8214c77c9e8103ca4e1d697ae02d5 /scripts/gh.py
parent5aef304fa112d4b11e401671900877d3c844e07d (diff)
parentd4b6e9839823e27af646a915436462254758e053 (diff)
Merge tag 'v2.1.2' into debian/sid
Diffstat (limited to 'scripts/gh.py')
-rw-r--r--scripts/gh.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/scripts/gh.py b/scripts/gh.py
new file mode 100644
index 0000000..81db1b2
--- /dev/null
+++ b/scripts/gh.py
@@ -0,0 +1,32 @@
+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=[], quiet=True, parse=True, auth=True):
+ cmd = (["curl"] +
+ (["-s"] if quiet else []) +
+ args +
+ (["-H", "Authorization: token " + tok] if auth else []) +
+ [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()
+ if parse: return json.loads(resp if resp else '{}')
+ else: return resp
+
+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