|
| 1 | +name: Notify documentation review assignees on new commits |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + # Fires on new commits and on label changes, so the job |
| 6 | + # starts as soon as the label is added, then on every push. |
| 7 | + types: [synchronize, labeled] |
| 8 | + |
| 9 | +permissions: |
| 10 | + issues: write |
| 11 | + pull-requests: read |
| 12 | + |
| 13 | +concurrency: |
| 14 | + group: pr-${{ github.event.pull_request.number }}-doc-notify |
| 15 | + cancel-in-progress: true |
| 16 | + |
| 17 | +jobs: |
| 18 | + ping: |
| 19 | + if: contains(github.event.pull_request.labels.*.name, 'documentation') |
| 20 | + runs-on: ubuntu-latest |
| 21 | + steps: |
| 22 | + - uses: actions/github-script@v7 |
| 23 | + with: |
| 24 | + github-token: ${{ secrets.YDBOT_TOKEN }} |
| 25 | + script: | |
| 26 | + const pr = context.payload.pull_request; |
| 27 | + const assignees = pr.assignees.map(a => `@${a.login}`).join(' '); |
| 28 | + if (!assignees) { |
| 29 | + core.info('No assignees, nothing to ping.'); |
| 30 | + return; |
| 31 | + } |
| 32 | +
|
| 33 | + // Check when the bot (this token) last commented |
| 34 | + const { data: me } = await github.rest.users.getAuthenticated(); |
| 35 | + const { data: comments } = await github.rest.issues.listComments({ |
| 36 | + owner: context.repo.owner, |
| 37 | + repo: context.repo.repo, |
| 38 | + issue_number: pr.number, |
| 39 | + per_page: 1, |
| 40 | + sort: 'created', |
| 41 | + direction: 'desc' |
| 42 | + }); |
| 43 | + const myLast = comments.find(c => c.user.login === me.login); |
| 44 | +
|
| 45 | + // Skip if commented recently enough |
| 46 | + if (myLast && Date.now() - new Date(myLast.created_at) < 15 * 60 * 1000) { |
| 47 | + core.info('Skip: already commented within 15 minutes.'); |
| 48 | + return; |
| 49 | + } |
| 50 | +
|
| 51 | + await github.rest.issues.createComment({ |
| 52 | + owner: context.repo.owner, |
| 53 | + repo: context.repo.repo, |
| 54 | + issue_number: pr.number, |
| 55 | + body: `🔄 New commits pushed — ${assignees} please take another look.` |
| 56 | + }); |
0 commit comments