예제 #1
0
파일: check_pr.py 프로젝트: SDxKeeper/dldt
def update_labels(gh_api, pull, non_org_intel_pr_users, non_org_pr_users):
    """Checks and updates labels"""
    print("Check and update labels:")
    pr_type_by_labels = get_pr_type_by_labels(pull)
    add_labels = []

    # Checks PR source type
    if gh_api.is_org_user(pull.user):
        print(" - Org user")
    elif github_api.is_intel_email(
            pull.user.email) or github_api.is_intel_company(pull.user.company):
        print(" - Non org user with Intel email or company")
        non_org_intel_pr_users.add(pull.user)
        if pr_type_by_labels is not PrType.INTEL:
            print(f'NO "{PrType.INTEL.value}" label: ', end="")
            github_api.print_users(pull.user)
            add_labels.append(PrType.INTEL.value)
    elif github_api.is_user_ignored(pull.user):
        print(" - IGNORED non org user with NO Intel email or company")
    else:
        print(" - Non org user with NO Intel email or company")
        non_org_pr_users.add(pull.user)
        if pr_type_by_labels is not PrType.EXTERNAL:
            print(f'NO "{PrType.EXTERNAL.value}" label: ', end="")
            github_api.print_users(pull.user)
            add_labels.append(PrType.EXTERNAL.value)

    add_labels += get_category_labels(pull)
    add_pr_labels(pull, add_labels)
예제 #2
0
def main():
    """The main entry point function"""
    arg_parser = ArgumentParser()
    arg_parser.add_argument(
        "--cfg-file",
        metavar="PATH",
        default=Config.default_cfg_path,
        help=f"Path to json configuration file, e.g. {Config.default_cfg_path}"
    )
    arg_parser.add_argument("--pr",
                            metavar="NUMBER",
                            help="Get GitHub pull request with the number")
    arg_parser.add_argument("--pr-state",
                            default="open",
                            choices=["open", "closed"],
                            help="Set GitHub pull request state")
    arg_parser.add_argument("--newer",
                            metavar="MINUTES",
                            help="Get newly created GitHub pull request only")
    args, unknown_args = arg_parser.parse_known_args()

    Config(args.cfg_file, unknown_args)
    gh_api = github_api.GithubOrgApi()

    if args.pr:
        pulls = [gh_api.repo.get_pull(int(args.pr))]
    else:
        pulls = gh_api.repo.get_pulls(state=args.pr_state)
        print(f'\nPRs count ({args.pr_state}):', pulls.totalCount)

    if args.newer:
        pr_created_after = (
            datetime.datetime.now() -
            datetime.timedelta(minutes=int(args.newer))).astimezone()
        print('Checking PRs created after:', pr_created_after)
    non_org_intel_pr_users = set()
    non_org_pr_users = set()
    for pull in pulls:
        pr_created_at = pull.created_at.replace(
            tzinfo=datetime.timezone.utc).astimezone()
        if args.newer and pr_created_at <= pr_created_after:
            print(f'\nIGNORE: {get_pr_info_str(pull)}')
            continue
        pr_type_by_labels = get_pr_type_by_labels(pull)
        add_labels = []
        print(f'\n{get_pr_info_str(pull)}', end='')

        # Checks PR source type
        if gh_api.is_org_user(pull.user):
            print(' - Org user')
        elif github_api.is_intel_email(pull.user.email) or \
             github_api.is_intel_company(pull.user.company):
            print(' - Non org user with Intel email or company')
            non_org_intel_pr_users.add(pull.user)
            if pr_type_by_labels is not PrType.INTEL:
                print(f'NO "{PrType.INTEL.value}" label: ', end='')
                github_api.print_users(pull.user)
                add_labels.append(PrType.INTEL.value)
        elif github_api.is_user_ignored(pull.user):
            print(' - IGNORED non org user with NO Intel email or company')
        else:
            print(' - Non org user with NO Intel email or company')
            non_org_pr_users.add(pull.user)
            if pr_type_by_labels is not PrType.EXTERNAL:
                print(f'NO "{PrType.EXTERNAL.value}" label: ', end='')
                github_api.print_users(pull.user)
                add_labels.append(PrType.EXTERNAL.value)

        add_labels += get_category_labels(pull)
        add_pr_labels(pull, add_labels)

    print('\nNon org user with Intel email or company:')
    github_api.print_users(non_org_intel_pr_users)
    print('\nNon org user with NO Intel email or company:')
    github_api.print_users(non_org_pr_users)