diff --git a/frontend/coprs_frontend/coprs/views/apiv3_ns/apiv3_project_chroots.py b/frontend/coprs_frontend/coprs/views/apiv3_ns/apiv3_project_chroots.py index 0fe3f9ab1..b91037d16 100644 --- a/frontend/coprs_frontend/coprs/views/apiv3_ns/apiv3_project_chroots.py +++ b/frontend/coprs_frontend/coprs/views/apiv3_ns/apiv3_project_chroots.py @@ -4,12 +4,12 @@ import flask from flask_restx import Namespace, Resource -from coprs.views.misc import api_login_required +from coprs.views.misc import api_login_required, get_from_payload from coprs.views.apiv3_ns import apiv3_ns, api, rename_fields_helper -from coprs.views.apiv3_ns.schema import ( +from coprs.views.apiv3_ns.schema.schemas import ( project_chroot_model, project_chroot_build_config_model, - project_chroot_parser, + project_chroot_get_input_model, ) from coprs.logic.complex_logic import ComplexLogic, BuildConfigLogic from coprs.exceptions import ObjectNotFound, InvalidForm @@ -75,35 +75,35 @@ def rename_fields(input_dict): @apiv3_project_chroots_ns.route("/") class ProjectChroot(Resource): - parser = project_chroot_parser() - - @apiv3_project_chroots_ns.expect(parser) + @apiv3_project_chroots_ns.expect(project_chroot_get_input_model) @apiv3_project_chroots_ns.marshal_with(project_chroot_model) def get(self): """ Get a project chroot Get settings for a single project chroot. """ - args = self.parser.parse_args() - copr = get_copr(args.ownername, args.projectname) - chroot = ComplexLogic.get_copr_chroot_safe(copr, args.chrootname) + ownername, projectname, chrootname = get_from_payload( + apiv3_project_chroots_ns.payload, "ownername", "projectname", "chrootname" + ) + copr = get_copr(ownername, projectname) + chroot = ComplexLogic.get_copr_chroot_safe(copr, chrootname) return to_dict(chroot) @apiv3_project_chroots_ns.route("/build-config") class BuildConfig(Resource): - parser = project_chroot_parser() - - @apiv3_project_chroots_ns.expect(parser) + @apiv3_project_chroots_ns.expect(project_chroot_get_input_model) @apiv3_project_chroots_ns.marshal_with(project_chroot_build_config_model) def get(self): """ Get a build config Generate a build config based on a project chroot settings. """ - args = self.parser.parse_args() - copr = get_copr(args.ownername, args.projectname) - chroot = ComplexLogic.get_copr_chroot_safe(copr, args.chrootname) + ownername, projectname, chrootname = get_from_payload( + apiv3_project_chroots_ns.payload, "ownername", "projectname", "chrootname" + ) + copr = get_copr(ownername, projectname) + chroot = ComplexLogic.get_copr_chroot_safe(copr, chrootname) if not chroot: raise ObjectNotFound('Chroot not found.') return to_build_config_dict(chroot) diff --git a/frontend/coprs_frontend/coprs/views/apiv3_ns/schema/docs.py b/frontend/coprs_frontend/coprs/views/apiv3_ns/schema/docs.py index 4bf54c420..a4a660025 100644 --- a/frontend/coprs_frontend/coprs/views/apiv3_ns/schema/docs.py +++ b/frontend/coprs_frontend/coprs/views/apiv3_ns/schema/docs.py @@ -5,7 +5,7 @@ def _generate_docs(field_names, extra_fields=None): result_dict = {} for field_name in field_names: - result_dict[field_name] = getattr(fields, field_names) + result_dict[field_name] = getattr(fields, field_name) if extra_fields is None: return result_dict 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 096a08a2f..607e8cbc8 100644 --- a/frontend/coprs_frontend/coprs/views/apiv3_ns/schema/fields.py +++ b/frontend/coprs_frontend/coprs/views/apiv3_ns/schema/fields.py @@ -1,7 +1,6 @@ from flask_restx.fields import String, List, Integer, Boolean, Url, Raw -# TODO: you can split these fields to some hierarchy e.g. using dataclasses but I -# don't see any hierarchy in it +# 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 @@ -14,6 +13,12 @@ example=123, ) + +build_id = Integer( + description="ID of the build", + example=123456, +) + mock_chroot = String( description="Mock chroot", example="fedora-rawhide-x86_64", @@ -24,7 +29,7 @@ example="@copr", ) -fullname = String( +full_name = String( description="Full name of the project", example="@copr/pull-requests", ) @@ -44,6 +49,8 @@ example="copr-cli", ) +package_name = packagename + comps_name = String( description="Name of the comps.xml file", ) @@ -128,7 +135,7 @@ # 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 -pypi_spec_generator = String( +spec_generator = String( description=( "Tool for generating specfile from a PyPI package. " "The options are full-featured pyp2rpm with cross " @@ -138,7 +145,7 @@ example="pyp2spec", ) -pypi_spec_template = String( +spec_template = String( description=( "Name of the spec template. " "This option is limited to pyp2rpm spec generator." @@ -146,7 +153,7 @@ example="default", ) -pypi_versions = List( +python_versions = List( String, # We currently return string but should this be number? description=( "For what python versions to build. " @@ -239,22 +246,22 @@ example="hello", ) -custom_script = String( +script = String( description="Script code to produce a SRPM package", example="#! /bin/sh -x", ) -custom_builddeps = String( +builddeps = String( description="URL to additional yum repos, which can be used during build.", example="copr://@copr/copr", ) -custom_resultdir = String( +resultdir = String( description="Directory where SCRIPT generates sources", example="./_build", ) -custom_chroot = String( +chroot = String( description="What chroot to run the script in", example="fedora-latest-x86_64", ) @@ -400,3 +407,15 @@ multilib = Boolean verify = Boolean + +priority = Integer + +# TODO: specify those only in Repo schema? + +baseurl = Url + +url = String + +version = String + +webhook_rebuild = Boolean diff --git a/frontend/coprs_frontend/coprs/views/apiv3_ns/schema/schemas.py b/frontend/coprs_frontend/coprs/views/apiv3_ns/schema/schemas.py index 663412e16..1b7f8c728 100644 --- a/frontend/coprs_frontend/coprs/views/apiv3_ns/schema/schemas.py +++ b/frontend/coprs_frontend/coprs/views/apiv3_ns/schema/schemas.py @@ -6,7 +6,6 @@ # somewhere - CLI, Frontend and backend shares these data with each other -from abc import ABC from dataclasses import dataclass, fields, asdict, MISSING from typing import Any @@ -18,7 +17,7 @@ @dataclass -class Schema(ABC): +class Schema: @classmethod def schema_from_fields(cls) -> dict[str, Any]: result_schema = {} @@ -41,7 +40,7 @@ def model(self): return api.model(self.__class__.__name__, self.to_dict()) -class InputSchema(ABC, Schema): +class InputSchema(Schema): @property def get_required_attrs(self) -> list: """ @@ -100,7 +99,7 @@ def get_required_attrs(self) -> list: @dataclass class Repo(Schema): - baseurl: String + baseurl: Url module_hotfixes: Boolean priority: Integer id: String = String(example="copr_base") @@ -309,6 +308,7 @@ class ProjectGet(InputSchema): build_model = _build_model package_builds_model = _package_builds_model project_model = Project.get_cls().model() +package_model = Package.get_cls().model() # INPUT MODELS