Exemple #1
0
def api_instance(upstream_and_remote, distgit_and_remote):
    u, _ = upstream_and_remote
    d, _ = distgit_and_remote

    c = get_test_config()
    api = get_packit_api(config=c, local_project=LocalProject(working_dir=Path.cwd()))
    return u, d, api
Exemple #2
0
def update(
    config,
    dist_git_path,
    dist_git_branch,
    force_new_sources,
    local_content,
    path_or_url,
    version,
):
    """
    Release current upstream release into Fedora

    PATH_OR_URL argument is a local path or a URL to the upstream git repository,
    it defaults to the current working directory

    VERSION argument is optional, the latest upstream version
    will be used by default
    """
    api = get_packit_api(
        config=config, dist_git_path=dist_git_path, local_project=path_or_url
    )
    api.sync_release(
        dist_git_branch,
        use_local_content=local_content,
        version=version,
        force_new_sources=force_new_sources,
    )
Exemple #3
0
def mock(
    config, upstream_ref, release_suffix, default_release_suffix, root, path_or_url
):
    """
    Build RPMs in mock using content of the upstream repository.

    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)
    release_suffix = ChangelogHelper.resolve_release_suffix(
        api.package_config, release_suffix, default_release_suffix
    )

    if not config.srpm_path:
        config.srpm_path = api.create_srpm(
            upstream_ref=upstream_ref,
            srpm_dir=api.up.local_project.working_dir,
            release_suffix=release_suffix,
        )

    rpm_paths = api.run_mock_build(root=root, srpm_path=config.srpm_path)
    logger.info("RPMs:")
    for path in rpm_paths:
        logger.info(f" * {path}")
Exemple #4
0
def create_update(
    config, dist_git_branch, koji_build, update_notes, update_type, path_or_url
):
    """
    Create a bodhi update for the selected upstream project

    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)
    default_dg_branch = api.dg.local_project.git_project.default_branch
    dist_git_branch = dist_git_branch or default_dg_branch
    branches_to_update = get_branches(
        *dist_git_branch.split(","), default_dg_branch=default_dg_branch
    )
    click.echo(
        f"Creating Bodhi update for the following branches: {', '.join(branches_to_update)}"
    )

    if branches_to_update:
        click.echo("Please provide Bodhi username and password when asked for.")

    for branch in branches_to_update:
        api.create_update(
            koji_builds=koji_build,
            dist_git_branch=branch,
            update_notes=update_notes,
            update_type=update_type,
        )
Exemple #5
0
def sync_from_downstream(
    config,
    dist_git_branch,
    upstream_branch,
    no_pr,
    path_or_url,
    fork,
    remote,
    exclude,
    force,
):
    """
    Copy synced files from Fedora dist-git into upstream by opening a pull request.

    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)
    api.sync_from_downstream(
        dist_git_branch,
        upstream_branch,
        no_pr=no_pr,
        fork=fork,
        remote_name=remote,
        exclude_files=exclude,
        force=force,
    )
def sync_from_downstream(
    config,
    dist_git_branch,
    upstream_branch,
    no_pr,
    path_or_url,
    fork,
    remote_to_push,
    exclude,
    force,
):
    """
    Copy synced files from Fedora dist-git into upstream by opening a pull request.

    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)
    default_dg_branch = api.dg.local_project.git_project.default_branch
    dist_git_branch = dist_git_branch or default_dg_branch
    branches_to_sync = get_branches(
        *dist_git_branch.split(","), default_dg_branch=default_dg_branch
    )
    click.echo(f"Syncing from the following branches: {', '.join(branches_to_sync)}")

    for branch in branches_to_sync:
        api.sync_from_downstream(
            dist_git_branch=branch,
            upstream_branch=upstream_branch,
            no_pr=no_pr,
            fork=fork,
            remote_name=remote_to_push,
            exclude_files=exclude,
            force=force,
        )
