]> git.ipfire.org Git - pbs.git/commitdiff
repos: Show recently added builds
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 11 May 2023 19:14:35 +0000 (19:14 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 11 May 2023 19:14:35 +0000 (19:14 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/buildservice/repository.py
src/templates/repos/show.html

index a16036b456317b611ef52453f68b40cccfeec5b2..5ab73ed39edb8c8457111cd2dab79698013a157e 100644 (file)
@@ -538,6 +538,31 @@ class Repository(base.DataObject):
 
                return list(builds)
 
+       def get_recent_builds(self, limit=None, offset=None):
+               builds = self.backend.builds._get_builds("""
+                       SELECT
+                               builds.*
+                       FROM
+                               repository_builds
+                       LEFT JOIN
+                               builds ON repository_builds.build_id = builds.id
+                       WHERE
+                               builds.deleted_at IS NULL
+                       AND
+                               repository_builds.repo_id = %s
+                       AND
+                               repository_builds.removed_at IS NULL
+                       ORDER BY
+                               repository_builds.added_at DESC
+                       LIMIT
+                               %s
+                       OFFSET
+                               %s
+                       """, self.id, limit, offset,
+               )
+
+               return list(builds)
+
        @lazy_property
        def total_builds(self):
                res = self.db.get("""
@@ -556,7 +581,7 @@ class Repository(base.DataObject):
                        """, self.id,
                )
 
-               return res.count
+               return res.count or 0
 
        def get_builds_by_name(self, name):
                """
@@ -763,7 +788,7 @@ class Repository(base.DataObject):
                )
 
                if res:
-                       return res.size
+                       return res.size or 0
 
                return 0
 
index 54d8b0b1624b99fcb106ce0a6029c58753b90b66..60e83a4ddc56ff8ffa285ef853cc432fa63c62c6 100644 (file)
                        </div>
                </div>
        </section>
+
+       {% set builds = repo.get_recent_builds(limit=6) %}
+
+       {# Builds #}
+       {% if builds %}
+               <section class="section">
+                       <div class="container">
+                               <h4 class="title is-4">{{ _("Recently Added Builds") }}</h4>
+
+                               {% module BuildsList(builds) %}
+
+                               <a class="button is-primary" href="{{ repo.url }}/builds">
+                                       {{ _("Show All Builds") }}
+                               </a>
+                       </div>
+               </section>
+       {% end %}
 {% end block %}