fix: update the comment template (#2)
This commit is contained in:
committed by
Randell Dawson
parent
507d40ba60
commit
ce6129809f
10
README.md
10
README.md
@ -1,3 +1,7 @@
|
|||||||
# github-bots
|
# automation
|
||||||
Github bots and crawlers for FCC
|
|
||||||
# github-bots
|
Scripts for @freeCodeCamp's GitHub automation tasks.
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
Todo
|
||||||
|
@ -1,73 +1,85 @@
|
|||||||
|
const dedent = require("dedent");
|
||||||
|
|
||||||
const allowedLangDirNames = [
|
const allowedLangDirNames = [
|
||||||
'arabic',
|
"arabic",
|
||||||
'chinese',
|
"chinese",
|
||||||
'english',
|
"english",
|
||||||
'portuguese',
|
"portuguese",
|
||||||
'russian',
|
"russian",
|
||||||
'spanish'
|
"spanish"
|
||||||
];
|
];
|
||||||
|
|
||||||
const createErrorMsg = (errors, user, hasPrevComments) => {
|
const createErrorMsg = (errors, user) => {
|
||||||
let finalMsg = `**Hi @${user},**\n`;
|
let errorMsgHeader = dedent`
|
||||||
if (!hasPrevComments) {
|
Hi @${user},
|
||||||
finalMsg += `
|
|
||||||
**Thanks for this pull request (PR).**\n
|
|
||||||
\n
|
|
||||||
Unfortunately, some of your commits have caused our CI tests to fail.\n
|
|
||||||
\n`;
|
|
||||||
}
|
|
||||||
finalMsg += `Please correct the issue(s) listed below, so we can consider merging your content.\n
|
|
||||||
\n`;
|
|
||||||
finalMsg += errors.reduce((msgStr, error, idx) => {
|
|
||||||
return msgStr += `#### Issue ${idx + 1}:\n
|
|
||||||
> ${error}\n
|
|
||||||
\n`;
|
|
||||||
}, '');
|
|
||||||
|
|
||||||
return `\n${finalMsg}\n
|
Thanks for this pull request (PR).
|
||||||
\n
|
|
||||||
P.S: I am just friendly bot. You should reach out to the [Contributors Chat room](https://gitter.im/FreeCodeCamp/Contributors) for more help.
|
Unfortunately, these changes have failed some of our recommended guidelines. Please correct the issue(s) listed below, so we can consider merging your content.
|
||||||
`;
|
|
||||||
}
|
| Issue | Description | File Path |
|
||||||
|
| :---: | --- | --- |
|
||||||
|
`;
|
||||||
|
|
||||||
|
let errorMsgTable = errors.reduce((msgStr, { msg, fullPath }, idx) => {
|
||||||
|
return (msgStr += "\n" + dedent`
|
||||||
|
| ${idx + 1} | ${msg} | ${fullPath} |
|
||||||
|
`);
|
||||||
|
}, "");
|
||||||
|
|
||||||
|
let errorMsgFooter = dedent`
|
||||||
|
P.S: I am just friendly bot. You should reach out to the [Contributors Chat room](https://gitter.im/FreeCodeCamp/Contributors) for more help.
|
||||||
|
`;
|
||||||
|
|
||||||
|
return errorMsgHeader + errorMsgTable + "\n\n" + errorMsgFooter;
|
||||||
|
};
|
||||||
|
|
||||||
const checkPath = fullPath => {
|
const checkPath = fullPath => {
|
||||||
let errorMsgs = [];
|
let errorMsgs = [];
|
||||||
const remaining = fullPath.split('/');
|
const remaining = fullPath.split("/");
|
||||||
|
|
||||||
if (!allowedLangDirNames.includes(remaining[1])) {
|
if (!allowedLangDirNames.includes(remaining[1])) {
|
||||||
errorMsgs.push(`${remaining[1]} should not be in the guide directory`);
|
errorMsgs.push({
|
||||||
|
msg: `\`${remaining[1]}\` is not a valid language directory`,
|
||||||
|
fullPath
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (remaining[remaining.length - 1] !== 'index.md') {
|
if (remaining[remaining.length - 1] !== "index.md") {
|
||||||
errorMsgs.push(`${remaining[remaining.length - 1]} is not a valid file name, please use 'index.md'
|
errorMsgs.push({
|
||||||
Found in:
|
msg: `\`${remaining[remaining.length - 1]}\` is not a valid file name, please use \`index.md\``,
|
||||||
${fullPath}`);
|
fullPath
|
||||||
|
});
|
||||||
|
} else if (remaining[2] === "index.md") {
|
||||||
|
errorMsgs.push({
|
||||||
|
msg: `This file is not in its own sub-directory`,
|
||||||
|
fullPath
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (remaining[2] === 'index.md') {
|
const dirName = fullPath.replace("/index.md", "");
|
||||||
errorMsgs.push(`${remaining[2]} is not valid in the guide directory`);
|
if (dirName.replace(/(\s|\_)/, "") !== dirName) {
|
||||||
}
|
errorMsgs.push({
|
||||||
|
msg: `Invalid character found in a directory name, please use \`-\` as separators`,
|
||||||
const dirName = fullPath.replace('/index.md', '');
|
fullPath
|
||||||
if (dirName.replace(/(\s|\_)/, '') !== dirName) {
|
});
|
||||||
errorMsgs.push(`Invalid character found in a folder name, please use '-' for spaces and underscores\n
|
|
||||||
Found in:\n
|
|
||||||
${fullPath}`);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dirName.toLowerCase() !== dirName) {
|
if (dirName.toLowerCase() !== dirName) {
|
||||||
errorMsgs.push(`Upper case characters found in a folder name, all folder names must be lower case\n
|
errorMsgs.push({
|
||||||
Found in :\n
|
msg: `Upper case characters found in the file path, all file paths must be lower case`,
|
||||||
${fullPath}`);
|
fullPath
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return errorMsgs;
|
return errorMsgs;
|
||||||
};
|
};
|
||||||
|
|
||||||
const guideFolderChecks = (fullPath, user, hasPrevComments) => {
|
const guideFolderChecks = (fullPath, user) => {
|
||||||
if (/^guide\//.test(fullPath)) {
|
if (/^guide\//.test(fullPath)) {
|
||||||
const errors = checkPath(fullPath);
|
const errors = checkPath(fullPath);
|
||||||
if (errors.length) {
|
if (errors.length) {
|
||||||
return createErrorMsg(errors, user, hasPrevComments);
|
return createErrorMsg(errors, user);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -12,6 +12,6 @@ exports.octokitConfig = {
|
|||||||
|
|
||||||
exports.octokitAuth = {
|
exports.octokitAuth = {
|
||||||
type: 'basic',
|
type: 'basic',
|
||||||
username: process.env.myUN,
|
username: process.env.USERNAME,
|
||||||
password: process.env.myPW
|
password: process.env.ACCESS_TOKEN
|
||||||
}
|
}
|
||||||
|
5
package-lock.json
generated
5
package-lock.json
generated
@ -87,6 +87,11 @@
|
|||||||
"ms": "^2.1.1"
|
"ms": "^2.1.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"dedent": {
|
||||||
|
"version": "0.7.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/dedent/-/dedent-0.7.0.tgz",
|
||||||
|
"integrity": "sha1-JJXduvbrh0q7Dhvp3yLS5aVEMmw="
|
||||||
|
},
|
||||||
"dotenv": {
|
"dotenv": {
|
||||||
"version": "6.1.0",
|
"version": "6.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-6.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-6.1.0.tgz",
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@octokit/rest": "^15.16.1",
|
"@octokit/rest": "^15.16.1",
|
||||||
"date-fns": "^1.29.0",
|
"date-fns": "^1.29.0",
|
||||||
|
"dedent": "^0.7.0",
|
||||||
"dotenv": "^6.1.0",
|
"dotenv": "^6.1.0",
|
||||||
"gray-matter": "^4.0.1",
|
"gray-matter": "^4.0.1",
|
||||||
"lodash": "^4.17.11",
|
"lodash": "^4.17.11",
|
||||||
|
2
sample.env
Normal file
2
sample.env
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
USERNAME='camperbot'
|
||||||
|
ACCESS_TOKEN='replace this with a personal access token'
|
Reference in New Issue
Block a user