@@ -13,23 +13,56 @@ jobs:
1313 - name : Comment on PR with manual deployment instructions
1414 uses : actions/github-script@v7
1515 with :
16- script : |
16+ script : |-
1717 const prNumber = context.payload.pull_request.number;
1818 const workflowUrl = `https://github.com/ruby/rdoc/actions/workflows/cloudflare-preview.yml`;
1919 const branch = context.payload.pull_request.head.ref;
20+ const commentMarker = "## Cloudflare Preview Deployment";
2021
2122 // Create a direct link that pre-fills the PR number input
2223 const dispatchUrl = `${workflowUrl}/dispatch?ref=main&inputs%5Bpull_request_number%5D=${prNumber}`;
2324
24- await github.rest.issues.createComment({
25+ // Get all comments on the PR
26+ const comments = await github.rest.issues.listComments({
2527 issue_number: prNumber,
2628 owner: context.repo.owner,
2729 repo: context.repo.repo,
28- body: `## Cloudflare Preview Deployment
29- ⚠️ This PR is from a fork, so the preview deployment workflow doesn't run automatically for security reasons.
30- If you're a maintainer and want to preview this PR :
30+ per_page: 100
31+ });
3132
32- [➡️ Click here to run the workflow with PR # ${prNumber} pre-filled](${dispatchUrl})
33+ // Look for our previous bot comment
34+ const existingComment = comments.data.find(comment =>
35+ comment.body.includes(commentMarker)
36+ );
3337
34- This will trigger a Cloudflare Pages preview deployment for this PR.`
35- });
38+ const messageLines = [
39+ `${commentMarker}`,
40+ `⚠️ This PR is from a fork, so the preview deployment workflow doesn't run automatically for security reasons.`,
41+ `If you're a maintainer and want to preview this PR:`,
42+ ``,
43+ `[➡️ Click here to run the workflow with PR #${prNumber} pre-filled](${dispatchUrl})`,
44+ ``,
45+ `This will trigger a Cloudflare Pages preview deployment for this PR.`
46+ ];
47+
48+ const commentBody = messageLines.join('\n');
49+
50+ if (existingComment) {
51+ // Update existing comment
52+ await github.rest.issues.updateComment({
53+ comment_id: existingComment.id,
54+ owner: context.repo.owner,
55+ repo: context.repo.repo,
56+ body: commentBody
57+ });
58+ console.log("Updated existing fork PR comment");
59+ } else {
60+ // Create new comment
61+ await github.rest.issues.createComment({
62+ issue_number: prNumber,
63+ owner: context.repo.owner,
64+ repo: context.repo.repo,
65+ body: commentBody
66+ });
67+ console.log("Created new fork PR comment");
68+ }
0 commit comments