From: Michael Tremer Date: Mon, 15 May 2023 16:37:05 +0000 (+0000) Subject: builds: Add controls to clone builds X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9e2b040dedff685e26fa4ba74008885b3e58d609;p=pbs.git builds: Add controls to clone builds Signed-off-by: Michael Tremer --- diff --git a/Makefile.am b/Makefile.am index 88b13b3f..b13acdf8 100644 --- a/Makefile.am +++ b/Makefile.am @@ -182,6 +182,7 @@ templates_builders_modulesdir = $(templates_buildersdir)/modules dist_templates_builds_DATA = \ src/templates/builds/bug.html \ src/templates/builds/bug-created.html \ + src/templates/builds/clone.html \ src/templates/builds/delete.html \ src/templates/builds/index.html \ src/templates/builds/show.html diff --git a/src/templates/builds/clone.html b/src/templates/builds/clone.html new file mode 100644 index 00000000..fe3e6393 --- /dev/null +++ b/src/templates/builds/clone.html @@ -0,0 +1,56 @@ +{% extends "../modal.html" %} + +{% block title %}{{ build }} - {{ _("Clone") }}{% end block %} + +{% block breadcrumbs %} + +{% end block %} + +{% block modal_title %} +

{{ _("Clone Build") }}

+
{{ build }}
+{% end block %} + +{% block modal %} +
+ {% raw xsrf_form_html() %} + + {# Repositories #} +
+ +
+
+ +
+
+
+ + {# Submit! #} +
+ +
+
+{% end block %} diff --git a/src/templates/builds/show.html b/src/templates/builds/show.html index 862f97c1..380bf544 100644 --- a/src/templates/builds/show.html +++ b/src/templates/builds/show.html @@ -118,6 +118,13 @@ {{ _("Source Package") }} + {# Clone #} + {% if not build.is_test() %} + + {{ _("Clone") }} + + {% end %} + {# Delete #} {% if build.can_be_deleted(current_user) %} diff --git a/src/web/__init__.py b/src/web/__init__.py index c87fcf04..aef1d435 100644 --- a/src/web/__init__.py +++ b/src/web/__init__.py @@ -135,6 +135,7 @@ class Application(tornado.web.Application): (r"/builds", builds.IndexHandler), (r"/builds/([\w]{8}-[\w]{4}-[\w]{4}-[\w]{4}-[\w]{12})", builds.ShowHandler), (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})/clone", builds.CloneHandler), (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), diff --git a/src/web/builds.py b/src/web/builds.py index 6d0c0e1f..d6c45213 100644 --- a/src/web/builds.py +++ b/src/web/builds.py @@ -96,6 +96,42 @@ class ShowHandler(base.BaseHandler): distro=build.distro, bugs=bugs) +class CloneHandler(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 repositories + try: + repos = self.current_user.repos[build.distro] + except KeyError: + repos = [] + + self.render("builds/clone.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) + + # Fetch the repository + repo = self.current_user.get_repo(build.distro, self.get_argument("repo")) + + # Clone the build + with self.db.transaction(): + clone = await self.backend.builds.create( + repo=repo, package=build.pkg, owner=self.current_user, + ) + + # Launch all jobs (in the background) + self.backend.run_task(self.backend.builds.launch, [clone]) + + self.redirect("/builds/%s" % clone.uuid) + + class DeleteHandler(base.BaseHandler): @tornado.web.authenticated def get(self, uuid):