Beispiel #1
0
def find(_, name, commit=None):
    """
    Search a release from the commit hash.
    """
    repo = utils.git_repo()
    commit = commit or next(utils.git_log(repo)).hex

    client = utils.s3_client()

    releases = {
        release.commit: release
        for release in get_releases(client, name)
    }

    release = None
    for log in utils.git_log(repo):
        release = releases.get(log.hex, release)

        if commit == log.hex:
            break

    if release:
        utils.printfmt(release)

    else:
        LOG.error("commit not released yet")
Beispiel #2
0
def find(_, name, commit=None, profile=None):
    """
    Find the first release containing a specific commit.
    """
    if commit is None:
        commit = "HEAD"

    repo = utils.git_repo()
    oid = utils.revparse(repo, commit)

    client = utils.s3_client(profile)

    releases = {
        release.commit: release
        for release in get_releases(client, name)
    }

    release = None
    for log in utils.git_log(repo):
        if log.hex in releases:
            release = releases[log.hex]

        if oid.hex == log.hex:
            break

    if release:
        utils.printfmt(release)

    else:
        LOG.error("Commit not released yet")
Beispiel #3
0
def new(
    ctx,
    name,
    commit=None,
    version=None,
    dry=False,
    yes=False,
    image_name=None,
    rollback=False,
):
    """
    Create a new release.
    """
    repo = utils.git_repo()

    client = utils.s3_client()
    latest = next(get_releases(client, name), None)

    if commit is None:
        # get last commit
        commit = next(utils.git_log(repo), None)
        commit = commit and commit.hex

    if version is None:
        # crate next version
        version = 1 if latest is None else latest.version + 1

    else:
        version = int(version)

    image_id = _get_image_id(ctx, image_name or name, commit)
    if image_id is None:
        LOG.critical("image ID not found")
        sys.exit(1)

    changelog = utils.changelog(repo, commit, latest and latest.commit)

    release = Release(
        version=version,
        commit=commit,
        changelog=changelog.text,
        version_id="",
        image=image_id,
        timestamp=datetime.now(),
        author=utils.get_author(repo),
        rollback=changelog.rollback,
    )

    utils.printfmt(release)

    if dry:
        return

    if release.rollback:
        utils.warning("this is a rollback! :warning:\n")

        if not rollback:
            utils.warning("missing flag --rollback\n")
            utils.error("aborted!\n")
            sys.exit(1)

    if not yes:

        if release.rollback:
            ok = utils.confirm("sure you want to start a rollback?",
                               style=utils.TextStyle.warning)

            if not ok:
                utils.error("aborted!\n")
                sys.exit(1)

        ok = utils.confirm("sure you want to create this release?")
        if not ok:
            sys.exit(1)

    put_release(client,
                utils.get_config()["release"]["s3_bucket"], name, release)

    utils.success("created new release :tada:\n")