From a500a2e45663a4bf9150140ca02c12340d3cef26 Mon Sep 17 00:00:00 2001 From: katiacih Date: Mon, 31 Jul 2023 15:22:45 -0300 Subject: [PATCH] refactor: adiciona log ao ktlint --- dist/index.js/index.js | 53 +++++++++++++++++++++++++++-------- index.js | 20 ++++++------- src/controller/writeOutput.js | 26 +++++++++++++++++ 3 files changed, 77 insertions(+), 22 deletions(-) create mode 100644 src/controller/writeOutput.js diff --git a/dist/index.js/index.js b/dist/index.js/index.js index f750374..f272b0e 100644 --- a/dist/index.js/index.js +++ b/dist/index.js/index.js @@ -12838,6 +12838,39 @@ module.exports = { } +/***/ }), + +/***/ 7545: +/***/ ((module) => { + + +/** + * Formata saída de report via detekt + * @param {string} repotr + * @example writeOutput([{'version':'4.3','file':[{'name':'app/src/main/java/com/example/trybegenius/MainActivity.kt','error':[{'line':'89','column':'50','severity':'warning','message':'This expression contains a magic number. Consider defining it to a well named constant.','source':'detekt.MagicNumber'}]}]) + * @output + version: '4.3', + Verifique os erros abaixo: + `Formatado em tabela` + } + */ + +function writeReport(report) { + console.log(`Version: ${report[0].version}`) + console.log('Verifique os erros abaixo:') + if(report.length > 0 && report[0].file.length > 0) { + report[0].file.forEach((element) => { + console.log(`Arquivo: ${element.name}`) + console.table(element.error) + }) + } +} + +module.exports = { + writeReport +} + + /***/ }), /***/ 5984: @@ -13054,15 +13087,16 @@ var __webpack_exports__ = {}; const { getDetektReport, getKtlintReport } = __nccwpck_require__(6109) const { spawn } = __nccwpck_require__(2081) const core = __nccwpck_require__(9943) +const { writeReport } = __nccwpck_require__(7545) function runDetekt() { const command = './gradlew detekt' const childProcess = spawn(command, { shell: true }) try { - childProcess.stdout.on('data', (data) => { - core.info(`\u001b[38;5;6m[info] Saída do comando: ${data}`) - }) + // childProcess.stdout.on('data', (data) => { + // core.info(`\u001b[38;5;6m[info] Saída do comando: ${data}`) + // }) childProcess.stderr.on('data', (data) => { core.setFailed(`\u001b[38;5;6m[erro] EXEC -> Erro no comando bash: ${data}`) @@ -13074,14 +13108,8 @@ function runDetekt() { report = getDetektReport() core.setOutput('Detekt', JSON.stringify(report)) core.notice(`\u001b[32;5;6m 🚀 Processo concluído verifique abaixo os erros reportados ${JSON.stringify(report)}`) - console.log(`Version: ${report[0].version}`) - console.log('Verifique os erros abaixo:') - if(report.length > 0 && report[0].file.length > 0) { - report[0].file.forEach((element) => { - console.log(`Arquivo: ${element.name}`) - console.table(element.error) - }) - } + + writeReport(report) return report }) @@ -13098,6 +13126,9 @@ function runKtlint() { const childProcess = spawn(command, { shell: true }) try { + childProcess.stdout.on('data', (data) => { + core.info(`\u001b[38;5;6m[info] Saída do comando: ${data}`) + }) childProcess.stderr.on('data', (data) => { core.setFailed(`\u001b[38;5;6m[erro] EXEC -> Erro no comando bash: ${data}`) }) diff --git a/index.js b/index.js index f36cb5c..90800e7 100644 --- a/index.js +++ b/index.js @@ -1,15 +1,16 @@ const { getDetektReport, getKtlintReport } = require('./src/controller/linterManager') const { spawn } = require('child_process') const core = require('@actions/core') +const { writeReport } = require('./src/controller/writeOutput') function runDetekt() { const command = './gradlew detekt' const childProcess = spawn(command, { shell: true }) try { - childProcess.stdout.on('data', (data) => { - core.info(`\u001b[38;5;6m[info] Saída do comando: ${data}`) - }) + // childProcess.stdout.on('data', (data) => { + // core.info(`\u001b[38;5;6m[info] Saída do comando: ${data}`) + // }) childProcess.stderr.on('data', (data) => { core.setFailed(`\u001b[38;5;6m[erro] EXEC -> Erro no comando bash: ${data}`) @@ -21,14 +22,8 @@ function runDetekt() { report = getDetektReport() core.setOutput('Detekt', JSON.stringify(report)) core.notice(`\u001b[32;5;6m 🚀 Processo concluído verifique abaixo os erros reportados ${JSON.stringify(report)}`) - console.log(`Version: ${report[0].version}`) - console.log('Verifique os erros abaixo:') - if(report.length > 0 && report[0].file.length > 0) { - report[0].file.forEach((element) => { - console.log(`Arquivo: ${element.name}`) - console.table(element.error) - }) - } + + writeReport(report) return report }) @@ -45,6 +40,9 @@ function runKtlint() { const childProcess = spawn(command, { shell: true }) try { + childProcess.stdout.on('data', (data) => { + core.info(`\u001b[38;5;6m[info] Saída do comando: ${data}`) + }) childProcess.stderr.on('data', (data) => { core.setFailed(`\u001b[38;5;6m[erro] EXEC -> Erro no comando bash: ${data}`) }) diff --git a/src/controller/writeOutput.js b/src/controller/writeOutput.js new file mode 100644 index 0000000..ca4b836 --- /dev/null +++ b/src/controller/writeOutput.js @@ -0,0 +1,26 @@ + +/** + * Formata saída de report via detekt + * @param {string} repotr + * @example writeOutput([{'version':'4.3','file':[{'name':'app/src/main/java/com/example/trybegenius/MainActivity.kt','error':[{'line':'89','column':'50','severity':'warning','message':'This expression contains a magic number. Consider defining it to a well named constant.','source':'detekt.MagicNumber'}]}]) + * @output + version: '4.3', + Verifique os erros abaixo: + `Formatado em tabela` + } + */ + +function writeReport(report) { + console.log(`Version: ${report[0].version}`) + console.log('Verifique os erros abaixo:') + if(report.length > 0 && report[0].file.length > 0) { + report[0].file.forEach((element) => { + console.log(`Arquivo: ${element.name}`) + console.table(element.error) + }) + } +} + +module.exports = { + writeReport +}