Skip to content

Commit

Permalink
frontend: allow to specify repo priority in package settings
Browse files Browse the repository at this point in the history
  • Loading branch information
nikromen committed May 19, 2023
1 parent 8979db9 commit 99853f6
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 0 deletions.
2 changes: 2 additions & 0 deletions frontend/coprs_frontend/coprs/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@


BANNER_LOCATION = "/var/lib/copr/data/banner-include.html"

DEFAULT_REPO_PRIORITY_VALUE = 99
12 changes: 12 additions & 0 deletions frontend/coprs_frontend/coprs/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
from flask_wtf.file import FileRequired, FileField
from fnmatch import fnmatch

from coprs.constants import DEFAULT_REPO_PRIORITY_VALUE

try: # get rid of deprecation warning with newer flask_wtf
from flask_wtf import FlaskForm
except ImportError:
Expand Down Expand Up @@ -862,6 +864,16 @@ class BasePackageForm(BaseForm):
wtforms.validators.NumberRange(min=0, max=100)],
default=None,
)
repo_priority = wtforms.IntegerField(
"The priority value of this repository",
description="""If there is more than one package to install from (e.g. vim from
Fedora repo and Copr repo), the repo with lower priority is picked.""",
render_kw={"placeholder": "Optional - integer, e.g. 22"},
validators=[
wtforms.validators.Optional(),
wtforms.validators.NumberRange(min=1, max=DEFAULT_REPO_PRIORITY_VALUE)],
default=DEFAULT_REPO_PRIORITY_VALUE,
)


class PackageFormScm(BasePackageForm):
Expand Down
22 changes: 22 additions & 0 deletions frontend/coprs_frontend/coprs/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
from coprs import helpers
from coprs import app

from coprs.constants import DEFAULT_REPO_PRIORITY_VALUE
from coprs.helpers import JSONEncodedDict, ChrootDeletionStatus


Expand Down Expand Up @@ -874,6 +875,20 @@ def validate_max_builds(self, field, value):
# not be built against, e.g. "fedora-*, epel-*-i386"
chroot_denylist_raw = db.Column(db.Text)

# priority=NUMBER in repo configs
repo_priority_raw = db.Column(
db.Integer,
default=DEFAULT_REPO_PRIORITY_VALUE,
server_default=DEFAULT_REPO_PRIORITY_VALUE
)

@validates("repo_priority_raw")
def validate_repo_priority(self, key, value):
if value < 1:
raise ValueError("Repo priority can't be lower than 1")

return value

@property
def dist_git_repo(self):
return "{}/{}".format(self.copr.full_name, self.name)
Expand Down Expand Up @@ -983,6 +998,13 @@ def chroots(self):
# We never want to filter everything, this is a misconfiguration.
return filtered if filtered else chroots

@property
def repo_priority(self):
if self.repo_priority_raw == DEFAULT_REPO_PRIORITY_VALUE:
return None

return self.repo_priority_raw


class Build(db.Model, helpers.Serializer):
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ <h3 class="panel-title">{{ counter('instructions') }}. Generic package setup</h3
info="What chroots should be skipped for this package, by default we build for all.",
)}}
{{ render_field(form.max_builds)}}
{{ render_field(form.repo_priority)}}
{% endmacro %}

{% macro render_anitya_autorebuild(form) %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,8 @@ def process_package_add_or_edit(copr, source_type_text, package=None, data=None)
package.max_builds = form.max_builds.data
if "chroot_denylist" in formdata:
package.chroot_denylist_raw = form.chroot_denylist.data
if "repo_priority" in formdata:
package.repo_priority_raw = form.repo_priority.data

PackagesLogic.log_being_admin(flask.g.user, package)
db.session.add(package)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ def get_build_record(task, for_backend=False):
"isolation": task.build.isolation,
"fedora_review": task.build.copr.fedora_review,
"appstream": bool(task.build.appstream),
"priority": task.build.package.repo_priority
})

copr_chroot = CoprChrootsLogic.get_by_name_safe(task.build.copr, task.mock_chroot.name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ def process_save_package(copr, source_type_text, package_name, view, view_method
package.source_json = form.source_json
package.chroot_denylist_raw = form.chroot_denylist.data
package.max_builds = form.max_builds.data
package.repo_priority_raw = form.repo_priority.data

PackagesLogic.log_being_admin(flask.g.user, package)
db.session.add(package)
Expand Down

0 comments on commit 99853f6

Please sign in to comment.