build_repo = repo,
pkg = package,
owner = owner,
- group = group,
+ build_group_id = group.id if group else None,
test = test,
disable_test_builds = disable_test_builds,
)
return await self.db.fetch_one(stmt)
+ # Clone!
+
+ async def clone(self, owner, repo=None):
+ """
+ Creates a clone of this build
+ """
+ # Create a new build from the same package
+ clone = await self.backend.builds.create(
+ # Build the same package
+ package = self.pkg,
+
+ # Owner
+ owner = owner,
+
+ # Repository
+ repo = repo or self.build_repo,
+ )
+
+ log.info("Cloned %s as %s" % (self, clone))
+
+ return clone
+
class BuildGroup(database.Base, database.SoftDeleteMixin):
__tablename__ = "build_groups"
# Custom repositories
- async def get_repos(self):
+ async def get_repos(self, distro=None):
"""
Returns all custom repositories
"""
)
)
+ # Filter by distribution
+ if distro:
+ stmt = stmt.where(
+ repos.Repo.distro == distro,
+ )
+
return await self.db.fetch_as_list(stmt)
async def get_repo(self, distro, slug=None):
-{% extends "../modal.html" %}
+{% extends "modal.html" %}
-{% block title %}{{ build }} - {{ _("Clone") }}{% end block %}
+{% block title %}{{ build }} - {{ _("Clone") }}{% endblock %}
{% block breadcrumbs %}
<nav class="breadcrumb" aria-label="breadcrumbs">
</li>
</ul>
</nav>
-{% end block %}
+{% endblock %}
{% block modal_title %}
<h4 class="title is-4">{{ _("Clone Build") }}</h4>
<h6 class="subtitle is-6">{{ build }}</h6>
-{% end block %}
+{% endblock %}
{% block modal %}
<form method="POST" action="">
- {% raw xsrf_form_html() %}
+ {{ xsrf_form_html() | safe }}
{# Repositories #}
+ {% set repos = current_user.get_repos(distro=build.distro) %}
+
<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) %}
+ {% for repo in repos | sort %}
<option value="{{ repo.slug }}">{{ repo }}</option>
- {% end %}
+ {% endfor %}
</select>
</div>
</div>
</button>
</div>
</form>
-{% end block %}
+{% endblock %}
if slug:
return await self.backend.distros.get_by_slug(slug)
+ async def get_argument_repo(self, *args, distro=None, user=None, **kwargs):
+ if distro is None:
+ raise ValueError("Distro required")
+
+ # Fetch the slug of the repository
+ slug = self.get_argument(*args, **kwargs)
+
+ # Fetch the user repository
+ if user:
+ return await user.get_repo(slug=slug, distro=distro)
+
+ # Or fetch it from the distribution
+ return await distro.get_repo(slug=slug)
+
# Uploads
async def _get_upload(self, uuid):
class CloneHandler(base.BaseHandler):
@base.authenticated
- def get(self, uuid):
- build = self.backend.builds.get_by_uuid(uuid)
+ async def get(self, uuid):
+ build = await 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)
+ await self.render("builds/clone.html", build=build)
@base.authenticated
async def post(self, uuid):
- build = self.backend.builds.get_by_uuid(uuid)
+ build = await 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"))
+ repo = await self.get_argument_repo(
+ "repo",
+ user = self.current_user,
+ distro = build.distro,
+ )
# Clone the build
- with self.db.transaction():
- clone = await self.backend.builds.create(
- repo=repo, package=build.pkg, owner=self.current_user,
- )
+ clone = await build.clone(
+ owner = self.current_user,
+ repo = repo,
+ )
# Launch all jobs (in the background)
self.backend.run_task(self.backend.builds.launch, [clone])