@codacy/codacy-mcp
Version:
Codacy MCP server
54 lines (53 loc) • 1.73 kB
JavaScript
export const CODACY_FOLDER_NAME = '.codacy';
import { exec } from 'child_process';
// Set a larger buffer size (10MB)
const MAX_BUFFER_SIZE = 1024 * 1024 * 10;
export class CodacyCli {
_cliCommand = '';
_accountToken = process.env.CODACY_ACCOUNT_TOKEN;
_cliVersion = process.env.CODACY_CLI_VERSION;
rootPath;
provider;
organization;
repository;
constructor(rootPath, provider, organization, repository) {
this.rootPath = rootPath;
this.provider = provider;
this.organization = organization;
this.repository = repository;
}
getCliCommand() {
return this._cliCommand;
}
setCliCommand(command) {
this._cliCommand = command;
}
preparePathForExec(path) {
return path;
}
execAsync(command, args) {
// stringyfy the args
const argsString = Object.entries(args || {})
.map(([key, value]) => `--${key} ${value}`)
.join(' ');
// Add the args to the command and remove any shell metacharacters
const cmd = `${command} ${argsString}`.trim().replace(/[;&|`$]/g, '');
return new Promise((resolve, reject) => {
exec(cmd, {
cwd: this.rootPath,
maxBuffer: MAX_BUFFER_SIZE, // To solve: stdout maxBuffer exceeded
encoding: 'utf-8',
}, (error, stdout, stderr) => {
if (error) {
reject(error);
return;
}
if (stderr && !stdout) {
reject(new Error(stderr));
return;
}
resolve({ stdout, stderr });
});
});
}
}