2020-08-03 01:17:34 +08:00
|
|
|
const core = require("@actions/core");
|
|
|
|
const github = require("@actions/github");
|
|
|
|
const parse = require("parse-diff");
|
|
|
|
require("dotenv").config();
|
|
|
|
|
2020-08-10 22:31:19 +08:00
|
|
|
function getPrNumber() {
|
|
|
|
const pullRequest = github.context.payload.pull_request;
|
|
|
|
if (!pullRequest) {
|
|
|
|
return undefined;
|
2020-08-03 01:17:34 +08:00
|
|
|
}
|
2020-08-10 22:31:19 +08:00
|
|
|
|
|
|
|
return pullRequest.number;
|
|
|
|
}
|
2020-08-03 01:17:34 +08:00
|
|
|
|
2021-01-10 15:46:01 +08:00
|
|
|
const themeContribGuidelines = `
|
2021-10-02 04:14:10 +08:00
|
|
|
\rHi, thanks for the theme contribution, please read our theme [contribution guidelines](https://github.com/anuraghazra/github-readme-stats/blob/master/CONTRIBUTING.md#themes-contribution).
|
|
|
|
\rWe are currently only accepting color combinations from any VSCode theme or themes which have good color combination to minimize bloating the themes collection.
|
2021-01-10 15:46:01 +08:00
|
|
|
|
2021-10-02 04:14:10 +08:00
|
|
|
\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)
|
2021-01-10 15:46:01 +08:00
|
|
|
`;
|
|
|
|
|
2020-08-03 01:17:34 +08:00
|
|
|
async function run() {
|
|
|
|
try {
|
2020-08-06 00:27:11 +08:00
|
|
|
const token = core.getInput("token");
|
|
|
|
const octokit = github.getOctokit(token || process.env.PERSONAL_TOKEN);
|
2020-08-10 22:31:19 +08:00
|
|
|
const pullRequestId = getPrNumber();
|
|
|
|
|
|
|
|
if (!pullRequestId) {
|
|
|
|
console.log("PR not found");
|
|
|
|
return;
|
|
|
|
}
|
2020-08-03 01:17:34 +08:00
|
|
|
|
|
|
|
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: `
|
2021-09-26 23:46:20 +08:00
|
|
|
\r**Automated Theme preview**
|
2021-01-10 15:46:01 +08:00
|
|
|
|
|
|
|
\rCannot create theme preview
|
|
|
|
|
|
|
|
${themeContribGuidelines}
|
2020-08-03 01:17:34 +08:00
|
|
|
`,
|
|
|
|
issue_number: pullRequestId,
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
colors = colors.map((color) =>
|
2020-09-25 00:08:14 +08:00
|
|
|
color.replace(/.*\:\s/, "").replace(/\"/g, ""),
|
2020-08-03 01:17:34 +08:00
|
|
|
);
|
|
|
|
|
2021-01-10 15:46:01 +08:00
|
|
|
const titleColor = colors[0];
|
|
|
|
const iconColor = colors[1];
|
|
|
|
const textColor = colors[2];
|
|
|
|
const bgColor = colors[3];
|
2020-08-03 01:17:34 +08:00
|
|
|
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: `
|
2021-09-26 23:46:20 +08:00
|
|
|
\r**Automated Theme preview**
|
2020-08-14 23:57:45 +08:00
|
|
|
|
2021-01-10 16:08:11 +08:00
|
|
|
\ntitle_color: <code>#${titleColor}</code> | icon_color: <code>#${iconColor}</code> | text_color: <code>#${textColor}</code> | bg_color: <code>#${bgColor}</code>
|
2020-08-14 23:31:33 +08:00
|
|
|
|
2021-09-26 23:46:20 +08:00
|
|
|
\r[Preview Link](${url})
|
2021-01-10 15:46:01 +08:00
|
|
|
|
2020-08-14 23:31:33 +08:00
|
|
|
\r[![](${url})](${url})
|
2021-01-10 15:46:01 +08:00
|
|
|
|
|
|
|
${themeContribGuidelines}
|
2020-08-03 01:17:34 +08:00
|
|
|
`,
|
|
|
|
issue_number: pullRequestId,
|
|
|
|
});
|
|
|
|
} catch (error) {
|
2020-08-14 23:25:54 +08:00
|
|
|
console.log(error);
|
2020-08-03 01:17:34 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
run();
|