示例#1
0
    def get_package_config(self) -> Optional[PackageConfig]:
        logger.debug(f"Getting package_config:\n"
                     f"\tproject: {self.project}\n"
                     f"\tbase_project: {self.base_project}\n"
                     f"\treference: {self.commit_sha}\n"
                     f"\tpr_id: {self.pr_id}")

        spec_path = None
        if self.project_url and RepoUrl.parse(self.project_url).hostname in [
                "git.centos.org",
                "git.stg.centos.org",
        ]:
            spec_path = f"SPECS/{self.project.repo}.spec"
            logger.debug(f"Getting package_config from CentOS dist-git. "
                         f"(Spec-file is expected to be in {spec_path}.)")
        package_config = PackageConfigGetter.get_package_config_from_repo(
            base_project=self.base_project,
            project=self.project,
            reference=self.commit_sha,
            pr_id=self.pr_id,
            fail_when_missing=self.fail_when_config_file_missing,
            spec_file_path=spec_path,
        )

        # job config change note:
        #   this is used in sync-from-downstream which is buggy - we don't need to change this
        if package_config:
            package_config.upstream_project_url = self.project_url
        return package_config
示例#2
0
文件: repo.py 项目: packit/packit
    def get_repo(
        self,
        url: str,
        directory: Union[Path, str] = None,
    ) -> git.Repo:
        """
        Clone the repository.
        * If we have this repository in a cache, use the cached repo as a reference when cloning.
        * If we don't have this repository in a cache and {add_new} is True,
          clone the repository to cache first and then use it as a reference.

        :param url: will be used to clone the repo
        :param directory: target path for cloning the repository
        :return: cloned repository
        """
        directory = str(directory) if directory else tempfile.mkdtemp()

        if is_git_repo(directory=directory):
            logger.debug(f"Repo already exists in {directory}.")
            return git.repo.Repo(directory)

        logger.debug(
            f"Cloning repo {url} -> {directory} using repository cache at {self.cache_path}"
        )
        cached_projects = self.cached_projects
        cached_projects_str = "\n".join(f"- {project}"
                                        for project in cached_projects)
        logger.debug(
            f"Repositories in the cache ({len(cached_projects)} project(s)):\n{cached_projects_str}"
        )

        project_name = RepoUrl.parse(url).repo
        reference_repo = self.cache_path.joinpath(project_name)
        if project_name not in cached_projects and self.add_new:
            logger.debug(f"Creating reference repo: {reference_repo}")
            self._clone(url=url, to_path=str(reference_repo), tags=True)
            self.projects_added.append(project_name)

        if self.add_new or project_name in cached_projects:
            logger.debug(f"Using reference repo: {reference_repo}")
            self.projects_cloned_using_cache.append(project_name)
            return self._clone(url=url,
                               to_path=directory,
                               tags=True,
                               reference=str(reference_repo))

        return self._clone(url=url, to_path=directory, tags=True)
示例#3
0
import pytest

from ogr.parsing import parse_git_repo, RepoUrl


@pytest.mark.parametrize(
    "url,expected",
    [
        (
            "https://host.name/namespace/repo",
            RepoUrl(
                repo="repo",
                namespace="namespace",
                scheme="https",
                hostname="host.name",
                username="******",
            ),
        ),
        (
            "https://host.name/namespace/repo.git",
            RepoUrl(
                repo="repo",
                namespace="namespace",
                scheme="https",
                hostname="host.name",
                username="******",
            ),
        ),
        (
            "http://host.name/namespace/repo",
            RepoUrl(
示例#4
0
import pytest

from ogr.parsing import parse_git_repo, RepoUrl


@pytest.mark.parametrize(
    "url,result",
    [
        (
            "https://host.name/namespace/repo",
            RepoUrl(repo="repo",
                    namespace="namespace",
                    scheme="https",
                    hostname="host.name"),
        ),
        (
            "https://host.name/namespace/repo.git",
            RepoUrl(repo="repo",
                    namespace="namespace",
                    scheme="https",
                    hostname="host.name"),
        ),
        (
            "http://host.name/namespace/repo",
            RepoUrl(repo="repo",
                    namespace="namespace",
                    scheme="http",
                    hostname="host.name"),
        ),
        (
            "git://host.name/namespace/repo",
示例#5
0
import pytest

from ogr.parsing import parse_git_repo, RepoUrl


@pytest.mark.parametrize(
    "url,result",
    [
        (
            "https://host.name/namespace/repo",
            RepoUrl(repo="repo",
                    namespace="namespace",
                    scheme="https",
                    hostname="host.name"),
        ),
        (
            "https://host.name/namespace/repo.git",
            RepoUrl(repo="repo",
                    namespace="namespace",
                    scheme="https",
                    hostname="host.name"),
        ),
        (
            "http://host.name/namespace/repo",
            RepoUrl(repo="repo",
                    namespace="namespace",
                    scheme="http",
                    hostname="host.name"),
        ),
        (
            "git://host.name/namespace/repo",