Skip to content

Commit

Permalink
core: Introduce --debug flag support for CodeClimate.
Browse files Browse the repository at this point in the history
Should solve #42 (comment)
  • Loading branch information
paambaati committed Oct 31, 2019
1 parent 578f402 commit f960a4e
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { ExecOptions } from '@actions/exec/lib/interfaces';
const DOWNLOAD_URL = `https://codeclimate.com/downloads/test-reporter/test-reporter-latest-${platform()}-amd64`;
const EXECUTABLE = './cc-reporter';
const DEFAULT_COVERAGE_COMMAND = 'yarn coverage';
const DEFAULT_CODECLIMATE_DEBUG = 'false';

export function downloadToFile(
url: string,
Expand Down Expand Up @@ -36,14 +37,16 @@ function prepareEnv() {
if (process.env.GITHUB_REF !== undefined)
env.GIT_BRANCH = process.env.GITHUB_REF;

env.GIT_BRANCH = env.GIT_BRANCH.replace(/^refs\/head\//, ''); // Remove 'refs/head/' prefix (See https://github.com/paambaati/codeclimate-action/issues/42)
if (env.GIT_BRANCH)
env.GIT_BRANCH = env.GIT_BRANCH.replace(/^refs\/head\//, ''); // Remove 'refs/head/' prefix (See https://github.com/paambaati/codeclimate-action/issues/42)
return env;
}

export function run(
downloadUrl: string = DOWNLOAD_URL,
executable: string = EXECUTABLE,
coverageCommand: string = DEFAULT_COVERAGE_COMMAND
coverageCommand: string = DEFAULT_COVERAGE_COMMAND,
codeClimateDebug: string = DEFAULT_CODECLIMATE_DEBUG,
): Promise<void> {
return new Promise(async (resolve, reject) => {
let lastExitCode = 1;
Expand Down Expand Up @@ -79,9 +82,11 @@ export function run(
return reject(err);
}
try {
const commands = ['after-build', '--exit-code', lastExitCode.toString()]
if (codeClimateDebug === 'true') commands.push('--debug');
await exec(
executable,
['after-build', '--exit-code', lastExitCode.toString()],
commands,
execOpts
);
debug('✅ CC Reporter after-build checkin completed!');
Expand All @@ -97,5 +102,7 @@ export function run(
if (!module.parent) {
let coverageCommand = getInput('coverageCommand', { required: false });
if (!coverageCommand.length) coverageCommand = DEFAULT_COVERAGE_COMMAND;
run(DOWNLOAD_URL, EXECUTABLE, coverageCommand);
let codeClimateDebug = getInput('codeClimateDebug', { required: false });
if (!coverageCommand.length) codeClimateDebug = DEFAULT_CODECLIMATE_DEBUG;
run(DOWNLOAD_URL, EXECUTABLE, coverageCommand, codeClimateDebug);
}

0 comments on commit f960a4e

Please sign in to comment.