From d56b294ca16e63c58567ac3b54fabf30bb508446 Mon Sep 17 00:00:00 2001 From: Rick Staa Date: Sun, 2 Oct 2022 14:50:03 +0200 Subject: [PATCH 1/4] style: improve code style --- scripts/close-stale-theme-prs.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/close-stale-theme-prs.js b/scripts/close-stale-theme-prs.js index 69e5e193..8c14c1e3 100644 --- a/scripts/close-stale-theme-prs.js +++ b/scripts/close-stale-theme-prs.js @@ -126,7 +126,7 @@ const run = async () => { const prs = await fetchOpenPRs(octokit, owner, repo); const themePRs = pullsWithLabel(prs, "themes"); const invalidThemePRs = pullsWithLabel(themePRs, "invalid"); - debug("Retrieving stale themePRs..."); + debug("Retrieving stale theme PRs..."); const staleThemePRs = invalidThemePRs.filter((pr) => isStale(pr, staleDays), ); From 84c9d354b3fabec196b1a4fc9cb4700582b803dd Mon Sep 17 00:00:00 2001 From: Anurag Hazra Date: Sun, 2 Oct 2022 21:01:38 +0530 Subject: [PATCH 2/4] docs(theme): Auto update theme readme (#2091) Co-authored-by: Github Readme Stats Bot --- themes/README.md | 84 +++++++++++++++++++++++++----------------------- 1 file changed, 44 insertions(+), 40 deletions(-) diff --git a/themes/README.md b/themes/README.md index e8b22b26..b8649d43 100644 --- a/themes/README.md +++ b/themes/README.md @@ -16,26 +16,27 @@ Use `?theme=THEME_NAME` parameter like so :- | | | | | :--: | :--: | :--: | -| `default` ![default][default] | `dark` ![dark][dark] | `radical` ![radical][radical] | -| `merko` ![merko][merko] | `gruvbox` ![gruvbox][gruvbox] | `gruvbox_light` ![gruvbox_light][gruvbox_light] | -| `tokyonight` ![tokyonight][tokyonight] | `onedark` ![onedark][onedark] | `cobalt` ![cobalt][cobalt] | -| `synthwave` ![synthwave][synthwave] | `highcontrast` ![highcontrast][highcontrast] | `dracula` ![dracula][dracula] | -| `prussian` ![prussian][prussian] | `monokai` ![monokai][monokai] | `vue` ![vue][vue] | -| `vue-dark` ![vue-dark][vue-dark] | `shades-of-purple` ![shades-of-purple][shades-of-purple] | `nightowl` ![nightowl][nightowl] | -| `buefy` ![buefy][buefy] | `blue-green` ![blue-green][blue-green] | `algolia` ![algolia][algolia] | -| `great-gatsby` ![great-gatsby][great-gatsby] | `darcula` ![darcula][darcula] | `bear` ![bear][bear] | -| `solarized-dark` ![solarized-dark][solarized-dark] | `solarized-light` ![solarized-light][solarized-light] | `chartreuse-dark` ![chartreuse-dark][chartreuse-dark] | -| `nord` ![nord][nord] | `gotham` ![gotham][gotham] | `material-palenight` ![material-palenight][material-palenight] | -| `graywhite` ![graywhite][graywhite] | `vision-friendly-dark` ![vision-friendly-dark][vision-friendly-dark] | `ayu-mirage` ![ayu-mirage][ayu-mirage] | -| `midnight-purple` ![midnight-purple][midnight-purple] | `calm` ![calm][calm] | `flag-india` ![flag-india][flag-india] | -| `omni` ![omni][omni] | `react` ![react][react] | `jolly` ![jolly][jolly] | -| `maroongold` ![maroongold][maroongold] | `yeblu` ![yeblu][yeblu] | `blueberry` ![blueberry][blueberry] | -| `slateorange` ![slateorange][slateorange] | `kacho_ga` ![kacho_ga][kacho_ga] | `outrun` ![outrun][outrun] | -| `ocean_dark` ![ocean_dark][ocean_dark] | `city_lights` ![city_lights][city_lights] | `github_dark` ![github_dark][github_dark] | -| `discord_old_blurple` ![discord_old_blurple][discord_old_blurple] | `aura_dark` ![aura_dark][aura_dark] | `panda` ![panda][panda] | -| `noctis_minimus` ![noctis_minimus][noctis_minimus] | `cobalt2` ![cobalt2][cobalt2] | `swift` ![swift][swift] | -| `aura` ![aura][aura] | `apprentice` ![apprentice][apprentice] | `moltack` ![moltack][moltack] | -| `codeSTACKr` ![codeSTACKr][codeSTACKr] | `rose_pine` ![rose_pine][rose_pine] | [Add your theme][add-theme] | +| `default` ![default][default] | `transparent` ![transparent][transparent] | `dark` ![dark][dark] | +| `radical` ![radical][radical] | `merko` ![merko][merko] | `gruvbox` ![gruvbox][gruvbox] | +| `gruvbox_light` ![gruvbox_light][gruvbox_light] | `tokyonight` ![tokyonight][tokyonight] | `onedark` ![onedark][onedark] | +| `cobalt` ![cobalt][cobalt] | `synthwave` ![synthwave][synthwave] | `highcontrast` ![highcontrast][highcontrast] | +| `dracula` ![dracula][dracula] | `prussian` ![prussian][prussian] | `monokai` ![monokai][monokai] | +| `vue` ![vue][vue] | `vue-dark` ![vue-dark][vue-dark] | `shades-of-purple` ![shades-of-purple][shades-of-purple] | +| `nightowl` ![nightowl][nightowl] | `buefy` ![buefy][buefy] | `blue-green` ![blue-green][blue-green] | +| `algolia` ![algolia][algolia] | `great-gatsby` ![great-gatsby][great-gatsby] | `darcula` ![darcula][darcula] | +| `bear` ![bear][bear] | `solarized-dark` ![solarized-dark][solarized-dark] | `solarized-light` ![solarized-light][solarized-light] | +| `chartreuse-dark` ![chartreuse-dark][chartreuse-dark] | `nord` ![nord][nord] | `gotham` ![gotham][gotham] | +| `material-palenight` ![material-palenight][material-palenight] | `graywhite` ![graywhite][graywhite] | `vision-friendly-dark` ![vision-friendly-dark][vision-friendly-dark] | +| `ayu-mirage` ![ayu-mirage][ayu-mirage] | `midnight-purple` ![midnight-purple][midnight-purple] | `calm` ![calm][calm] | +| `flag-india` ![flag-india][flag-india] | `omni` ![omni][omni] | `react` ![react][react] | +| `jolly` ![jolly][jolly] | `maroongold` ![maroongold][maroongold] | `yeblu` ![yeblu][yeblu] | +| `blueberry` ![blueberry][blueberry] | `slateorange` ![slateorange][slateorange] | `kacho_ga` ![kacho_ga][kacho_ga] | +| `outrun` ![outrun][outrun] | `ocean_dark` ![ocean_dark][ocean_dark] | `city_lights` ![city_lights][city_lights] | +| `github_dark` ![github_dark][github_dark] | `discord_old_blurple` ![discord_old_blurple][discord_old_blurple] | `aura_dark` ![aura_dark][aura_dark] | +| `panda` ![panda][panda] | `noctis_minimus` ![noctis_minimus][noctis_minimus] | `cobalt2` ![cobalt2][cobalt2] | +| `swift` ![swift][swift] | `aura` ![aura][aura] | `apprentice` ![apprentice][apprentice] | +| `moltack` ![moltack][moltack] | `codeSTACKr` ![codeSTACKr][codeSTACKr] | `rose_pine` ![rose_pine][rose_pine] | +| [Add your theme][add-theme] | | | ## Repo Card @@ -43,30 +44,32 @@ Use `?theme=THEME_NAME` parameter like so :- | | | | | :--: | :--: | :--: | -| `default_repocard` ![default_repocard][default_repocard_repo] | `dark` ![dark][dark_repo] | `radical` ![radical][radical_repo] | -| `merko` ![merko][merko_repo] | `gruvbox` ![gruvbox][gruvbox_repo] | `gruvbox_light` ![gruvbox_light][gruvbox_light_repo] | -| `tokyonight` ![tokyonight][tokyonight_repo] | `onedark` ![onedark][onedark_repo] | `cobalt` ![cobalt][cobalt_repo] | -| `synthwave` ![synthwave][synthwave_repo] | `highcontrast` ![highcontrast][highcontrast_repo] | `dracula` ![dracula][dracula_repo] | -| `prussian` ![prussian][prussian_repo] | `monokai` ![monokai][monokai_repo] | `vue` ![vue][vue_repo] | -| `vue-dark` ![vue-dark][vue-dark_repo] | `shades-of-purple` ![shades-of-purple][shades-of-purple_repo] | `nightowl` ![nightowl][nightowl_repo] | -| `buefy` ![buefy][buefy_repo] | `blue-green` ![blue-green][blue-green_repo] | `algolia` ![algolia][algolia_repo] | -| `great-gatsby` ![great-gatsby][great-gatsby_repo] | `darcula` ![darcula][darcula_repo] | `bear` ![bear][bear_repo] | -| `solarized-dark` ![solarized-dark][solarized-dark_repo] | `solarized-light` ![solarized-light][solarized-light_repo] | `chartreuse-dark` ![chartreuse-dark][chartreuse-dark_repo] | -| `nord` ![nord][nord_repo] | `gotham` ![gotham][gotham_repo] | `material-palenight` ![material-palenight][material-palenight_repo] | -| `graywhite` ![graywhite][graywhite_repo] | `vision-friendly-dark` ![vision-friendly-dark][vision-friendly-dark_repo] | `ayu-mirage` ![ayu-mirage][ayu-mirage_repo] | -| `midnight-purple` ![midnight-purple][midnight-purple_repo] | `calm` ![calm][calm_repo] | `flag-india` ![flag-india][flag-india_repo] | -| `omni` ![omni][omni_repo] | `react` ![react][react_repo] | `jolly` ![jolly][jolly_repo] | -| `maroongold` ![maroongold][maroongold_repo] | `yeblu` ![yeblu][yeblu_repo] | `blueberry` ![blueberry][blueberry_repo] | -| `slateorange` ![slateorange][slateorange_repo] | `kacho_ga` ![kacho_ga][kacho_ga_repo] | `outrun` ![outrun][outrun_repo] | -| `ocean_dark` ![ocean_dark][ocean_dark_repo] | `city_lights` ![city_lights][city_lights_repo] | `github_dark` ![github_dark][github_dark_repo] | -| `discord_old_blurple` ![discord_old_blurple][discord_old_blurple_repo] | `aura_dark` ![aura_dark][aura_dark_repo] | `panda` ![panda][panda_repo] | -| `noctis_minimus` ![noctis_minimus][noctis_minimus_repo] | `cobalt2` ![cobalt2][cobalt2_repo] | `swift` ![swift][swift_repo] | -| `aura` ![aura][aura_repo] | `apprentice` ![apprentice][apprentice_repo] | `moltack` ![moltack][moltack_repo] | -| `codeSTACKr` ![codeSTACKr][codeSTACKr_repo] | `rose_pine` ![rose_pine][rose_pine_repo] | [Add your theme][add-theme] | +| `default_repocard` ![default_repocard][default_repocard_repo] | `transparent` ![transparent][transparent_repo] | `dark` ![dark][dark_repo] | +| `radical` ![radical][radical_repo] | `merko` ![merko][merko_repo] | `gruvbox` ![gruvbox][gruvbox_repo] | +| `gruvbox_light` ![gruvbox_light][gruvbox_light_repo] | `tokyonight` ![tokyonight][tokyonight_repo] | `onedark` ![onedark][onedark_repo] | +| `cobalt` ![cobalt][cobalt_repo] | `synthwave` ![synthwave][synthwave_repo] | `highcontrast` ![highcontrast][highcontrast_repo] | +| `dracula` ![dracula][dracula_repo] | `prussian` ![prussian][prussian_repo] | `monokai` ![monokai][monokai_repo] | +| `vue` ![vue][vue_repo] | `vue-dark` ![vue-dark][vue-dark_repo] | `shades-of-purple` ![shades-of-purple][shades-of-purple_repo] | +| `nightowl` ![nightowl][nightowl_repo] | `buefy` ![buefy][buefy_repo] | `blue-green` ![blue-green][blue-green_repo] | +| `algolia` ![algolia][algolia_repo] | `great-gatsby` ![great-gatsby][great-gatsby_repo] | `darcula` ![darcula][darcula_repo] | +| `bear` ![bear][bear_repo] | `solarized-dark` ![solarized-dark][solarized-dark_repo] | `solarized-light` ![solarized-light][solarized-light_repo] | +| `chartreuse-dark` ![chartreuse-dark][chartreuse-dark_repo] | `nord` ![nord][nord_repo] | `gotham` ![gotham][gotham_repo] | +| `material-palenight` ![material-palenight][material-palenight_repo] | `graywhite` ![graywhite][graywhite_repo] | `vision-friendly-dark` ![vision-friendly-dark][vision-friendly-dark_repo] | +| `ayu-mirage` ![ayu-mirage][ayu-mirage_repo] | `midnight-purple` ![midnight-purple][midnight-purple_repo] | `calm` ![calm][calm_repo] | +| `flag-india` ![flag-india][flag-india_repo] | `omni` ![omni][omni_repo] | `react` ![react][react_repo] | +| `jolly` ![jolly][jolly_repo] | `maroongold` ![maroongold][maroongold_repo] | `yeblu` ![yeblu][yeblu_repo] | +| `blueberry` ![blueberry][blueberry_repo] | `slateorange` ![slateorange][slateorange_repo] | `kacho_ga` ![kacho_ga][kacho_ga_repo] | +| `outrun` ![outrun][outrun_repo] | `ocean_dark` ![ocean_dark][ocean_dark_repo] | `city_lights` ![city_lights][city_lights_repo] | +| `github_dark` ![github_dark][github_dark_repo] | `discord_old_blurple` ![discord_old_blurple][discord_old_blurple_repo] | `aura_dark` ![aura_dark][aura_dark_repo] | +| `panda` ![panda][panda_repo] | `noctis_minimus` ![noctis_minimus][noctis_minimus_repo] | `cobalt2` ![cobalt2][cobalt2_repo] | +| `swift` ![swift][swift_repo] | `aura` ![aura][aura_repo] | `apprentice` ![apprentice][apprentice_repo] | +| `moltack` ![moltack][moltack_repo] | `codeSTACKr` ![codeSTACKr][codeSTACKr_repo] | `rose_pine` ![rose_pine][rose_pine_repo] | +| [Add your theme][add-theme] | | | [default]: https://github-readme-stats.vercel.app/api?username=anuraghazra&show_icons=true&hide=contribs,prs&cache_seconds=86400&theme=default [default_repocard]: https://github-readme-stats.vercel.app/api?username=anuraghazra&show_icons=true&hide=contribs,prs&cache_seconds=86400&theme=default_repocard +[transparent]: https://github-readme-stats.vercel.app/api?username=anuraghazra&show_icons=true&hide=contribs,prs&cache_seconds=86400&theme=transparent [dark]: https://github-readme-stats.vercel.app/api?username=anuraghazra&show_icons=true&hide=contribs,prs&cache_seconds=86400&theme=dark [radical]: https://github-readme-stats.vercel.app/api?username=anuraghazra&show_icons=true&hide=contribs,prs&cache_seconds=86400&theme=radical [merko]: https://github-readme-stats.vercel.app/api?username=anuraghazra&show_icons=true&hide=contribs,prs&cache_seconds=86400&theme=merko @@ -129,6 +132,7 @@ Use `?theme=THEME_NAME` parameter like so :- [default_repo]: https://github-readme-stats.vercel.app/api/pin/?username=anuraghazra&repo=github-readme-stats&cache_seconds=86400&theme=default [default_repocard_repo]: https://github-readme-stats.vercel.app/api/pin/?username=anuraghazra&repo=github-readme-stats&cache_seconds=86400&theme=default_repocard +[transparent_repo]: https://github-readme-stats.vercel.app/api/pin/?username=anuraghazra&repo=github-readme-stats&cache_seconds=86400&theme=transparent [dark_repo]: https://github-readme-stats.vercel.app/api/pin/?username=anuraghazra&repo=github-readme-stats&cache_seconds=86400&theme=dark [radical_repo]: https://github-readme-stats.vercel.app/api/pin/?username=anuraghazra&repo=github-readme-stats&cache_seconds=86400&theme=radical [merko_repo]: https://github-readme-stats.vercel.app/api/pin/?username=anuraghazra&repo=github-readme-stats&cache_seconds=86400&theme=merko From 822efbf6cb991732ed3fe7460c6831e48a407a38 Mon Sep 17 00:00:00 2001 From: Rick Staa Date: Sun, 2 Oct 2022 17:41:28 +0200 Subject: [PATCH 3/4] ci: fix small bugs in theme-preview action (#2093) * ci: fix small bugs in theme-preview action * ci: format code --- scripts/helpers.js | 4 +++- scripts/preview-theme.js | 49 ++++++++++++++++++++++++++++------------ 2 files changed, 38 insertions(+), 15 deletions(-) diff --git a/scripts/helpers.js b/scripts/helpers.js index fabf300f..3fc5fc7d 100644 --- a/scripts/helpers.js +++ b/scripts/helpers.js @@ -2,6 +2,8 @@ * @file Contains helper functions used in the scripts. */ +import { getInput } from "@actions/core"; + // Script variables. const OWNER = "anuraghazra"; const REPO = "github-readme-stats"; @@ -32,7 +34,7 @@ export const getRepoInfo = (ctx) => { * @returns {string} Github token. */ export const getGithubToken = () => { - const token = core.getInput("github_token") || process.env.GITHUB_TOKEN; + const token = getInput("github_token") || process.env.GITHUB_TOKEN; if (!token) { throw Error("Could not find github token"); } diff --git a/scripts/preview-theme.js b/scripts/preview-theme.js index 94145fb2..6bb29e68 100644 --- a/scripts/preview-theme.js +++ b/scripts/preview-theme.js @@ -33,12 +33,15 @@ 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 REQUIRED_COLOR_PROPS = [ - "title_color", - "icon_color", - "text_color", - "bg_color", -]; +const COLOR_PROPS = { + title_color: 6, + icon_color: 6, + text_color: 6, + bg_color: 8, + border_color: 6, +}; +const ACCEPTED_COLOR_PROPS = Object.keys(COLOR_PROPS); +const REQUIRED_COLOR_PROPS = ACCEPTED_COLOR_PROPS.slice(0, 4); const INVALID_REVIEW_COMMENT = (commentUrl) => `Some themes are invalid. See the [Automated Theme Preview](${commentUrl}) comment above for more information.`; @@ -271,11 +274,11 @@ const parseJSON = (json) => { } } catch (error) { let parsedJson = json - .split(/(?:\s*)(}\s*,?)(?:\s*)(?=\s*[a-z_"]+:+)/) + .split(/([\s\r\s]*}[\s\r\s]*,[\s\r\s]*)(?=[\w"-]+:)/) .filter((x) => typeof x !== "string" || !!x.trim()); if (parsedJson[0].replace(/\s+/g, "") === "},") { parsedJson[0] = "},"; - if (!/\s*}\s*,?\s*$/.test(parsedJson[0])) { + if (!/\s*}\s*,?\s*$/.test(parsedJson[1])) { parsedJson.push(parsedJson.shift()); } else { parsedJson.shift(); @@ -299,7 +302,7 @@ const themeNameAlreadyExists = (name) => { /** * Main function. */ -const run = async () => { +export const run = async (prNumber) => { try { const dryRun = process.env.DRY_RUN === "true" || false; debug("Retrieve action information from context..."); @@ -310,7 +313,7 @@ const run = async () => { `; const ccc = new ColorContrastChecker(); const octokit = github.getOctokit(getGithubToken()); - const pullRequestId = getPrNumber(); + const pullRequestId = prNumber ? prNumber : getPrNumber(); const commenter = getCommenter(); const { owner, repo } = getRepoInfo(github.context); debug(`Owner: ${owner}`); @@ -387,10 +390,19 @@ const run = async () => { const missingKeys = REQUIRED_COLOR_PROPS.filter( (x) => !Object.keys(colors).includes(x), ); - if (missingKeys.length > 0) { + const extraKeys = Object.keys(colors).filter( + (x) => !ACCEPTED_COLOR_PROPS.includes(x), + ); + if (missingKeys.length > 0 || extraKeys.length > 0) { for (const missingKey of missingKeys) { errors.push(`Theme color properties \`${missingKey}\` are missing`); } + + for (const extraKey of extraKeys) { + warnings.push( + `Theme color properties \`${extraKey}\` is not supported`, + ); + } invalidColors = true; } else { for (const [colorKey, colorValue] of Object.entries(colors)) { @@ -399,6 +411,11 @@ const run = async () => { `Theme color property \`${colorKey}\` should not start with '#'`, ); invalidColors = true; + } else if (colorValue.length > COLOR_PROPS[colorKey]) { + errors.push( + `Theme color property \`${colorKey}\` can not be longer than \`${COLOR_PROPS[colorKey]}\` characters`, + ); + invalidColors = true; } else if (!isValidHexColor(colorValue)) { errors.push( `Theme color property \`${colorKey}\` is not a valid hex color: #${colorValue}`, @@ -437,8 +454,10 @@ const run = async () => { text_color: [textColor, bgColor], }; Object.keys(colorPairs).forEach((item) => { - const color1 = colorPairs[item][0]; - const color2 = colorPairs[item][1]; + let color1 = colorPairs[item][0]; + let color2 = colorPairs[item][1]; + color1 = color1.length === 4 ? color1.slice(0, 3) : color1.slice(0, 6); + color2 = color2.length === 4 ? color2.slice(0, 3) : color2.slice(0, 6); if (!ccc.isLevelAA(`#${color1}`, `#${color2}`)) { const permalink = getWebAimLink(color1, color2); warnings.push( @@ -543,4 +562,6 @@ const run = async () => { } }; -run(); +if (typeof require !== "undefined" && require.main === module) { + run(); +} From 5d42af59c0214de3627788c7b1a4e22c5f32a655 Mon Sep 17 00:00:00 2001 From: rickstaa Date: Sun, 2 Oct 2022 17:42:58 +0200 Subject: [PATCH 4/4] ci: fix small bug in theme-preview action --- scripts/preview-theme.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/scripts/preview-theme.js b/scripts/preview-theme.js index 6bb29e68..58aad028 100644 --- a/scripts/preview-theme.js +++ b/scripts/preview-theme.js @@ -562,6 +562,4 @@ export const run = async (prNumber) => { } }; -if (typeof require !== "undefined" && require.main === module) { - run(); -} +run();