|
| 1 | +name: Comment Review App URL |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: [opened, synchronize] |
| 6 | + |
| 7 | +jobs: |
| 8 | + comment: |
| 9 | + runs-on: ubuntu-latest |
| 10 | + steps: |
| 11 | + - name: Comment PR with Review App URL |
| 12 | + uses: actions/github-script@v7 |
| 13 | + with: |
| 14 | + script: | |
| 15 | + const prNumber = context.payload.pull_request.number; |
| 16 | + const reviewAppUrl = `https://kernelboard-pr-${prNumber}.herokuapp.com`; |
| 17 | +
|
| 18 | + // Check if we already commented |
| 19 | + const comments = await github.rest.issues.listComments({ |
| 20 | + owner: context.repo.owner, |
| 21 | + repo: context.repo.repo, |
| 22 | + issue_number: prNumber, |
| 23 | + }); |
| 24 | +
|
| 25 | + const botComment = comments.data.find(c => |
| 26 | + c.body.includes('Review App Preview') |
| 27 | + ); |
| 28 | +
|
| 29 | + const body = `## 🔍 Review App Preview |
| 30 | +
|
| 31 | +Your preview deployment will be available at: |
| 32 | +**${reviewAppUrl}** |
| 33 | + |
| 34 | +> Note: The review app may take a few minutes to build and deploy after pushing.`; |
| 35 | + |
| 36 | + if (botComment) { |
| 37 | + // Update existing comment |
| 38 | + await github.rest.issues.updateComment({ |
| 39 | + owner: context.repo.owner, |
| 40 | + repo: context.repo.repo, |
| 41 | + comment_id: botComment.id, |
| 42 | + body: body |
| 43 | + }); |
| 44 | + } else { |
| 45 | + // Create new comment |
| 46 | + await github.rest.issues.createComment({ |
| 47 | + owner: context.repo.owner, |
| 48 | + repo: context.repo.repo, |
| 49 | + issue_number: prNumber, |
| 50 | + body: body |
| 51 | + }); |
| 52 | + } |
0 commit comments