import re
from urllib.parse import urlparse
import logging

def check_url_is_http(repo_url):
    predicate = re.compile('^https?://.*$')
    match = predicate.search(repo_url)
    return False if match is None else True

def check_url_is_ssh(repo_url):
    predicate = re.compile(r'^git\@.*\.git$')
    match = predicate.search(repo_url)
    return False if match is None else True

def get_domain_name_from_http_url(repo_url):
    site_object = urlparse(repo_url)
    return site_object.netloc

def get_repo_name_from_http_url(repo_url):
    site_object = urlparse(repo_url)
    parsed_string = re.sub(r'\.git$', '', site_object.path)
    if parsed_string[0] == '/':
        return parsed_string[1:]
    return parsed_string

def get_repo_name_from_ssh_url(repo_url):
    predicate = re.compile(r'(?<=\:)(.*)(?=\.)')
    match = predicate.search(repo_url)
    return match.group()

def get_domain_name_from_ssh_url(repo_url):
    predicate = re.compile(r'(?<=\@)(.*)(?=\:)')
    match = predicate.search(repo_url)
    return match.group()

def validate_protocol_exists(is_ssh, is_http):
    if not is_ssh and not is_http:
        err_message = "Error: repository url provided is not http(s) or ssh"
        logging.critical(err_message)
        raise RuntimeError(err_message)

def check_url_protocol(repo_url):
    is_ssh = check_url_is_ssh(repo_url)
    is_http = check_url_is_http(repo_url)
    validate_protocol_exists(is_ssh, is_http)
    return (is_ssh, is_http)

[((109, 136), 're.compile', 're.compile', (['"""^https?://.*$"""'], {}), "('^https?://.*$')\n", (119, 136), False, 'import re\n'), ((269, 299), 're.compile', 're.compile', (['"""^git\\\\@.*\\\\.git$"""'], {}), "('^git\\\\@.*\\\\.git$')\n", (279, 299), False, 'import re\n'), ((446, 464), 'urllib.parse.urlparse', 'urlparse', (['repo_url'], {}), '(repo_url)\n', (454, 464), False, 'from urllib.parse import urlparse\n'), ((557, 575), 'urllib.parse.urlparse', 'urlparse', (['repo_url'], {}), '(repo_url)\n', (565, 575), False, 'from urllib.parse import urlparse\n'), ((596, 635), 're.sub', 're.sub', (['"""\\\\.git$"""', '""""""', 'site_object.path'], {}), "('\\\\.git$', '', site_object.path)\n", (602, 635), False, 'import re\n'), ((785, 818), 're.compile', 're.compile', (['"""(?<=\\\\:)(.*)(?=\\\\.)"""'], {}), "('(?<=\\\\:)(.*)(?=\\\\.)')\n", (795, 818), False, 'import re\n'), ((943, 976), 're.compile', 're.compile', (['"""(?<=\\\\@)(.*)(?=\\\\:)"""'], {}), "('(?<=\\\\@)(.*)(?=\\\\:)')\n", (953, 976), False, 'import re\n'), ((1208, 1237), 'logging.critical', 'logging.critical', (['err_message'], {}), '(err_message)\n', (1224, 1237), False, 'import logging\n')]