diff --git a/frontend/coprs_frontend/coprs/constants.py b/frontend/coprs_frontend/coprs/constants.py
index 85166a53f..e92dbebc0 100644
--- a/frontend/coprs_frontend/coprs/constants.py
+++ b/frontend/coprs_frontend/coprs/constants.py
@@ -1,8 +1,56 @@
"""
File which contains only constants. Nothing else.
"""
-
+from collections import namedtuple
+from enum import Enum
+from typing import Any
BANNER_LOCATION = "/var/lib/copr/data/banner-include.html"
DEFAULT_COPR_REPO_PRIORITY = 99
+
+
+CommonAttribute = namedtuple(
+ "CommonAttribute", ["description", "default"], defaults=("", None)
+)
+
+
+# just shortcut
+c = CommonAttribute # pylint: disable=invalid-name
+
+
+# Common descriptions for forms, fields, etc.
+class CommonDescriptions(Enum):
+ """
+ Enumerator for common descriptions and their default value between forms,
+ fields, etc.
+ """
+ ADDITIONAL_PACKAGES = c(
+ "Additional packages to be always present in minimal buildroot"
+ )
+ MOCK_CHROOT = c("Mock chroot", "fedora-latest-x86_64")
+ ADDITIONAL_REPOS = c("Additional repos to be used for builds in this chroot")
+ ENABLE_NET = c("Enable internet access during builds")
+ PYPI_PACKAGE_NAME = c("Package name in the Python Package Index")
+ PYPI_PACKAGE_VERSION = c("PyPI package version")
+ SPEC_GENERATOR = c(
+ "Tool for generating specfile from a PyPI package. "
+ "The options are full-featured pyp2rpm with cross "
+ "distribution support, and pyp2spec that is being actively "
+ "developed and considered to be the future."
+ )
+ AUTO_REBUILD = c("Auto-rebuild the package? (i.e. every commit or new tag)")
+
+ @property
+ def description(self) -> str:
+ """
+ Get description of Enum member
+ """
+ return self.value.description
+
+ @property
+ def default(self) -> Any:
+ """
+ Fet default value of Enum member
+ """
+ return self.value.default
diff --git a/frontend/coprs_frontend/coprs/forms.py b/frontend/coprs_frontend/coprs/forms.py
index 9b96bd45f..49e33971f 100644
--- a/frontend/coprs_frontend/coprs/forms.py
+++ b/frontend/coprs_frontend/coprs/forms.py
@@ -18,6 +18,7 @@
from coprs import exceptions
from coprs import helpers
from coprs import models
+from coprs.constants import CommonDescriptions
from coprs.logic.coprs_logic import CoprsLogic, MockChrootsLogic
from coprs.logic.users_logic import UsersLogic
from coprs.logic.dist_git_logic import DistGitLogic
@@ -625,11 +626,11 @@ class CoprForm(BaseForm):
# Deprecated, use `enable_net` instead
build_enable_net = wtforms.BooleanField(
- "Enable internet access during builds",
+ CommonDescriptions.ENABLE_NET.description,
default=False, false_values=FALSE_VALUES)
enable_net = wtforms.BooleanField(
- "Enable internet access during builds",
+ CommonDescriptions.ENABLE_NET.description,
default=False, false_values=FALSE_VALUES)
module_hotfixes = wtforms.BooleanField(
@@ -1057,9 +1058,9 @@ class PackageFormCustom(BasePackageForm):
filters=[StringListFilter()])
chroot = wtforms.SelectField(
- 'Mock chroot',
+ CommonDescriptions.MOCK_CHROOT.description,
choices=[],
- default='fedora-latest-x86_64',
+ default=CommonDescriptions.MOCK_CHROOT.default,
)
resultdir = wtforms.StringField(
@@ -1624,8 +1625,8 @@ class F(BaseForm):
class ModifyChrootForm(ChrootForm):
- buildroot_pkgs = wtforms.StringField('Additional packages to be always present in minimal buildroot')
- repos = wtforms.TextAreaField('Additional repos to be used for builds in chroot',
+ buildroot_pkgs = wtforms.StringField(CommonDescriptions.ADDITIONAL_PACKAGES.description)
+ repos = wtforms.TextAreaField(CommonDescriptions.ADDITIONAL_REPOS.description,
validators=[UrlRepoListValidator(),
wtforms.validators.Optional()],
filters=[StringListFilter()])
diff --git a/frontend/coprs_frontend/coprs/templates/coprs/detail/_builds_forms.html b/frontend/coprs_frontend/coprs/templates/coprs/detail/_builds_forms.html
index 94ae5a744..72df1a2b6 100644
--- a/frontend/coprs_frontend/coprs/templates/coprs/detail/_builds_forms.html
+++ b/frontend/coprs_frontend/coprs/templates/coprs/detail/_builds_forms.html
@@ -149,7 +149,7 @@
{{ counter('instructions') }}. Select chroots and other
{% endmacro %}
-{% macro copr_build_form_pypi(form, view, copr) %}
+{% macro copr_build_form_pypi(form, view, copr, common_descriptions) %}
{{ copr_build_form_begin(form, view, copr) }}
{{ source_description(
@@ -161,15 +161,12 @@ {{ counter('instructions') }}. Select chroots and other
)
}}
- {{ render_field(form.pypi_package_name, placeholder="Package name in the Python Package Index.") }}
+ {{ render_field(form.pypi_package_name, placeholder="{{ common_descriptions.PYPI_PACKAGE_NAME.description }}.") }}
{{ render_field(form.pypi_package_version, placeholder="Optional - Version of the package PyPI") }}
{{ render_field(
form.spec_generator,
- info="Tool for generating specfile from a PyPI package. The options "
- "are full-featured pyp2rpm with cross "
- "distribution support, and pyp2spec that is "
- "being actively developed and considered to be the future."
+ info="{{ common_descriptions.SPEC_GENERATOR.description }}"
)
}}
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..8d681f3ff 100644
--- a/frontend/coprs_frontend/coprs/templates/coprs/detail/_package_forms.html
+++ b/frontend/coprs_frontend/coprs/templates/coprs/detail/_package_forms.html
@@ -37,14 +37,14 @@ {{ counter('instructions') }}. Provide the source
{% endmacro %}
-{% macro render_webhook_rebuild(form) %}
+{% macro render_webhook_rebuild(form, common_descriptions) %}
@@ -88,7 +88,7 @@ {{ counter('instructions') }}. Generic package setup
{% endmacro %}
-{% macro copr_package_form_custom(form, view, copr, package) %}
+{% macro copr_package_form_custom(form, view, copr, package, common_descriptions) %}
{{ copr_package_form_begin(form, view, copr, package) }}
{{ copr_method_form_fileds_custom(form) }}
{{ render_generic_pkg_form(form) }}
- {{ render_webhook_rebuild(form) }}
+ {{ render_webhook_rebuild(form, common_descriptions) }}
{{ copr_package_form_end(form, package, 'custom') }}
{% endmacro %}
@@ -164,7 +164,7 @@
{% endmacro %}
-{% macro copr_package_form_scm(form, view, copr, package) %}
+{% macro copr_package_form_scm(form, view, copr, package, common_descriptions) %}
{{ copr_package_form_begin(form, view, copr, package) }}
{{ render_field(form.scm_type) }}
@@ -175,7 +175,7 @@
{{ render_srpm_build_method_box(form) }}
{{ render_generic_pkg_form(form) }}
- {{ render_webhook_rebuild(form) }}
+ {{ render_webhook_rebuild(form, common_descriptions) }}
{{ copr_package_form_end(form, package, 'mock_scm') }}
{% endmacro %}
diff --git a/frontend/coprs_frontend/coprs/templates/coprs/detail/_package_helpers.html b/frontend/coprs_frontend/coprs/templates/coprs/detail/_package_helpers.html
index 82adcee88..a6284cd9a 100644
--- a/frontend/coprs_frontend/coprs/templates/coprs/detail/_package_helpers.html
+++ b/frontend/coprs_frontend/coprs/templates/coprs/detail/_package_helpers.html
@@ -41,7 +41,7 @@
{{ copr_package_form_rubygems(form_rubygems, view, copr, package) }}
{% elif source_type_text == "custom" %}
- {{ copr_package_form_custom(form_custom, view, copr, package) }}
+ {{ copr_package_form_custom(form_custom, view, copr, package, common_descriptions) }}
{% else %}
Wrong source type
diff --git a/frontend/coprs_frontend/coprs/views/apiv3_ns/schema/fields.py b/frontend/coprs_frontend/coprs/views/apiv3_ns/schema/fields.py
index 6449578d3..cfc8c640e 100644
--- a/frontend/coprs_frontend/coprs/views/apiv3_ns/schema/fields.py
+++ b/frontend/coprs_frontend/coprs/views/apiv3_ns/schema/fields.py
@@ -8,10 +8,12 @@
from flask_restx.fields import String, List, Integer, Boolean, Url, Raw
+from coprs.constants import CommonDescriptions
+
# TODO: split these fields to some hierarchy e.g. using dataclasses or to some clusters
-# TODO: Use some shared constants for description - a lot of it is basically copied
-# description from forms
+# If you find that some descriptions/examples can be shared between forms and
+# fields, please specify it in CommonDescriptions
id_field = Integer(
description="Numeric ID",
@@ -19,17 +21,17 @@
)
mock_chroot = String(
- description="Mock chroot",
- example="fedora-rawhide-x86_64",
+ description=CommonDescriptions.MOCK_CHROOT.description,
+ example=CommonDescriptions.MOCK_CHROOT.default,
)
ownername = String(
- description="User or group name",
+ description="User name or group name (starts with @)",
example="@copr",
)
full_name = String(
- description="Full name of the project",
+ description="Full name of the project in format ownername/projectname",
example="@copr/pull-requests",
)
@@ -39,12 +41,12 @@
)
project_dirname = String(
- description="",
+ description="Path to directory in project separated by colon",
example="copr-dev:pr:123",
)
packagename = String(
- description="Name of the package",
+ description="Name of the package in project",
example="copr-cli",
)
@@ -56,18 +58,18 @@
additional_repos = List(
String,
- description="Additional repos to be used for builds in this chroot",
+ description=CommonDescriptions.ADDITIONAL_REPOS.description,
)
additional_packages = List(
String,
- description="Additional packages to be always present in minimal buildroot",
+ description=CommonDescriptions.ADDITIONAL_PACKAGES.description,
)
additional_modules = List(
String,
description=(
- "List of modules that will be enabled " "or disabled in the given chroot"
+ "List of modules that will be enabled or disabled in the given chroot"
),
example=["module1:stream", "!module2:stream"],
)
@@ -101,7 +103,7 @@
)
enable_net = Boolean(
- description="Enable internet access during builds",
+ description=CommonDescriptions.ENABLE_NET.description,
)
source_type = String(
@@ -123,24 +125,17 @@
)
pypi_package_name = String(
- description="Package name in the Python Package Index.",
+ description=CommonDescriptions.PYPI_PACKAGE_NAME.description,
example="copr",
)
pypi_package_version = String(
- description="PyPI package version",
+ description=CommonDescriptions.PYPI_PACKAGE_VERSION.description,
example="1.128pre",
)
-# TODO We are copy-pasting descriptions from web UI to this file. This field
-# is an ideal candidate for figuring out how to share the descriptions
spec_generator = String(
- description=(
- "Tool for generating specfile from a PyPI package. "
- "The options are full-featured pyp2rpm with cross "
- "distribution support, and pyp2spec that is being actively "
- "developed and considered to be the future."
- ),
+ description=CommonDescriptions.SPEC_GENERATOR.description,
example="pyp2spec",
)
@@ -162,7 +157,7 @@
)
auto_rebuild = Boolean(
- description="Auto-rebuild the package? (i.e. every commit or new tag)",
+ description=CommonDescriptions.AUTO_REBUILD.description,
)
clone_url = String(
diff --git a/frontend/coprs_frontend/coprs/views/coprs_ns/coprs_builds.py b/frontend/coprs_frontend/coprs/views/coprs_ns/coprs_builds.py
index 51eb97965..18f42f2c2 100644
--- a/frontend/coprs_frontend/coprs/views/coprs_ns/coprs_builds.py
+++ b/frontend/coprs_frontend/coprs/views/coprs_ns/coprs_builds.py
@@ -9,6 +9,7 @@
from coprs import helpers
from coprs import models
+from coprs.constants import CommonDescriptions
from coprs.logic import builds_logic
from coprs.logic.builds_logic import BuildsLogic
from coprs.logic.complex_logic import ComplexLogic
@@ -271,7 +272,8 @@ def render_add_build_pypi(copr, form, view, package=None):
if not form:
form = forms.BuildFormPyPIFactory(copr.active_chroots)()
return flask.render_template("coprs/detail/add_build/pypi.html",
- copr=copr, form=form, view=view, package=package)
+ copr=copr, form=form, view=view, package=package,
+ common_descriptions=CommonDescriptions)
@coprs_ns.route("///new_build_pypi/", methods=["POST"])
diff --git a/frontend/coprs_frontend/coprs/views/coprs_ns/coprs_packages.py b/frontend/coprs_frontend/coprs/views/coprs_ns/coprs_packages.py
index ac6089247..09ece52b3 100644
--- a/frontend/coprs_frontend/coprs/views/coprs_ns/coprs_packages.py
+++ b/frontend/coprs_frontend/coprs/views/coprs_ns/coprs_packages.py
@@ -6,6 +6,7 @@
from coprs import db
from coprs import forms
from coprs import helpers
+from coprs.constants import CommonDescriptions
from coprs.views.coprs_ns import coprs_ns
from coprs.views.coprs_ns.coprs_builds import (
render_add_build_scm,
@@ -185,7 +186,8 @@ def copr_add_package(copr, source_type_text="scm", **kwargs):
form_scm=form["scm"], form_pypi=form["pypi"],
form_rubygems=form["rubygems"],
form_distgit=form['distgit'],
- form_custom=form['custom'])
+ form_custom=form['custom'],
+ common_descriptions=CommonDescriptions)
@coprs_ns.route("///package/new/", methods=["POST"])
@@ -234,7 +236,8 @@ def copr_edit_package(copr, package_name, source_type_text=None, **kwargs):
form_scm=form["scm"], form_pypi=form["pypi"],
form_rubygems=form["rubygems"],
form_distgit=form["distgit"],
- form_custom=form['custom'])
+ form_custom=form['custom'],
+ common_descriptions=CommonDescriptions)
@coprs_ns.route("///package//edit/", methods=["POST"])