Skip to content

Commit 5998396

Browse files
Add-reviewers workflow
1 parent c080a8a commit 5998396

2 files changed

Lines changed: 73 additions & 0 deletions

File tree

.github/autoreviewers.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Defines PR reviewers based on modified file paths.
2+
# The syntax is as the dorny/paths-filter action accepts,
3+
# but our filter names are a label plus a comma-delimited people/teams to assign.
4+
backend Couchers-org/backend:
5+
- 'app/backend/**'
6+
- '!app/backend/**/locales/*.json'
7+
- 'app/media/**'
8+
web Couchers-org/web:
9+
- 'app/web/**'
10+
- '!app/web/**/locales/*.json'
11+
mobile Couchers-org/mobile:
12+
- 'app/mobile/**'
13+
- '!app/mobile/**/locales/*.json'
14+
i18n tristanlabelle:
15+
- 'app/**/locales/*.json'
16+
- 'app/**/i18n/**'
17+
docs aapeliv,nabramow:
18+
- 'docs/**'
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Adds reviewers upon publishing a PR based on changed files.
2+
# Works around limitations of GitHub's CODEOWNERS, which can only match one rule,
3+
# whereas our changes can straddle frontend and backend, for example.
4+
name: Add reviewers
5+
6+
on:
7+
pull_request:
8+
types: [opened, ready_for_review, reopened]
9+
10+
concurrency:
11+
group: ${{ github.workflow }}-${{ github.head_ref }}
12+
cancel-in-progress: true
13+
14+
permissions:
15+
contents: read
16+
pull-requests: write
17+
18+
jobs:
19+
add-reviewers:
20+
name: Add reviewers
21+
runs-on: ubuntu-latest
22+
# Let tristanlabelle validate this workflow before switching from CODEOWNERS
23+
if: github.event.pull_request.user.login == 'tristanlabelle' && github.actor != 'dependabot[bot]' && !github.event.pull_request.draft
24+
steps:
25+
- uses: dorny/paths-filter@v4
26+
id: filter
27+
with:
28+
filters: .github/autoreviewers.yml
29+
30+
- name: Add reviewers
31+
env:
32+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
33+
GH_REPO: ${{ github.repository }}
34+
PR_NUMBER: ${{ github.event.pull_request.number }}
35+
PR_AUTHOR: ${{ github.event.pull_request.user.login }}
36+
# The "changes" output is a JSON array of filter names.
37+
FILTER_CHANGES: ${{ steps.filter.outputs.changes }}
38+
run: |
39+
# Filter keys are "<name> <reviewer1,reviewer2,...>"; extract reviewers from matched filters.
40+
MATCHED_REVIEWERS=$(echo "$FILTER_CHANGES" | jq -r '.[] | split(" ")[1] | split(",") | .[]')
41+
42+
ARGS=()
43+
while IFS= read -r reviewer; do
44+
# Ignore empty entries
45+
[[ -n "$reviewer" ]] || continue
46+
# The PR author cannot be a reviewer on their own PR
47+
[[ "$reviewer" == "$PR_AUTHOR" ]] && continue
48+
49+
echo "Adding reviewer: $reviewer"
50+
ARGS+=(--add-reviewer "$reviewer")
51+
done <<< "$MATCHED_REVIEWERS"
52+
53+
if [[ ${#ARGS[@]} -gt 0 ]]; then
54+
gh pr edit "$PR_NUMBER" "${ARGS[@]}"
55+
fi

0 commit comments

Comments
 (0)