Exemple #7
0
def srpm(
    config,
    output,
    path_or_url,
    upstream_ref,
    bump,
    release_suffix,
    default_release_suffix,
):
    """
    Create new SRPM (.src.rpm file) using content of the upstream repository.

    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)
    release_suffix = ChangelogHelper.resolve_release_suffix(
        api.package_config,
        release_suffix,
        default_release_suffix,
    )

    srpm_path = api.create_srpm(
        output_file=output,
        upstream_ref=upstream_ref,
        bump_version=bump,
        release_suffix=release_suffix,
    )
    logger.info(f"SRPM: {srpm_path}")
Exemple #8
0
def update(
    config,
    dist_git_path,
    dist_git_branch,
    force_new_sources,
    no_pr,
    local_content,
    path_or_url,
    upstream_ref,
    version,
    remote,  # click introspects this in LocalProjectParameter
    force,
):
    """
    Release current upstream release into Fedora

    PATH_OR_URL argument is a local path or a URL to the upstream git repository,
    it defaults to the current working directory

    VERSION argument is optional, the latest upstream version
    will be used by default
    """
    api = get_packit_api(config=config,
                         dist_git_path=dist_git_path,
                         local_project=path_or_url)
    api.sync_release(
        dist_git_branch,
        use_local_content=local_content,
        version=version,
        force_new_sources=force_new_sources,
        upstream_ref=upstream_ref,
        create_pr=not no_pr,
        force=force,
    )
Exemple #9
0
def copr_build(
    config,
    nowait,
    owner,
    project,
    targets,
    description,
    instructions,
    upstream_ref,
    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)
    default_project_name = f"packit-cli-{path_or_url.repo_name}-{path_or_url.ref}"

    targets_to_build = get_build_targets(
        *targets.split(","), default="fedora-rawhide-x86_64"
    )

    build_id, repo_url = api.run_copr_build(
        project=project or default_project_name,
        chroots=list(targets_to_build),
        owner=owner,
        description=description,
        instructions=instructions,
        upstream_ref=upstream_ref,
    )
    click.echo(f"Build id: {build_id}, repo url: {repo_url}")
    if not nowait:
        api.watch_copr_build(build_id=build_id, timeout=60 * 60 * 2)
Exemple #10
0
def init(
    config,
    path_or_url,
    force,
    upstream_url,
    upstream_ref,
    fedora_package,
    centos_package,
    dist_git_branch,
    dist_git_path: Optional[str],
):
    """
    Initiate a repository to start using packit.

    If you specify --upstream-url, then a source-git repository is made,
    otherwise only configuration file packit.yaml is created.

    To learn more about source-git, please check
    https://packit.dev/docs/source-git/
    """
    working_dir = path_or_url.working_dir
    config_path = get_existing_config(working_dir)
    if config_path:
        if not force:
            raise PackitException(
                f"Packit config {config_path} already exists."
                " If you want to regenerate it use `packit init --force`")
    else:
        # Use default name
        config_path = working_dir / ".packit.yaml"

    if fedora_package or centos_package or dist_git_branch or dist_git_path:
        # we're doing a source-git repo
        logger.warning(
            "Generating source-git repositories is experimental, "
            "please give us feedback if it does things differently than you expect."
        )
        api = get_packit_api(config=config,
                             local_project=path_or_url,
                             load_packit_yaml=False)
        dg_path = Path(dist_git_path) if dist_git_path else None
        api.create_sourcegit_from_upstream(
            upstream_url=upstream_url,
            upstream_ref=upstream_ref,
            dist_git_path=dg_path,
            dist_git_branch=dist_git_branch,
            fedora_package=fedora_package,
            centos_package=centos_package,
        )
        return

    template_data = {
        "upstream_package_name": path_or_url.repo_name,
        "downstream_package_name": path_or_url.repo_name,
    }

    generate_config(config_file=config_path,
                    write_to_file=True,
                    template_data=template_data)
Exemple #11
0
def push_updates(update_alias, config, path_or_url):
    """
    Find all Bodhi updates that have been in testing for more than 'Stable days' (7 by default)
    and push them to stable.

    """
    api = get_packit_api(config=config, local_project=path_or_url)
    api.push_updates(update_alias)
Exemple #12
0
 def dump_cfg(self):
     logger.info(f"Dumping new version of {self.pkg_cfg_path}")
     logger.info(self.pkg_cfg)
     with open(self.pkg_cfg_path, 'w') as pcf:
         yaml.safe_dump(self.pkg_cfg, pcf)
     # reload packit API
     self.packit_api = get_packit_api(
         config=self.packit_cfg, local_project=self.packit_local_project)
def test_srpm_on_example(example_repo):
    c = get_test_config()
    api = get_packit_api(
        config=c, local_project=LocalProject(working_dir=str(example_repo)))
    with cwd(example_repo):
        path = api.create_srpm()
    assert path.exists()
    build_srpm(path)
Exemple #14
0
def test_url_is_downstream():
    c = get_test_config()
    api = get_packit_api(
        config=c,
        local_project=LocalProject(git_url="https://src.fedoraproject.org/rpms/packit"),
    )
    assert api.downstream_local_project
    assert not api.upstream_local_project
Exemple #15
0
def status(config, path_or_url):
    """
    Display status
    """

    api = get_packit_api(config=config, local_project=path_or_url)

    api.status()
Exemple #16
0
def test_url_is_upstream():
    c = get_test_config()
    api = get_packit_api(
        config=c,
        local_project=LocalProject(git_url="https://github.com/packit/ogr"),
    )
    assert api.upstream_local_project
    assert not api.downstream_local_project
Exemple #17
0
def test_is_downstream(distgit_and_remote):
    downstream, _ = distgit_and_remote
    c = get_test_config()
    api = get_packit_api(config=c,
                         local_project=LocalProject(working_dir=downstream))
    assert api.downstream_local_project
    assert not api.upstream_local_project
    assert api.downstream_local_project.working_dir == downstream
Exemple #18
0
def srpm(config, output, path_or_url):
    """
    Create new SRPM (.src.rpm file) using content of the upstream repository.

    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)
    srpm_path = api.create_srpm(output_file=output)
    logger.info("SRPM: %s", srpm_path)
