Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow setting up repo priority #2733

Merged
merged 1 commit into from
Aug 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cli/copr_cli/build_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
[{{ repo.id }}]
name="{{ repo.name }}"
baseurl={{ repo.baseurl }}
{%- if repo.priority %}
{%- if repo.priority and repo.priority is not none %}
priority={{ repo.priority }}
{%- endif %}
{%- if repo.module_hotfixes %}
Expand All @@ -64,6 +64,7 @@
{%- endif %}
"""


class MockProfile(object):
def __init__(self, data):
self.data = data
Expand Down
8 changes: 8 additions & 0 deletions cli/copr_cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,7 @@ def action_create(self, args):
appstream=ON_OFF_MAP[args.appstream],
runtime_dependencies=args.runtime_dependencies,
packit_forge_projects_allowed=args.packit_forge_projects_allowed,
repo_priority=args.repo_priority,
)

owner_part = username.replace('@', "g/")
Expand Down Expand Up @@ -514,6 +515,7 @@ def action_modify_project(self, args):
appstream=ON_OFF_MAP[args.appstream],
runtime_dependencies=args.runtime_dependencies,
packit_forge_projects_allowed=args.packit_forge_projects_allowed,
repo_priority=args.repo_priority,
)

@requires_api_auth
Expand Down Expand Up @@ -1177,6 +1179,9 @@ def setup_parser():
"created for you (as soon as they are available) as rawhide "
"chroot forks."))

parser_create.add_argument("--repo-priority", default=None,
help="Set the priority value of this repository")

create_and_modify_common_opts(parser_create)

parser_create.set_defaults(func="action_create")
Expand Down Expand Up @@ -1244,6 +1249,9 @@ def setup_parser():
"created for you (as soon as they are available) as rawhide "
"chroot forks."))

parser_modify.add_argument("--repo-priority", default=None,
help="Set the priority value of this repository")

create_and_modify_common_opts(parser_modify)

parser_modify.set_defaults(func="action_modify_project")
Expand Down
2 changes: 2 additions & 0 deletions cli/tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,7 @@ def test_create_project(config_from_file, project_proxy_add, capsys):
"appstream": False,
"runtime_dependencies": None,
"packit_forge_projects_allowed": None,
"repo_priority": None,
}
assert stdout == "New project was successfully created: http://copr/coprs/jdoe/foo/\n"

Expand Down Expand Up @@ -575,6 +576,7 @@ def test_create_multilib_project(config_from_file, project_proxy_add, capsys):
"appstream": False,
"runtime_dependencies": None,
"packit_forge_projects_allowed": None,
"repo_priority": None,
}
assert stdout == "New project was successfully created: http://copr/coprs/jdoe/foo/\n"

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"""
Add repo priority field
Revision ID: 7d9f6f921fa0
Revises: ba6ac0936bfb
Create Date: 2023-05-25 11:05:39.877208
"""

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '7d9f6f921fa0'
down_revision = 'ba6ac0936bfb'
branch_labels = None
depends_on = None


def upgrade():
op.add_column('copr', sa.Column('repo_priority', sa.Integer(), nullable=True))


def downgrade():
op.drop_column('copr', 'repo_priority')
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_COPR_REPO_PRIORITY = 99
14 changes: 13 additions & 1 deletion frontend/coprs_frontend/coprs/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
from flask_wtf import Form as FlaskForm

from coprs import app
from coprs import exceptions
from coprs import helpers
from coprs import models
from coprs.logic.coprs_logic import CoprsLogic, MockChrootsLogic
from coprs.logic.users_logic import UsersLogic
from coprs.logic.dist_git_logic import DistGitLogic
from coprs.logic.complex_logic import ComplexLogic
from coprs import exceptions

from wtforms import ValidationError

Expand Down Expand Up @@ -655,6 +655,18 @@ class CoprForm(BaseForm):
filters=[StringListFilter(), StripUrlSchemaListFilter()],
validators=[wtforms.validators.Optional()],)

repo_priority = wtforms.IntegerField(
"The priority value of this repository",
description="""The priority value of this repository, default is 99. If there is more than one candidate
package for a particular operation, the one from a repo with the lowest priority value is
picked, possibly despite being less convenient otherwise (e.g. by being a lower version).""",
render_kw={"placeholder": "Optional - integer, e.g. 22"},
validators=[
wtforms.validators.Optional(),
wtforms.validators.NumberRange(min=1)],
default=None,
)

@property
def errors(self):
"""
Expand Down
11 changes: 10 additions & 1 deletion frontend/coprs_frontend/coprs/logic/complex_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from coprs import models
from coprs import exceptions
from coprs import cache
from coprs.constants import DEFAULT_COPR_REPO_PRIORITY
from coprs.exceptions import ObjectNotFound, ActionInProgressException
from coprs.logic.builds_logic import BuildsLogic
from coprs.logic.batches_logic import BatchesLogic
Expand Down Expand Up @@ -456,7 +457,6 @@ def create_object(self, clazz, from_object, exclude=list()):


