def _best_local_candidate(local_candidates, git_repo):
    """
    Given @local_candidates, a list of LocalCandidate named tuples,
    scraped from a diffscuss file, return the best candidate.

    The best candidate is:

    * the earliest candidate in the list where the matching line was
      found

    * or the earliest candidate in the list, if none of the matching
      lines were found
    """
    best_candidate = None

    for candidate in local_candidates:
        if best_candidate is None:
            best_candidate = candidate
        elif candidate.found_match and not best_candidate.found_match:
            best_candidate = candidate

    return best_candidate