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_working_dir_namespace_repo_name():
url = "https://server.git/my_namespace/package_name"
flexmock(local_project).should_receive("is_git_repo").with_args(
"./local/directory/to/git"
).and_return(True)
flexmock(git).should_receive("Repo").with_args(
path="./local/directory/to/git"
).and_return(
flexmock(
active_branch=flexmock(name="branch"), head=flexmock(is_detached=False)
)
)
project = LocalProject(
working_dir="./local/directory/to/git",
namespace="my_namespace",
repo_name="package_name",
git_service=flexmock()
.should_receive("get_project")
.and_return(flexmock(get_git_urls=lambda: {"git": url}))
.mock(),
)
assert project
assert project.git_url == url
assert project.namespace == "my_namespace"
assert project.repo_name == "package_name"
assert project.git_service
assert project.git_project
assert project.git_repo
def test_base_push_bad(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.REMOTE_REJECTED, None, None, None, None)
],
)
with pytest.raises(PackitException) as e:
b.push("master")
assert "unable to push" in str(e.value)
def test_parse_namespace_from_git_project():
project = LocalProject(git_project=flexmock(namespace="namespace"), refresh=False)
changed = project._parse_namespace_from_git_project()
assert changed
assert project.git_project
assert project.namespace
assert project.namespace == "namespace"
def test_parse_git_url_from_git_project():
project = LocalProject(
git_project=flexmock()
.should_receive("get_git_urls")
.and_return({"git": "http://some.example/namespace/reponame"})
.once()
.mock(),
refresh=False,
)
changed = project._parse_git_url_from_git_project()
assert changed
assert project.git_project
assert project.git_url == "http://some.example/namespace/reponame"
def test_parse_ref_from_git_repo_detached():
project = LocalProject(
git_repo=flexmock(
active_branch="branch",
head=flexmock(is_detached=True, commit=flexmock(hexsha="sha")),
),
refresh=False,
)
changed = project._parse_ref_from_git_repo()
assert changed
assert project.git_repo
assert project._ref == "sha"
def test_parse_ref_from_git_repo():
"""Get working_dir from git_repo"""
project = LocalProject(
git_repo=flexmock(
active_branch=flexmock(name="branch"), head=flexmock(is_detached=False)
),
refresh=False,
)
changed = project._parse_ref_from_git_repo()
assert changed
assert project.git_repo
assert project._ref == "branch"
synchronize selected source-git pull request to respective downstream dist-git repo via a pagure pull request
:param target_url:
:param target_ref:
:param full_name: str, name of the github repo (e.g. user-cont/source-git)
:param top_commit: str, commit hash of the top commit in source-git PR
:param pr_id:
:param pr_url:
:param title:
:param package_config: PackageConfig, configuration of the sg - dg mapping
:param repo_directory: use this directory instead of pulling the url
:return:
"""
logger.info("starting sync for project %s", target_url)
sourcegit = LocalProject(
git_url=target_url, working_dir=repo_directory, full_name=full_name
)
distgit = LocalProject(
git_url=package_config.metadata["dist_git_url"],
ref=f"source-git-{pr_id}",
git_service=PagureService(token=self.pagure_fork_token),
namespace="rpms",
repo_name=package_config.metadata["package_name"],
)
checkout_pr(repo=sourcegit.git_repo, pr_id=pr_id)
with Transformator(
sourcegit=sourcegit, distgit=distgit, package_config=package_config
) as transformator:
def handle_release(self):
if not self.job.metadata.get("targets"):
logger.error(
"'targets' value is required in packit config for copr_build job"
)
tag_name = self.event["release"]["tag_name"]
local_project = LocalProject(git_project=self.project, ref=tag_name)
api = PackitAPI(self.config, self.package_config, local_project)
build_id, repo_url = api.run_copr_build(
owner=self.job.metadata.get("owner") or "packit",
project=self.job.metadata.get("project")
or f"{self.project.namespace}-{self.project.repo}",
chroots=self.job.metadata.get("targets"),
)
# report
commit_sha = self.project.get_sha_from_tag(tag_name)
r = self.BuildStatusReporter(self.project, commit_sha, build_id, repo_url)
timeout = 60 * 60 * 2
timeout_config = self.job.metadata.get("timeout")
if timeout_config:
timeout = int(timeout_config)
:param full_name: str, name of the github repo (e.g. user-cont/source-git)
:param top_commit: str, commit hash of the top commit in source-git PR
:param pr_id:
:param pr_url:
:param title:
:param package_config: PackageConfig, configuration of the sg - dg mapping
:param repo_directory: use this directory instead of pulling the url
:return:
"""
logger.info("starting sync for project %s", target_url)
sourcegit = LocalProject(
git_url=target_url, working_dir=repo_directory, full_name=full_name
)
distgit = LocalProject(
git_url=package_config.metadata["dist_git_url"],
ref=f"source-git-{pr_id}",
git_service=PagureService(token=self.pagure_fork_token),
namespace="rpms",
repo_name=package_config.metadata["package_name"],
)
checkout_pr(repo=sourcegit.git_repo, pr_id=pr_id)
with Transformator(
sourcegit=sourcegit, distgit=distgit, package_config=package_config
) as transformator:
transformator.create_archive()
transformator.copy_synced_content_to_distgit_directory(
synced_files=package_config.synced_files
)