class BuildConfigLogic(object):

@classmethod
def generate_build_config(cls, copr, chroot_id):
""" Return dict with proper build config contents """
Expand Down Expand Up @@ -486,6 +486,15 @@ def generate_build_config(cls, copr, chroot_id):
"name": "Copr buildroot",
})

# None value of the priority won't show in API
if copr.repo_priority in [None, DEFAULT_COPR_REPO_PRIORITY]:
repo_priority = None
else:
repo_priority = copr.repo_priority

for repo in repos:
repo["priority"] = repo_priority
nikromen marked this conversation as resolved.
Show resolved Hide resolved

nikromen marked this conversation as resolved.
Show resolved Hide resolved
repos.extend(cls.get_additional_repo_views(copr.repos_list, chroot_id))
repos.extend(cls.get_additional_repo_views(chroot.repos_list, chroot_id))

Expand Down
11 changes: 11 additions & 0 deletions frontend/coprs_frontend/coprs/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,17 @@ class _CoprPublic(db.Model, helpers.Serializer):
# allowed to build in this Copr via Packit
packit_forge_projects_allowed = db.Column(db.Text)

# priority=NUMBER in repo configs
repo_priority = db.Column(db.Integer, nullable=True)

@validates("repo_priority")
def validate_repo_priority(self, _, value):
"""Checks whether priority value is correct"""
if value < 1:
raise ValueError("Repo priority can't be lower than 1")

return value


class _CoprPrivate(db.Model, helpers.Serializer):
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,11 @@ <h3 class="panel-title">{{ counter('instructions') }}. Other options</h3>
placeholder='Optional',
info='Delete the project after the specfied period of time (empty = disabled)') }}

{{ render_field(form.repo_priority,
class="short-input-field",
placeholder='Optional',
info='Set the priority value of this repository. Defaults to 99.') }}

{{ render_field(form.isolation, placeholder='default') }}

{{ render_bootstrap_options(form) }}
Expand Down
4 changes: 4 additions & 0 deletions frontend/coprs_frontend/coprs/templates/coprs/copr_dir.repo
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@ enabled_metadata=1
{% if copr_dir.copr.module_hotfixes %}
module_hotfixes=1
{% endif %}

{%- if repo_priority is not none %}
priority={{ repo_priority }}
{%- endif %}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def to_dict(copr):
"appstream": copr.appstream,
"packit_forge_projects_allowed": copr.packit_forge_projects_allowed_list,
"follow_fedora_branching": copr.follow_fedora_branching,
"repo_priority": copr.repo_priority,
}


Expand Down Expand Up @@ -162,6 +163,7 @@ def _form_field_repos(form_field):
runtime_dependencies=_form_field_repos(form.runtime_dependencies),
appstream=form.appstream.data,
packit_forge_projects_allowed=_form_field_repos(form.packit_forge_projects_allowed),
repo_priority=form.repo_priority.data,
)
db.session.commit()
except (DuplicateException,
Expand Down
6 changes: 6 additions & 0 deletions frontend/coprs_frontend/coprs/views/apiv3_ns/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@
example="nspawn",
)

repo_priority_field = Integer(
description="The priority value of this repository. Defaults to 99",
example=42,
)

enable_net_field = Boolean(
description="Enable internet access during builds",
)
Expand Down Expand Up @@ -311,6 +316,7 @@
"id": String(example="copr_base"),
"name": String(example="Copr repository"),
"module_hotfixes": module_hotfixes_field,
"priority": repo_priority_field,
}

repo_model = api.model("Repo", repo_schema)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,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),
"repo_priority": task.build.copr.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 @@ -282,6 +282,7 @@ def copr_new(username=None, group_name=None):
isolation=form.isolation.data,
appstream=form.appstream.data,
packit_forge_projects_allowed=form.packit_forge_projects_allowed.data,
repo_priority=form.repo_priority.data
)

db.session.commit()
Expand Down Expand Up @@ -554,6 +555,8 @@ def process_copr_update(copr, form):
copr.isolation = form.isolation.data
copr.appstream = form.appstream.data
copr.packit_forge_projects_allowed = form.packit_forge_projects_allowed.data
copr.repo_priority = form.repo_priority.data

if flask.g.user.admin:
copr.auto_prune = form.auto_prune.data
else:
Expand Down Expand Up @@ -856,7 +859,7 @@ def render_repo_template(copr_dir, mock_chroot, arch=None, cost=None, runtime_de
return flask.render_template("coprs/copr_dir.repo", copr_dir=copr_dir,
url=repo_url, pubkey_url=pubkey_url,
repo_id=repo_id, arch=arch, cost=cost,
name=name)
name=name, repo_priority=copr_dir.copr.repo_priority)


