Slack Open PRs Notification #30
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
| name: Slack Open PRs Notification | |
| on: | |
| schedule: | |
| - cron: '0 13 * * *' # 13:00 UTC daily (08:00 EST / 09:00 EDT — cron does not observe DST) | |
| workflow_dispatch: | |
| permissions: | |
| pull-requests: read | |
| jobs: | |
| notify-slack: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Get open PRs | |
| id: open-prs | |
| uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8 | |
| with: | |
| script: | | |
| const prs = await github.paginate(github.rest.pulls.list, { | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| state: 'open', | |
| per_page: 100, | |
| }); | |
| const count = prs.length; | |
| // Format each PR with plain text and bare URL (Slack auto-links URLs) | |
| const prList = prs.map(pr => | |
| `• #${pr.number} - ${pr.title} (by ${pr.user?.login ?? 'unknown'})\n ${pr.html_url}` | |
| ).join('\n'); | |
| core.setOutput('count', count); | |
| // Use GITHUB_OUTPUT delimiter for multiline support | |
| const crypto = require('crypto'); | |
| const delimiter = `PRLIST_${crypto.randomUUID()}`; | |
| const fs = require('fs'); | |
| fs.appendFileSync( | |
| process.env.GITHUB_OUTPUT, | |
| `pr_list<<${delimiter}\n${prList}\n${delimiter}\n` | |
| ); | |
| - name: Send open PRs summary to Slack | |
| if: ${{ steps.open-prs.outputs.count != '0' }} | |
| uses: slackapi/slack-github-action@b0fa283ad8fea605de13dc3f449259339835fc52 # v2.1.0 | |
| with: | |
| webhook: ${{ secrets.SLACK_WEBHOOK_OSS_ALERTS }} | |
| webhook-type: incoming-webhook | |
| payload: | | |
| { "text": ${{ toJSON(format(':bar_chart: *Open PRs in {0}* ({1}): https://github.com/{0}/pulls\n{2}', github.repository, steps.open-prs.outputs.count, steps.open-prs.outputs.pr_list)) }} } |