Repository navigation
Add Santa Clawd π #35
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
| # Posts (and keeps updated) a PR comment embedding every emoji image the PR | ||
|
Check warning on line 1 in .github/workflows/preview.yml
|
||
| # adds or changes, so reviewing an emoji PR means *looking at the emoji*. | ||
| # | ||
| # Uses pull_request_target for comment permissions on fork PRs, but never | ||
| # checks out or executes PR code β it only reads the changed-file list via the | ||
| # API and links raw.githubusercontent.com URLs at the head SHA. | ||
| name: emoji-preview | ||
| on: | ||
| pull_request_target: | ||
| types: [opened, synchronize, reopened] | ||
| permissions: | ||
| pull-requests: write | ||
| jobs: | ||
| comment: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/github-script@v7 | ||
| with: | ||
| script: | | ||
| const { owner, repo } = context.repo; | ||
| const pr = context.payload.pull_request; | ||
| const files = await github.paginate(github.rest.pulls.listFiles, { | ||
| owner, repo, pull_number: pr.number, per_page: 100, | ||
| }); | ||
| const imgs = files.filter(f => | ||
| /^emoji\/[^/]+\/[^/]+\.(gif|png)$/.test(f.filename) && | ||
| f.status !== "removed"); | ||
| if (imgs.length === 0) return; | ||
| const base = `https://raw.githubusercontent.com/${pr.head.repo.full_name}/${pr.head.sha}`; | ||
| const rows = imgs.map(f => | ||
| `| \`${f.filename}\` |  |` | ||
| ).join("\n"); | ||
| const body = [ | ||
| "<!-- emoji-preview -->", | ||
| "### π Emoji preview", | ||
| "", | ||
| "| file | preview |", | ||
| "|---|:---:|", | ||
| rows, | ||
| "", | ||
| `_from ${pr.head.sha.slice(0, 7)} β GIFs animate, squint like it's Slack (32 px)_`, | ||
| ].join("\n"); | ||
| const comments = await github.paginate(github.rest.issues.listComments, { | ||
| owner, repo, issue_number: pr.number, per_page: 100, | ||
| }); | ||
| const mine = comments.find(c => c.body.includes("<!-- emoji-preview -->")); | ||
| if (mine) { | ||
| await github.rest.issues.updateComment({ owner, repo, comment_id: mine.id, body }); | ||
| } else { | ||
| await github.rest.issues.createComment({ owner, repo, issue_number: pr.number, body }); | ||
| } | ||