From 61df40744c391035919be440a8aa90c4a0db6f80 Mon Sep 17 00:00:00 2001 From: Zach Harel Date: Thu, 3 Sep 2026 19:33:07 -0400 Subject: [PATCH] Enhance preview comment functionality to list changed pages --- .github/workflows/preview.yml | 43 +++++++++++++++++++++++++++++++---- 1 file changed, 39 insertions(+), 4 deletions(-) diff --git a/.github/workflows/preview.yml b/.github/workflows/preview.yml index 2d296b95..84b00bbc 100644 --- a/.github/workflows/preview.yml +++ b/.github/workflows/preview.yml @@ -69,6 +69,8 @@ jobs: - name: Comment PR with preview URL if: success() uses: actions/github-script@v9 + env: + WRANGLER_OUTPUT: ${{ steps.upload.outputs.command-output }} with: script: | const prNumber = parseInt('${{ steps.get-pr.outputs.pr-number }}'); @@ -83,19 +85,52 @@ jobs: `$1${alias}-`, ); + // wrangler lists each newly uploaded asset as "+ /some/path/index.html" + const uploaded = (process.env.WRANGLER_OUTPUT || '') + .split('\n') + .map(line => line.replace(/\[[0-9;]*m/g, '').trim()) + .map(line => /^\+\s+(\/\S*)$/.exec(line)?.[1]) + .filter(path => path && path.endsWith('.html')); + + const pages = [...new Set(uploaded)] + .map(path => path.replace(/index\.html$/, '').replace(/\.html$/, '/')) + .sort(); + + const pageList = pages.length + ? pages + .map(path => `- [${path}](${previewUrl}${path})`) + .join('\n') + : '_No changed pages detected._'; + + const marker = ''; + const body = [ + marker, + `🌐 Preview URL: ${previewUrl}`, + '', + '**Changed pages**', + pageList, + ].join('\n'); + const { data: comments } = await github.rest.issues.listComments({ owner: context.repo.owner, repo: context.repo.repo, issue_number: prNumber, }); - const alreadyCommented = comments.some( - c => c.user?.type === 'Bot' && c.body?.includes(previewUrl) + const existing = comments.find( + c => c.user?.type === 'Bot' && c.body?.includes(marker) ); - if (!alreadyCommented) { + if (existing) { + await github.rest.issues.updateComment({ + owner: context.repo.owner, + repo: context.repo.repo, + comment_id: existing.id, + body, + }); + } else { await github.rest.issues.createComment({ owner: context.repo.owner, repo: context.repo.repo, issue_number: prNumber, - body: `🌐 Preview URL: ${previewUrl}`, + body, }); }