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_allowed_gpg_keys_not_allowed(
allowed_gpg_keys, api_instance_source_git: PackitAPI, gnupg_key_fingerprint: str
):
api_instance_source_git.up.local_project.git_repo.git.commit(
message="signed commit", gpg_sign=gnupg_key_fingerprint, allow_empty=True
)
api_instance_source_git.up.allowed_gpg_keys = allowed_gpg_keys
with pytest.raises(PackitException) as ex:
api_instance_source_git.up.check_last_commit()
assert "not signed" in str(ex)
def covered_func():
raise PackitException("Test exception")
def test_download_gpg_key_if_needed(keyid, ok):
cf = CommitVerifier()
if ok:
assert cf.download_gpg_key_if_needed(keyid)
else:
with pytest.raises(PackitException):
cf.download_gpg_key_if_needed(keyid)
def get_namespace_and_repo_name(url: str) -> Tuple[Optional[str], str]:
if Path(url).exists():
return None, Path(url).name
url = url.strip("/")
try:
if url.endswith(".git"):
url = url[:-4]
if url.startswith("http"):
# if git_url is in format http{s}://github.com/org/repo_name
_, namespace, repo_name = url.rsplit("/", 2)
else:
# If git_url is in format git@github.com:org/repo_name
org_repo = url.split(":", 2)[1]
namespace, repo_name = org_repo.split("/", 2)
except (IndexError, ValueError) as ex:
raise PackitException(
f"Invalid URL format, can't obtain namespace and repository name: {url}: {ex!r}"
)
return namespace, repo_name
def _parse_repo_name_from_git_project(self):
if self.git_project and not self.repo_name:
self.repo_name = self.git_project.repo
if not self.repo_name:
raise PackitException(
"Repo name should have been set but isn't, this is bug!"
)
logger.debug(
f"Parsed repo name {self.repo_name!r} from the git project {self.git_project}."
)
return True
return False
logger.debug(f"Name + version = {dir_name}")
env = {
"PACKIT_PROJECT_VERSION": version,
"PACKIT_PROJECT_NAME_VERSION": dir_name,
}
if self.has_action(action=ActionName.create_archive):
outputs = self.get_output_from_action(
action=ActionName.create_archive, env=env
)
if not outputs:
raise PackitException("No output from create-archive action.")
archive_path = self._get_archive_path_from_output(outputs)
if not archive_path:
raise PackitException(
"The create-archive action did not output a path to the generated archive. "
"Please make sure that you have valid path in the single line of the output."
)
self._add_link_to_archive_from_specdir_if_needed(archive_path)
return archive_path.name
return self._create_archive_using_default_way(dir_name, env, version)
logger.error(
"This package is not using %(auto)setup macro in prep, "
"packit can't work in this environment."
)
return
new_setup_line = m[1]
# replace -n with our -n because it's better
args_match = re.search(r"(.*?)\s+-n\s+\S+(.*)", m[2])
if args_match:
new_setup_line += args_match.group(1)
new_setup_line += args_match.group(2)
else:
new_setup_line += m[2]
if not self.package_config.upstream_package_name:
raise PackitException(
'"upstream_package_name" is not set: unable to fix the spec file; please set it.'
)
new_setup_line += f" -n {self.package_config.upstream_package_name}-{version}"
logger.debug(
f"New {'%autosetup' if 'autosetup' in new_setup_line else '%setup'}"
f" line:\n{new_setup_line}"
)
prep[idx] = new_setup_line
self.specfile.spec_content.replace_section("%prep", prep)
self.specfile.write_spec_content()
def _fix_spec_source(self, archive):
response = self.specfile.get_source(self.package_config.spec_source_id)
if response:
idx, source_name, _ = response
self.specfile.spec_content.section(SPEC_PACKAGE_SECTION)[
idx
] = f"{source_name}: {archive}"
else:
raise PackitException(
"The spec file doesn't have sources set "
f"via {self.package_config.spec_source_id} nor Source."
class PackitCoprException(PackitException):
pass
class PackitCoprProjectException(PackitCoprException):
pass
class PackitInvalidConfigException(PackitConfigException):
""" provided configuration file is not valid """
@deprecated(reason="Use the PackitFailedToCreateSRPMException instead.")
class FailedCreateSRPM(PackitException):
""" Failed to create SRPM """
class PackitSRPMException(PackitException):
""" Problem with the SRPM """
class PackitSRPMNotFoundException(PackitSRPMException):
""" SRPM created but not found """
class PackitFailedToCreateSRPMException(PackitSRPMException):
""" Failed to create SRPM """
class PackitRPMException(PackitException):
fork: bool = True,
remote_name: str = None,
):
"""
Sync content of Fedora dist-git repo back to upstream
:param dist_git_branch: branch in dist-git
:param upstream_branch: upstream branch
:param no_pr: won't create a pull request if set to True
:param fork: forks the project if set to True
:param remote_name: name of remote where we should push; if None, try to find a ssh_url
"""
if not dist_git_branch:
raise PackitException("Dist-git branch is not set.")
if not upstream_branch:
raise PackitException("Upstream branch is not set.")
logger.info(f"upstream active branch {self.up.active_branch}")
self.dg.update_branch(dist_git_branch)
self.dg.checkout_branch(dist_git_branch)
local_pr_branch = f"{dist_git_branch}-downstream-sync"
logger.info(f'using "{dist_git_branch}" dist-git branch')
self.up.create_branch(local_pr_branch)
self.up.checkout_branch(local_pr_branch)
raw_sync_files = self.package_config.synced_files.get_raw_files_to_sync(
Path(self.dg.local_project.working_dir),
Path(self.up.local_project.working_dir),
)