Example #1
0
    def get_request_details(cls, request_id: str) -> Dict[str, Any]:
        """Testing Farm sends only request/pipeline id in a notification.
        We need to get more details ourselves."""
        self = cls(
            service_config=ServiceConfig.get_service_config(),
            package_config=PackageConfig(),
            project=None,
            metadata=None,
            db_trigger=None,
            job_config=JobConfig(
                # dummy values to be able to construct the object
                type=JobType.tests,
                trigger=JobConfigTriggerType.pull_request,
            ),
        )

        response = self.send_testing_farm_request(
            endpoint=f"requests/{request_id}", method="GET"
        )
        if not response or response.status_code != 200:
            msg = f"Failed to get request/pipeline {request_id} details from TF. {response.reason}"
            logger.error(msg)
            return {}

        details = response.json()
        # logger.debug(f"Request/pipeline {request_id} details: {details}")

        return details
Example #2
0
    def get_from_dict(cls,
                      raw_dict: dict,
                      config_file_path: str = None,
                      validate=True) -> "PackageConfig":
        if validate:
            cls.validate(raw_dict)

        synced_files = raw_dict.get("synced_files", None)
        actions = raw_dict.get("actions", {})
        raw_jobs = raw_dict.get("jobs", [])
        create_tarball_command = raw_dict.get("create_tarball_command", None)
        current_version_command = raw_dict.get("current_version_command", None)

        upstream_package_name = cls.get_deprecated_key(
            raw_dict, "upstream_package_name",
            "upstream_project_name") or cls.get_deprecated_key(
                raw_dict, "upstream_package_name", "upstream_name")
        upstream_project_url = raw_dict.get("upstream_project_url", None)

        if raw_dict.get("dist_git_url", None):
            logger.warning(
                "dist_git_url is no longer being processed, "
                "it is generated from dist_git_base_url and downstream_package_name"
            )
        downstream_package_name = cls.get_deprecated_key(
            raw_dict, "downstream_package_name", "package_name")
        specfile_path = raw_dict.get("specfile_path", None)
        if not specfile_path:
            if downstream_package_name:
                specfile_path = f"{downstream_package_name}.spec"
                logger.info(f"We guess that spec file is at {specfile_path}")
            else:
                # guess it?
                logger.warning("Path to spec file is not set.")

        dist_git_base_url = raw_dict.get("dist_git_base_url")
        dist_git_namespace = raw_dict.get("dist_git_namespace")
        upstream_ref = raw_dict.get("upstream_ref")

        allowed_gpg_keys = raw_dict.get("allowed_gpg_keys")
        create_pr = raw_dict.get("create_pr", False)
        upstream_tag_template = raw_dict.get("upstream_tag_template",
                                             "{version}")

        # it can be int as well
        spec_source_id = raw_dict.get("spec_source_id", "Source0")
        try:
            spec_source_id = int(spec_source_id)
        except ValueError:
            # not a number
            pass
        else:
            # is a number!
            spec_source_id = f"Source{spec_source_id}"

        pc = PackageConfig(
            config_file_path=config_file_path,
            specfile_path=specfile_path,
            synced_files=SyncFilesConfig.get_from_dict(synced_files,
                                                       validate=False),
            actions={ActionName(a): cmd
                     for a, cmd in actions.items()},
            jobs=[
                JobConfig.get_from_dict(raw_job, validate=False)
                for raw_job in raw_jobs
            ],
            upstream_package_name=upstream_package_name,
            downstream_package_name=downstream_package_name,
            upstream_project_url=upstream_project_url,
            dist_git_base_url=dist_git_base_url,
            dist_git_namespace=dist_git_namespace,
            create_tarball_command=create_tarball_command,
            current_version_command=current_version_command,
            upstream_ref=upstream_ref,
            allowed_gpg_keys=allowed_gpg_keys,
            create_pr=create_pr,
            spec_source_id=spec_source_id,
            upstream_tag_template=upstream_tag_template,
        )
        return pc
Example #3
0
 def make_instance(self, data, **_):
     return JobConfig(**data)
Example #4
0
 def make_instance(self, data, **_):
     type = data.pop("job")
     return JobConfig(type=type, **data)
Example #5
0
 def make_instance(self, data, **_):
     if "metadata" in data:
         metadata = data.pop("metadata")
         data.update(metadata)
     return JobConfig(**data)