Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: improve theme preview action #2088

Merged
merged 1 commit into from
Oct 2, 2022
Merged
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
30 changes: 10 additions & 20 deletions scripts/preview-theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import Hjson from "hjson";
import snakeCase from "lodash.snakecase";
import parse from "parse-diff";
import { inspect } from "util";
import { isValidHexColor } from "../src/common/utils.js";
import { themes } from "../themes/index.js";

// Script variables
Expand All @@ -33,11 +34,11 @@ const THEME_CONTRIB_GUIDELINESS = `

\r> Also, note that if this theme is exclusively for your personal use, then instead of adding it to our theme collection, you can use card [customization options](https://github.com/anuraghazra/github-readme-stats#customization).
`;
const AVAILABLE_COLOR_PROPS = [
"bg_color",
const REQUIRED_COLOR_PROPS = [
"title_color",
"icon_color",
"text_color",
"title_color",
"bg_color",
];
const INVALID_REVIEW_COMMENT = (commentUrl) =>
`Some themes are invalid. See the [Automated Theme Preview](${commentUrl}) comment above for more information.`;
Expand Down Expand Up @@ -320,20 +321,6 @@ const parseJSON = (json) => {
}
};

/**
* Check if string is a valid hex color.
*
* @param {string} str String to check.
* @returns {boolean} Whether the string is a valid hex color.
*/
const isHexColor = (str, prefix = false) => {
if (prefix) {
return /^#[a-f0-9]{6}$/i.exec(str);
} else {
return /^[a-f0-9]{6}$/i.exec(str);
}
};

/**
* Check whether the theme name is still available.
* @param {string} name Theme name.
Expand Down Expand Up @@ -431,7 +418,7 @@ const run = async () => {
warning.push("Theme colors are missing");
invalidColors = true;
} else {
const missingKeys = AVAILABLE_COLOR_PROPS.filter(
const missingKeys = REQUIRED_COLOR_PROPS.filter(
(x) => !Object.keys(colors).includes(x),
);
if (missingKeys.length > 0) {
Expand All @@ -446,7 +433,7 @@ const run = async () => {
`Theme color property \`${colorKey}\` should not start with '#'`,
);
invalidColors = true;
} else if (!isHexColor(colorValue)) {
} else if (!isValidHexColor(colorValue)) {
errors.push(
`Theme color property \`${colorKey}\` is not a valid hex color: <code>#${colorValue}</code>`,
);
Expand Down Expand Up @@ -476,6 +463,7 @@ const run = async () => {
const iconColor = colors.icon_color;
const textColor = colors.text_color;
const bgColor = colors.bg_color;
const borderColor = colors.border_color;
const url = getGRSLink(colors);
const colorPairs = {
title_color: [titleColor, bgColor],
Expand Down Expand Up @@ -503,7 +491,9 @@ const run = async () => {

\r${warnings.map((warning) => `- :warning: ${warning}.\n`).join("")}

\ntitle_color: <code>#${titleColor}</code> | icon_color: <code>#${iconColor}</code> | text_color: <code>#${textColor}</code> | bg_color: <code>#${bgColor}</code>
\ntitle_color: <code>#${titleColor}</code> | icon_color: <code>#${iconColor}</code> | text_color: <code>#${textColor}</code> | bg_color: <code>#${bgColor}</code>${
borderColor ? ` | border_color: <code>#${borderColor}</code>` : ""
}

\r[Preview Link](${url})

Expand Down