That is very annoying, especially if you have layers of codeowners.
For instance, an ops team who has codeowner across the entire repo, but who is not reviewing most PRs day to day.
True: when you have layered code owners, with a default or catch-all team (like an ops team) that has code owner rights over the entire repository but is only supposed to review occasionally, it becomes a bit trickier.
The key challenge is to make sure the ops team does not get spammed with review requests, even if they are the catch-all codeowners, unless their review is actually needed.
You can start with fine-tuning your CODEOWNERS file.
Make sure to organize your .github/CODEOWNERS
file such that specific paths and folders have their respective code owners, while the ops team is the fallback for general oversight or unassigned paths:
* @ops-team
/docs/ @documentation-team
/app/ @app-team
You will then still utilize GitHub Actions, but you will be a bit more specific this time. You will need an action that checks the files changed in the PR.
But:
- If the files changed are specific to a team, and not in the general category of ops, then you can skip review request removal for that team and only remove for the ops team. (See "Remove requested reviewers from a pull request" API call)
- If it touches something general, then it will automatically request a review from the ops team.
For instance:
name: Handle Review Requests
on:
pull_request:
types:
- opened
jobs:
handle-requests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Check changed files
id: files
run: |
FILES=$(git diff --name-only ${{ github.event.before }} ${{ github.event.after }})
echo "modified_files=$FILES" >> $GITHUB_ENV
- name: Conditionally remove requested reviewers
run: |
MODIFIED_FILES="${modified_files}"
# Check if the PR modifies files inside /app/ or /docs/
if [[ "$MODIFIED_FILES" == *"app/"* ]] || [[ "$MODIFIED_FILES" == *"docs/"* ]]; then
# Remove ops team from the review request list
gh api \
--method DELETE \
/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/requested_reviewers \
-F reviewers='["ops-team"]'
fi
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
See also discussions/25797 for an illustration around ${{ github.event.before }}
and ${{ github.event.after }}
.