diff --git a/frontend/coprs_frontend/coprs/constants.py b/frontend/coprs_frontend/coprs/constants.py index 4f51c2511..0bd8ab83a 100644 --- a/frontend/coprs_frontend/coprs/constants.py +++ b/frontend/coprs_frontend/coprs/constants.py @@ -4,3 +4,5 @@ BANNER_LOCATION = "/var/lib/copr/data/banner-include.html" + +DEFAULT_REPO_PRIORITY_VALUE = 99 diff --git a/frontend/coprs_frontend/coprs/forms.py b/frontend/coprs_frontend/coprs/forms.py index 2c658f9d8..7f8d901e9 100644 --- a/frontend/coprs_frontend/coprs/forms.py +++ b/frontend/coprs_frontend/coprs/forms.py @@ -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: @@ -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): diff --git a/frontend/coprs_frontend/coprs/models.py b/frontend/coprs_frontend/coprs/models.py index 038534b47..1de7d6409 100644 --- a/frontend/coprs_frontend/coprs/models.py +++ b/frontend/coprs_frontend/coprs/models.py @@ -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 @@ -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) @@ -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): """ diff --git a/frontend/coprs_frontend/coprs/templates/coprs/detail/_package_forms.html b/frontend/coprs_frontend/coprs/templates/coprs/detail/_package_forms.html index 59d8a3200..921120ff2 100644 --- a/frontend/coprs_frontend/coprs/templates/coprs/detail/_package_forms.html +++ b/frontend/coprs_frontend/coprs/templates/coprs/detail/_package_forms.html @@ -63,6 +63,7 @@

{{ counter('instructions') }}. Generic package setup