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("--teams", action="store_true", help="Check GitHub teams") args, unknown_args = arg_parser.parse_known_args() Config(args.cfg_file, unknown_args) gh_api = github_api.GithubOrgApi() if args.teams: gh_api.get_org_teams() else: dev_emails = github_api.get_dev_emails() print(f'\nDeveloper emails {len(dev_emails)}:', '; '.join(dev_emails)) org_emails = gh_api.get_org_emails() print(f'\nOrg emails {len(org_emails)}:', '; '.join(org_emails)) org_pendig_invitation_emails = gh_api.get_org_invitation_emails() invite_emails = dev_emails.difference(org_emails).difference( org_pendig_invitation_emails) print(f'\nInvite emails {len(invite_emails)}:', '; '.join(invite_emails)) no_in_dev_emails = org_emails.difference(dev_emails) print( f'\nOrg members - no in developers list {len(no_in_dev_emails)}:', '; '.join(no_in_dev_emails)) valid_github_users = gh_api.get_valid_github_users(invite_emails) gh_api.invite_users(valid_github_users)
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") arg_parser.add_argument( "--check-commits", action="store_true", help="Check and compare git commit email with GitHub account email", ) 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() wrong_pulls = {} 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 print(f"\n{get_pr_info_str(pull)}") if args.check_commits: wrong_commits = get_wrong_commits(pull) if wrong_commits: wrong_pulls[pull.number] = wrong_commits else: update_labels(gh_api, pull, non_org_intel_pr_users, non_org_pr_users) if wrong_pulls: for pull_number, wrong_commits in wrong_pulls.items(): print( f"\nERROR: Remove or replace wrong commits in the PR {pull_number}:\n ", "\n ".join(wrong_commits), ) print( "\nAbout commit signature verification:\n ", "https://docs.github.com/en/github/authenticating-to-github/" "managing-commit-signature-verification/about-commit-signature-verification", ) sys.exit(1) if non_org_intel_pr_users: print("\nNon org user with Intel email or company:") github_api.print_users(non_org_intel_pr_users) if non_org_pr_users: print("\nNon org user with NO Intel email or company:") github_api.print_users(non_org_pr_users)
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)) print('PRs created after:', pr_created_after) non_org_intel_pr_users = set() non_org_pr_users = set() for pull in pulls: if args.newer and pull.created_at <= pr_created_after: print(f'\nIGNORE: {pull} - Created: {pull.created_at}') continue pr_lables = get_pr_labels(pull) pr_type_by_labels = get_pr_type_by_labels(pull) set_labels = [] print(f'\n{pull} - Created: {pull.created_at} - Labels: {pr_lables} -', f'Type: {pr_type_by_labels}', 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) set_labels.append(PrType.INTEL.value) else: print(f' - 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) set_labels.append(PrType.EXTERNAL.value) set_labels += get_category_labels(pull) set_pr_labels(pull, set_labels) print(f'\nNon org user with Intel email or company:') github_api.print_users(non_org_intel_pr_users) print(f'\nNon org user with NO Intel email or company:') github_api.print_users(non_org_pr_users)
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") 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'PRs count ({args.pr_state}):', pulls.totalCount) non_org_intel_pr_users = set() non_org_pr_users = set() set_labels = [] for pull in pulls: pr_lables = get_pr_labels(pull) pr_type = get_pr_type(pull) print('\n', pull, f'- Labels: {pr_lables} -', f'Type: {pr_type}', end='') if gh_api.is_org_user(pull.user): print(' - Org user') if pr_type is not PrType.ORG: print(f'NO "{PrType.ORG.value}" label - ', end='') github_api.print_users(pull.user) set_labels.append(PrType.ORG.value) 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 is not PrType.INTEL: print(f'NO "{PrType.INTEL.value}" label - ', end='') github_api.print_users(pull.user) set_labels.append(PrType.INTEL.value) else: print(f' - Non org user with NO Intel email or company') non_org_pr_users.add(pull.user) if pr_type is not PrType.EXTERNAL: print(f'NO "{PrType.EXTERNAL.value}" label - ', end='') github_api.print_users(pull.user) set_labels.append(PrType.EXTERNAL.value) print('Add category labels: ', end='') for reviewer_team in pull.get_review_requests()[1]: reviewer_label = get_label_by_team_name(reviewer_team.name) if reviewer_label and reviewer_label not in pr_lables: print(get_label_by_team_name(reviewer_team.name), '| ', end='') set_labels.append(reviewer_label) print() set_pr_label(pull, set_labels) print(f'\nNon org user with Intel email or company:') github_api.print_users(non_org_intel_pr_users) print(f'\nNon org user with NO Intel email or company:') github_api.print_users(non_org_pr_users)