Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .github/autoreviewers.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Defines PR reviewers based on modified file paths.
# The syntax is as the dorny/paths-filter action accepts,
# but our filter names are a label plus a comma-delimited people/teams to assign.
backend Couchers-org/backend:
- 'app/backend/**'
- '!app/backend/**/locales/*.json'
- 'app/media/**'
web Couchers-org/web:
- 'app/web/**'
- '!app/web/**/locales/*.json'
mobile Couchers-org/mobile:
- 'app/mobile/**'
- '!app/mobile/**/locales/*.json'
i18n tristanlabelle:
- 'app/**/locales/*.json'
- 'app/**/i18n/**'
docs aapeliv,nabramow:
- 'docs/**'
55 changes: 55 additions & 0 deletions .github/workflows/add-reviewers.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Adds reviewers upon publishing a PR based on changed files.
# Works around limitations of GitHub's CODEOWNERS, which can only match one rule,
# whereas our changes can straddle frontend and backend, for example.
name: Add reviewers

on:
pull_request:
types: [opened, ready_for_review, reopened]

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref }}
cancel-in-progress: true

permissions:
contents: read
pull-requests: write

jobs:
add-reviewers:
name: Add reviewers
runs-on: ubuntu-latest
# Let tristanlabelle validate this workflow before switching from CODEOWNERS
if: github.event.pull_request.user.login == 'tristanlabelle' && github.actor != 'dependabot[bot]' && !github.event.pull_request.draft
steps:
- uses: dorny/paths-filter@v4
id: filter
with:
filters: .github/autoreviewers.yml

- name: Add reviewers
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
PR_NUMBER: ${{ github.event.pull_request.number }}
PR_AUTHOR: ${{ github.event.pull_request.user.login }}
# The "changes" output is a JSON array of filter names.
FILTER_CHANGES: ${{ steps.filter.outputs.changes }}
run: |
# Filter keys are "<name> <reviewer1,reviewer2,...>"; extract reviewers from matched filters.
MATCHED_REVIEWERS=$(echo "$FILTER_CHANGES" | jq -r '.[] | split(" ")[1] | split(",") | .[]')

ARGS=()
while IFS= read -r reviewer; do
# Ignore empty entries
[[ -n "$reviewer" ]] || continue
# The PR author cannot be a reviewer on their own PR
[[ "$reviewer" == "$PR_AUTHOR" ]] && continue

echo "Adding reviewer: $reviewer"
ARGS+=(--add-reviewer "$reviewer")
done <<< "$MATCHED_REVIEWERS"

if [[ ${#ARGS[@]} -gt 0 ]]; then
gh pr edit "$PR_NUMBER" "${ARGS[@]}"
fi
Loading