|
| 1 | +name: on eco-tests change notification |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: [opened, synchronize, reopened, ready_for_review] |
| 6 | + paths: |
| 7 | + - 'eco-tests/**' |
| 8 | + |
| 9 | +permissions: |
| 10 | + contents: read |
| 11 | + pull-requests: write |
| 12 | + issues: write |
| 13 | + |
| 14 | +concurrency: |
| 15 | + group: eco-tests-indexer-notify-${{ github.ref }} |
| 16 | + cancel-in-progress: true |
| 17 | + |
| 18 | +env: |
| 19 | + ECO_TESTS_REVIEWERS: "evgeny-s" |
| 20 | + |
| 21 | +jobs: |
| 22 | + notify: |
| 23 | + name: Notify indexer reviewer |
| 24 | + runs-on: ubuntu-latest |
| 25 | + steps: |
| 26 | + - name: Check out repository |
| 27 | + uses: actions/checkout@v4 |
| 28 | + with: |
| 29 | + fetch-depth: 0 |
| 30 | + |
| 31 | + - name: List changed files under eco-tests/ |
| 32 | + id: changes |
| 33 | + env: |
| 34 | + BASE_SHA: ${{ github.event.pull_request.base.sha }} |
| 35 | + HEAD_SHA: ${{ github.event.pull_request.head.sha }} |
| 36 | + run: | |
| 37 | + set -euo pipefail |
| 38 | + changed=$(git diff --name-only "$BASE_SHA" "$HEAD_SHA" -- 'eco-tests/' || true) |
| 39 | + { |
| 40 | + echo "files<<EOF" |
| 41 | + echo "$changed" |
| 42 | + echo "EOF" |
| 43 | + } >> "$GITHUB_OUTPUT" |
| 44 | +
|
| 45 | + - name: Post or update sticky review-request comment |
| 46 | + if: steps.changes.outputs.files != '' |
| 47 | + uses: actions/github-script@v7 |
| 48 | + env: |
| 49 | + CHANGED_FILES: ${{ steps.changes.outputs.files }} |
| 50 | + REVIEWERS: ${{ env.ECO_TESTS_REVIEWERS }} |
| 51 | + with: |
| 52 | + script: | |
| 53 | + const marker = '<!-- eco-tests-indexer-notify -->'; |
| 54 | +
|
| 55 | + const reviewers = (process.env.REVIEWERS || '') |
| 56 | + .split(',') |
| 57 | + .map(s => s.trim()) |
| 58 | + .filter(Boolean); |
| 59 | + const ccLine = reviewers.length |
| 60 | + ? reviewers.map(u => `@${u}`).join(' ') |
| 61 | + : '_(no reviewers configured — set ECO_TESTS_REVIEWERS in the workflow)_'; |
| 62 | +
|
| 63 | + const changed = (process.env.CHANGED_FILES || '').trim(); |
| 64 | + const fileList = changed |
| 65 | + .split('\n') |
| 66 | + .filter(Boolean) |
| 67 | + .map(f => `- \`${f}\``) |
| 68 | + .join('\n'); |
| 69 | +
|
| 70 | + const body = [ |
| 71 | + marker, |
| 72 | + '### eco-tests changed — indexer review required', |
| 73 | + '', |
| 74 | + 'This PR modifies files under `eco-tests/`. and may affect downstream indexing.', |
| 75 | + `**cc ${ccLine}** — please review manually`, |
| 76 | + '', |
| 77 | + '<details><summary>Changed files</summary>', |
| 78 | + '', |
| 79 | + fileList, |
| 80 | + '', |
| 81 | + '</details>', |
| 82 | + ].join('\n'); |
| 83 | +
|
| 84 | + const { owner, repo } = context.repo; |
| 85 | + const issue_number = context.issue.number; |
| 86 | +
|
| 87 | + const comments = await github.paginate( |
| 88 | + github.rest.issues.listComments, |
| 89 | + { owner, repo, issue_number, per_page: 100 } |
| 90 | + ); |
| 91 | + const existing = comments.find(c => c.body && c.body.includes(marker)); |
| 92 | +
|
| 93 | + if (existing) { |
| 94 | + if (existing.body !== body) { |
| 95 | + await github.rest.issues.updateComment({ |
| 96 | + owner, repo, comment_id: existing.id, body, |
| 97 | + }); |
| 98 | + } |
| 99 | + } else { |
| 100 | + await github.rest.issues.createComment({ |
| 101 | + owner, repo, issue_number, body, |
| 102 | + }); |
| 103 | + } |
| 104 | +
|
| 105 | + - name: Request reviews from configured reviewers |
| 106 | + if: steps.changes.outputs.files != '' |
| 107 | + uses: actions/github-script@v7 |
| 108 | + env: |
| 109 | + REVIEWERS: ${{ env.ECO_TESTS_REVIEWERS }} |
| 110 | + with: |
| 111 | + script: | |
| 112 | + const reviewers = (process.env.REVIEWERS || '') |
| 113 | + .split(',') |
| 114 | + .map(s => s.trim()) |
| 115 | + .filter(Boolean); |
| 116 | + if (reviewers.length === 0) { |
| 117 | + core.info('ECO_TESTS_REVIEWERS is empty — skipping review request.'); |
| 118 | + return; |
| 119 | + } |
| 120 | +
|
| 121 | + const { owner, repo } = context.repo; |
| 122 | + const pull_number = context.issue.number; |
| 123 | + const pr = await github.rest.pulls.get({ owner, repo, pull_number }); |
| 124 | +
|
| 125 | + // GitHub rejects requesting a review from the PR author. |
| 126 | + const author = pr.data.user && pr.data.user.login; |
| 127 | + const filtered = reviewers.filter(u => u !== author); |
| 128 | + if (filtered.length === 0) { |
| 129 | + core.info(`All configured reviewers are the PR author (${author}) — skipping.`); |
| 130 | + return; |
| 131 | + } |
| 132 | +
|
| 133 | + try { |
| 134 | + await github.rest.pulls.requestReviewers({ |
| 135 | + owner, repo, pull_number, |
| 136 | + reviewers: filtered, |
| 137 | + }); |
| 138 | + } catch (e) { |
| 139 | + core.warning(`requestReviewers failed: ${e.message}`); |
| 140 | + } |
0 commit comments