From fa24cbd82b92fb1144638b4ad41c48bbd76e032e Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Sat, 21 Jan 2023 22:10:37 +0100 Subject: [PATCH] Handle state/maintained badges previously handled by CI_package_check --- app/app.py | 48 +++++++++++++++++++++++++++++--------- app/models/appcatalog.py | 7 +----- app/static/badges/fetch.sh | 9 +++++++ 3 files changed, 47 insertions(+), 17 deletions(-) diff --git a/app/app.py b/app/app.py index 807d3a4..49fe974 100644 --- a/app/app.py +++ b/app/app.py @@ -115,22 +115,48 @@ def appci_compare(ref, target): @main.route('/integration/') @main.route('/integration/.svg') -def badge(app): +@main.route('/badge//') +@main.route('/badge//.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' diff --git a/app/models/appcatalog.py b/app/models/appcatalog.py index 4ec24b0..a1981f6 100644 --- a/app/models/appcatalog.py +++ b/app/models/appcatalog.py @@ -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) diff --git a/app/static/badges/fetch.sh b/app/static/badges/fetch.sh index 4ba12cb..5f1c94d 100644 --- a/app/static/badges/fetch.sh +++ b/app/static/badges/fetch.sh @@ -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