Handle state/maintained badges previously handled by CI_package_check

This commit is contained in:
Alexandre Aubin 2023-01-21 22:10:37 +01:00
parent c3be88afca
commit fa24cbd82b
3 changed files with 47 additions and 17 deletions

View file

@ -115,22 +115,48 @@ def appci_compare(ref, target):
@main.route('/integration/<app>')
@main.route('/integration/<app>.svg')
def badge(app):
@main.route('/badge/<type>/<app>')
@main.route('/badge/<type>/<app>.svg')
def badge(app, type="integration"):
app = App.query.filter_by(name=app).first_or_404()
branch_results = list(app.most_recent_tests_per_branch())
apps = App.query.filter_by(name=app).all()
app = apps[0] if len(apps) == 1 else None
level = None
for r in branch_results:
if r.branch.name == "stable":
level = r.level
break
badge = "level%s.svg" % level if not level is None else "unknown.svg"
if app:
branch_results = list(app.most_recent_tests_per_branch())
for r in branch_results:
if r.branch.name == "stable":
level = r.level
break
if app.state != "working":
badge = "unknown.svg"
if type == "integration":
if app and app.state == "working" and level:
badge = f"level{level}"
else:
badge = "unknown"
elif type == "state":
svg = open("./app/static/badges/%s" % badge).read()
if not app:
badge = "state-unknown"
elif app.state == "working":
if app.public_level is None or app.public_level == "?":
badge = "state-just-got-added-to-catalog"
elif app.public_level in [0, -1]:
badge = "state-broken"
else:
badge = "state-working"
else:
badge = f"state-{app.state}"
elif type == "maintained":
if app and not app.maintained:
badge = "unmaintained"
else:
badge = "empty"
else:
badge = "empty"
svg = open(f"./app/static/badges/{badge}.svg").read()
response = make_response(svg)
response.content_type = 'image/svg+xml'
response.headers['Cache-Control'] = 'no-cache, no-store, must-revalidate'

View file

@ -47,12 +47,7 @@ class AppCatalog():
if isinstance(maintainers_info, list):
known_app.maintainers = [ maintainer["name"] for maintainer in maintainers_info ]
known_app.maintained = app.get("maintained", True)
# Quick and dirty fix to convert maintained state to boolean
if known_app.maintained == "orphaned":
known_app.maintained = False
elif isinstance(known_app.maintained, str):
known_app.maintained = True
known_app.maintained = 'package-not-maintained' not in app.get('antifeatures', []),
known_app.state = app["state"]
known_app.public_level = app.get("level", None)

View file

@ -9,3 +9,12 @@ wget -O - https://img.shields.io/badge/Integration-Level_2-orange.svg > lev
wget -O - https://img.shields.io/badge/Integration-Level_1-orange.svg > level1.svg
wget -O - https://img.shields.io/badge/Integration-Level_0-red.svg > level0.svg
wget -O - https://img.shields.io/badge/Integration-Unknown-lightgrey.svg > unknown.svg
wget -O - https://upload.wikimedia.org/wikipedia/commons/1/1d/No_image.svg > empty.svg
wget -O - https://img.shields.io/badge/Status-Package%20not%20maintained-red.svg > unmaintained.svg
wget -O - https://img.shields.io/badge/Status-working-brightgreen.svg > state-working.svg
wget -O - https://img.shields.io/badge/Status-Just%20got%20added%20to%20catalog-yellowgreen.svg > state-just-got-added-to-catalog.svg
wget -O - https://img.shields.io/badge/Status-In%20progress-orange.svg > state-inprogress.svg
wget -O - https://img.shields.io/badge/Status-Not%20working-red.svg > state-notworking.svg
wget -O - https://img.shields.io/badge/Status-Broken-red.svg > state-broken.svg