import re


def _get_git_ref_from_chartpress_based_version(version):
    """
    Get a git ref from a chartpress set version of format like
    1.2.3-beta.1.n123.h1234567, 1.2.3-n123.h1234567, or 1.2.3.
    """
    tag_hash_split = re.split("[\.|-]n\d\d\d\.h", version)
    if len(tag_hash_split) == 2:
        return tag_hash_split[1]
    else:
        return tag_hash_split[0]