Example #1
0
def check_changed_files(pr_num, bad_phrase=BAD_PHRASE):
    """Check the files in a Pull Request for an undesirable phrase

    Arguments:
        pr_num {str} -- Number of the Pull Request with modified files

    Keyword Arguments:
        bad_phrase {str} -- The undesirable phrase to check for (default: {BAD_PHRASE})

    Returns:
        {list} -- List of filenames that contain the undesirable phrase
    """
    filenames = filter_files(pr_num)
    failed = []

    for filename in filenames:
        try:
            with open(
            os.path.join(ABSOLUTE_HERE, filename), encoding="utf8", errors="ignore"
            ) as f:
                text = f.read()
                text = remove_comments(text)
                if bad_phrase in text.lower():
                    failed.append(filename.name)
        except FileNotFoundError:
            pass

    return failed
Example #2
0
def main():
    """Main function"""
    args = parse_args()

    if args.pull_request is not None:
        files = filter_files(args.pull_request)
    else:
        files = get_all_files()

    failing_files = read_and_check_files(files)

    if bool(failing_files):
        error_message = construct_error_message(failing_files)
        raise Exception(error_message)