Merge branch 'master' into issue#287

This commit is contained in:
rjoydip
2020-08-07 10:16:33 +05:30
5 changed files with 145 additions and 8 deletions
+30
View File
@@ -0,0 +1,30 @@
name: Theme preview
on:
pull_request:
types: [opened, synchronize, reopened]
branches:
- master
- theme-preview-script
- "themes/index.js"
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: setup node
uses: actions/setup-node@v1
with:
node-version: "12.x"
- name: npm install, preview theme
run: |
npm install
npm run preview-theme
env:
CI: true
PERSONAL_TOKEN: ${{ secrets.PERSONAL_TOKEN }}
with:
token: ${{ secrets.GITHUB_TOKEN }}
+6 -2
View File
@@ -6,18 +6,22 @@
"scripts": {
"test": "jest --coverage",
"test:watch": "jest --watch",
"theme-readme-gen": "node scripts/generate-theme-doc"
"theme-readme-gen": "node scripts/generate-theme-doc",
"preview-theme": "node scripts/preview-theme"
},
"author": "Anurag Hazra",
"license": "MIT",
"devDependencies": {
"@actions/core": "^1.2.4",
"@actions/github": "^4.0.0",
"@testing-library/dom": "^7.20.0",
"@testing-library/jest-dom": "^5.11.0",
"axios": "^0.19.2",
"axios-mock-adapter": "^1.18.1",
"css-to-object": "^1.1.0",
"husky": "^4.2.5",
"jest": "^26.1.0"
"jest": "^26.1.0",
"parse-diff": "^0.7.0"
},
"dependencies": {
"dotenv": "^8.2.0",
+77
View File
@@ -0,0 +1,77 @@
const core = require("@actions/core");
const github = require("@actions/github");
const parse = require("parse-diff");
require("dotenv").config();
const parsePullRequestId = (githubRef) => {
const result = /refs\/pull\/(\d+)\/merge/g.exec(githubRef);
if (!result) {
console.log("Reference not found.");
return 297;
}
const [, pullRequestId] = result;
return pullRequestId;
};
async function run() {
try {
const token = core.getInput("token");
const octokit = github.getOctokit(token || process.env.PERSONAL_TOKEN);
const pullRequestId = parsePullRequestId(process.env.GITHUB_REF);
let res = await octokit.pulls.get({
owner: "anuraghazra",
repo: "github-readme-stats",
pull_number: pullRequestId,
mediaType: {
format: "diff",
},
});
let diff = parse(res.data);
let colorStrings = diff
.find((file) => file.to === "themes/index.js")
.chunks[0].changes.filter((c) => c.type === "add")
.map((c) => c.content.replace("+", ""))
.join("");
let matches = colorStrings.match(/(title_color:.*bg_color.*\")/);
let colors = matches && matches[0].split(",");
if (!colors) {
await octokit.issues.createComment({
owner: "anuraghazra",
repo: "github-readme-stats",
body: `
\rTheme preview (bot)
Cannot create theme preview
`,
issue_number: pullRequestId,
});
return;
}
colors = colors.map((color) =>
color.replace(/.*\:\s/, "").replace(/\"/g, "")
);
let titleColor = colors[0];
let iconColor = colors[1];
let textColor = colors[2];
let bgColor = colors[3];
const url = `https://github-readme-stats.vercel.app/api?username=anuraghazra&title_color=${titleColor}&icon_color=${iconColor}&text_color=${textColor}&bg_color=${bgColor}&show_icons=true`;
await octokit.issues.createComment({
owner: "anuraghazra",
repo: "github-readme-stats",
body: `
\rTheme preview (bot)
\r![](${url})
`,
issue_number: pullRequestId,
});
} catch (error) {
core.setFailed(error.message);
}
}
run();
+12 -4
View File
@@ -22,8 +22,9 @@ Use `?theme=THEME_NAME` parameter like so :-
| `highcontrast` ![highcontrast][highcontrast] | `dracula` ![dracula][dracula] | `prussian` ![prussian][prussian] |
| `monokai` ![monokai][monokai] | `vue` ![vue][vue] | `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] | `solarized-dark` ![solarized-dark][solarized-dark] |
| `solarized-light` ![solarized-light][solarized-light] | | [Add your theme][add-theme] |
| `algolia` ![algolia][algolia] | `great-gatsby` ![great-gatsby][great-gatsby] | `bear` ![bear][bear] |
| `solarized-dark` ![solarized-dark][solarized-dark] | `solarized-light` ![solarized-light][solarized-light] | `nord` ![nord][nord] |
| `gotham` ![gotham][gotham] | | [Add your theme][add-theme] |
## Repo Card
@@ -37,8 +38,9 @@ Use `?theme=THEME_NAME` parameter like so :-
| `highcontrast` ![highcontrast][highcontrast_repo] | `dracula` ![dracula][dracula_repo] | `prussian` ![prussian][prussian_repo] |
| `monokai` ![monokai][monokai_repo] | `vue` ![vue][vue_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] | `solarized-dark` ![solarized-dark][solarized-dark_repo] |
| `solarized-light` ![solarized-light][solarized-light_repo] | | [Add your theme][add-theme] |
| `algolia` ![algolia][algolia_repo] | `great-gatsby` ![great-gatsby][great-gatsby_repo] | `bear` ![bear][bear_repo] |
| `solarized-dark` ![solarized-dark][solarized-dark_repo] | `solarized-light` ![solarized-light][solarized-light_repo] | `nord` ![nord][nord_repo] |
| `gotham` ![gotham][gotham_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
@@ -62,8 +64,11 @@ Use `?theme=THEME_NAME` parameter like so :-
[blue-green]: https://github-readme-stats.vercel.app/api?username=anuraghazra&show_icons=true&hide=contribs,prs&cache_seconds=86400&theme=blue-green
[algolia]: https://github-readme-stats.vercel.app/api?username=anuraghazra&show_icons=true&hide=contribs,prs&cache_seconds=86400&theme=algolia
[great-gatsby]: https://github-readme-stats.vercel.app/api?username=anuraghazra&show_icons=true&hide=contribs,prs&cache_seconds=86400&theme=great-gatsby
[bear]: https://github-readme-stats.vercel.app/api?username=anuraghazra&show_icons=true&hide=contribs,prs&cache_seconds=86400&theme=bear
[solarized-dark]: https://github-readme-stats.vercel.app/api?username=anuraghazra&show_icons=true&hide=contribs,prs&cache_seconds=86400&theme=solarized-dark
[solarized-light]: https://github-readme-stats.vercel.app/api?username=anuraghazra&show_icons=true&hide=contribs,prs&cache_seconds=86400&theme=solarized-light
[nord]: https://github-readme-stats.vercel.app/api?username=anuraghazra&show_icons=true&hide=contribs,prs&cache_seconds=86400&theme=nord
[gotham]: https://github-readme-stats.vercel.app/api?username=anuraghazra&show_icons=true&hide=contribs,prs&cache_seconds=86400&theme=gotham
[default_repo]: https://github-readme-stats.vercel.app/api/pin/?username=anuraghazra&repo=github-readme-stats&cache_seconds=86400&theme=default
@@ -87,8 +92,11 @@ Use `?theme=THEME_NAME` parameter like so :-
[blue-green_repo]: https://github-readme-stats.vercel.app/api/pin/?username=anuraghazra&repo=github-readme-stats&cache_seconds=86400&theme=blue-green
[algolia_repo]: https://github-readme-stats.vercel.app/api/pin/?username=anuraghazra&repo=github-readme-stats&cache_seconds=86400&theme=algolia
[great-gatsby_repo]: https://github-readme-stats.vercel.app/api/pin/?username=anuraghazra&repo=github-readme-stats&cache_seconds=86400&theme=great-gatsby
[bear_repo]: https://github-readme-stats.vercel.app/api/pin/?username=anuraghazra&repo=github-readme-stats&cache_seconds=86400&theme=bear
[solarized-dark_repo]: https://github-readme-stats.vercel.app/api/pin/?username=anuraghazra&repo=github-readme-stats&cache_seconds=86400&theme=solarized-dark
[solarized-light_repo]: https://github-readme-stats.vercel.app/api/pin/?username=anuraghazra&repo=github-readme-stats&cache_seconds=86400&theme=solarized-light
[nord_repo]: https://github-readme-stats.vercel.app/api/pin/?username=anuraghazra&repo=github-readme-stats&cache_seconds=86400&theme=nord
[gotham_repo]: https://github-readme-stats.vercel.app/api/pin/?username=anuraghazra&repo=github-readme-stats&cache_seconds=86400&theme=gotham
[add-theme]: https://github.com/anuraghazra/github-readme-stats/edit/master/themes/index.js
+20 -2
View File
@@ -113,18 +113,24 @@ const themes = {
text_color: "0cf574",
bg_color: "040f0f",
},
"algolia": {
algolia: {
title_color: "00AEFF",
icon_color: "2DDE98",
text_color: "FFFFFF",
bg_color: "050F2C",
},
"great-gatsby":{
"great-gatsby": {
title_color: "ffa726",
icon_color: "ffb74d",
text_color: "ffd95b",
bg_color: "000000",
},
bear: {
title_color: "e03c8a",
icon_color: "00AEFF",
text_color: "bcb28d",
bg_color: "1f2023",
},
"solarized-dark": {
title_color: "268bd2",
icon_color: "b58900",
@@ -137,6 +143,18 @@ const themes = {
text_color: "859900",
bg_color: "fdf6e3",
},
nord: {
title_color: "81a1c1",
text_color: "d8dee9",
icon_color: "88c0d0",
bg_color: "2e3440",
},
"gotham": {
title_color: "2aa889",
icon_color: "599cab",
text_color: "99d1ce",
bg_color: "0c1014",
},
};
module.exports = themes;