From ce6129809fb854f36ca815875e56c81708b01142 Mon Sep 17 00:00:00 2001 From: mrugesh mohapatra <1884376+raisedadead@users.noreply.github.com> Date: Sat, 10 Nov 2018 04:02:26 +0530 Subject: [PATCH] fix: update the comment template (#2) --- README.md | 10 ++-- guideFolderChecks.js | 106 ++++++++++++++++++++++++------------------- octokitConfig.js | 4 +- package-lock.json | 5 ++ package.json | 1 + sample.env | 2 + 6 files changed, 76 insertions(+), 52 deletions(-) create mode 100644 sample.env diff --git a/README.md b/README.md index dde2ccdb9b..6150ff7bac 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,7 @@ -# github-bots -Github bots and crawlers for FCC -# github-bots +# automation + +Scripts for @freeCodeCamp's GitHub automation tasks. + +## Usage + +Todo diff --git a/guideFolderChecks.js b/guideFolderChecks.js index 2855ba33ac..adb35135ab 100644 --- a/guideFolderChecks.js +++ b/guideFolderChecks.js @@ -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 -P.S: I am just friendly bot. You should reach out to the [Contributors Chat room](https://gitter.im/FreeCodeCamp/Contributors) for more help. -`; -} + 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); } } }; diff --git a/octokitConfig.js b/octokitConfig.js index ce5b47c219..ea9f26a960 100644 --- a/octokitConfig.js +++ b/octokitConfig.js @@ -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 } diff --git a/package-lock.json b/package-lock.json index 95fb5a3870..f6f6ba3c72 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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", diff --git a/package.json b/package.json index b36af4fea3..b0e19404c7 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/sample.env b/sample.env new file mode 100644 index 0000000000..5a54e6b41f --- /dev/null +++ b/sample.env @@ -0,0 +1,2 @@ +USERNAME='camperbot' +ACCESS_TOKEN='replace this with a personal access token' \ No newline at end of file