Exemple #19
0
 def run_srpm(self):
     try:
         packit_api = get_packit_api(
             config=packit_conf,
             local_project=LocalProject(git.Repo(self.src_package_dir)),
         )
         self.srpm_path = packit_api.create_srpm(
             srpm_dir=self.src_package_dir)
     except Exception as e:
         self.result["error"] = f"SRPMError: {e}"
Exemple #20
0
def local_build(config, path_or_url, upstream_ref):
    """
    Create RPMs using content of the upstream repository.

    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)
    rpm_paths = api.create_rpms(upstream_ref=upstream_ref)
    logger.info("RPMs:")
    for path in rpm_paths:
        logger.info(f" * {path}")
Exemple #21
0
def build(config, dist_git_path, dist_git_branch, scratch, path_or_url):
    """
    Build selected upstream project in Fedora.

    Packit goes to dist-git and performs `fedpkg build` for the selected branch.

    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,
                         dist_git_path=dist_git_path,
                         local_project=path_or_url)
    api.build(dist_git_branch, scratch=scratch)
Exemple #22
0
def status(config, path_or_url):
    """
    Display status.

    \b
    - latest downstream pull requests
    - versions from all downstream branches
    - latest upstream releases
    - latest builds in Koji
    - latest updates in Bodhi
    """

    api = get_packit_api(config=config, local_project=path_or_url)
    api.status()
Exemple #23
0
def copr_build(
    config,
    nowait,
    owner,
    project,
    targets,
    description,
    instructions,
    list_on_homepage,
    preserve_project,
    upstream_ref,
    additional_repos,
    request_admin_if_needed,
    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,
        instructions=instructions,
        upstream_ref=upstream_ref,
        list_on_homepage=list_on_homepage,
        preserve_project=preserve_project,
        additional_repos=additional_repos_list,
        request_admin_if_needed=request_admin_if_needed,
    )
    click.echo(f"Build id: {build_id}, repo url: {repo_url}")
    if not nowait:
        api.watch_copr_build(build_id=build_id, timeout=60 * 60 * 2)
Exemple #24
0
def build(
    config,
    dist_git_path,
    dist_git_branch,
    from_upstream,
    scratch,
    nowait,
    path_or_url,
    koji_target,
):
    """
    Build selected upstream project in Fedora.

    By default, packit checks out the respective dist-git repository and performs
    `fedpkg build` for the selected branch. With `--from-upstream`, packit creates a SRPM
    out of the current checkout and sends it to koji.

    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,
                         dist_git_path=dist_git_path,
                         local_project=path_or_url)

    branches_to_build = get_branches(*dist_git_branch.split(","),
                                     default="master")
    click.echo(
        f"Building for the following branches: {', '.join(branches_to_build)}")

    for branch in branches_to_build:
        try:
            out = api.build(
                dist_git_branch=branch,
                scratch=scratch,
                nowait=nowait,
                koji_target=koji_target,
                from_upstream=from_upstream,
            )
        except PackitCommandFailedError as ex:
            logs_stdout = "\n>>> ".join(ex.stdout_output.strip().split("\n"))
            logs_stderr = "\n!!! ".join(ex.stderr_output.strip().split("\n"))
            click.echo(
                f"Build for branch '{branch}' failed. \n"
                f">>> {logs_stdout}\n"
                f"!!! {logs_stderr}\n",
                err=True,
            )
        else:
            if out:
                print(ensure_str(out))
Exemple #25
0
def create_update(config, dist_git_branch, koji_build, update_notes,
                  update_type, path_or_url):
    """
    Create a bodhi update for the selected upstream project

    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)
    api.create_update(
        koji_builds=koji_build,
        dist_git_branch=dist_git_branch,
        update_notes=update_notes,
        update_type=update_type,
    )
