add the pr comment ourselves and request reviews

This commit is contained in:
Zach White 2021-09-21 14:28:28 -07:00
parent 1db04e4622
commit 610111583b
3 changed files with 37 additions and 15 deletions

View file

@ -23,13 +23,6 @@ jobs:
- name: Install dependencies - name: Install dependencies
run: pip3 install -r requirements-dev.txt run: pip3 install -r requirements-dev.txt
- name: Get our ping message - name: Ping maintainers and request reviews
shell: "bash {0}" shell: "bash {0}"
run: echo "ping_message=$(qmk ping-maintainers $(< ~/files.txt))" > $GITHUB_ENV run: qmk ping-maintainers --pr ${{ github.event.number }} ${{ steps.file_changes.outputs.files }}
- uses: mshick/add-pr-comment@v1
with:
message: ${{ env.ping_message }}
repo-token: ${{ secrets.GITHUB_TOKEN }}
repo-token-user-login: "github-actions[bot]" # The user.login for temporary GitHub tokens
allow-repeats: false # This is the default

View file

@ -7,17 +7,45 @@ from milc import cli
from qmk.maintainers import maintainers from qmk.maintainers import maintainers
@cli.argument('--pr', type=int, arg_only=True, help="PR to send ping to (optional)")
@cli.argument('--owner', default='qmk', arg_only=True, help="Owner for the repo (Default: qmk)")
@cli.argument('--repo', default='qmk_firmware', arg_only=True, help="Repo to send pings to (Default: qmk_firmware)")
@cli.argument("files", type=Path, arg_only=True, nargs='*', help="File to ping maintainers for.") @cli.argument("files", type=Path, arg_only=True, nargs='*', help="File to ping maintainers for.")
@cli.subcommand("Ping the maintainers for one or more files.") @cli.subcommand("Ping the maintainers and request reviews for one or more files.")
def ping_maintainers(cli): def ping_maintainers(cli):
"""List the maintainers for one or more files. """Ping the maintainers for one or more files.
""" """
github_maintainers = set() github_maintainers = set()
github_teams = set()
for file in cli.args.files: for file in cli.args.files:
for maintainer in maintainers(file): for maintainer in maintainers(file):
if not maintainer.startswith('@qmk/'): if '/' in maintainer:
github_teams.add(maintainer)
else:
github_maintainers.add(maintainer) github_maintainers.add(maintainer)
if github_maintainers: if cli.args.pr:
print(f'If you were pinged by this comment you have one or more files being changed by this PR: {" ".join(sorted(github_maintainers))}') from ghapi.all import GhApi
ghapi = GhApi(owner=cli.args.owner, repo=cli.args.repo)
pr = ghapi.pulls(cli.args.pr)
if not pr.draft:
for team in pr.requested_teams:
team_name = f'@{cli.args.owner}/{team.slug}'
if team_name in github_teams:
cli.log.info('Found %s in reviews already, skipping', team_name)
github_teams.remove(team_name)
for team in github_teams:
cli.log.info('Requesting review from team %s', team.split('/', 1)[1])
ghapi.pulls.request_reviewers(pull_number=cli.args.pr, team_reviewers=team.split('/', 1)[1])
if github_maintainers:
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))}')
else:
print(f'Team Reviews: {" ".join(sorted(github_teams))}')
print(f'Individual Reviews: {" ".join(sorted(github_maintainers))}')

View file

@ -3,7 +3,8 @@
# Python development requirements # Python development requirements
codeowners codeowners
nose2
flake8 flake8
ghapi
nose2
pep8-naming pep8-naming
yapf yapf