Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ You can go ahead and try it out. The Playground will automatically install the t
| `language` | `en_US` | Sets the locale for the WordPress instance. This must be used in combination with `networking=yes` otherwise WordPress won't be able to download translations. |
| `core-pr` | | Installs a specific https://github.com/WordPress/wordpress-develop core PR. Accepts the PR number. For example, `core-pr=6883`. |
| `gutenberg-pr` | | Installs a specific https://github.com/WordPress/gutenberg PR. Accepts the PR number. For example, `gutenberg-pr=65337`. |
| `core-branch` | | Installs a specific branch from https://github.com/WordPress/wordpress-develop. Accepts the branch name. For example, `core-branch=trunk`. |
| `gutenberg-branch` | | Installs a specific branch from https://github.com/WordPress/gutenberg. Accepts the branch name. For example, `gutenberg-branch=trunk`. |
| `gutenberg-branch` | | Installs a specific branch from https://github.com/WordPress/gutenberg. Accepts the branch name. For example, `gutenberg-branch=trunk`. |
| `if-stored-site-missing` | | Indicates how to handle the scenario where the `site-slug` parameter identifies a site that does not exist. Use `if-stored-site-missing=prompt` to indicate that the user should be asked whether they would like to save a new site with the specified `site-slug`. |

For example, the following code embeds a Playground with a preinstalled Gutenberg plugin and opens the post editor:
Expand Down
26 changes: 20 additions & 6 deletions packages/playground/website/src/github/preview-pr/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,13 @@ export default function PreviewPRForm({
function buildArtifactUrl(ref: string, isBranch: boolean): string {
const refType = isBranch ? 'branch' : 'pr';
// For WordPress PRs: artifact name is wordpress-build-{PR_NUMBER}
// For WordPress branches: artifact name is wordpress-build-{COMMIT_HASH}
// We use wordpress-build- (with trailing dash) to trigger prefix matching
// For Gutenberg: artifact name is always gutenberg-plugin
// For Gutenberg PRs: artifact name is always gutenberg-plugin
// For Gutenberg branches: artifact name is always gutenberg-plugin
// (we use prefix matching with trailing dash for branches)
let artifactSuffix = '';
if (target === 'wordpress') {
artifactSuffix = isBranch ? '-' : ref;
// WordPress only supports PRs, not branches
artifactSuffix = ref;
}
return `https://playground.wordpress.net/plugin-proxy.php?org=WordPress&repo=${targetParams[target].repo}&workflow=${targetParams[target].workflow}&artifact=${targetParams[target].artifact}${artifactSuffix}&${refType}=${ref}`;
}
Expand All @@ -93,7 +94,15 @@ export default function PreviewPRForm({
if (prNumber.toLowerCase().includes(targetParams[target].pull)) {
prNumber = prNumber.match(/\/pull\/(\d+)/)![1];
} else if (!/^\d+$/.test(prNumber)) {
// If it's not a number and not a PR URL, treat it as a branch name
// For WordPress core, only allow PR numbers/URLs, not branch names
if (target === 'wordpress') {
setError(
'Please enter a valid PR number or PR URL for WordPress Core.'
);
setSubmitting(false);
return;
}
// For Gutenberg, treat non-numeric input as a branch name
branchName = prNumber;
}

Expand Down Expand Up @@ -217,6 +226,11 @@ export default function PreviewPRForm({
window.location.href = urlWithPreview.toString();
}

const inputLabel =
target === 'wordpress'
? 'PR number or URL'
: 'PR number, URL, or a branch name';

return (
<form onSubmit={handleSubmit}>
<div className={css.content}>
Expand All @@ -227,7 +241,7 @@ export default function PreviewPRForm({
)}
<TextControl
disabled={submitting}
label="PR number, URL, or a branch name"
label={inputLabel}
value={value}
autoFocus
onChange={(e) => {
Expand Down
10 changes: 5 additions & 5 deletions packages/playground/website/src/github/preview-pr/modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ export function PreviewPRModal({ target }: PreviewPRModalProps) {
const closeModal = () => {
dispatch(setActiveModal(null));
};
const title =
target === 'wordpress'
? `Preview a ${targetName[target]} PR`
: `Preview a ${targetName[target]} PR or Branch`;
return (
<Modal
small
title={`Preview a ${targetName[target]} PR or Branch`}
onRequestClose={closeModal}
>
<Modal small title={title} onRequestClose={closeModal}>
<PreviewPRForm onClose={closeModal} target={target} />
</Modal>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,17 +266,12 @@ function applyQueryOverridesToDeclaration(
});
}

// Handle WordPress core PR or branch preview
const coreRef = query.get('core-pr') || query.get('core-branch');
// Handle WordPress core PR preview
const coreRef = query.get('core-pr');
if (coreRef) {
const refType = query.has('core-pr') ? 'pr' : 'branch';
// For WordPress PRs: artifact name is wordpress-build-{PR_NUMBER}
// For WordPress branches: artifact name is wordpress-build-{COMMIT_HASH}
// We use wordpress-build- (with trailing dash) to trigger prefix matching in plugin-proxy.php
const artifactName = query.has('core-pr')
? `wordpress-build-${coreRef}`
: 'wordpress-build-';
blueprint.preferredVersions!.wp = `https://playground.wordpress.net/plugin-proxy.php?org=WordPress&repo=wordpress-develop&workflow=Test%20Build%20Processes&artifact=${artifactName}&${refType}=${coreRef}`;
const artifactName = `wordpress-build-${coreRef}`;
blueprint.preferredVersions!.wp = `https://playground.wordpress.net/plugin-proxy.php?org=WordPress&repo=wordpress-develop&workflow=Test%20Build%20Processes&artifact=${artifactName}&pr=${coreRef}`;
}

// Handle Gutenberg PR or branch preview
Expand Down