Skip to content

Instantly share code, notes, and snippets.

@elbosso
Created January 6, 2019 07:54
Show Gist options
  • Save elbosso/cbce113805735478e926c28a9079cede to your computer and use it in GitHub Desktop.
Save elbosso/cbce113805735478e926c28a9079cede to your computer and use it in GitHub Desktop.
This is another followup to the Gist https://gist.github.com/elbosso/4f3bb0fb95dd1dc499cd46db422900bf (the other one can be found here https://gist.github.com/elbosso/e160341d5e00e0a726ff8725af560373): We do want the operation count(items in gitlab) to execute in constant time independently from the actual number of items - we do not want to spa…
from anybadge import Badge
from urlparse import parse_qs
import requests
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':
url = 'http://<gitlab-host>/api/v4/projects/'+projid+'/issues?state=opened&scope=all&per_page=1'
headers = {'Private-Token': 'xxxx-xxxx-xxxxxxxxxx'}
r = requests.get(url, headers=headers)
v=r.headers['X-Total']
elif action == 'closedissues' :
url = 'http://<gitlab-host>/api/v4/projects/'+projid+'/issues?state=closed&scope=all&per_page=1'
headers = {'Private-Token': 'xxxx-xxxx-xxxxxxxxxx'}
r = requests.get(url, headers=headers)
v=r.headers['X-Total']
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