Skip to content

Commit

Permalink
Update playgrounds link to include github export preconfig
Browse files Browse the repository at this point in the history
  • Loading branch information
robertsreberski committed May 17, 2024
1 parent dfce47d commit 9034c10
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions .github/scripts/create-preview-links.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,26 @@ function getParentThemeName(themeSlug) {
: '';
}

async function createPlaygroundPreconfiguredLink(themeName = '', blueprint = '', existingPr = false) {
const url = new URL('https://wordpress.org/playground/');
const searchParams = new URLSearchParams();

searchParams.set('storage', 'browser'); // We need to have the storage to be able to create/update the PR
searchParams.set('ghexport-repo-url', encodeURIComponent('https://github.com/WordPress/community-themes'));
searchParams.set('ghexport-content-type', 'theme');
searchParams.set('ghexport-theme', themeName);

if ( existingPr ) {
searchParams.set('ghexport-pr-action', 'update');
searchParams.set('ghexport-pr-number', existingPr); // It's not supported yet - see PR WordPress/wordpress-playground# TODO
}

url.search = searchParams.toString();
url.hash = encodeURIComponent(blueprint);

return url.toString();
}

/*
* This function creates a comment on a PR with preview links for the changed themes.
* It is used by `preview-theme` workflow.
Expand All @@ -78,16 +98,15 @@ async function createPreviewLinksComment(github, context, changedThemeSlugs) {
const previewLinks = changedThemes
.map((themeSlug) => {
const parentThemeName = getParentThemeName(themeSlug);
const themeName = getThemeName( themeSlug );
const blueprint = createBlueprint( themeSlug, context.payload.pull_request.head.ref );
const playgroundUrl = createPlaygroundPreconfiguredLink( themeName, blueprint, context.payload.pull_request.number );

const note = parentThemeName
? ` (child theme of **${parentThemeName}**)`
: '';

return `- [Preview changes for **${getThemeName(
themeSlug
)}**](https://playground.wordpress.net/#${createBlueprint(
themeSlug,
context.payload.pull_request.head.ref
)})${note}`;
return `- [Preview changes for **${ themeName }**](${playgroundUrl})${note}`;
})
.join('\n');

Expand Down

0 comments on commit 9034c10

Please sign in to comment.