You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
2.1 KiB

2 years ago
  1. """Generate a message to ping people responsible for one or more files.
  2. """
  3. from pathlib import Path
  4. from milc import cli
  5. from qmk.maintainers import maintainers
  6. @cli.argument('--pr', type=int, arg_only=True, help="PR to send ping to (optional)")
  7. @cli.argument('--owner', default='qmk', arg_only=True, help="Owner for the repo (Default: qmk)")
  8. @cli.argument('--repo', default='qmk_firmware', arg_only=True, help="Repo to send pings to (Default: qmk_firmware)")
  9. @cli.argument("files", type=Path, arg_only=True, nargs='*', help="File to ping maintainers for.")
  10. @cli.subcommand("Ping the maintainers and request reviews for one or more files.")
  11. def ping_maintainers(cli):
  12. """Ping the maintainers for one or more files.
  13. """
  14. github_maintainers = set()
  15. github_teams = set()
  16. for file in cli.args.files:
  17. for maintainer in maintainers(file):
  18. if '/' in maintainer:
  19. github_teams.add(maintainer)
  20. else:
  21. github_maintainers.add(maintainer)
  22. if cli.args.pr:
  23. from ghapi.all import GhApi
  24. ghapi = GhApi(owner=cli.args.owner, repo=cli.args.repo)
  25. pr = ghapi.pulls.get(cli.args.pr)
  26. if not pr.draft:
  27. for team in pr.requested_teams:
  28. team_name = f'@{cli.args.owner}/{team.slug}'
  29. if team_name in github_teams:
  30. cli.log.info('Found %s in reviews already, skipping', team_name)
  31. github_teams.remove(team_name)
  32. for team in github_teams:
  33. cli.log.info('Requesting review from team %s', team.split('/', 1)[1])
  34. ghapi.pulls.request_reviewers(pull_number=cli.args.pr, team_reviewers=team.split('/', 1)[1])
  35. if github_maintainers:
  36. ghapi.issues.create_comment(cli.args.pr, f'If you were pinged by this comment you have one or more files being changed by this PR: {" ".join(sorted(github_maintainers))}')
  37. else:
  38. print(f'Team Reviews: {" ".join(sorted(github_teams))}')
  39. print(f'Individual Reviews: {" ".join(sorted(github_maintainers))}')