Return an incremented version string.

def increment(version):
        """Return an incremented version string."""
        release_version = os.environ.get("RELEASE_VERSION", None)
        if release_version is not None:
            return release_version
        if isinstance(version, LegacyVersion):
            msg = """{0} is considered a legacy version and does not
            support automatic incrementing.  Please bring your version
            numbering into PEP440 standards and then it can be
            automatically incremented.
            """
            raise Exception(msg.format(version))
        release_type = os.environ.get("RELEASE_TYPE", "micro")
        v = version._version
        # epoch
        epoch_name, epoch = VersionUtils.get_version_number(v, 0, None, "!")
        pre_name, pre = VersionUtils.get_version_number(v, 3, None, "pre")
        post_name, post = VersionUtils.get_version_number(v, 4, None, "post")
        dev_name, dev = VersionUtils.get_version_number(v, 2, None, "dev")
        _, major = VersionUtils.get_version_number(v[1], 0, 0)
        _, minor = VersionUtils.get_version_number(v[1], 1, None)
        _, micro = VersionUtils.get_version_number(v[1], 2, None)

        # Handle dev/pre/post
        if release_type == "pre":
            micro, post, pre = VersionUtils.process_pre(micro, post, pre)

        if release_type == "post":
            dev, post = VersionUtils.process_post(dev, post)

        if release_type == "dev":
            dev = VersionUtils.process_dev(dev)

        if release_type == "micro":
            dev, micro, minor, post, pre = VersionUtils.process_micro(
                dev, micro, minor, post, pre
            )

        if release_type == "minor":
            dev, micro, minor, post, pre = VersionUtils.process_minor(
                dev, micro, minor, post, pre
            )

        if release_type == "major":
            dev, major, micro, minor, post, pre = VersionUtils.process_major(
                dev, major, micro, minor, post, pre
            )

        # Handle Epoch
        if release_type == "epoch":
            dev, epoch, major, micro, minor, post, pre = VersionUtils.process_epoch(
                dev, epoch, major, micro, minor, post, pre
            )

        local = "".join(v[5] or []) or None

        version_list = [major, minor, micro]
        if release_type not in ["epoch", "major", "minor", "micro", "pre"]:
            version_list += list(v[1][3:])
        version_string = ".".join([str(x) for x in version_list if x or x == 0])

        if epoch:
            version_string = str(epoch) + epoch_name + version_string
        if pre is not None:
            version_string = VersionUtils.calc_pre_version_string(
                pre, pre_name, version_string
            )
        if post is not None:
            version_string += "." + post_name + str(post)
        if dev is not None:
            version_string += "." + dev_name + str(dev)
        if local is not None:
            version_string += "." + str(local)

        return version_string