diff options
| author | Nick Merwin <[email protected]> | 2019-11-20 17:05:48 -0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2019-11-20 17:05:48 -0800 |
| commit | 336123fe05e7f80d79fc8522b4ff21a60fffe77c (patch) | |
| tree | 97e5b9343471fc73ddf4ffb20cd71ca58367d6c6 /lib | |
| parent | eba01a29c69f28ffd7f50556492a43b5ba2486d7 (diff) | |
| download | node-coveralls-336123fe05e7f80d79fc8522b4ff21a60fffe77c.tar.xz node-coveralls-336123fe05e7f80d79fc8522b4ff21a60fffe77c.zip | |
ES6
* remove unused variables
* move `require`s at the top
* check for prototype built-ins
* run in strict mode
* always check for error values in tests
* make style consistent
* mark Node.js 6 as the minimum supported version in package.json
* Use the arrow return syntax
* logger.js: use `Boolean` to make the intention clearer.
* Use the rest params instead of arguments.
* test/getOptions.js: beautify git data.
* Update logger.js
Remove `hasDebugEnvVariable` function; it's just a `process.env` check
* Create .jshintrc
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/convertLcovToCoveralls.js | 102 | ||||
| -rw-r--r-- | lib/detectLocalGit.js | 68 | ||||
| -rw-r--r-- | lib/fetchGitData.js | 84 | ||||
| -rw-r--r-- | lib/getOptions.js | 108 | ||||
| -rw-r--r-- | lib/handleInput.js | 34 | ||||
| -rw-r--r-- | lib/logger.js | 18 | ||||
| -rw-r--r-- | lib/sendToCoveralls.js | 23 |
7 files changed, 249 insertions, 188 deletions
diff --git a/lib/convertLcovToCoveralls.js b/lib/convertLcovToCoveralls.js index 521e749..a6d5665 100644 --- a/lib/convertLcovToCoveralls.js +++ b/lib/convertLcovToCoveralls.js @@ -1,90 +1,104 @@ -var TRAVIS_JOB_ID = process.env.TRAVIS_JOB_ID || 'unknown'; -var fs = require('fs'); -var lcovParse = require('lcov-parse'); -var path = require('path'); -var logger = require('./logger')(); - -var detailsToCoverage = function(length, details){ - var coverage = new Array(length); - details.forEach(function(obj){ +'use strict'; + +const fs = require('fs'); +const path = require('path'); +const lcovParse = require('lcov-parse'); +const logger = require('./logger')(); + +const detailsToCoverage = (length, details) => { + const coverage = new Array(length); + details.forEach(obj => { coverage[obj.line - 1] = obj.hit; }); return coverage; }; -var detailsToBranches = function(details){ - var branches = []; - details.forEach(function(obj){ - ['line','block','branch','taken'].forEach(function(key){ +const detailsToBranches = details => { + const branches = []; + details.forEach(obj => { + ['line', 'block', 'branch', 'taken'].forEach(key => { branches.push(obj[key] || 0); }); }); return branches; }; -var convertLcovFileObject = function(file, filepath){ - var rootpath = filepath; +const convertLcovFileObject = (file, filepath) => { + const rootpath = filepath; filepath = path.resolve(rootpath, file.file); - var source = fs.readFileSync(filepath, 'utf8'); - var lines = source.split("\n"); - var coverage = detailsToCoverage(lines.length, file.lines.details); - var branches = detailsToBranches(file.branches.details); - return { name : path.relative(rootpath, path.resolve(rootpath, file.file)).split( path.sep ).join( "/" ), - source : source, - coverage : coverage, - branches : branches }; + const source = fs.readFileSync(filepath, 'utf8'); + const lines = source.split('\n'); + const coverage = detailsToCoverage(lines.length, file.lines.details); + const branches = detailsToBranches(file.branches.details); + + return { + name: path.relative(rootpath, path.resolve(rootpath, file.file)).split(path.sep).join('/'), + source, + coverage, + branches + }; }; -var cleanFilePath = function(file) { - if (file.indexOf('!') > -1) { - var regex = /^(.*!)(.*)$/g; - var matches = regex.exec(file); - return matches[matches.length-1]; +const cleanFilePath = file => { + if (file.includes('!')) { + const regex = /^(.*!)(.*)$/g; + const matches = regex.exec(file); + return matches[matches.length - 1]; } return file; }; -var convertLcovToCoveralls = function(input, options, cb){ - var filepath = options.filepath || ''; - logger.debug("in: ", filepath); +const convertLcovToCoveralls = (input, options, cb) => { + let filepath = options.filepath || ''; + logger.debug('in: ', filepath); filepath = path.resolve(process.cwd(), filepath); - lcovParse(input, function(err, parsed){ - if (err){ - logger.error("error from lcovParse: ", err); - logger.error("input: ", input); + lcovParse(input, (err, parsed) => { + if (err) { + logger.error('error from lcovParse: ', err); + logger.error('input: ', input); return cb(err); } - var postJson = { - source_files : [] + + const postJson = { + source_files: [] }; - if (options.git){ + + if (options.git) { postJson.git = options.git; } - if (options.run_at){ + + if (options.run_at) { postJson.run_at = options.run_at; } - if (options.service_name){ + + if (options.service_name) { postJson.service_name = options.service_name; } - if (options.service_job_id){ + + if (options.service_job_id) { postJson.service_job_id = options.service_job_id; } + if (options.service_pull_request) { postJson.service_pull_request = options.service_pull_request; } + if (options.repo_token) { postJson.repo_token = options.repo_token; } + if (options.parallel) { postJson.parallel = options.parallel; } + if (options.service_pull_request) { postJson.service_pull_request = options.service_pull_request; } - parsed.forEach(function(file){ + + parsed.forEach(file => { file.file = cleanFilePath(file.file); - var currentFilePath = path.resolve(filepath, file.file); + const currentFilePath = path.resolve(filepath, file.file); if (fs.existsSync(currentFilePath)) { postJson.source_files.push(convertLcovFileObject(file, filepath)); } @@ -97,7 +111,6 @@ module.exports = convertLcovToCoveralls; /* example coveralls json file - { "service_job_id": "1234567890", "service_name": "travis-ci", @@ -115,7 +128,6 @@ module.exports = convertLcovToCoveralls; ] } - example output from lcov parser: [ diff --git a/lib/detectLocalGit.js b/lib/detectLocalGit.js index 46a9e67..89133ff 100644 --- a/lib/detectLocalGit.js +++ b/lib/detectLocalGit.js @@ -1,47 +1,59 @@ -var fs = require('fs'); -var path = require('path'); +'use strict'; + +const fs = require('fs'); +const path = require('path'); // branch naming only has a few excluded characters, see git-check-ref-format(1) -var REGEX_BRANCH = /^ref: refs\/heads\/([^?*\[\\~^:]+)$/; +const REGEX_BRANCH = /^ref: refs\/heads\/([^?*[\\~^:]+)$/; + +function detectLocalGit() { + let dir = process.cwd(); + let gitDir; -module.exports = function detectLocalGit() { - var dir = process.cwd(), gitDir; while (path.resolve('/') !== dir) { gitDir = path.join(dir, '.git'); - var existsSync = fs.existsSync || path.existsSync; - if (existsSync(path.join(gitDir, 'HEAD'))) + const existsSync = fs.existsSync || path.existsSync; + if (existsSync(path.join(gitDir, 'HEAD'))) { break; + } dir = path.dirname(dir); } - if (path.resolve('/') === dir) + if (path.resolve('/') === dir) { return; + } - var head = fs.readFileSync(path.join(dir, '.git', 'HEAD'), 'utf-8').trim(); - var branch = (head.match(REGEX_BRANCH) || [])[1]; - if (!branch) + const head = fs.readFileSync(path.join(dir, '.git', 'HEAD'), 'utf-8').trim(); + const branch = (head.match(REGEX_BRANCH) || [])[1]; + if (!branch) { return { git_commit: head }; + } - var commit = _parseCommitHashFromRef(dir, branch); + const commit = _parseCommitHashFromRef(dir, branch); - return { git_commit: commit, git_branch: branch }; -}; + return { + git_commit: commit, + git_branch: branch + }; +} function _parseCommitHashFromRef(dir, branch) { - var ref = path.join(dir, '.git', 'refs', 'heads', branch); - if (fs.existsSync(ref)) { - return fs.readFileSync(ref, 'utf-8').trim(); - } else { - // ref does not exist; get it from packed-refs - var commit = ''; - var packedRefs = path.join(dir, '.git', 'packed-refs'); - var packedRefsText = fs.readFileSync(packedRefs, 'utf-8'); - packedRefsText.split('\n').forEach(function (line) { - if (line.match('refs/heads/'+branch)) { - commit = line.split(' ')[0]; - } - }); - return commit; + const ref = path.join(dir, '.git', 'refs', 'heads', branch); + if (fs.existsSync(ref)) { + return fs.readFileSync(ref, 'utf-8').trim(); + } + + // ref does not exist; get it from packed-refs + let commit = ''; + const packedRefs = path.join(dir, '.git', 'packed-refs'); + const packedRefsText = fs.readFileSync(packedRefs, 'utf-8'); + packedRefsText.split('\n').forEach(line => { + if (line.match(`refs/heads/${branch}`)) { + commit = line.split(' ')[0]; } + }); + return commit; } + +module.exports = detectLocalGit; diff --git a/lib/fetchGitData.js b/lib/fetchGitData.js index f04720e..ee69246 100644 --- a/lib/fetchGitData.js +++ b/lib/fetchGitData.js @@ -1,47 +1,53 @@ -var exec = require('child_process').exec; -var logger = require('./logger')(); +'use strict'; + +const { exec } = require('child_process'); +require('./logger')(); function fetchGitData(git, cb) { - if (!cb){ - throw new Error("fetchGitData requires a callback"); + if (!cb) { + throw new Error('fetchGitData requires a callback'); } //-- Malformed/undefined git object - if ('undefined' === typeof git) { + if (typeof git === 'undefined') { return cb(new Error('No options passed')); } - if (!git.hasOwnProperty('head')) { + + if (!Object.prototype.hasOwnProperty.call(git, 'head')) { return cb(new Error('You must provide the head')); } - if (!git.head.hasOwnProperty('id')) { + + if (!Object.prototype.hasOwnProperty.call(git.head, 'id')) { return cb(new Error('You must provide the head.id')); } //-- Set required properties of git if they weren"t provided - if (!git.hasOwnProperty("branch")) { - git.branch = ""; + if (!Object.prototype.hasOwnProperty.call(git, 'branch')) { + git.branch = ''; } - if (!git.hasOwnProperty("remotes")) { + + if (!Object.prototype.hasOwnProperty.call(git, 'remotes')) { git.remotes = []; } //-- Assert the property types - if ("string" !== typeof git.branch) { - git.branch = ""; + if (typeof git.branch !== 'string') { + git.branch = ''; } - if (!(git.remotes instanceof Array)) { + + if (!(Array.isArray(git.remotes))) { git.remotes = []; } //-- Use git? - exec("git rev-parse --verify " + git.head.id, function(err, response){ - if (err){ + exec(`git rev-parse --verify ${git.head.id}`, err => { + if (err) { // git is not available... - git.head.author_name = git.head.author_name || "Unknown Author"; - git.head.author_email = git.head.author_email || ""; - git.head.committer_name = git.head.committer_name || "Unknown Committer"; - git.head.committer_email = git.head.committer_email || ""; - git.head.message = git.head.message || "Unknown Commit Message"; + git.head.author_name = git.head.author_name || 'Unknown Author'; + git.head.author_email = git.head.author_email || ''; + git.head.committer_name = git.head.committer_name || 'Unknown Committer'; + git.head.committer_email = git.head.committer_email || ''; + git.head.message = git.head.message || 'Unknown Commit Message'; return cb(null, git); } @@ -50,25 +56,27 @@ function fetchGitData(git, cb) { } function fetchBranch(git, cb) { - exec("git branch", function(err, branches){ - if (err) + exec('git branch', (err, branches) => { + if (err) { return cb(err); + } git.branch = (branches.match(/^\* (\w+)/) || [])[1]; fetchRemotes(git, cb); }); } -var REGEX_COMMIT_DETAILS = /\nauthor (.+?) <([^>]*)>.+\ncommitter (.+?) <([^>]*)>.+[\S\s]*?\n\n(.*)/m; +const REGEX_COMMIT_DETAILS = /\nauthor (.+?) <([^>]*)>.+\ncommitter (.+?) <([^>]*)>.+[\S\s]*?\n\n(.*)/m; function fetchHeadDetails(git, cb) { - exec('git cat-file -p ' + git.head.id, function(err, response) { - if (err) + exec(`git cat-file -p ${git.head.id}`, (err, response) => { + if (err) { return cb(err); + } - var items = response.match(REGEX_COMMIT_DETAILS).slice(1); - var fields = ['author_name', 'author_email', 'committer_name', 'committer_email', 'message']; - fields.forEach(function(field, index) { + const items = response.match(REGEX_COMMIT_DETAILS).slice(1); + const fields = ['author_name', 'author_email', 'committer_name', 'committer_email', 'message']; + fields.forEach((field, index) => { git.head[field] = items[index]; }); @@ -81,14 +89,17 @@ function fetchHeadDetails(git, cb) { } function fetchRemotes(git, cb) { - exec("git remote -v", function(err, remotes){ - if (err) + exec('git remote -v', (err, remotes) => { + if (err) { return cb(err); + } - var processed = {}; - remotes.split("\n").forEach(function(remote) { - if (!/\s\(push\)$/.test(remote)) + const processed = {}; + remotes.split('\n').forEach(remote => { + if (!/\s\(push\)$/.test(remote)) { return; + } + remote = remote.split(/\s+/); saveRemote(processed, git, remote[0], remote[1]); }); @@ -97,12 +108,13 @@ function fetchRemotes(git, cb) { } function saveRemote(processed, git, name, url) { - var key = name + "-" + url; - if (processed.hasOwnProperty(key)) + const key = `${name}-${url}`; + if (Object.prototype.hasOwnProperty.call(processed, key)) { return; + } processed[key] = true; - git.remotes.push({ name: name, url: url }); + git.remotes.push({ name, url }); } module.exports = fetchGitData; diff --git a/lib/getOptions.js b/lib/getOptions.js index aa24f43..8a0305f 100644 --- a/lib/getOptions.js +++ b/lib/getOptions.js @@ -1,23 +1,28 @@ -var fs = require('fs'); -var path = require('path'); -var yaml = require('js-yaml'); -var index = require('../index'); -var logger = require('./logger')(); -var fetchGitData = require('./fetchGitData'); - -var getBaseOptions = function(cb){ - var options = {}; - var git_commit = process.env.COVERALLS_GIT_COMMIT; - var git_branch = process.env.COVERALLS_GIT_BRANCH; - var git_committer_name, git_committer_email, git_message; - - var match = (process.env.CI_PULL_REQUEST || "").match(/(\d+)$/); +'use strict'; + +const fs = require('fs'); +const path = require('path'); +const yaml = require('js-yaml'); +const logger = require('./logger')(); +const fetchGitData = require('./fetchGitData'); +const detectLocalGit = require('./detectLocalGit'); +const index = require('..'); + +const getBaseOptions = cb => { + const options = {}; + let git_commit = process.env.COVERALLS_GIT_COMMIT; + let git_branch = process.env.COVERALLS_GIT_BRANCH; + let git_committer_name; + let git_committer_email; + let git_message; + + const match = (process.env.CI_PULL_REQUEST || '').match(/(\d+)$/); if (match) { options.service_pull_request = match[1]; } - if (process.env.TRAVIS){ + if (process.env.TRAVIS) { options.service_name = 'travis-ci'; options.service_job_id = process.env.TRAVIS_JOB_ID; options.service_pull_request = process.env.TRAVIS_PULL_REQUEST; @@ -25,7 +30,7 @@ var getBaseOptions = function(cb){ git_branch = process.env.TRAVIS_BRANCH; } - if (process.env.DRONE){ + if (process.env.DRONE) { options.service_name = 'drone'; options.service_job_id = process.env.DRONE_BUILD_NUMBER; options.service_pull_request = process.env.DRONE_PULL_REQUEST; @@ -36,7 +41,7 @@ var getBaseOptions = function(cb){ git_message = process.env.DRONE_COMMIT_MESSAGE; } - if (process.env.JENKINS_URL || process.env.JENKINS_HOME){ + if (process.env.JENKINS_URL || process.env.JENKINS_HOME) { options.service_name = 'jenkins'; options.service_job_id = process.env.BUILD_ID; options.service_pull_request = process.env.CHANGE_ID || process.env.ghprbPullId; @@ -46,19 +51,20 @@ var getBaseOptions = function(cb){ git_branch = process.env.CHANGE_BRANCH || process.env.GIT_BRANCH || process.env.BRANCH_NAME; } - if (process.env.CIRCLECI){ + if (process.env.CIRCLECI) { options.service_name = 'circleci'; options.service_job_id = process.env.CIRCLE_BUILD_NUM; if (process.env.CI_PULL_REQUEST) { - var pr = process.env.CI_PULL_REQUEST.split('/pull/'); + const pr = process.env.CI_PULL_REQUEST.split('/pull/'); options.service_pull_request = pr[1]; } + git_commit = process.env.CIRCLE_SHA1; git_branch = process.env.CIRCLE_BRANCH; } - if (process.env.CI_NAME && process.env.CI_NAME === 'codeship'){ + if (process.env.CI_NAME && process.env.CI_NAME === 'codeship') { options.service_name = 'codeship'; options.service_job_id = process.env.CI_BUILD_NUMBER; git_commit = process.env.CI_COMMIT_ID; @@ -68,14 +74,14 @@ var getBaseOptions = function(cb){ git_message = process.env.CI_COMMIT_MESSAGE; } - if (process.env.WERCKER){ + if (process.env.WERCKER) { options.service_name = 'wercker'; options.service_job_id = process.env.WERCKER_BUILD_ID; git_commit = process.env.WERCKER_GIT_COMMIT; git_branch = process.env.WERCKER_GIT_BRANCH; } - if (process.env.GITLAB_CI){ + if (process.env.GITLAB_CI) { options.service_name = 'gitlab-ci'; options.service_job_number = process.env.CI_BUILD_NAME; options.service_job_id = process.env.CI_BUILD_ID; @@ -83,20 +89,22 @@ var getBaseOptions = function(cb){ git_commit = process.env.CI_BUILD_REF; git_branch = process.env.CI_BUILD_REF_NAME; } - if(process.env.APPVEYOR){ + + if (process.env.APPVEYOR) { options.service_name = 'appveyor'; options.service_job_number = process.env.APPVEYOR_BUILD_NUMBER; options.service_job_id = process.env.APPVEYOR_BUILD_ID; git_commit = process.env.APPVEYOR_REPO_COMMIT; git_branch = process.env.APPVEYOR_REPO_BRANCH; } - if(process.env.SURF_SHA1){ + + if (process.env.SURF_SHA1) { options.service_name = 'surf'; git_commit = process.env.SURF_SHA1; git_branch = process.env.SURF_REF; } - if(process.env.BUILDKITE){ + if (process.env.BUILDKITE) { options.service_name = 'buildkite'; options.service_job_number = process.env.BUILDKITE_BUILD_NUMBER; options.service_job_id = process.env.BUILDKITE_BUILD_ID; @@ -108,14 +116,14 @@ var getBaseOptions = function(cb){ git_message = process.env.BUILDKITE_MESSAGE; } - if(process.env.SEMAPHORE){ + if (process.env.SEMAPHORE) { options.service_name = 'semaphore'; options.service_job_id = process.env.SEMAPHORE_BUILD_NUMBER; git_commit = process.env.REVISION; git_branch = process.env.BRANCH_NAME; } - if(process.env.TF_BUILD){ + if (process.env.TF_BUILD) { options.service_name = 'Azure Pipelines'; options.service_job_id = process.env.BUILD_BUILDID; options.service_pull_request = process.env.SYSTEM_PULLREQUEST_PULLREQUESTNUMBER; @@ -124,15 +132,16 @@ var getBaseOptions = function(cb){ } options.run_at = process.env.COVERALLS_RUN_AT || JSON.stringify(new Date()).slice(1, -1); - if (process.env.COVERALLS_SERVICE_NAME){ + if (process.env.COVERALLS_SERVICE_NAME) { options.service_name = process.env.COVERALLS_SERVICE_NAME; } - if (process.env.COVERALLS_SERVICE_JOB_ID){ + + if (process.env.COVERALLS_SERVICE_JOB_ID) { options.service_job_id = process.env.COVERALLS_SERVICE_JOB_ID; } if (!git_commit || !git_branch) { - var data = require('./detectLocalGit')(); + const data = detectLocalGit(); if (data) { git_commit = git_commit || data.git_commit; git_branch = git_branch || data.git_branch; @@ -148,18 +157,18 @@ var getBaseOptions = function(cb){ options.repo_token = process.env.COVERALLS_REPO_TOKEN; } else { // try to get the repo token from a .coveralls.yml file - var yml = path.join(process.cwd(), '.coveralls.yml'); + const yml = path.join(process.cwd(), '.coveralls.yml'); try { if (fs.statSync(yml).isFile()) { - var coveralls_yaml_conf = yaml.safeLoad(fs.readFileSync(yml, 'utf8')); + const coveralls_yaml_conf = yaml.safeLoad(fs.readFileSync(yml, 'utf8')); options.repo_token = coveralls_yaml_conf.repo_token; - if(coveralls_yaml_conf.service_name) { + if (coveralls_yaml_conf.service_name) { options.service_name = coveralls_yaml_conf.service_name; } } - } catch(ex){ - logger.warn("Repo token could not be determined. Continuing without it." + - "This is necessary for private repos only, so may not be an issue at all."); + } catch (_) { + logger.warn('Repo token could not be determined. Continuing without it. ' + + 'This is necessary for private repos only, so may not be an issue at all.'); } } @@ -167,7 +176,7 @@ var getBaseOptions = function(cb){ options.flag_name = process.env.COVERALLS_FLAG_NAME; } - if (git_commit){ + if (git_commit) { fetchGitData({ head: { id: git_commit, @@ -176,12 +185,13 @@ var getBaseOptions = function(cb){ message: git_message }, branch: git_branch - }, function(err, git){ - if (err){ + }, (err, git) => { + if (err) { logger.warn('there was an error getting git data: ', err); } else { options.git = git; } + return cb(err, options); }); } else { @@ -189,24 +199,28 @@ var getBaseOptions = function(cb){ } }; -var getOptions = function(cb, _userOptions){ - if (!cb){ +const getOptions = (cb, _userOptions) => { + if (!cb) { throw new Error('getOptions requires a callback'); } - var userOptions = _userOptions || {}; + const userOptions = _userOptions || {}; - getBaseOptions(function(err, options){ + getBaseOptions((err, options) => { // minimist populates options._ with non-option command line arguments - var firstNonOptionArgument = index.options._[0]; + const firstNonOptionArgument = index.options._[0]; - if (firstNonOptionArgument) + if (firstNonOptionArgument) { options.filepath = firstNonOptionArgument; + } // lodash or else would be better, but no need for the extra dependency - for (var option in userOptions) { - options[option] = userOptions[option]; + for (const option in userOptions) { + if (Object.prototype.hasOwnProperty.call(userOptions, option)) { + options[option] = userOptions[option]; + } } + cb(err, options); }); }; diff --git a/lib/handleInput.js b/lib/handleInput.js index 326671e..e7da536 100644 --- a/lib/handleInput.js +++ b/lib/handleInput.js @@ -1,33 +1,39 @@ -var index = require('../index'); -var logger = require('./logger')(); +'use strict'; + +const logger = require('./logger')(); +const index = require('..'); function handleInput(input, cb, userOptions) { logger.debug(input); - logger.debug('user options ' + userOptions); - index.getOptions(function(err, options){ - if (err){ - logger.error("error from getOptions"); + logger.debug(`user options ${userOptions}`); + index.getOptions((err, options) => { + if (err) { + logger.error('error from getOptions'); cb(err); return; } + logger.debug(options); - index.convertLcovToCoveralls(input, options, function(err, postData){ - if (err){ - logger.error("error from convertLcovToCoveralls"); + index.convertLcovToCoveralls(input, options, (err, postData) => { + if (err) { + logger.error('error from convertLcovToCoveralls'); cb(err); return; } - logger.info("sending this to coveralls.io: ", JSON.stringify(postData)); - index.sendToCoveralls(postData, function(err, response, body){ - if (err){ + + logger.info('sending this to coveralls.io: ', JSON.stringify(postData)); + index.sendToCoveralls(postData, (err, response, body) => { + if (err) { cb(err); return; } - if (response.statusCode >= 400){ - cb("Bad response: " + response.statusCode + " " + body); + + if (response.statusCode >= 400) { + cb(`Bad response: ${response.statusCode} ${body}`); return; } + logger.debug(response.statusCode); logger.debug(body); cb(null, body); diff --git a/lib/logger.js b/lib/logger.js index 1c2ba68..4f71d74 100644 --- a/lib/logger.js +++ b/lib/logger.js @@ -1,16 +1,14 @@ -var index = require('../index'); +'use strict'; -module.exports = function(){ - return require('log-driver')({level : getLogLevel()}); -}; +const logDriver = require('log-driver'); +const index = require('..'); -function getLogLevel(){ - if (index.options.verbose || hasDebugEnvVariable()) { +module.exports = () => logDriver({ level: getLogLevel() }); + +function getLogLevel() { + if (index.options.verbose || Boolean(process.env.NODE_COVERALLS_DEBUG)) { return 'debug'; } - return 'error'; -} -function hasDebugEnvVariable(){ - return process.env.NODE_COVERALLS_DEBUG == 1; + return 'error'; } diff --git a/lib/sendToCoveralls.js b/lib/sendToCoveralls.js index fcf63a8..0421556 100644 --- a/lib/sendToCoveralls.js +++ b/lib/sendToCoveralls.js @@ -1,20 +1,27 @@ -var request = require('request'); -var index = require('../index'); +'use strict'; -var sendToCoveralls = function(obj, cb){ - var urlBase = 'https://coveralls.io'; +const request = require('request'); +const index = require('..'); + +const sendToCoveralls = (obj, cb) => { + let urlBase = 'https://coveralls.io'; if (process.env.COVERALLS_ENDPOINT) { urlBase = process.env.COVERALLS_ENDPOINT; } - var str = JSON.stringify(obj); - var url = urlBase + '/api/v1/jobs'; - + const str = JSON.stringify(obj); + const url = `${urlBase}/api/v1/jobs`; + if (index.options.stdout) { process.stdout.write(str); cb(null, { statusCode: 200 }, ''); } else { - request.post({url : url, form : { json : str}}, function(err, response, body){ + request.post({ + url, + form: { + json: str + } + }, (err, response, body) => { cb(err, response, body); }); } |
