Created
January 5, 2019 13:32
-
-
Save elbosso/4f3bb0fb95dd1dc499cd46db422900bf to your computer and use it in GitHub Desktop.
This is an inspiration concerning truly dynamic gitlab badges - install it onto an apache2 webserver with mod python and enjoy badges telling how many issues are open/closed right now - accurate with every reload of the page!
This file contains hidden or 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 | |
import gitlab | |
from urlparse import parse_qs | |
def index(req): | |
#change the next two lines to accomodate your installation | |
url='http://myhost' | |
token='xxxx-xxxx-xxxxxxxxxx' | |
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='open_issues.svg' | |
req.headers_out["Content-Disposition"] = "attachment; filename=%s" % filename | |
gl = gitlab.Gitlab(url, private_token=token) | |
project = None | |
if projid is not None : | |
project = gl.projects.get(1) | |
vfmt="%d" | |
if project is not None : | |
if action is None: | |
v='error' | |
vfmt="%s" | |
elif action == 'openedissues': | |
issues = project.issues.list(state='opened',all=True) | |
v=str(len(issues)) | |
elif action == 'closedissues' : | |
issues = project.issues.list(state='closed',all=True) | |
v=str(len(issues)) | |
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