Exemple #26
0
def copr_build(config, nowait, owner, project, targets, 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)
    default_project_name = f"packit-cli-{path_or_url.repo_name}-{path_or_url.ref}"
    build_id, repo_url = api.run_copr_build(project=project
                                            or default_project_name,
                                            chroots=targets.split(","),
                                            owner=owner)
    click.echo(f"Build id: {build_id}, repo url: {repo_url}")
    if not nowait:
        api.watch_copr_build(build_id=build_id, timeout=60 * 60 * 2)
Exemple #27
0
def srpm(
        config,
        output,
        path_or_url,
        upstream_ref,
        remote,  # click introspects this in LocalProjectParameter
):
    """
    Create new SRPM (.src.rpm file) using content of the upstream repository.

    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)
    srpm_path = api.create_srpm(output_file=output, upstream_ref=upstream_ref)
    logger.info(f"SRPM: {srpm_path}")
Exemple #28
0
def test_get_api(tmp_path, remotes, package_config, is_upstream):
    repo = tmp_path / "project_repo"
    repo.mkdir(parents=True, exist_ok=True)
    initiate_git_repo(repo, remotes=remotes)

    flexmock(utils).should_receive("get_local_package_config").and_return(
        package_config)

    c = get_test_config()
    api = get_packit_api(config=c,
                         local_project=LocalProject(working_dir=str(repo)))

    if is_upstream:
        assert api.upstream_local_project
    else:
        flexmock(PackitAPI).should_receive("_run_kinit").once()
        assert api.downstream_local_project
        assert api.dg
Exemple #29
0
def propose_downstream(
    config,
    dist_git_path,
    dist_git_branch,
    force_new_sources,
    pr,
    local_content,
    path_or_url,
    upstream_ref,
    version,
    force,
):
    """
    Land a new upstream release in Fedora.

    PATH_OR_URL argument is a local path or a URL to the upstream git repository,
    it defaults to the current working directory

    VERSION argument is optional, the latest upstream version
    will be used by default
    """

    api = get_packit_api(config=config,
                         dist_git_path=dist_git_path,
                         local_project=path_or_url)
    if pr is None:
        pr = api.package_config.create_pr

    branches_to_update = get_dg_branches(api, dist_git_branch)

    click.echo(
        f"Proposing update of the following branches: {', '.join(branches_to_update)}"
    )

    for branch in branches_to_update:
        api.sync_release(
            dist_git_branch=branch,
            use_local_content=local_content,
            version=version,
            force_new_sources=force_new_sources,
            upstream_ref=upstream_ref,
            create_pr=pr,
            force=force,
        )
Exemple #30
0
    def _run(self):
        self.clone_repo()
        self.load_packit_config()

        # try running status
        self.packit_api = get_packit_api(
            config=self.packit_cfg, local_project=self.packit_local_project
        )

        if self.is_onboared():
            self.result["skipped"] = True
            logger.info(
                f"Project already has a branch {ONBOARD_BRANCH_NAME} "
                f"in {WHOAMI} namespace. Skipping."
            )
            return

        self.announce_operation("Getting status")
        self.packit_api.status()

        self.packit_local_project.git_repo.create_head(ONBOARD_BRANCH_NAME).checkout()
        up_spec = self.get_upstream_spec()
        if up_spec and os.path.exists(up_spec):
            self.announce_operation("Building srpm with upstream spec")
            self.result["downstream_spec_used"] = False
            self.build_srpm()
        else:
            self.result["downstream_spec_used"] = True
            down_spec = self.get_spec_from_packit_config()
            self.announce_operation("Building srpm with downstream spec")
            self.get_downstream_spec(dest=down_spec)
            self.build_srpm()

        self.enable_copr_builds()
        if (
            self.result["already_had_packit_conf"]
            and self.result["already_copr_enabled"]
        ):
            logger.info("Repo had already copr enabled in packit")
            return

        self.push_and_create_pr()