def get_contact_name_and_email(github_repo, git_repo):
    """Get the name and email of the person to be contacted for the repo.

    The priority order is the most frequent contributors(up to three).
    If the name or email is empty, the next item is tried.
    If no contributor with name and email is found, the name and email of
    the last committer on the default branch is selected.

    Contact rank:
        1..3 = contributor rank
        4 = last committer on default the branch

    Args:
        github_repo: The GitHub repo
        git_repo: The cloned git repo.
    Returns:
        Tuple with name, email and contact rank.
    """
    name = ""
    email = ""
    contributors = github_repo.get_contributors()
    for i, contributor in enumerate(contributors, start=1):
        name = contributor.name
        email = contributor.email
        if name and email:
            return name, email, i
        if i >= 3:
            break

    # Fallback to name and email of last commit on default branch
    git_repo.git.switch(github_repo.default_branch)
    last_commit = git_repo.head.commit
    author_email = git_repo.git.show("-s", "--format=%ae", last_commit.hexsha)
    return last_commit.author.name, author_email, 4