Skip to content

Commit c2d6079

Browse files
Copilotmmcky
andcommitted
Add automatic PR comment posting for preview links
Co-authored-by: mmcky <8263752+mmcky@users.noreply.github.com>
1 parent 0d40ee5 commit c2d6079

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

.github/workflows/ci.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,3 +198,44 @@ jobs:
198198
env:
199199
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
200200
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
201+
- name: Post PR Comment with Preview Links
202+
if: github.event_name == 'pull_request'
203+
uses: actions/github-script@v7
204+
with:
205+
script: |
206+
const changedFiles = `${{ steps.detect-changes.outputs.changed_files }}`;
207+
const previewUrls = `${{ steps.detect-changes.outputs.preview_urls }}`;
208+
const manualPage = `${{ github.event.inputs.preview_page }}`;
209+
const prNumber = ${{ github.event.pull_request.number }};
210+
const baseUrl = `https://deploy-preview-${prNumber}--sunny-cactus-210e3e.netlify.app`;
211+
212+
let comment = `## 📖 Netlify Preview Ready!\n\n`;
213+
comment += `**Preview URL:** ${baseUrl}\n\n`;
214+
215+
// Add manual preview page if specified
216+
if (manualPage) {
217+
comment += `🎯 **Manual Preview:** [${manualPage}](${baseUrl}/${manualPage})\n\n`;
218+
}
219+
220+
// Add direct links to changed lecture pages
221+
if (changedFiles && previewUrls) {
222+
comment += `📚 **Changed Lecture Pages:**\n`;
223+
const files = changedFiles.split('\n').filter(f => f.trim());
224+
const urls = previewUrls.split('\n').filter(u => u.trim());
225+
226+
for (let i = 0; i < files.length && i < urls.length; i++) {
227+
const fileName = files[i].replace('lectures/', '').replace('.md', '');
228+
const url = urls[i].trim();
229+
if (url) {
230+
comment += `- [${fileName}](${url})\n`;
231+
}
232+
}
233+
}
234+
235+
// Post the comment
236+
await github.rest.issues.createComment({
237+
issue_number: prNumber,
238+
owner: context.repo.owner,
239+
repo: context.repo.repo,
240+
body: comment
241+
});

0 commit comments

Comments
 (0)