diff --git a/.github/workflows/danger_pr.yml b/.github/workflows/danger_pr.yml index d3e8072065a891..78b4ee9b562531 100644 --- a/.github/workflows/danger_pr.yml +++ b/.github/workflows/danger_pr.yml @@ -12,6 +12,8 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 + - run: yarn install + working-directory: . - run: yarn install working-directory: bots - name: Danger diff --git a/bots/dangerfile.js b/bots/dangerfile.js index 40e28921179560..b2bab7411b132d 100644 --- a/bots/dangerfile.js +++ b/bots/dangerfile.js @@ -11,6 +11,8 @@ const {danger, fail, message, warn} = require('danger'); const includes = require('lodash.includes'); +const { execSync } = require('child_process'); +const fs = require('fs'); const isFromPhabricator = danger.github.pr.body && @@ -112,3 +114,35 @@ if (isMergeRefStable) { }, ); } + +console.log("Running eslint on Danger") +const js_files = danger.git.modified_files.filter((name) => name.endsWith('.js') || name.endsWith('.jsx') ) +if (js_files.length > 0) { + const joined_files = js_files.map((name) => process.cwd() + "/../" + name).join(' '); + try { + console.log(joined_files[0]); + const res = execSync(`npx eslint ${joined_files[0]}`);// -f json ${joined_files}`); + console.log('Eslint result'); + console.log(res.toString()); +// const eslintOutput = fs.readFileSync('/tmp/eslint.output', 'utf8'); +// const eslintJSON = JSON.parse(eslintOutput); +// const faultyFiles = eslintJSON.filter((file) => file.messages.length > 0); + +// let messageText = "" +// faultyFiles.forEach((file) => { +// const path = file.filePath +// const splitPath = path.split("/") +// messageText += `${splitPath[splitPath.length - 1]} - ${path}\n` + +// file.messages.forEach((msg) => { +// const emoji = msg.severity === 1 ? "⚠️" : msg.severity === 2 ? "⛔️" : "✅" +// const format = `${emoji} - [${msg.line}:${msg.column}] ${msg.message} (${msg.ruleId})\n` +// messageText += format +// }) +// }) +// warn(messageText); + + } catch (err) { + fail(`Couldn't read the lint file output\n${err}`); + } +}