Skip to content

Add version selector #23

Add version selector

Add version selector #23

name: Comment on Fork PRs
on:
pull_request_target:
types: [opened, reopened, synchronize]
# Required permissions for commenting on PRs
permissions:
contents: read
pull-requests: write
jobs:
comment-on-fork-pr:
runs-on: ubuntu-latest
# Only run for fork PRs
if: github.event.pull_request.head.repo.fork == true
steps:
- name: Comment on PR with manual deployment instructions
uses: actions/github-script@v7
with:
script: |-
const prNumber = context.payload.pull_request.number;
const workflowUrl = `https://github.com/ruby/rdoc/actions/workflows/cloudflare-preview.yml`;
const commentMarker = "## Cloudflare Preview Deployment";
// Create a direct link that pre-fills the PR number input
const dispatchUrl = `${workflowUrl}/dispatch?ref=main&inputs%5Bpull_request_number%5D=${prNumber}`;
// Get all comments on the PR
const comments = await github.rest.issues.listComments({
issue_number: prNumber,
owner: context.repo.owner,
repo: context.repo.repo,
per_page: 100
});
// Look for our previous bot comment
const existingComment = comments.data.find(comment =>
comment.body.includes(commentMarker)
);
const messageLines = [
`${commentMarker}`,
`⚠️ This PR is from a fork, so the preview deployment workflow doesn't run automatically for security reasons.`,
``,
`### For Maintainers:`,
`[🚀 Click here to run the preview deployment workflow](${dispatchUrl})`,
``,
`This will trigger a Cloudflare Pages preview deployment for this PR.`
];
const commentBody = messageLines.join('\n');
if (existingComment) {
// Update existing comment
await github.rest.issues.updateComment({
comment_id: existingComment.id,
owner: context.repo.owner,
repo: context.repo.repo,
body: commentBody
});
console.log("Updated existing fork PR comment");
} else {
// Create new comment
await github.rest.issues.createComment({
issue_number: prNumber,
owner: context.repo.owner,
repo: context.repo.repo,
body: commentBody
});
console.log("Created new fork PR comment");
}