from typing import List


def get_new_tags(newversion, existing_verions) -> List[str]:
    """
    Taka a version (newversion) and return the relevant tags we should set on this:

    So for the following:
    0.1.0, 0.2.0, 0.3.0

    If we get 0.2.1 we should set the following:
     0.2.1, 0.2
     Not 0 as 0.3.0 should point to 0 and 0.3

    Rules for return values:
     * always return the full (1.2.3)
     * always return major.minor (1.2)
     * if we're the highest minor in the major version we're on then we return the major as well (1)
     * if the major doesn't exists return the major (1)
    """
    major, minor, patch, prerelease, buildmetadata = newversion
    if prerelease is not None:
        prerelease = '-' + newversion[3]
    else:
        prerelease = ''
    if (major, minor, patch) in existing_verions:
        raise ValueError("Version already exists")

    tags = []

    tags.append(f"{major}.{minor}.{patch}{prerelease}")
    tags.append(f"{major}.{minor}{prerelease}")

    majors = [ver[0] for ver in existing_verions]
    our_minors = [ver[1] for ver in existing_verions if ver[1] != None and ver[0] == major]
    if major not in majors:
        tags.append(f"{major}{prerelease}")
    elif max(our_minors) <= minor:
        tags.append(f"{major}{prerelease}")
    return tags