from typing import Tuple
from typing import Optional
import re


def parse_git_url(git_url: str) -> Tuple[Optional[str], Optional[str], Optional[str]]:
    """Parse the git url.

    Args:
        git_url (str): url of a git repository (https or ssh)

    Returns:
        (str, str, str): tupple of domain, user and project name parsed from url
    """
    regex = re.compile(
        r"(?:git@|https:\/\/)"  # Prefix
        r"([\w\-_\.]+)"  # Domain
        r"[:\/]"  # Separator : or /
        r"([\w\-_\.\/]+)"  # User or folders
        r"[\/]"  # Separator /
        r"([\w\-_]+)"  # Project name
        r"(?:.git)*$"
    )  # .git or nothing
    match = regex.search(git_url)
    if not match:
        return None, None, None
    domain, user, project = match.groups()
    return domain, user, project