forked from enviPath/enviPy
Current Dev State
This commit is contained in:
145
static/js/ketcher2/node_modules/coveralls/lib/convertLcovToCoveralls.js
generated
vendored
Normal file
145
static/js/ketcher2/node_modules/coveralls/lib/convertLcovToCoveralls.js
generated
vendored
Normal file
@ -0,0 +1,145 @@
|
||||
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){
|
||||
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){
|
||||
branches.push(obj[key] || 0);
|
||||
});
|
||||
});
|
||||
return branches;
|
||||
};
|
||||
|
||||
var convertLcovFileObject = function(file, filepath){
|
||||
var 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 };
|
||||
};
|
||||
|
||||
var cleanFilePath = function(file) {
|
||||
if (file.indexOf('!') > -1) {
|
||||
var regex = /^(.*!)(.*)$/g;
|
||||
var 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);
|
||||
filepath = path.resolve(process.cwd(), filepath);
|
||||
lcovParse(input, function(err, parsed){
|
||||
if (err){
|
||||
logger.error("error from lcovParse: ", err);
|
||||
logger.error("input: ", input);
|
||||
return cb(err);
|
||||
}
|
||||
var postJson = {
|
||||
source_files : []
|
||||
};
|
||||
if (options.git){
|
||||
postJson.git = options.git;
|
||||
}
|
||||
if (options.run_at){
|
||||
postJson.run_at = options.run_at;
|
||||
}
|
||||
if (options.service_name){
|
||||
postJson.service_name = options.service_name;
|
||||
}
|
||||
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){
|
||||
file.file = cleanFilePath(file.file);
|
||||
var currentFilePath = path.resolve(filepath, file.file);
|
||||
if (fs.existsSync(currentFilePath)) {
|
||||
postJson.source_files.push(convertLcovFileObject(file, filepath));
|
||||
}
|
||||
});
|
||||
return cb(null, postJson);
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = convertLcovToCoveralls;
|
||||
|
||||
/* example coveralls json file
|
||||
|
||||
|
||||
{
|
||||
"service_job_id": "1234567890",
|
||||
"service_name": "travis-ci",
|
||||
"source_files": [
|
||||
{
|
||||
"name": "example.rb",
|
||||
"source": "def four\n 4\nend",
|
||||
"coverage": [null, 1, null]
|
||||
},
|
||||
{
|
||||
"name": "two.rb",
|
||||
"source": "def seven\n eight\n nine\nend",
|
||||
"coverage": [null, 1, 0, null]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
example output from lcov parser:
|
||||
|
||||
[
|
||||
{
|
||||
"file": "index.js",
|
||||
"lines": {
|
||||
"found": 0,
|
||||
"hit": 0,
|
||||
"details": [
|
||||
{
|
||||
"line": 1,
|
||||
"hit": 1
|
||||
},
|
||||
{
|
||||
"line": 2,
|
||||
"hit": 1
|
||||
},
|
||||
{
|
||||
"line": 3,
|
||||
"hit": 1
|
||||
},
|
||||
{
|
||||
"line": 5,
|
||||
"hit": 1
|
||||
},
|
||||
|
||||
*/
|
||||
47
static/js/ketcher2/node_modules/coveralls/lib/detectLocalGit.js
generated
vendored
Normal file
47
static/js/ketcher2/node_modules/coveralls/lib/detectLocalGit.js
generated
vendored
Normal file
@ -0,0 +1,47 @@
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
|
||||
// branch naming only has a few excluded characters, see git-check-ref-format(1)
|
||||
var REGEX_BRANCH = /^ref: refs\/heads\/([^?*\[\\~^:]+)$/;
|
||||
|
||||
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')))
|
||||
break;
|
||||
|
||||
dir = path.dirname(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)
|
||||
return { git_commit: head };
|
||||
|
||||
var commit = _parseCommitHashFromRef(dir, 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;
|
||||
}
|
||||
}
|
||||
108
static/js/ketcher2/node_modules/coveralls/lib/fetchGitData.js
generated
vendored
Normal file
108
static/js/ketcher2/node_modules/coveralls/lib/fetchGitData.js
generated
vendored
Normal file
@ -0,0 +1,108 @@
|
||||
var exec = require('child_process').exec;
|
||||
var logger = require('./logger')();
|
||||
|
||||
function fetchGitData(git, cb) {
|
||||
if (!cb){
|
||||
throw new Error("fetchGitData requires a callback");
|
||||
}
|
||||
|
||||
//-- Malformed/undefined git object
|
||||
if ('undefined' === typeof git) {
|
||||
return cb(new Error('No options passed'));
|
||||
}
|
||||
if (!git.hasOwnProperty('head')) {
|
||||
return cb(new Error('You must provide the head'));
|
||||
}
|
||||
if (!git.head.hasOwnProperty('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 (!git.hasOwnProperty("remotes")) {
|
||||
git.remotes = [];
|
||||
}
|
||||
|
||||
//-- Assert the property types
|
||||
if ("string" !== typeof git.branch) {
|
||||
git.branch = "";
|
||||
}
|
||||
if (!(git.remotes instanceof Array)) {
|
||||
git.remotes = [];
|
||||
}
|
||||
|
||||
//-- Use git?
|
||||
exec("git rev-parse --verify " + git.head.id, function(err, response){
|
||||
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";
|
||||
return cb(null, git);
|
||||
}
|
||||
|
||||
fetchHeadDetails(git, cb);
|
||||
});
|
||||
}
|
||||
|
||||
function fetchBranch(git, cb) {
|
||||
exec("git branch", function(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;
|
||||
|
||||
function fetchHeadDetails(git, cb) {
|
||||
exec('git cat-file -p ' + git.head.id, function(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) {
|
||||
git.head[field] = items[index];
|
||||
});
|
||||
|
||||
if (git.branch) {
|
||||
fetchRemotes(git, cb);
|
||||
} else {
|
||||
fetchBranch(git, cb);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function fetchRemotes(git, cb) {
|
||||
exec("git remote -v", function(err, remotes){
|
||||
if (err)
|
||||
return cb(err);
|
||||
|
||||
var processed = {};
|
||||
remotes.split("\n").forEach(function(remote) {
|
||||
if (!/\s\(push\)$/.test(remote))
|
||||
return;
|
||||
remote = remote.split(/\s+/);
|
||||
saveRemote(processed, git, remote[0], remote[1]);
|
||||
});
|
||||
cb(null, git);
|
||||
});
|
||||
}
|
||||
|
||||
function saveRemote(processed, git, name, url) {
|
||||
var key = name + "-" + url;
|
||||
if (processed.hasOwnProperty(key))
|
||||
return;
|
||||
|
||||
processed[key] = true;
|
||||
git.remotes.push({ name: name, url: url });
|
||||
}
|
||||
|
||||
module.exports = fetchGitData;
|
||||
181
static/js/ketcher2/node_modules/coveralls/lib/getOptions.js
generated
vendored
Normal file
181
static/js/ketcher2/node_modules/coveralls/lib/getOptions.js
generated
vendored
Normal file
@ -0,0 +1,181 @@
|
||||
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+)$/);
|
||||
|
||||
if (match) {
|
||||
options.service_pull_request = match[1];
|
||||
}
|
||||
|
||||
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;
|
||||
git_commit = 'HEAD';
|
||||
git_branch = process.env.TRAVIS_BRANCH;
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
git_committer_name = process.env.DRONE_COMMIT_AUTHOR;
|
||||
git_committer_email = process.env.DRONE_COMMIT_AUTHOR_EMAIL;
|
||||
git_commit = process.env.DRONE_COMMIT;
|
||||
git_branch = process.env.DRONE_BRANCH;
|
||||
git_message = process.env.DRONE_COMMIT_MESSAGE;
|
||||
}
|
||||
|
||||
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.ghprbPullId;
|
||||
git_commit = process.env.GIT_COMMIT;
|
||||
git_branch = process.env.GIT_BRANCH || process.env.BRANCH_NAME;
|
||||
}
|
||||
|
||||
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/');
|
||||
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'){
|
||||
options.service_name = 'codeship';
|
||||
options.service_job_id = process.env.CI_BUILD_NUMBER;
|
||||
git_commit = process.env.CI_COMMIT_ID;
|
||||
git_branch = process.env.CI_BRANCH;
|
||||
git_committer_name = process.env.CI_COMMITTER_NAME;
|
||||
git_committer_email = process.env.CI_COMMITTER_EMAIL;
|
||||
git_message = process.env.CI_COMMIT_MESSAGE;
|
||||
}
|
||||
|
||||
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){
|
||||
options.service_name = 'gitlab-ci';
|
||||
options.service_job_number = process.env.CI_BUILD_NAME;
|
||||
options.service_job_id = process.env.CI_BUILD_ID;
|
||||
git_commit = process.env.CI_BUILD_REF;
|
||||
git_branch = process.env.CI_BUILD_REF_NAME;
|
||||
}
|
||||
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){
|
||||
options.service_name = 'surf';
|
||||
git_commit = process.env.SURF_SHA1;
|
||||
git_branch = process.env.SURF_REF;
|
||||
}
|
||||
options.run_at = process.env.COVERALLS_RUN_AT || JSON.stringify(new Date()).slice(1, -1);
|
||||
if (process.env.COVERALLS_SERVICE_NAME){
|
||||
options.service_name = process.env.COVERALLS_SERVICE_NAME;
|
||||
}
|
||||
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')();
|
||||
if (data) {
|
||||
git_commit = git_commit || data.git_commit;
|
||||
git_branch = git_branch || data.git_branch;
|
||||
}
|
||||
}
|
||||
|
||||
if (process.env.COVERALLS_PARALLEL) {
|
||||
options.parallel = true;
|
||||
}
|
||||
|
||||
// try to get the repo token as an environment variable
|
||||
if (process.env.COVERALLS_REPO_TOKEN) {
|
||||
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');
|
||||
try {
|
||||
if (fs.statSync(yml).isFile()) {
|
||||
var coveralls_yaml_conf = yaml.safeLoad(fs.readFileSync(yml, 'utf8'));
|
||||
options.repo_token = coveralls_yaml_conf.repo_token;
|
||||
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.");
|
||||
}
|
||||
}
|
||||
|
||||
if (git_commit){
|
||||
fetchGitData({
|
||||
head: {
|
||||
id: git_commit,
|
||||
committer_name: git_committer_name,
|
||||
committer_email: git_committer_email,
|
||||
message: git_message
|
||||
},
|
||||
branch: git_branch
|
||||
}, function(err, git){
|
||||
if (err){
|
||||
logger.warn('there was an error getting git data: ', err);
|
||||
} else {
|
||||
options.git = git;
|
||||
}
|
||||
return cb(err, options);
|
||||
});
|
||||
} else {
|
||||
return cb(null, options);
|
||||
}
|
||||
};
|
||||
|
||||
var getOptions = function(cb, _userOptions){
|
||||
if (!cb){
|
||||
throw new Error('getOptions requires a callback');
|
||||
}
|
||||
|
||||
var userOptions = _userOptions || {};
|
||||
|
||||
getBaseOptions(function(err, options){
|
||||
// minimist populates options._ with non-option command line arguments
|
||||
var firstNonOptionArgument = index.options._[0];
|
||||
|
||||
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];
|
||||
}
|
||||
cb(err, options);
|
||||
});
|
||||
};
|
||||
|
||||
module.exports.getBaseOptions = getBaseOptions;
|
||||
module.exports.getOptions = getOptions;
|
||||
40
static/js/ketcher2/node_modules/coveralls/lib/handleInput.js
generated
vendored
Normal file
40
static/js/ketcher2/node_modules/coveralls/lib/handleInput.js
generated
vendored
Normal file
@ -0,0 +1,40 @@
|
||||
var index = require('../index');
|
||||
var logger = require('./logger')();
|
||||
|
||||
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");
|
||||
cb(err);
|
||||
return;
|
||||
}
|
||||
logger.debug(options);
|
||||
|
||||
index.convertLcovToCoveralls(input, options, function(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){
|
||||
cb(err);
|
||||
return;
|
||||
}
|
||||
if (response.statusCode >= 400){
|
||||
cb("Bad response: " + response.statusCode + " " + body);
|
||||
return;
|
||||
}
|
||||
logger.debug(response.statusCode);
|
||||
logger.debug(body);
|
||||
cb(null);
|
||||
});
|
||||
});
|
||||
}, userOptions);
|
||||
}
|
||||
|
||||
module.exports = handleInput;
|
||||
16
static/js/ketcher2/node_modules/coveralls/lib/logger.js
generated
vendored
Normal file
16
static/js/ketcher2/node_modules/coveralls/lib/logger.js
generated
vendored
Normal file
@ -0,0 +1,16 @@
|
||||
var index = require('../index');
|
||||
|
||||
module.exports = function(){
|
||||
return require('log-driver')({level : getLogLevel()});
|
||||
};
|
||||
|
||||
function getLogLevel(){
|
||||
if (index.options.verbose || hasDebugEnvVariable()) {
|
||||
return 'warn';
|
||||
}
|
||||
return 'error';
|
||||
}
|
||||
|
||||
function hasDebugEnvVariable(){
|
||||
return process.env.NODE_COVERALLS_DEBUG == 1;
|
||||
}
|
||||
23
static/js/ketcher2/node_modules/coveralls/lib/sendToCoveralls.js
generated
vendored
Normal file
23
static/js/ketcher2/node_modules/coveralls/lib/sendToCoveralls.js
generated
vendored
Normal file
@ -0,0 +1,23 @@
|
||||
var request = require('request');
|
||||
var index = require('../index');
|
||||
|
||||
var sendToCoveralls = function(obj, cb){
|
||||
var 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';
|
||||
|
||||
if (index.options.stdout) {
|
||||
process.stdout.write(str);
|
||||
cb(null, { statusCode: 200 }, '');
|
||||
} else {
|
||||
request.post({url : url, form : { json : str}}, function(err, response, body){
|
||||
cb(err, response, body);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = sendToCoveralls;
|
||||
Reference in New Issue
Block a user