]> git.ipfire.org Git - pbs.git/commitdiff
monitorings: Create some first pages to show current status
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 23 May 2023 13:06:27 +0000 (13:06 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 23 May 2023 13:06:27 +0000 (13:06 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
src/buildservice/releasemonitoring.py
src/templates/monitorings/modules/releases-list.html [new file with mode: 0644]
src/templates/monitorings/show.html [new file with mode: 0644]
src/templates/packages/name.html
src/web/__init__.py
src/web/monitorings.py [new file with mode: 0644]

index 0fb7ec5500eb532abbbec02dfe09b40f02ad81a8..3ccfb95d703c9a717439bcba5c06fdc6a3053a80 100644 (file)
@@ -135,6 +135,7 @@ web_PYTHON = \
        src/web/jobs.py \
        src/web/keys.py \
        src/web/mirrors.py \
+       src/web/monitorings.py \
        src/web/packages.py \
        src/web/repos.py \
        src/web/search.py \
@@ -231,6 +232,16 @@ dist_templates_distros_modules_DATA = \
 
 templates_distros_modulesdir = $(templates_distrosdir)/modules
 
+dist_templates_monitorings_DATA = \
+       src/templates/monitorings/show.html
+
+templates_monitoringsdir = $(templatesdir)/monitorings
+
+dist_templates_monitorings_modules_DATA = \
+       src/templates/monitorings/modules/releases-list.html
+
+templates_monitorings_modulesdir = $(templates_monitoringsdir)/modules
+
 dist_templates_errors_DATA = \
        src/templates/errors/error.html
 
index 1f790ff1236e99512241addf9114f24d4d352482..1144434a0e77cd74624e602e14b8116349c2f710 100644 (file)
@@ -123,6 +123,21 @@ class Monitorings(base.Object):
                        """, id,
                )
 
+       def get_by_distro_and_name(self, distro, name):
+               return self._get_monitoring("""
+                       SELECT
+                               *
+                       FROM
+                               release_monitorings
+                       WHERE
+                               deleted_at IS NULL
+                       AND
+                               distro_id = %s
+                       AND
+                               name = %s
+                       """, distro, name,
+               )
+
        async def create(self, distro, name, created_by, project_id,
                        follow="mainline", create_builds=True):
                monitoring = self._get_monitoring("""
@@ -202,6 +217,10 @@ class Monitoring(base.DataObject):
                return "%s - %s" % (self.distro, self.name)
 
        @property
+       def url(self):
+               return "/distros/%s/monitorings/%s" % (self.distro.slug, self.name)
+
+       @lazy_property
        def distro(self):
                """
                        The distribution
@@ -219,6 +238,12 @@ class Monitoring(base.DataObject):
        def project_id(self):
                return self.data.project_id
 
+       # Last Check At
+
+       @property
+       def last_check_at(self):
+               return self.data.last_check_at
+
        @property
        def follow(self):
                return self.data.follow
@@ -289,8 +314,6 @@ class Monitoring(base.DataObject):
                        FROM
                                release_monitoring_releases
                        WHERE
-                               deleted_at IS NULL
-                       AND
                                monitoring_id = %s
                        ORDER BY
                                created_at DESC
@@ -405,6 +428,12 @@ class Release(base.DataObject):
        def version(self):
                return self.data.version
 
+       # Created At
+
+       @property
+       def created_at(self):
+               return self.data.created_at
+
        # Bug
 
        async def _create_bug(self):
@@ -453,6 +482,10 @@ class Release(base.DataObject):
 
                return bug
 
+       @property
+       def bug_id(self):
+               return self.data.bug_id
+
        # Build
 
        def get_build(self):
diff --git a/src/templates/monitorings/modules/releases-list.html b/src/templates/monitorings/modules/releases-list.html
new file mode 100644 (file)
index 0000000..a18f69f
--- /dev/null
@@ -0,0 +1,25 @@
+{# Show a message if we don't have any releases, yet #}
+{% if show_empty and not releases %}
+       <p class="notification">
+               {{ _("No new releases have been found, yet") }}
+       </p>
+
+{# Show releases #}
+{% elif releases %}
+       {% for release in releases %}
+               <div class="block">
+                       <div class="box">
+                               <h5 class="title is-5">
+                                       {{ release }}
+
+                                       <a class="is-pulled-right" href="{{ backend.bugzilla.bug_url(release.bug_id) }}">
+                                               <small>{{ _("Bug #%s") % release.bug_id }}</small>
+                                       </a>
+                               </h5>
+                               <h6 class="subtitle is-6">{{ locale.format_date(release.created_at, shorter=True) }}</h6>
+
+                               {# XXX Show build and build status #}
+                       </div>
+               </div>
+       {% end %}
+{% end %}
diff --git a/src/templates/monitorings/show.html b/src/templates/monitorings/show.html
new file mode 100644 (file)
index 0000000..f44f152
--- /dev/null
@@ -0,0 +1,93 @@
+{% extends "../base.html" %}
+
+{% block title %}{{ _("Release Monitoring") }} - {{ monitoring }}{% end block %}
+
+{% block body %}
+       <section class="hero is-light">
+               <div class="hero-body">
+                       <div class="container">
+                               <nav class="breadcrumb" aria-label="breadcrumbs">
+                                       <ul>
+                                               <li>
+                                                       <a href="/distros">{{ _("Distributions") }}</a>
+                                               </li>
+                                               <li>
+                                                       <a href="/distros/{{ monitoring.distro.slug }}">{{ monitoring.distro }}</a>
+                                               </li>
+                                               <li>
+                                                       <a href="#" disabled>{{ _("Monitorings") }}</a>
+                                               </li>
+                                               <li class="is-active">
+                                                       <a href="/distros/{{ monitoring.distro.slug }}/monitorings/{{ monitoring.name }}"
+                                                               aria-current="page">{{ monitoring.name }}</a>
+                                               </li>
+                                       </ul>
+                               </nav>
+
+                               <h1 class="title is-1">{{ monitoring }}</h1>
+
+                               <div class="level">
+                                       {% if monitoring.latest_release %}
+                                               <div class="level-item has-text-centered">
+                                                       <div>
+                                                               <p class="heading">{{ _("Latest Release") }}</p>
+                                                               <p>
+                                                                       {{ monitoring.latest_release.version }}
+                                                               </p>
+                                                       </div>
+                                               </div>
+                                       {% end %}
+
+                                       {% if monitoring.latest_build %}
+                                               <div class="level-item has-text-centered">
+                                                       <div>
+                                                               <p class="heading">{{ _("Current Release") }}</p>
+                                                               <p>
+                                                                       <a href="/builds/{{ monitoring.latest_build.uuid }}">
+                                                                               {{ monitoring.latest_build.pkg.evr }}
+                                                                       </a>
+                                                               </p>
+                                                       </div>
+                                               </div>
+                                       {% end %}
+
+                                       <div class="level-item has-text-centered">
+                                               <div>
+                                                       <p class="heading">{{ _("Last Check") }}</p>
+                                                       <p>
+                                                               {{ locale.format_date(monitoring.last_check_at, shorter=True) }}
+                                                       </p>
+                                               </div>
+                                       </div>
+                               </div>
+                       </div>
+               </div>
+       </section>
+
+       {% if current_user and current_user.is_admin() %}
+               <section class="section">
+                       <div class="container">
+                               <div class="buttons">
+                                       <a class="button is-light" href="{{ monitoring.url }}/check">
+                                               {{ _("Check Now") }}
+                                       </a>
+
+                                       <a class="button is-warning" href="{{ monitoring.url }}/edit">
+                                               {{ _("Edit") }}
+                                       </a>
+
+                                       <a class="button is-danger" href="{{ monitoring.url }}/delete">
+                                               {{ _("Delete") }}
+                                       </a>
+                               </div>
+                       </div>
+               </section>
+       {% end %}
+
+       {# List Releases #}
+       <section class="section">
+               <div class="container">
+                       {% module MonitoringsReleasesList(monitoring.releases) %}
+               </div>
+       </section>
+{% end block %}
index 5c0e3993028afd066b9cb0b5f05128bf38f4d0ae..4cb594ef7ec72c3d005a1e6f15254b4259dec6f3 100644 (file)
@@ -25,6 +25,9 @@
        <section class="section">
                <div class="container">
                        {% for distro in distros %}
+                               {# Fetch Monitoring Status #}
+                               {% set monitoring = backend.monitorings.get_by_distro_and_name(distro, package.name) %}
+
                                <div class="block">
                                        <h3 class="title is-3">{{ distro }}</h3>
 
                                                {% end %}
                                        {% end %}
                                </div>
+
+                               {# Release Monitoring #}
+                               {% if current_user and current_user.is_admin() %}
+                                       {% if monitoring %}
+                                               <div class="buttons">
+                                                       <a class="button is-light" href="{{ monitoring.url }}">
+                                                               {{ _("Show Upstream Releases") }}
+                                                       </a>
+
+                                                       <a class="button is-warning" href="{{ monitoring.url }}/edit">
+                                                               {{ _("Edit Release Monitoring") }}
+                                                       </a>
+                                               </div>
+                                       {% else %}
+                                               <a class="button is-success" href="{{ monitoring.url }}/create">
+                                                       {{ _("Enable Release Monitoring") }}
+                                               </a>
+                                       {% end %}
+                               {% end %}
                        {% end %}
                </div>
        </section>
index 4bf3cab2d536cca75ce4d036d6ec59329fa5bdbb..11a6a1231533f15a15fbceaf3e32870144248993 100644 (file)
@@ -22,6 +22,7 @@ from . import events
 from . import jobs
 from . import keys
 from . import mirrors
+from . import monitorings
 from . import packages
 from . import repos
 from . import search
@@ -71,6 +72,9 @@ class Application(tornado.web.Application):
                                # Mirrors
                                "MirrorsList"        : mirrors.ListModule,
 
+                               # Monitorings
+                               "MonitoringsReleasesList" : monitorings.ReleasesListModule,
+
                                # Packages
                                "PackageInfo"        : packages.InfoModule,
                                "PackageDependencies": packages.DependenciesModule,
@@ -198,6 +202,9 @@ class Application(tornado.web.Application):
                        (r"/distros/(?P<distro_slug>[A-Za-z0-9\-\.]+)/repos/(?P<repo_slug>[A-Za-z0-9\-]+)/sources/(?P<source_slug>[A-Za-z0-9\-]+)",
                                sources.ShowHandler),
 
+                       # Distro Monitorings
+                       (r"/distros/([A-Za-z0-9\-\.]+)/monitorings/([\w\-_]+)", monitorings.ShowHandler),
+
                        # Mirrors
                        (r"/mirrors",                                    mirrors.IndexHandler),
                        (r"/mirrors/create",             mirrors.CreateHandler),
diff --git a/src/web/monitorings.py b/src/web/monitorings.py
new file mode 100644 (file)
index 0000000..68b5bc4
--- /dev/null
@@ -0,0 +1,44 @@
+###############################################################################
+#                                                                             #
+# Pakfire - The IPFire package management system                              #
+# Copyright (C) 2022 Pakfire development team                                 #
+#                                                                             #
+# This program is free software: you can redistribute it and/or modify        #
+# it under the terms of the GNU General Public License as published by        #
+# the Free Software Foundation, either version 3 of the License, or           #
+# (at your option) any later version.                                         #
+#                                                                             #
+# This program is distributed in the hope that it will be useful,             #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of              #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               #
+# GNU General Public License for more details.                                #
+#                                                                             #
+# You should have received a copy of the GNU General Public License           #
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+###############################################################################
+
+import tornado.web
+
+from . import base
+from . import ui_modules
+
+class ShowHandler(base.BaseHandler):
+       def get(self, slug, name):
+               # Fetch the distribution
+               distro = self.backend.distros.get_by_slug(slug)
+               if not distro:
+                       raise tornado.web.HTTPError(404, "Could not find distro %s" % slug)
+
+               # Fetch the monitoring
+               monitoring = self.backend.monitorings.get_by_distro_and_name(distro, name)
+               if not monitoring:
+                       raise tornado.web.HTTPError(404, "Could not find monitoring for %s in %s" % (name, distro))
+
+               self.render("monitorings/show.html", monitoring=monitoring)
+
+
+class ReleasesListModule(ui_modules.UIModule):
+       def render(self, releases, show_empty=True):
+               return self.render_string("monitorings/modules/releases-list.html",
+                       releases=releases, show_empty=show_empty)