fix theme preview (#2564)
* ci: fix theme preview action * fix: fix some bugs in the 'theme-preveiw' action
This commit is contained in:
1 parent
976771080f
commit
1e61f9f3fe
1 file changed
+32
-9
@@ -43,12 +43,24 @@ const ACCEPTED_COLOR_PROPS = Object.keys(COLOR_PROPS);
|
|||||||
const REQUIRED_COLOR_PROPS = ACCEPTED_COLOR_PROPS.slice(0, 4);
|
const REQUIRED_COLOR_PROPS = ACCEPTED_COLOR_PROPS.slice(0, 4);
|
||||||
const INVALID_REVIEW_COMMENT = (commentUrl) =>
|
const INVALID_REVIEW_COMMENT = (commentUrl) =>
|
||||||
`Some themes are invalid. See the [Automated Theme Preview](${commentUrl}) comment above for more information.`;
|
`Some themes are invalid. See the [Automated Theme Preview](${commentUrl}) comment above for more information.`;
|
||||||
|
var OCTOKIT;
|
||||||
// Retrieve octokit instance.
|
var OWNER;
|
||||||
const OCTOKIT = github.getOctokit(getGithubToken());
|
var REPO;
|
||||||
const { OWNER, REPO } = getRepoInfo(github.context);
|
|
||||||
var PULL_REQUEST_ID;
|
var PULL_REQUEST_ID;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Incorrect JSON format error.
|
||||||
|
* @extends Error
|
||||||
|
* @param {string} message Error message.
|
||||||
|
* @returns {Error} IncorrectJsonFormatError.
|
||||||
|
*/
|
||||||
|
class IncorrectJsonFormatError extends Error {
|
||||||
|
constructor(message) {
|
||||||
|
super(message);
|
||||||
|
this.name = "IncorrectJsonFormatError";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve PR number from the event payload.
|
* Retrieve PR number from the event payload.
|
||||||
*
|
*
|
||||||
@@ -274,7 +286,9 @@ const parseJSON = (json) => {
|
|||||||
if (typeof parsedJson === "object") {
|
if (typeof parsedJson === "object") {
|
||||||
return parsedJson;
|
return parsedJson;
|
||||||
} else {
|
} else {
|
||||||
throw new Error("PR diff is not a valid theme JSON object.");
|
throw new IncorrectJsonFormatError(
|
||||||
|
"PR diff is not a valid theme JSON object.",
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
let parsedJson = json
|
let parsedJson = json
|
||||||
@@ -289,7 +303,9 @@ const parseJSON = (json) => {
|
|||||||
}
|
}
|
||||||
return Hjson.parse(parsedJson.join(""));
|
return Hjson.parse(parsedJson.join(""));
|
||||||
} else {
|
} else {
|
||||||
throw error;
|
throw new IncorrectJsonFormatError(
|
||||||
|
`Theme JSON file could not be parsed: ${error.message}`,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -317,6 +333,11 @@ export const run = async () => {
|
|||||||
\r${THEME_CONTRIB_GUIDELINESS}
|
\r${THEME_CONTRIB_GUIDELINESS}
|
||||||
`;
|
`;
|
||||||
const ccc = new ColorContrastChecker();
|
const ccc = new ColorContrastChecker();
|
||||||
|
OCTOKIT = github.getOctokit(getGithubToken());
|
||||||
|
PULL_REQUEST_ID = getPrNumber();
|
||||||
|
const { owner, repo } = getRepoInfo(github.context);
|
||||||
|
OWNER = owner;
|
||||||
|
REPO = repo;
|
||||||
const commenter = getCommenter();
|
const commenter = getCommenter();
|
||||||
PULL_REQUEST_ID = getPrNumber();
|
PULL_REQUEST_ID = getPrNumber();
|
||||||
debug(`Owner: ${OWNER}`);
|
debug(`Owner: ${OWNER}`);
|
||||||
@@ -326,8 +347,8 @@ export const run = async () => {
|
|||||||
// Retrieve the PR diff and preview-theme comment.
|
// Retrieve the PR diff and preview-theme comment.
|
||||||
debug("Retrieve PR diff...");
|
debug("Retrieve PR diff...");
|
||||||
const res = await OCTOKIT.pulls.get({
|
const res = await OCTOKIT.pulls.get({
|
||||||
OWNER,
|
owner: OWNER,
|
||||||
REPO,
|
repo: REPO,
|
||||||
pull_number: PULL_REQUEST_ID,
|
pull_number: PULL_REQUEST_ID,
|
||||||
mediaType: {
|
mediaType: {
|
||||||
format: "diff",
|
format: "diff",
|
||||||
@@ -569,7 +590,9 @@ export const run = async () => {
|
|||||||
OWNER,
|
OWNER,
|
||||||
REPO,
|
REPO,
|
||||||
"REQUEST_CHANGES",
|
"REQUEST_CHANGES",
|
||||||
error.message,
|
"**Something went wrong in the theme preview action:** `" +
|
||||||
|
error.message +
|
||||||
|
"`",
|
||||||
);
|
);
|
||||||
await addRemoveLabel(
|
await addRemoveLabel(
|
||||||
OCTOKIT,
|
OCTOKIT,
|
||||||
|
|||||||
Reference in new issue
Block a user