Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_base_push_good(distgit_and_remote):
distgit, _ = distgit_and_remote
b = PackitRepositoryBase(config=Config(), package_config=PackageConfig())
b.local_project = LocalProject(
working_dir=str(distgit), git_url="https://github.com/packit-service/lol"
)
flexmock(
LocalProject,
push=lambda *args, **kwargs: [
PushInfo(PushInfo.FAST_FORWARD, None, None, None, None)
],
)
b.push("master")
def test_get_output_from_action_defined_in_sandcastle():
from sandcastle.api import Sandcastle
echo_cmd = "hello world"
flexmock(Sandcastle).should_receive("get_api_client")
flexmock(Sandcastle).should_receive("is_pod_already_deployed").and_return(True)
c = Config()
c.command_handler = RunCommandType.sandcastle
packit_repository_base = PackitRepositoryBase(
config=c, package_config=PackageConfig(actions={ActionName.pre_sync: echo_cmd})
)
packit_repository_base.local_project = LocalProject()
flexmock(Sandcastle).should_receive("run")
flexmock(Sandcastle).should_receive("exec").and_return(echo_cmd)
flexmock(Sandcastle).should_receive("delete_pod").and_return(None)
result = packit_repository_base.get_output_from_action(ActionName.pre_sync)
assert result[-1] == echo_cmd
def packit_repository_base():
return PackitRepositoryBase(
config=Config(),
package_config=PackageConfig(
actions={
ActionName.pre_sync: "command --a",
ActionName.get_current_version: "command --b",
}
def packit_repository_base_with_sandcastle_object():
c = Config()
c.command_handler = RunCommandType.sandcastle
b = PackitRepositoryBase(
config=c,
package_config=PackageConfig(
actions={
ActionName.pre_sync: "command -a",
ActionName.get_current_version: "command -b",
}
),
)
b.local_project = LocalProject()
return b
def upstream_with_actions():
return Upstream(
config=flexmock(Config()),
package_config=flexmock(
PackageConfig(
actions={
ActionName.pre_sync: "command --a",
ActionName.get_current_version: "command --b",
}
)
),
local_project=flexmock(
repo_name=flexmock(),
refresh_the_arguments=lambda: None,
git_project=flexmock(),
git_service=flexmock(),
),
def test_run_in_sandbox():
packit_repository_base = PackitRepositoryBase(
config=Config(),
package_config=PackageConfig(actions={ActionName.pre_sync: "ls -lha"}),
)
packit_repository_base.config.actions_handler = "sandcastle"
result = packit_repository_base.get_output_from_action(ActionName.pre_sync)
assert "total 4.0K" in result
assert "drwxr-xr-x. 1 root root" in result
preserve_project,
upstream_ref,
additional_repos,
path_or_url,
):
"""
Build selected upstream project in COPR.
PATH_OR_URL argument is a local path or a URL to the upstream git repository,
it defaults to the current working directory.
"""
api = get_packit_api(config=config, local_project=path_or_url)
if not project:
logger.debug("COPR project name was not passed via CLI.")
project = f"packit-cli-{path_or_url.repo_name}-{path_or_url.ref}"
if isinstance(api.package_config, PackageConfig):
project = api.package_config.get_copr_build_project_value()
logger.info(f"Using COPR project name = {project}")
targets_to_build = get_build_targets(
*targets.split(","), default="fedora-rawhide-x86_64"
)
additional_repos_list: Optional[List[str]] = additional_repos.split(
","
) if additional_repos else None
build_id, repo_url = api.run_copr_build(
project=project,
chroots=list(targets_to_build),
owner=owner,
description=description,
def parse_loaded_config(loaded_config: dict) -> PackageConfig:
"""Tries to parse the config to PackageConfig."""
logger.debug(f"Package config:\n{json.dumps(loaded_config, indent=4)}")
try:
package_config = PackageConfig.get_from_dict(
raw_dict=loaded_config, validate=True
)
return package_config
except Exception as ex:
logger.error(f"Cannot parse package config. {ex}.")
raise Exception(f"Cannot parse package config: {ex}.")
allowed_gpg_keys = raw_dict.get("allowed_gpg_keys", None)
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(
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,
def make_instance(self, data, **kwargs):
return PackageConfig(**data)