Created
January 6, 2019 07:27
-
-
Save elbosso/e160341d5e00e0a726ff8725af560373 to your computer and use it in GitHub Desktop.
This is a followup to the Gist https://gist.github.com/elbosso/4f3bb0fb95dd1dc499cd46db422900bf - gitlab-python does not expose the header X:Total when listing items - so the response of this is noticeably slow from about 100 items upward. The shell approach demonstrated here works in constant time - regardless of the number of items queried
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from anybadge import Badge | |
from urlparse import parse_qs | |
from subprocess import Popen,PIPE,STDOUT,call | |
def index(req): | |
args=req.args | |
lbl='n/a' | |
action='closedissues' | |
projid=None | |
if args != None: | |
params = parse_qs(req.args) | |
lbl=params.get('label', 'n/a')[0] | |
action=params.get('action', None)[0] | |
projid=params.get('projid', None)[0] | |
req.content_type = 'image/svg+xml;charset=utf-8' | |
filename='test.svg' | |
req.headers_out["Content-Disposition"] = "attachment; filename=%s" % filename | |
vfmt="%d" | |
if projid is not None : | |
if action is None: | |
v='error' | |
vfmt="%s" | |
elif action == 'openedissues': | |
proc=Popen("curl -i --header 'Private-Token: SxUM-SNxc-DKeH5kLUcv' 'http://gitlab.fritz.box/api/v4/projects/"+projid+"/issues?state=opened&scope=all&per_page=1'|grep X-Total:|cut -d ' ' -f 2", shell=True, stdout=PIPE, ) | |
output=proc.communicate()[0] | |
v=output | |
elif action == 'closedissues' : | |
proc=Popen("curl -i --header 'Private-Token: SxUM-SNxc-DKeH5kLUcv' 'http://gitlab.fritz.box/api/v4/projects/"+projid+"/issues?state=closed&scope=all&per_page=1'|grep X-Total:|cut -d ' ' -f 2", shell=True, stdout=PIPE, ) | |
output=proc.communicate()[0] | |
v=output | |
else : | |
v='error' | |
vfmt="%s" | |
else : | |
v='error' | |
vfmt="%s" | |
badge = Badge(label=lbl, value=v, value_format=vfmt) | |
return badge.badge_svg_text | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment