Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit822efbf

Browse files
authored
ci: fix small bugs in theme-preview action (anuraghazra#2093)
* ci: fix small bugs in theme-preview action* ci: format code
1 parent84c9d35 commit822efbf

File tree

2 files changed

+38
-15
lines changed

2 files changed

+38
-15
lines changed

‎scripts/helpers.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
*@file Contains helper functions used in the scripts.
33
*/
44

5+
import{getInput}from"@actions/core";
6+
57
// Script variables.
68
constOWNER="anuraghazra";
79
constREPO="github-readme-stats";
@@ -32,7 +34,7 @@ export const getRepoInfo = (ctx) => {
3234
*@returns {string} Github token.
3335
*/
3436
exportconstgetGithubToken=()=>{
35-
consttoken=core.getInput("github_token")||process.env.GITHUB_TOKEN;
37+
consttoken=getInput("github_token")||process.env.GITHUB_TOKEN;
3638
if(!token){
3739
throwError("Could not find github token");
3840
}

‎scripts/preview-theme.js

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,15 @@ const THEME_CONTRIB_GUIDELINESS = `
3333
3434
\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).
3535
`;
36-
constREQUIRED_COLOR_PROPS=[
37-
"title_color",
38-
"icon_color",
39-
"text_color",
40-
"bg_color",
41-
];
36+
constCOLOR_PROPS={
37+
title_color:6,
38+
icon_color:6,
39+
text_color:6,
40+
bg_color:8,
41+
border_color:6,
42+
};
43+
constACCEPTED_COLOR_PROPS=Object.keys(COLOR_PROPS);
44+
constREQUIRED_COLOR_PROPS=ACCEPTED_COLOR_PROPS.slice(0,4);
4245
constINVALID_REVIEW_COMMENT=(commentUrl)=>
4346
`Some themes are invalid. See the [Automated Theme Preview](${commentUrl}) comment above for more information.`;
4447

@@ -271,11 +274,11 @@ const parseJSON = (json) => {
271274
}
272275
}catch(error){
273276
letparsedJson=json
274-
.split(/(?:\s*)(}\s*,?)(?:\s*)(?=\s*[a-z_"]+:+)/)
277+
.split(/([\s\r\s]*}[\s\r\s]*,[\s\r\s]*)(?=[\w"-]+:)/)
275278
.filter((x)=>typeofx!=="string"||!!x.trim());
276279
if(parsedJson[0].replace(/\s+/g,"")==="},"){
277280
parsedJson[0]="},";
278-
if(!/\s*}\s*,?\s*$/.test(parsedJson[0])){
281+
if(!/\s*}\s*,?\s*$/.test(parsedJson[1])){
279282
parsedJson.push(parsedJson.shift());
280283
}else{
281284
parsedJson.shift();
@@ -299,7 +302,7 @@ const themeNameAlreadyExists = (name) => {
299302
/**
300303
* Main function.
301304
*/
302-
construn=async()=>{
305+
exportconstrun=async(prNumber)=>{
303306
try{
304307
constdryRun=process.env.DRY_RUN==="true"||false;
305308
debug("Retrieve action information from context...");
@@ -310,7 +313,7 @@ const run = async () => {
310313
`;
311314
constccc=newColorContrastChecker();
312315
constoctokit=github.getOctokit(getGithubToken());
313-
constpullRequestId=getPrNumber();
316+
constpullRequestId=prNumber ?prNumber :getPrNumber();
314317
constcommenter=getCommenter();
315318
const{ owner, repo}=getRepoInfo(github.context);
316319
debug(`Owner:${owner}`);
@@ -387,10 +390,19 @@ const run = async () => {
387390
constmissingKeys=REQUIRED_COLOR_PROPS.filter(
388391
(x)=>!Object.keys(colors).includes(x),
389392
);
390-
if(missingKeys.length>0){
393+
constextraKeys=Object.keys(colors).filter(
394+
(x)=>!ACCEPTED_COLOR_PROPS.includes(x),
395+
);
396+
if(missingKeys.length>0||extraKeys.length>0){
391397
for(constmissingKeyofmissingKeys){
392398
errors.push(`Theme color properties \`${missingKey}\` are missing`);
393399
}
400+
401+
for(constextraKeyofextraKeys){
402+
warnings.push(
403+
`Theme color properties \`${extraKey}\` is not supported`,
404+
);
405+
}
394406
invalidColors=true;
395407
}else{
396408
for(const[colorKey,colorValue]ofObject.entries(colors)){
@@ -399,6 +411,11 @@ const run = async () => {
399411
`Theme color property \`${colorKey}\` should not start with '#'`,
400412
);
401413
invalidColors=true;
414+
}elseif(colorValue.length>COLOR_PROPS[colorKey]){
415+
errors.push(
416+
`Theme color property \`${colorKey}\` can not be longer than \`${COLOR_PROPS[colorKey]}\` characters`,
417+
);
418+
invalidColors=true;
402419
}elseif(!isValidHexColor(colorValue)){
403420
errors.push(
404421
`Theme color property \`${colorKey}\` is not a valid hex color: <code>#${colorValue}</code>`,
@@ -437,8 +454,10 @@ const run = async () => {
437454
text_color:[textColor,bgColor],
438455
};
439456
Object.keys(colorPairs).forEach((item)=>{
440-
constcolor1=colorPairs[item][0];
441-
constcolor2=colorPairs[item][1];
457+
letcolor1=colorPairs[item][0];
458+
letcolor2=colorPairs[item][1];
459+
color1=color1.length===4 ?color1.slice(0,3) :color1.slice(0,6);
460+
color2=color2.length===4 ?color2.slice(0,3) :color2.slice(0,6);
442461
if(!ccc.isLevelAA(`#${color1}`,`#${color2}`)){
443462
constpermalink=getWebAimLink(color1,color2);
444463
warnings.push(
@@ -543,4 +562,6 @@ const run = async () => {
543562
}
544563
};
545564

546-
run();
565+
if(typeofrequire!=="undefined"&&require.main===module){
566+
run();
567+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp