Simplify app list management, we don't have official vs. community anymore

This commit is contained in:
Alexandre Aubin 2020-11-12 15:35:02 +01:00
parent 75f5042eb7
commit 8c627522b2
6 changed files with 12 additions and 62 deletions

View file

@ -1,7 +1,7 @@
from datetime import datetime from datetime import datetime
from flask import render_template, make_response, Blueprint from flask import render_template, make_response, Blueprint
from .models.pr import PullRequest from .models.pr import PullRequest
from .models.applists import App from .models.appcatalog import App
from .models.appci import AppCI, AppCIBranch from .models.appci import AppCI, AppCIBranch
from .models.unlistedapps import UnlistedApp from .models.unlistedapps import UnlistedApp
from .settings import SITE_ROOT from .settings import SITE_ROOT
@ -189,10 +189,9 @@ def app_maintainer_dash(maintainer=None):
if isinstance(app.public_level, str): if isinstance(app.public_level, str):
app.public_level = -1 app.public_level = -1
if app.maintained and app.state in ["working", "official"]: if app.maintained and app.state == "working":
maintainers.update(app.maintainers) maintainers.update(app.maintainers)
maintainers = sorted(maintainers, key=lambda m: m.lower()) maintainers = sorted(maintainers, key=lambda m: m.lower())
apps = sorted(apps, key=lambda app: app.name.lower()) apps = sorted(apps, key=lambda app: app.name.lower())

View file

@ -1,5 +1,4 @@
import re import re
import os
import time import time
import json import json
import requests import requests
@ -8,35 +7,13 @@ import datetime
from .. import db from .. import db
class AppList(db.Model): class AppCatalog(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(64), unique=True, nullable=False)
url = db.Column(db.String(128), nullable=False)
state_for_ci = db.Column(db.String(32), nullable=False)
def __repr__(self):
return '<AppList %r>' % self.name
def init():
yield AppList(name='official',
url="https://app.yunohost.org/official.json",
state_for_ci='validated')
yield AppList(name='community',
url="https://app.yunohost.org/community.json",
state_for_ci='working')
def update(): def update():
applists = AppList.query.all()
for applist in applists:
applist.update_list()
def update_list(self):
g = Github() g = Github()
raw_apps = json.loads(requests.get(self.url).text) raw_apps = json.loads(requests.get("https://app.yunohost.org/default/v2/apps.json").text)
for name in sorted(raw_apps.keys()): for name in sorted(raw_apps.keys()):
@ -52,7 +29,6 @@ class AppList(db.Model):
print("Adding new app {}".format(name)) print("Adding new app {}".format(name))
known_app = App(name=name, known_app = App(name=name,
repo=app["url"], repo=app["url"],
list=self,
public_commit=app["git"]["revision"]) public_commit=app["git"]["revision"])
db.session.add(known_app) db.session.add(known_app)
else: else:
@ -76,7 +52,6 @@ class AppList(db.Model):
elif isinstance(known_app.maintained, str): elif isinstance(known_app.maintained, str):
known_app.maintained = True known_app.maintained = True
known_app.state = app["state"] known_app.state = app["state"]
known_app.ci_enabled = app["state"] == self.state_for_ci
known_app.public_level = app.get("level", None) known_app.public_level = app.get("level", None)
if "github" in known_app.repo: if "github" in known_app.repo:
@ -112,12 +87,8 @@ class App(db.Model):
maintainers = db.Column(db.PickleType) maintainers = db.Column(db.PickleType)
maintained = db.Column(db.Boolean, nullable=False) maintained = db.Column(db.Boolean, nullable=False)
state = db.Column(db.String(64), nullable=False) state = db.Column(db.String(64), nullable=False)
ci_enabled = db.Column(db.Boolean, nullable=False)
public_level = db.Column(db.Integer, default=-1, nullable=True) public_level = db.Column(db.Integer, default=-1, nullable=True)
list = db.relationship(AppList, backref='apps', lazy=True, uselist=False)
list_id = db.Column(db.ForeignKey(AppList.id))
# 'Status info' stuff # 'Status info' stuff
public_commit = db.Column(db.String(64), nullable=False) public_commit = db.Column(db.String(64), nullable=False)
master_commit = db.Column(db.String(64), nullable=False) master_commit = db.Column(db.String(64), nullable=False)

View file

@ -3,7 +3,7 @@ import requests
import datetime import datetime
from .. import db from .. import db
from app.models.applists import App from app.models.appcatalog import App
class AppCIBranch(db.Model): class AppCIBranch(db.Model):
@ -52,7 +52,7 @@ class AppCIBranch(db.Model):
def most_recent_tests_per_app(self): def most_recent_tests_per_app(self):
apps = App.query.filter_by(ci_enabled=True).all() apps = App.query.filter_by(state="working").all()
most_recent_tests = AppCIResult.query \ most_recent_tests = AppCIResult.query \
.filter_by(branch = self) \ .filter_by(branch = self) \
.order_by(AppCIResult.date.desc()) \ .order_by(AppCIResult.date.desc()) \

View file

@ -10,7 +10,7 @@ appdir = os.path.abspath(currentdir + "../../../../")
sys.path.insert(0, appdir) sys.path.insert(0, appdir)
from app import db, create_app from app import db, create_app
from app.models.applists import App from app.models.appcatalog import App
app_ = create_app() app_ = create_app()
def _time_points_until_today(): def _time_points_until_today():

View file

@ -64,26 +64,6 @@
<div class="col-sm-4 offset-sm-4"> <div class="col-sm-4 offset-sm-4">
<div class="card"> <div class="card">
<div class="card-body"> <div class="card-body">
{% if app.public_commit == 'HEAD' %}
<p class="card-text text-success">
<span class="oi oi-task" aria-hidden="true"></span>
This app points to HEAD in {{ app.list.name }}.json !
</p>
{% elif app.public_commit == app.master_commit %}
<p class="card-text text-success">
<span class="oi oi-task" aria-hidden="true"></span>
Master commit is up to date with {{ app.list.name }}.json !
</p>
{% else %}
{% if app.public_vs_master_time_diff > 60 %}
<p class="card-text text-danger">
{% else %}
<p class="card-text text-warning">
{% endif %}
<span class="oi oi-warning" aria-hidden="true"></span>
Commit is not up to date on {{ app.list.name }}.json !
</p>
{% endif %}
{% if app.testing_pr %} {% if app.testing_pr %}
<p class="card-text text-info"> <p class="card-text text-info">

View file

@ -21,13 +21,13 @@ class Update(Command):
def run(self, args=None): def run(self, args=None):
valid_what = ["applists", "appci", "pr", "appobservatory"] valid_what = ["catalog", "appci", "pr", "appobservatory"]
what = args[0] if args else None what = args[0] if args else None
assert what in valid_what, "Please specify what to update among %s" % ', '.join(valid_what) assert what in valid_what, "Please specify what to update among %s" % ', '.join(valid_what)
if what == "applists": if what == "catalog":
from app.models.applists import AppList from app.models.appcatalog import AppCatalog
AppList.update() AppCatalog.update()
elif what == "appci": elif what == "appci":
from app.models.appci import AppCI from app.models.appci import AppCI
AppCI.update() AppCI.update()
@ -49,7 +49,7 @@ class Nuke(Command):
def run(self): def run(self):
import app.models.applists import app.models.appcatalog
import app.models.appci import app.models.appci
import app.models.pr import app.models.pr
import app.models.unlistedapps import app.models.unlistedapps