Ejemplo n.º 1
0
class AliasedGroup(click.Group):
    def get_command(self, ctx, cmd_name):
        if cmd_name == "generate":
            click.secho(
                "WARNING: 'packit generate' is deprecated and it "
                "is going to be removed. Use 'packit init' instead.",
                fg="yellow",
            )
            return click.Group.get_command(self, ctx, "init")
        else:
            return click.Group.get_command(self, ctx, cmd_name)


@click.group("packit",
             cls=AliasedGroup,
             context_settings=get_context_settings())
@click.option("-d", "--debug", is_flag=True, help="Enable debug logs.")
@click.option("--fas-user", help="Fedora Account System username.")
@click.option("-k", "--keytab", help="Path to FAS keytab file.")
@click.option(
    "--remote",
    default=None,
    help=("Name of the remote to discover upstream project URL, "
          "If this is not specified, default to the first remote."),
)
@click.option(
    "--dry-run",
    is_flag=True,
    help="Do not perform any remote changes (pull requests or comments).",
)
@click.version_option(version=get_distribution("packitos").version,
Ejemplo n.º 2
0
Update selected component from upstream in Fedora
"""

import logging
import os

import click

from packit.cli.types import LocalProjectParameter
from packit.cli.utils import cover_packit_exception, get_packit_api
from packit.config import pass_config, get_context_settings

logger = logging.getLogger(__file__)


@click.command("sync-from-downstream", context_settings=get_context_settings())
@click.option("--dist-git-branch",
              help="Source branch in dist-git for sync.",
              default="master")
@click.option("--upstream-branch",
              help="Target branch in upstream to sync to.",
              default="master")
@click.option("--no-pr", is_flag=True, help="Pull request is not create.")
@click.option("--fork/--no-fork",
              is_flag=True,
              default=True,
              help="Push to a fork.")
@click.option(
    "--remote-name",
    default=None,
    help=
Ejemplo n.º 3
0
import logging
from typing import Optional

import click
import git

from packit.cli.types import GitRepoParameter
from packit.cli.utils import cover_packit_exception
from packit.api import PackitAPI
from packit.config.config import pass_config
from packit.config import get_context_settings

logger = logging.getLogger(__name__)


@click.command("init", context_settings=get_context_settings())
@click.argument("upstream_ref")
@click.argument("source_git",
                type=GitRepoParameter(from_ref_param="upstream_ref"))
@click.argument("dist_git", type=GitRepoParameter())
@click.option(
    "--upstream-url",
    help="""Git URL of the upstream repository. It is saved
    in the source-git configuration if it is specified.""",
)
@click.option(
    "--upstream-remote",
    help="""Name of the remote pointing to the upstream repository.
    If --upstream-url is not specified, the fetch URL of this remote
    is saved in the source-git configuration as the Git URL of the
    upstream project. Defaults to 'origin'.""",
Ejemplo n.º 4
0
# SPDX-License-Identifier: MIT

import logging
import os

import click

from packit.cli.types import LocalProjectParameter
from packit.cli.utils import cover_packit_exception, get_packit_api
from packit.config import pass_config, get_context_settings
from packit.utils.changelog_helper import ChangelogHelper

logger = logging.getLogger("packit")


@click.command("locally", context_settings=get_context_settings())
@click.option(
    "--upstream-ref",
    default=None,
    help="Git ref of the last upstream commit in the current branch "
    "from which packit should generate patches "
    "(this option implies the repository is source-git).",
)
@click.option(
    "--release-suffix",
    default=None,
    type=click.STRING,
    help="Specifies release suffix. Allows to override default generated:"
    "{current_time}.{sanitized_current_branch}{git_desc_suffix}",
)
@click.option(
Ejemplo n.º 5
0

class AliasedGroup(click.Group):
    def get_command(self, ctx, cmd_name):
        if cmd_name == "generate":
            click.secho(
                "WARNING: 'packit generate' is deprecated and it "
                "is going to be removed. Use 'packit init' instead.",
                fg="yellow",
            )
            return click.Group.get_command(self, ctx, "init")
        else:
            return click.Group.get_command(self, ctx, cmd_name)


@click.group("packit", cls=AliasedGroup, context_settings=get_context_settings())
@click.option("-d", "--debug", is_flag=True, help="Enable debug logs.")
@click.option("--fas-user", help="Fedora Account System username.")
@click.option("-k", "--keytab", help="Path to FAS keytab file.")
@click.option(
    "--dry-run",
    is_flag=True,
    help="Do not perform any remote changes (pull requests or comments).",
)
@click.version_option(
    version=get_distribution("packitos").version, message="%(version)s"
)
@click.pass_context
def packit_base(ctx, debug, fas_user, keytab, dry_run):
    """Integrate upstream open source projects into Fedora operating system."""
    if debug:
Ejemplo n.º 6
0
"""
Push Bodhi updates from testing to stable.
"""

import logging
import os

import click

from packit.cli.types import LocalProjectParameter
from packit.cli.utils import cover_packit_exception
from packit.cli.utils import get_packit_api
from packit.config import pass_config, get_context_settings

logger = logging.getLogger(__file__)


@click.command("push-updates", context_settings=get_context_settings())
@click.option("--update-alias", help="For example FEDORA-2019-ee5674e22c", default=None)
@click.argument("path_or_url", type=LocalProjectParameter(), default=os.path.curdir)
@pass_config
@cover_packit_exception
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)
Ejemplo n.º 7
0
# SOFTWARE.
import logging
import os
from typing import Optional, List

import click

from packit.cli.types import LocalProjectParameter
from packit.cli.utils import cover_packit_exception, get_packit_api
from packit.config import pass_config, get_context_settings, PackageConfig
from packit.config.aliases import get_build_targets

logger = logging.getLogger(__name__)


@click.command("copr-build", context_settings=get_context_settings())
@click.option("--nowait",
              is_flag=True,
              default=False,
              help="Don't wait for build")
@click.option(
    "--owner",
    help=
    "Copr user, owner of the project. (defaults to username from copr config)",
)
@click.option(
    "--project",
    help="Project name to build in. Will be created if does not exist. "
    "(defaults to the first found project value in the config file or "
    "'packit-cli-{repo_name}-{branch/commit}')",
)
Ejemplo n.º 8
0
import logging

import click

from packit.config import pass_config, get_context_settings, get_local_package_config
from packit.local_project import LocalProject
from packit.transformator import Transformator

logger = logging.getLogger(__file__)


@click.command("sg2dg", context_settings=get_context_settings())
@click.option("--dest-dir")
@click.option("--no-new-sources", is_flag=True)
@click.option("--upstream-ref")
@click.argument("repo")
@click.argument("version")
@pass_config
def sg2dg(config, dest_dir, no_new_sources, upstream_ref, repo, version):
    """
    Convert source-git repo to dist-git repo.

    1. Create tarball from the source git repo.

    2. Create patches from the downstream commits.

    3. Copy the redhat/ dir to the dist-git.

    4. Take the tarball and upload it to lookaside cache.

    5. The output is the directory (= dirty git repo)
Ejemplo n.º 9
0
from os import getcwd
from pathlib import Path
from typing import Optional

import click

from packit.cli.types import LocalProjectParameter
from packit.cli.utils import cover_packit_exception
from packit.config import get_context_settings
from packit.constants import CONFIG_FILE_NAMES, PACKIT_CONFIG_TEMPLATE
from packit.exceptions import PackitException

logger = logging.getLogger(__name__)


@click.command("generate", context_settings=get_context_settings())
@click.argument("path_or_url", type=LocalProjectParameter(), default=getcwd())
@click.option("-f",
              "--force",
              is_flag=True,
              help="Reset config to default if already exists.")
@cover_packit_exception
def generate(path_or_url, force):
    """
    Generate new packit config.
    """
    working_dir = Path(path_or_url.working_dir)
    config_path = get_existing_config(working_dir)
    if config_path:
        if not force:
            raise PackitException(
Ejemplo n.º 10
0
"""
This bot will listen on fedmsg for finished CI runs and will update respective source gits
"""
import logging

import click

from packit.api import PackitAPI
from packit.cli.utils import cover_packit_exception
from packit.config import get_context_settings, pass_config

logger = logging.getLogger(__name__)


@click.command("watch-fedora-ci", context_settings=get_context_settings())
@click.argument("message_id", nargs=-1, required=False)
@pass_config
@cover_packit_exception
def watcher(config, message_id):
    """
    Watch for flags on PRs: try to process those which we know mapping for

    :return: int, retcode
    """
    api = PackitAPI(config)

    if message_id:
        for msg_id in message_id:
            fedmsg_dict = api.fetch_fedmsg_dict(msg_id)
            api.process_ci_result(fedmsg_dict)
            return
Ejemplo n.º 11
0
import logging
import os

import click

from packit.api import PackitAPI
from packit.cli.types import LocalProjectParameter
from packit.cli.utils import cover_packit_exception
from packit.config import get_context_settings
from packit.local_project import LocalProject

logger = logging.getLogger(__name__)


@click.command("validate-config", context_settings=get_context_settings())
@click.argument("path_or_url",
                type=LocalProjectParameter(),
                default=os.path.curdir)
@cover_packit_exception
def validate_config(path_or_url: LocalProject):
    """
    Validate PackageConfig validation.

    \b
    - checks missing values
    - checks incorrect types

    PATH_OR_URL argument is a local path or a URL to a git repository with packit configuration file
    """
    # we use PackageConfig.load_from_dict for the validation, hence we don't parse it here
Ejemplo n.º 12
0
import os
from typing import Optional, List

import click

from packit.cli.types import LocalProjectParameter
from packit.cli.utils import cover_packit_exception, get_packit_api
from packit.config import pass_config, get_context_settings, PackageConfig
from packit.config.aliases import get_valid_build_targets, DEPRECATED_TARGET_MAP
from packit.utils import sanitize_branch_name
from packit.utils.changelog_helper import ChangelogHelper

logger = logging.getLogger(__name__)


@click.command("in-copr", context_settings=get_context_settings())
@click.option("--nowait", is_flag=True, default=False, help="Don't wait for build")
@click.option(
    "--owner",
    help="Copr user, owner of the project. (defaults to username from copr config)",
)
@click.option(
    "--project",
    help="Project name to build in. Will be created if does not exist. "
    "(defaults to the first found project value in the config file or "
    "'packit-cli-{repo_name}-{branch/commit}')",
)
@click.option(
    "--targets",
    help="Comma separated list of chroots to build in. (defaults to 'fedora-rawhide-x86_64')",
    default="fedora-rawhide-x86_64",
Ejemplo n.º 13
0
def get_dg_branches(api, dist_git_branch):
    cmdline_dg_branches = dist_git_branch.split(",") if dist_git_branch else []
    config_dg_branches = []
    if isinstance(api.package_config, PackageConfig):
        config_dg_branches = (
            api.package_config.get_propose_downstream_dg_branches_value())

    default_dg_branch = api.dg.local_project.git_project.default_branch

    dg_branches = (cmdline_dg_branches or config_dg_branches
                   or default_dg_branch.split(","))

    return get_branches(*dg_branches, default_dg_branch=default_dg_branch)


@click.command("propose-downstream", context_settings=get_context_settings())
@click.option(
    "--dist-git-branch",
    help="Comma separated list of target branches in dist-git to release into. "
    "(defaults to all branches)",
)
@click.option(
    "--dist-git-path",
    help="Path to dist-git repo to work in. "
    "Otherwise clone the repo in a temporary directory.",
)
@click.option(
    "--local-content",
    is_flag=True,
    default=False,
    help="Do not checkout release tag. Use the current state of the repo. "
Ejemplo n.º 14
0
from os import getcwd

import click

from packit.cli.types import LocalProjectParameter
from packit.cli.utils import cover_packit_exception, get_packit_api
from packit.config import pass_config, get_context_settings
from packit.config.aliases import get_branches, get_koji_targets
from packit.exceptions import PackitCommandFailedError, ensure_str
from packit.exceptions import PackitConfigException
from packit.utils.changelog_helper import ChangelogHelper

logger = logging.getLogger(__name__)


@click.command("in-koji", context_settings=get_context_settings())
@click.option(
    "--dist-git-branch",
    help="Comma separated list of target branches in dist-git to release into. "
    "(defaults to repo's default branch)",
)
@click.option(
    "--dist-git-path",
    help="Path to dist-git repo to work in. "
    "Otherwise clone the repo in a temporary directory.",
)
@click.option(
    "--from-upstream",
    help="Build the project in koji directly from the upstream repository",
    is_flag=True,
    default=False,
Ejemplo n.º 15
0
import logging

import click
from packit.config import get_context_settings
from packit.utils import set_logging
from pkg_resources import get_distribution

from packit_service.cli.process_message import process_message
from packit_service.cli.listen_to_fedmsg import listen_to_fedmsg
from packit_service.config import Config

logger = logging.getLogger("packit_service")


@click.group("packit", context_settings=get_context_settings())
@click.option("-d", "--debug", is_flag=True, help="Enable debug logs.")
@click.option("--fas-user", help="Fedora Account System username.")
@click.option("-k", "--keytab", help="Path to FAS keytab file.")
@click.pass_context
def packit_base(ctx, debug, fas_user, keytab):
    """Integrate upstream open source projects into Fedora operating system."""
    c = Config.get_service_config()
    c.debug = debug or c.debug
    c.fas_user = fas_user or c.fas_user
    c.keytab_path = keytab or c.keytab_path
    ctx.obj = c
    if ctx.obj.debug:
        set_logging(level=logging.DEBUG)
        logger.debug("logging set to DEBUG")
    else:
Ejemplo n.º 16
0
Update selected component from upstream in Fedora
"""

import logging
from os import getcwd

import click

from packit.cli.types import LocalProjectParameter
from packit.cli.utils import cover_packit_exception, get_packit_api
from packit.config import pass_config, get_context_settings

logger = logging.getLogger(__file__)


@click.command("propose-update", context_settings=get_context_settings())
@click.option(
    "--dist-git-branch",
    help="Target branch in dist-git to release into.",
    default="master",
)
@click.option(
    "--dist-git-path",
    help="Path to dist-git repo to work in. "
    "Otherwise clone the repo in a temporary directory.",
)
@click.option(
    "--local-content",
    is_flag=True,
    default=False,
    help="Do not checkout release tag. Use the current state of the repo.",
Ejemplo n.º 17
0
import logging
import os

import click

from packit.cli.types import LocalProjectParameter
from packit.cli.utils import cover_packit_exception, get_packit_api
from packit.config import pass_config, get_context_settings
from packit.config.aliases import get_branches
from packit.constants import DEFAULT_BODHI_NOTE

logger = logging.getLogger(__name__)


@click.command("create-update", context_settings=get_context_settings())
@click.option(
    "--dist-git-branch",
    help="Comma separated list of target branches in dist-git to create bodhi update in. "
    "(defaults to repo's default branch)",
)
@click.option(
    "--koji-build",
    help="Koji build (NVR) to add to the bodhi update (can be specified multiple times)",
    required=False,
    multiple=True,
)
# It would make sense to open an editor here,
# just like `git commit` and get notes like that
@click.option(
    "--update-notes",
Ejemplo n.º 18
0
# Copyright Contributors to the Packit project.
# SPDX-License-Identifier: MIT

import logging
import os

import click

from packit.cli.types import LocalProjectParameter
from packit.cli.utils import cover_packit_exception, get_packit_api
from packit.config import pass_config, get_context_settings

logger = logging.getLogger("packit")


@click.command("local-build", context_settings=get_context_settings())
@click.option(
    "--upstream-ref",
    default=None,
    help="Git ref of the last upstream commit in the current branch "
    "from which packit should generate patches "
    "(this option implies the repository is source-git).",
)
@click.argument(
    "path_or_url",
    type=LocalProjectParameter(),
    default=os.path.curdir,
)
@pass_config
@cover_packit_exception
def local_build(config, path_or_url, upstream_ref):
Ejemplo n.º 19
0
import logging
import os

import click

from packit.cli.utils import cover_packit_exception
from packit.config import pass_config, get_context_settings, get_local_package_config
from packit.local_project import LocalProject

logger = logging.getLogger(__file__)


@click.command("srpm", context_settings=get_context_settings())
@click.option("--dest-dir")
@click.option("--upstream-ref")
@click.option("--version")
@click.argument("repo", default=os.path.abspath(os.path.curdir))
@pass_config
@cover_packit_exception
def sg2srpm(config, dest_dir, upstream_ref, version, repo):
    """
    Generate a srpm from packit.

    This script is meant to accept a source git repo with a branch as an input and produce a SRPM.

    It is expected to do this:

    1. clone the repo

    2. create archive out of the sources
Ejemplo n.º 20
0
from packit.config import pass_config, get_context_settings
from packit.schema import JobConfigSchema

logger = logging.getLogger("packit")


def load_job_config(job_config):
    if job_config:
        try:
            return JobConfigSchema().loads(job_config)
        except Exception as ex:
            logger.error(f"Loading of JobConfig wasn't successful: {ex}")
    return None


@click.command("prepare-sources", context_settings=get_context_settings())
@click.option(
    "--result-dir",
    metavar="DIR",
    help=
    "Copy the sources into DIR. By default, `prepare_sources_result` directory "
    "in the current working directory is created.",
)
@click.option(
    "--upstream-ref",
    default=None,
    help="Git ref of the last upstream commit in the current branch "
    "from which packit should generate patches "
    "(this option implies the repository is source-git).",
)
@click.option(
Ejemplo n.º 21
0
"""

import logging
import os

import click

from packit.cli.types import LocalProjectParameter
from packit.cli.utils import cover_packit_exception
from packit.config import pass_config, get_context_settings
from packit.cli.utils import get_packit_api

logger = logging.getLogger(__file__)


@click.command("status", context_settings=get_context_settings())
@click.argument("path_or_url",
                type=LocalProjectParameter(),
                default=os.path.abspath(os.path.curdir))
@pass_config
@cover_packit_exception
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
Ejemplo n.º 22
0
# SPDX-License-Identifier: MIT

import logging
import os

import click

from packit.cli.types import LocalProjectParameter
from packit.cli.utils import cover_packit_exception, get_packit_api
from packit.config import pass_config, get_context_settings
from packit.utils.changelog_helper import ChangelogHelper

logger = logging.getLogger("packit")


@click.command("in-mock", context_settings=get_context_settings())
@click.option(
    "--upstream-ref",
    default=None,
    help="Git ref of the last upstream commit in the current branch "
    "from which packit should generate patches "
    "(this option implies the repository is source-git).",
)
@click.option(
    "--release-suffix",
    default=None,
    type=click.STRING,
    help="Specifies release suffix. Allows to override default generated:"
    "{current_time}.{sanitized_current_branch}{git_desc_suffix}",
)
@click.option(