Devex: Add workflow to assign PR reviewers #1
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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 | |
| if: github.actor != 'dependabot[bot]' && !github.event.pull_request.draft | |
| steps: | |
| - uses: dorny/paths-filter@v4 | |
| id: filter | |
| with: | |
| filters: | | |
| backend: | |
| - 'app/backend/**' | |
| - '!app/backend/**/locales/*.json' | |
| - 'app/media/**' | |
| web: | |
| - 'app/web/**' | |
| - '!app/web/**/locales/*.json' | |
| mobile: | |
| - 'app/mobile/**' | |
| - '!app/mobile/**/locales/*.json' | |
| i18n: | |
| - 'app/**/locales/*.json' | |
| - 'app/**/i18n/**' | |
| docs: | |
| - 'docs/**' | |
| - 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 }} | |
| BACKEND_CHANGED: ${{ steps.filter.outputs.backend }} | |
| WEB_CHANGED: ${{ steps.filter.outputs.web }} | |
| MOBILE_CHANGED: ${{ steps.filter.outputs.mobile }} | |
| I18N_CHANGED: ${{ steps.filter.outputs.i18n }} | |
| DOCS_CHANGED: ${{ steps.filter.outputs.docs }} | |
| run: | | |
| declare -A reviewers | |
| declare -A teams | |
| if [[ "$BACKEND_CHANGED" == "true" ]]; then | |
| teams[Couchers-org/backend]=1 | |
| fi | |
| if [[ "$WEB_CHANGED" == "true" ]]; then | |
| teams[Couchers-org/web]=1 | |
| fi | |
| if [[ "$MOBILE_CHANGED" == "true" ]]; then | |
| teams[Couchers-org/mobile]=1 | |
| fi | |
| if [[ "$I18N_CHANGED" == "true" ]]; then | |
| reviewers[tristanlabelle]=1 | |
| fi | |
| if [[ "$DOCS_CHANGED" == "true" ]]; then | |
| reviewers[aapeliv]=1 | |
| reviewers[nabramow]=1 | |
| fi | |
| # Remove the PR author to avoid self-review errors | |
| unset "reviewers[$PR_AUTHOR]" | |
| ARGS=() | |
| if [[ ${#reviewers[@]} -gt 0 ]]; then | |
| REVIEWER_LIST=$(IFS=,; echo "${!reviewers[*]}") | |
| ARGS+=(--add-reviewer "$REVIEWER_LIST") | |
| fi | |
| if [[ ${#teams[@]} -gt 0 ]]; then | |
| TEAM_LIST=$(IFS=,; echo "${!teams[*]}") | |
| ARGS+=(--add-reviewer "$TEAM_LIST") | |
| fi | |
| if [[ ${#ARGS[@]} -gt 0 ]]; then | |
| gh pr edit "$PR_NUMBER" "${ARGS[@]}" | |
| fi |