forked from mirrored/github-readme-stats
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
78d345d30e |
+30
-11
@@ -312,18 +312,30 @@ const parseJSON = (json) => {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
let parsedJson = json
|
// Remove trailing commas (if any).
|
||||||
|
let parsedJson = json.replace(/(,\s*})/g, "}");
|
||||||
|
|
||||||
|
// Remove JS comments (if any).
|
||||||
|
parsedJson = parsedJson.replace(/\/\/[A-z\s]*\s/g, "");
|
||||||
|
|
||||||
|
// Fix incorrect open bracket (if any).
|
||||||
|
const splitJson = parsedJson
|
||||||
.split(/([\s\r\s]*}[\s\r\s]*,[\s\r\s]*)(?=[\w"-]+:)/)
|
.split(/([\s\r\s]*}[\s\r\s]*,[\s\r\s]*)(?=[\w"-]+:)/)
|
||||||
.filter((x) => typeof x !== "string" || !!x.trim());
|
.filter((x) => typeof x !== "string" || !!x.trim()); // Split json into array of strings and objects.
|
||||||
if (parsedJson[0].replace(/\s+/g, "") === "},") {
|
if (splitJson[0].replace(/\s+/g, "") === "},") {
|
||||||
parsedJson[0] = "},";
|
splitJson[0] = "},";
|
||||||
if (!/\s*}\s*,?\s*$/.test(parsedJson[1])) {
|
if (!/\s*}\s*,?\s*$/.test(splitJson[1])) {
|
||||||
parsedJson.push(parsedJson.shift());
|
splitJson.push(splitJson.shift());
|
||||||
} else {
|
} else {
|
||||||
parsedJson.shift();
|
splitJson.shift();
|
||||||
}
|
}
|
||||||
return Hjson.parse(parsedJson.join(""));
|
parsedJson = splitJson.join("");
|
||||||
} else {
|
}
|
||||||
|
|
||||||
|
// Try to parse the fixed json.
|
||||||
|
try {
|
||||||
|
return Hjson.parse(parsedJson);
|
||||||
|
} catch (error) {
|
||||||
throw new IncorrectJsonFormatError(
|
throw new IncorrectJsonFormatError(
|
||||||
`Theme JSON file could not be parsed: ${error.message}`,
|
`Theme JSON file could not be parsed: ${error.message}`,
|
||||||
);
|
);
|
||||||
@@ -387,10 +399,17 @@ export const run = async () => {
|
|||||||
// Retrieve theme changes from the PR diff.
|
// Retrieve theme changes from the PR diff.
|
||||||
debug("Retrieve themes...");
|
debug("Retrieve themes...");
|
||||||
const diff = parse(res.data);
|
const diff = parse(res.data);
|
||||||
|
|
||||||
|
// Retrieve all theme changes from the PR diff and convert to JSON.
|
||||||
|
debug("Retrieve theme changes...");
|
||||||
const content = diff
|
const content = diff
|
||||||
.find((file) => file.to === "themes/index.js")
|
.find((file) => file.to === "themes/index.js")
|
||||||
.chunks[0].changes.filter((c) => c.type === "add")
|
.chunks.map((chunk) =>
|
||||||
.map((c) => c.content.replace("+", ""))
|
chunk.changes
|
||||||
|
.filter((c) => c.type === "add")
|
||||||
|
.map((c) => c.content.replace("+", ""))
|
||||||
|
.join(""),
|
||||||
|
)
|
||||||
.join("");
|
.join("");
|
||||||
const themeObject = parseJSON(content);
|
const themeObject = parseJSON(content);
|
||||||
if (
|
if (
|
||||||
|
|||||||
Reference in New Issue
Block a user