Skip to content

Commit

Permalink
split changed themes by ,
Browse files Browse the repository at this point in the history
  • Loading branch information
Vicente Canales committed Apr 28, 2024
1 parent ec3719d commit e69c6bd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
15 changes: 10 additions & 5 deletions .github/scripts/create-preview-links.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,28 @@ function createBlueprint(themeSlug, branch) {
* @param {string} changedThemeSlugs - A space-separated string of theme slugs that have changed.
*/
async function createPreviewLinksComment(github, context, changedThemeSlugs) {
const changedThemes = changedThemeSlugs.split(' ');
const changedThemes = changedThemeSlugs.split(',');
const previewLinks = changedThemes
.map((theme) => {
const [themeName, themeDir] = theme.split(':');
const themeSlug = themeDir.split('/')[0];
return `- [Preview changes for **${themeName}**](https://playground.wordpress.net/#${createBlueprint(
const parentThemeSlug = themeName.split('_childof_')[1];
return `- [Preview changes for **${
themeName.split('_childof_')[0]
}**](https://playground.wordpress.net/#${createBlueprint(
themeSlug,
context.payload.pull_request.head.ref
)})`;
)})${parentThemeSlug ? ` (child of **${parentThemeSlug}**)` : ''}`;
})
.join('\n');

const includesChildThemes = previewLinks.includes('Child of');
const includesChildThemes = previewLinks.includes('child of');

const comment = `
I've detected changes to the following themes in this PR: ${changedThemes
.map((changedThemes) => changedThemes.split(':')[0])
.map(
(changedThemes) => changedThemes.split(':')[0].split('_childof_')[0]
)
.join(', ')}.
You can preview these changes by following the links below:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/preview-theme.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ jobs:
if [[ -f "$dir_name/style.css" ]]; then
# Get theme name from style.css
theme_name=$(grep -m 1 "Theme Name:" "$dir_name/style.css" | sed 's/Theme Name: //')
parent_theme=$(grep -m 1 "Template:" "${unique_dirs[$theme]}/style.css" | sed 's/Template: //')
parent_theme=$(grep -m 1 "Template:" "$dir_name/style.css" | sed 's/Template: //')
# Append parent theme to the theme name if it exists
[ -n "$parent_theme" ] && theme_name="$theme (Child of $parent_theme)"
[ -n "$parent_theme" ] && theme_name="${theme_name}_childof_${parent_theme}"
# Store theme name and directory in associative array
unique_dirs["$theme_name"]=$dir_name
break
Expand Down

0 comments on commit e69c6bd

Please sign in to comment.