|
| 1 | +name: Onyx.connectWithoutView reviewers |
| 2 | + |
| 3 | +# Requests a review from the Onyx performance reviewers whenever a PR adds a new |
| 4 | +# `Onyx.connectWithoutView` call. CODEOWNERS can't express this because it triggers on file |
| 5 | +# paths, not on the content of a diff. |
| 6 | + |
| 7 | +on: |
| 8 | + pull_request_target: |
| 9 | + types: [opened, synchronize, ready_for_review] |
| 10 | + |
| 11 | +permissions: |
| 12 | + contents: read |
| 13 | + pull-requests: write |
| 14 | + issues: write |
| 15 | + |
| 16 | +concurrency: |
| 17 | + group: ${{ github.workflow }}-${{ github.event.pull_request.number }} |
| 18 | + cancel-in-progress: true |
| 19 | + |
| 20 | +jobs: |
| 21 | + requestReviewers: |
| 22 | + name: Request reviewers for new Onyx.connectWithoutView calls |
| 23 | + if: ${{ github.event.pull_request.draft == false }} |
| 24 | + runs-on: ubuntu-latest |
| 25 | + steps: |
| 26 | + - name: Request reviewers and leave a comment |
| 27 | + uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v7 |
| 28 | + with: |
| 29 | + script: | |
| 30 | + const REVIEWERS = ['tgolen', 'mountiny', 'luacmartins']; |
| 31 | + const pr = context.payload.pull_request; |
| 32 | + const {owner, repo} = context.repo; |
| 33 | +
|
| 34 | + // Trigger only on a net-new call. We compare added vs. removed call lines per file (a call |
| 35 | + // matches `Onyx.connectWithoutView(`), so editing a call in place nets to zero, removed |
| 36 | + // comments/strings don't count, and a removal in one file can't mask a new call in another. |
| 37 | + const CALL = /Onyx\.connectWithoutView\s*\(/; |
| 38 | + const files = await github.paginate(github.rest.pulls.listFiles, {owner, repo, pull_number: pr.number}); |
| 39 | + const addsNewCall = files.some((file) => { |
| 40 | + if (!file.patch) { |
| 41 | + return false; |
| 42 | + } |
| 43 | + let added = 0; |
| 44 | + let removed = 0; |
| 45 | + for (const line of file.patch.split('\n')) { |
| 46 | + if (line.startsWith('+') && !line.startsWith('+++') && CALL.test(line)) { |
| 47 | + added++; |
| 48 | + } else if (line.startsWith('-') && !line.startsWith('---') && CALL.test(line)) { |
| 49 | + removed++; |
| 50 | + } |
| 51 | + } |
| 52 | + return added > removed; |
| 53 | + }); |
| 54 | +
|
| 55 | + if (!addsNewCall) { |
| 56 | + return; |
| 57 | + } |
| 58 | +
|
| 59 | + // Don't request the PR author on their own PR, anyone already requested, or anyone who |
| 60 | + // already reviewed — so re-runs on `synchronize` never create duplicate requests. |
| 61 | + const alreadyRequested = (pr.requested_reviewers ?? []).map((user) => user.login); |
| 62 | + const reviews = await github.paginate(github.rest.pulls.listReviews, {owner, repo, pull_number: pr.number}); |
| 63 | + const alreadyReviewed = reviews.map((review) => review.user?.login).filter(Boolean); |
| 64 | + const skip = new Set([pr.user.login, ...alreadyRequested, ...alreadyReviewed]); |
| 65 | + const reviewersToRequest = REVIEWERS.filter((reviewer) => !skip.has(reviewer)); |
| 66 | +
|
| 67 | + if (reviewersToRequest.length === 0) { |
| 68 | + return; |
| 69 | + } |
| 70 | +
|
| 71 | + await github.rest.pulls.requestReviewers({owner, repo, pull_number: pr.number, reviewers: reviewersToRequest}); |
| 72 | +
|
| 73 | + const mentions = REVIEWERS.map((reviewer) => `@${reviewer}`).join(', '); |
| 74 | + await github.rest.issues.createComment({ |
| 75 | + owner, |
| 76 | + repo, |
| 77 | + issue_number: pr.number, |
| 78 | + body: `This PR adds a new \`Onyx.connectWithoutView\` call, so I've requested a review from the Onyx performance reviewers (${mentions}) — a review from any one of them is enough. Please add a link in your PR description to the Slack discussion where the \`@frontend-performance\` team approved using \`connectWithoutView\` here.`, |
| 79 | + }); |
0 commit comments