]> git.ipfire.org Git - pbs.git/commitdiff
builds: Add controls to add to another repository
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 15 May 2023 15:37:20 +0000 (15:37 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 15 May 2023 15:37:20 +0000 (15:37 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
src/buildservice/repository.py
src/templates/builds/repos/add.html [new file with mode: 0644]
src/web/__init__.py
src/web/builds.py

index ec44dc195c25abcd8595c75845c43793646a9234..70ab0f3075be53e7d34445c28c764fb4c93772d1 100644 (file)
@@ -212,6 +212,11 @@ dist_templates_builds_modules_DATA = \
 
 templates_builds_modulesdir = $(templates_buildsdir)/modules
 
+dist_templates_builds_repos_DATA = \
+       src/templates/builds/repos/add.html
+
+templates_builds_reposdir = $(templates_buildsdir)/repos
+
 dist_templates_distros_DATA = \
        src/templates/distros/edit.html \
        src/templates/distros/index.html \
index 2c57dcae358cb018f0416c83eb59fe7438a8e7c4..78a87b37d88e6ac2edd132270abe891630f0eb50 100644 (file)
@@ -165,7 +165,7 @@ class Repository(base.DataObject):
 
        def __lt__(self, other):
                if isinstance(other, self.__class__):
-                       return self.priority > other.priority or self.name < other.name
+                       return self.name < other.name
 
                return NotImplemented
 
diff --git a/src/templates/builds/repos/add.html b/src/templates/builds/repos/add.html
new file mode 100644 (file)
index 0000000..3449bfd
--- /dev/null
@@ -0,0 +1,55 @@
+{% extends "../../modal.html" %}
+
+{% block title %}{{ build }} - {{ _("Add To Repository") }}{% end block %}
+
+{% block breadcrumbs %}
+       <nav class="breadcrumb" aria-label="breadcrumbs">
+               <ul>
+                       <li>
+                               <a href="/packages">{{ _("Packages") }}</a>
+                       </li>
+                       <li>
+                               <a href="/packages/{{ build.pkg.name }}">{{ build.pkg.name }}</a>
+                       </li>
+                       <li>
+                               <a href="/builds/{{ build.uuid }}">{{ build.pkg.evr }}</a>
+                       </li>
+                       <li class="is-active">
+                               <a href="#" aria-current="page">{{ _("Add To Repository") }}</a>
+                       </li>
+               </ul>
+       </nav>
+{% end block %}
+
+{% block modal_title %}
+       <h4 class="title is-4">{{ _("Add Build To A Repository") }}</h4>
+       <h6 class="subtitle is-6">{{ build }}</h6>
+{% end block %}
+
+{% block modal %}
+       <form method="POST" action="">
+               {% raw xsrf_form_html() %}
+
+               {# Repositories #}
+               <div class="field">
+                       <label class="label">{{ _("Repository") }}</label>
+                       <div class="control">
+                               <select name="repo" required>
+                                       <option value="">{{ _("- Select One -") }}</option>
+
+                                       {% for repo in sorted(repos) %}
+                                               <option value="{{ repo.slug }}"
+                                                       {% if repo in build.repos %}disabled{% end %}>{{ repo }}</option>
+                                       {% end %}
+                               </select>
+                       </div>
+               </div>
+
+               {# Submit! #}
+               <div class="field">
+                       <button type="submit" class="button is-primary is-fullwidth">
+                               {{ _("Add To Repository") }}
+                       </button>
+               </div>
+       </form>
+{% end block %}
index 771a109da6ff0ef396c6473bb418306eb5955e16..a7e18c3f7c70c125277b06e673cd14bd6cefcc27 100644 (file)
@@ -137,6 +137,7 @@ class Application(tornado.web.Application):
                        (r"/builds/([\w]{8}-[\w]{4}-[\w]{4}-[\w]{4}-[\w]{12})/bug", builds.BugHandler),
                        (r"/builds/([\w]{8}-[\w]{4}-[\w]{4}-[\w]{4}-[\w]{12})/comment", builds.CommentHandler),
                        (r"/builds/([\w]{8}-[\w]{4}-[\w]{4}-[\w]{4}-[\w]{12})/delete", builds.DeleteHandler),
+                       (r"/builds/([\w]{8}-[\w]{4}-[\w]{4}-[\w]{4}-[\w]{12})/repos/add", builds.ReposAddHandler),
                        (r"/builds/([\w]{8}-[\w]{4}-[\w]{4}-[\w]{4}-[\w]{12})/watch", builds.WatchHandler),
                        (r"/builds/([\w]{8}-[\w]{4}-[\w]{4}-[\w]{4}-[\w]{12})/unwatch", builds.UnwatchHandler),
 
index 4a1cc4c62f066a3d53e96763c0178334bb8423be..b0cdf9e40850df9c39450dc285eacf10ddd483b1 100644 (file)
@@ -222,6 +222,44 @@ class BugHandler(base.BaseHandler):
                self.render("builds/bug-created.html", build=build, bug=bug)
 
 
+class ReposAddHandler(base.BaseHandler):
+       @tornado.web.authenticated
+       def get(self, uuid):
+               build = self.backend.builds.get_by_uuid(uuid)
+               if not build:
+                       raise tornado.web.HTTPError(404, "Could not find build %s" % uuid)
+
+               # Fetch all available repositories
+               try:
+                       repos = self.current_user.repos[build.distro]
+               except KeyError:
+                       repos = None
+
+               self.render("builds/repos/add.html", build=build, repos=repos)
+
+       @tornado.web.authenticated
+       async def post(self, uuid):
+               build = self.backend.builds.get_by_uuid(uuid)
+               if not build:
+                       raise tornado.web.HTTPError(404, "Could not find build %s" % uuid)
+
+               slug = self.get_argument("repo")
+
+               # Fetch the repository
+               repo = self.current_user.get_repo(build.distro, slug)
+               if not repo:
+                       raise tornado.web.HTTPError(400, "Could not find repository '%s'" % slug)
+
+               # Add the build to the repository
+               with self.db.transaction():
+                       await repo.add_build(build, user=self.current_user, update=False)
+
+               # Update the repository in the background
+               self.backend.run_task(repo.update)
+
+               self.redirect("/builds/%s" % build.uuid)
+
+
 class GroupShowHandler(base.BaseHandler):
        def get(self, uuid):
                group = self.backend.builds.groups.get_by_uuid(uuid)