Exemplo n.º 1
0
 def local_project(self):
     """ return an instance of LocalProject """
     if self._local_project is None:
         pagure_service = PagureService(
             token=self.pagure_user_token,
             instance_url=self.package_config.dist_git_base_url,
             read_only=self.config.dry_run,
         )
         if self.package_config.dist_git_clone_path:
             self._local_project = LocalProject(
                 working_dir=self.package_config.dist_git_clone_path,
                 git_url=self.package_config.dist_git_package_url,
                 namespace=self.package_config.dist_git_namespace,
                 repo_name=self.package_config.downstream_package_name,
                 git_service=pagure_service,
             )
         else:
             tmpdir = tempfile.mkdtemp(prefix="packit-dist-git")
             f = FedPKG(self.fas_user, tmpdir)
             f.clone(
                 self.package_config.downstream_package_name,
                 tmpdir,
                 anonymous=not cccolutils.has_creds(),
             )
             self._local_project = LocalProject(
                 working_dir=tmpdir,
                 git_url=self.package_config.dist_git_package_url,
                 namespace=self.package_config.dist_git_namespace,
                 repo_name=self.package_config.downstream_package_name,
                 git_service=pagure_service,
             )
             self._local_project.working_dir_temporary = True
     return self._local_project
Exemplo n.º 2
0
    def build(self, scratch: bool = False):
        """
        Perform a `fedpkg build` in the repository

        :param scratch: should the build be a scratch build?
        """
        fpkg = FedPKG(directory=self.local_project.working_dir)
        fpkg.build(scratch=scratch)
Exemplo n.º 3
0
 def upload_to_lookaside_cache(self, archive_path: str) -> None:
     """
     Upload files (archive) to the lookaside cache.
     """
     # TODO: can we check if the tarball is already uploaded so we don't have ot re-upload?
     logger.info("About to upload to lookaside cache.")
     f = FedPKG(fas_username=self.config.fas_user,
                directory=self.local_project.working_dir)
     try:
         f.new_sources(sources=archive_path)
     except Exception as ex:
         logger.error(
             f"The 'fedpkg new-sources' command failed for the following reason: {ex!r}"
         )
         raise PackitException(ex)
Exemplo n.º 4
0
    def build(
        self,
        scratch: bool = False,
        nowait: bool = False,
        koji_target: Optional[str] = None,
    ):
        """
        Perform a `fedpkg build` in the repository

        :param scratch: should the build be a scratch build?
        :param nowait: don't wait on build?
        :param koji_target: koji target to pick (see `koji list-targets`)
        """
        fpkg = FedPKG(directory=self.local_project.working_dir)
        fpkg.build(scratch=scratch, nowait=nowait, koji_target=koji_target)
Exemplo n.º 5
0
    def local_project(self):
        """ return an instance of LocalProject """
        if self._local_project is None:
            dist_git_project = self.config.get_project(
                url=self.package_config.dist_git_package_url
            )

            if self.package_config.dist_git_clone_path:
                self._local_project = LocalProject(
                    working_dir=self.package_config.dist_git_clone_path,
                    git_url=self.package_config.dist_git_package_url,
                    namespace=self.package_config.dist_git_namespace,
                    repo_name=self.package_config.downstream_package_name,
                    git_project=dist_git_project,
                )
            else:
                tmpdir = tempfile.mkdtemp(prefix="packit-dist-git")
                f = FedPKG(
                    fas_username=self.fas_user, directory=tmpdir, stage=self.stage
                )
                f.clone(
                    self.package_config.downstream_package_name,
                    tmpdir,
                    anonymous=not cccolutils.has_creds(),
                )
                self._local_project = LocalProject(
                    working_dir=tmpdir,
                    git_url=self.package_config.dist_git_package_url,
                    namespace=self.package_config.dist_git_namespace,
                    repo_name=self.package_config.downstream_package_name,
                    git_project=dist_git_project,
                )
                self._local_project.working_dir_temporary = True
            self._local_project.refresh_the_arguments()
        elif not self._local_project.git_project:
            self._local_project.git_project = self.config.get_project(
                url=self.package_config.dist_git_package_url
            )
            self._local_project.refresh_the_arguments()
        return self._local_project
Exemplo n.º 6
0
def test_create_srcgit_requre_populated(api_instance_source_git,
                                        tmp_path: Path):
    """
    use requre to create a source-git out of it in a branch with upstream git history
    - this should only layer downstream changes on top
    """
    # clone dist-git
    pkg = "python-requre"
    dist_git_ref = "6b27ffacda06289ca2d546e15b3c96845243005f"
    dist_git_path = tmp_path.joinpath(pkg)
    source_git_path = tmp_path.joinpath("requre-sg")
    FedPKG().clone(pkg, str(dist_git_path), anonymous=True)
    dg_lp = LocalProject(working_dir=dist_git_path)

    # check out specific ref
    subprocess.check_call(["git", "reset", "--hard", dist_git_ref],
                          cwd=dist_git_path)

    # add a patch in there
    spec = Specfile(dist_git_path / f"{pkg}.spec", sources_dir=dist_git_path)
    patch_name = "hello.patch"
    patch_path = dist_git_path.joinpath(patch_name)
    patch_path.write_text(REQURE_PATCH)
    patch = PatchMetadata(name=patch_name,
                          path=patch_path,
                          present_in_specfile=False)
    spec.add_patch(patch)
    dg_lp.stage()
    dg_lp.commit("add the hello patch")
    subprocess.check_call(["fedpkg", "prep"], cwd=dist_git_path)

    # create src-git
    source_git_path.mkdir()
    subprocess.check_call([
        "git", "clone", "https://github.com/packit/requre",
        str(source_git_path)
    ])
    subprocess.check_call(
        ["git", "checkout", "-B", "source-git-0.4.0", "0.4.0"],
        cwd=source_git_path)
    sgg = SourceGitGenerator(
        LocalProject(working_dir=source_git_path),
        api_instance_source_git.config,
        dist_git_path=dist_git_path,
    )
    sgg.create_from_upstream()

    # verify it
    subprocess.check_call(["packit", "srpm"], cwd=source_git_path)
    srpm_path = list(
        source_git_path.glob("python-requre-0.4.0-2.*.src.rpm"))[0]
    assert srpm_path.is_file()
Exemplo n.º 7
0
 def upload_to_lookaside_cache(self, archive_path: str) -> None:
     """
     Upload files (archive) to the lookaside cache.
     """
     # TODO: can we check if the tarball is already uploaded so we don't have ot re-upload?
     logger.info("About to upload to lookaside cache")
     f = FedPKG(fas_username=self.fas_user, directory=self.local_project.working_dir)
     f.init_ticket(self.config.keytab_path)
     try:
         f.new_sources(sources=archive_path)
     except Exception as ex:
         logger.error(
             f"`fedpkg new-sources` failed for some reason. "
             f"Either Fedora kerberos is invalid or there could be network outage."
         )
         raise PackitException(ex)
Exemplo n.º 8
0
 def test_fedpkg_clone(self):
     """ test `fedpkg clone -a` within an openshift pod """
     t = Path(self.tmpdir)
     f = FedPKG()
     f.clone("units", str(t), anonymous=True)
     assert t.joinpath("units.spec").is_file()