fix: update the comment template (#2)

This commit is contained in:
mrugesh mohapatra
2018-11-10 04:02:26 +05:30
committed by Randell Dawson
parent 507d40ba60
commit ce6129809f
6 changed files with 76 additions and 52 deletions

View File

@ -1,3 +1,7 @@
# github-bots
Github bots and crawlers for FCC
# github-bots
# automation
Scripts for @freeCodeCamp's GitHub automation tasks.
## Usage
Todo

View File

@ -1,73 +1,85 @@
const dedent = require("dedent");
const allowedLangDirNames = [
'arabic',
'chinese',
'english',
'portuguese',
'russian',
'spanish'
"arabic",
"chinese",
"english",
"portuguese",
"russian",
"spanish"
];
const createErrorMsg = (errors, user, hasPrevComments) => {
let finalMsg = `**Hi @${user},**\n`;
if (!hasPrevComments) {
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`;
}, '');
const createErrorMsg = (errors, user) => {
let errorMsgHeader = dedent`
Hi @${user},
return `\n${finalMsg}\n
\n
Thanks for this pull request (PR).
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 => {
let errorMsgs = [];
const remaining = fullPath.split('/');
const remaining = fullPath.split("/");
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') {
errorMsgs.push(`${remaining[remaining.length - 1]} is not a valid file name, please use 'index.md'
Found in:
${fullPath}`);
if (remaining[remaining.length - 1] !== "index.md") {
errorMsgs.push({
msg: `\`${remaining[remaining.length - 1]}\` is not a valid file name, please use \`index.md\``,
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') {
errorMsgs.push(`${remaining[2]} is not valid in the guide directory`);
}
const dirName = fullPath.replace('/index.md', '');
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}`);
const dirName = fullPath.replace("/index.md", "");
if (dirName.replace(/(\s|\_)/, "") !== dirName) {
errorMsgs.push({
msg: `Invalid character found in a directory name, please use \`-\` as separators`,
fullPath
});
}
if (dirName.toLowerCase() !== dirName) {
errorMsgs.push(`Upper case characters found in a folder name, all folder names must be lower case\n
Found in :\n
${fullPath}`);
errorMsgs.push({
msg: `Upper case characters found in the file path, all file paths must be lower case`,
fullPath
});
}
return errorMsgs;
};
const guideFolderChecks = (fullPath, user, hasPrevComments) => {
const guideFolderChecks = (fullPath, user) => {
if (/^guide\//.test(fullPath)) {
const errors = checkPath(fullPath);
if (errors.length) {
return createErrorMsg(errors, user, hasPrevComments);
return createErrorMsg(errors, user);
}
}
};

View File

@ -12,6 +12,6 @@ exports.octokitConfig = {
exports.octokitAuth = {
type: 'basic',
username: process.env.myUN,
password: process.env.myPW
username: process.env.USERNAME,
password: process.env.ACCESS_TOKEN
}

5
package-lock.json generated
View File

@ -87,6 +87,11 @@
"ms": "^2.1.1"
}
},
"dedent": {
"version": "0.7.0",
"resolved": "https://registry.npmjs.org/dedent/-/dedent-0.7.0.tgz",
"integrity": "sha1-JJXduvbrh0q7Dhvp3yLS5aVEMmw="
},
"dotenv": {
"version": "6.1.0",
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-6.1.0.tgz",

View File

@ -6,6 +6,7 @@
"dependencies": {
"@octokit/rest": "^15.16.1",
"date-fns": "^1.29.0",
"dedent": "^0.7.0",
"dotenv": "^6.1.0",
"gray-matter": "^4.0.1",
"lodash": "^4.17.11",

2
sample.env Normal file
View File

@ -0,0 +1,2 @@
USERNAME='camperbot'
ACCESS_TOKEN='replace this with a personal access token'