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)

[((6, 16, 6, 43), 're.compile', 're.compile', ({(6, 27, 6, 42): '"""^https?://.*$"""'}, {}), "('^https?://.*$')", False, 'import re\n'), ((11, 16, 11, 45), 're.compile', 're.compile', ({(11, 27, 11, 44): '"""^git\\\\@.*\\\\.git$"""'}, {}), "('^git\\\\@.*\\\\.git$')", False, 'import re\n'), ((16, 18, 16, 36), 'urllib.parse.urlparse', 'urlparse', ({(16, 27, 16, 35): 'repo_url'}, {}), '(repo_url)', False, 'from urllib.parse import urlparse\n'), ((20, 18, 20, 36), 'urllib.parse.urlparse', 'urlparse', ({(20, 27, 20, 35): 'repo_url'}, {}), '(repo_url)', False, 'from urllib.parse import urlparse\n'), ((21, 20, 21, 59), 're.sub', 're.sub', ({(21, 27, 21, 36): '"""\\\\.git$"""', (21, 38, 21, 40): '""""""', (21, 42, 21, 58): 'site_object.path'}, {}), "('\\\\.git$', '', site_object.path)", False, 'import re\n'), ((27, 16, 27, 48), 're.compile', 're.compile', ({(27, 27, 27, 47): '"""(?<=\\\\:)(.*)(?=\\\\.)"""'}, {}), "('(?<=\\\\:)(.*)(?=\\\\.)')", False, 'import re\n'), ((32, 16, 32, 48), 're.compile', 're.compile', ({(32, 27, 32, 47): '"""(?<=\\\\@)(.*)(?=\\\\:)"""'}, {}), "('(?<=\\\\@)(.*)(?=\\\\:)')", False, 'import re\n'), ((39, 8, 39, 37), 'logging.critical', 'logging.critical', ({(39, 25, 39, 36): 'err_message'}, {}), '(err_message)', False, 'import logging\n')]