def _render_external_repo_template(dep, copr_dir, mock_chroot, dep_idx):
Expand Down
7 changes: 5 additions & 2 deletions frontend/coprs_frontend/tests/test_apiv3/test_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def test_update_copr_api3(self):
# testing method!
already_tested = set([
"delete_after", "build_enable_net", "auto_createrepo", "repos",
"runtime_dependencies", "packit_forge_projects_allowed"
"runtime_dependencies", "packit_forge_projects_allowed", "repo_priority"
])

# check non-trivial changes
Expand All @@ -91,6 +91,7 @@ def test_update_copr_api3(self):
assert old_data["auto_prune"] is True
assert old_data["follow_fedora_branching"] is True
assert old_data["packit_forge_projects_allowed"] == ""
assert old_data["repo_priority"] is None
self.api3.modify_project(
"test", delete_after_days=5, enable_net=True, devel_mode=True,
repos=["http://example/repo/", "http://another/"],
Expand All @@ -100,7 +101,8 @@ def test_update_copr_api3(self):
"https://github.com/packit/ogr",
"github.com/packit/requre",
"http://github.com/packit/packit"
]
],
repo_priority=13,
)
new_data = self._get_copr_id_data(1)
delete_after = datetime.datetime.now() + datetime.timedelta(days=5)
Expand All @@ -113,6 +115,7 @@ def test_update_copr_api3(self):
old_data["bootstrap"] = "default"
old_data["packit_forge_projects_allowed"] = "github.com/packit/ogr\ngithub.com/packit/requre\ngithub.com" \
"/packit/packit"
old_data["repo_priority"] = 13
assert old_data == new_data
old_data = new_data

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ def test_generate_build_config_with_dep_mistake(self):
"name": "Copr repository",
"baseurl": "http://copr-be-dev.cloud.fedoraproject.org"
"/results/user1/foocopr/fedora-18-x86_64/",
"priority": None,
}
build_config = bcl.generate_build_config(self.c1, "fedora-18-x86_64")
assert build_config["repos"] == [main_repo]
Expand Down
8 changes: 6 additions & 2 deletions python/copr/v3/proxies/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ def add(self, ownername, projectname, chroots, description=None, instructions=No
auto_prune=True, use_bootstrap_container=None, devel_mode=False,
delete_after_days=None, multilib=False, module_hotfixes=False,
bootstrap=None, bootstrap_image=None, isolation=None, follow_fedora_branching=True,
fedora_review=None, appstream=False, runtime_dependencies=None, packit_forge_projects_allowed=None):
fedora_review=None, appstream=False, runtime_dependencies=None, packit_forge_projects_allowed=None,
repo_priority=None):
"""
Create a project
Expand Down Expand Up @@ -139,6 +140,7 @@ def add(self, ownername, projectname, chroots, description=None, instructions=No
"appstream": appstream,
"runtime_dependencies": runtime_dependencies,
"packit_forge_projects_allowed": packit_forge_projects_allowed,
"repo_priority": repo_priority,
}

_compat_use_bootstrap_container(data, use_bootstrap_container)
Expand All @@ -157,7 +159,8 @@ def edit(self, ownername, projectname, chroots=None, description=None, instructi
auto_prune=None, use_bootstrap_container=None, devel_mode=None,
delete_after_days=None, multilib=None, module_hotfixes=None,
bootstrap=None, bootstrap_image=None, isolation=None, follow_fedora_branching=None,
fedora_review=None, appstream=None, runtime_dependencies=None, packit_forge_projects_allowed=None):
fedora_review=None, appstream=None, runtime_dependencies=None, packit_forge_projects_allowed=None,
repo_priority=None):
"""
Edit a project
Expand Down Expand Up @@ -223,6 +226,7 @@ def edit(self, ownername, projectname, chroots=None, description=None, instructi
"appstream": appstream,
"runtime_dependencies": runtime_dependencies,
"packit_forge_projects_allowed": packit_forge_projects_allowed,
"repo_priority": repo_priority,
}

_compat_use_bootstrap_container(data, use_bootstrap_container)
Expand Down
2 changes: 1 addition & 1 deletion rpmbuild/mock-custom-build.cfg.j2
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ metadata_expire=0
cost=1
best=1

{%- if "priority" in repo %}
{%- if "priority" in repo and priority is not none %}
priority={{ repo["priority"] }}
{%- endif %}

Expand Down
2 changes: 1 addition & 1 deletion rpmbuild/mock.cfg.j2
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ metadata_expire=0
cost=1
best=1

{%- if "priority" in repo %}
{%- if "priority" in repo and priority is not none %}
priority={{ repo["priority"] }}
{%- endif %}

Expand Down