Skip to content

Commit fbe1bb2

Browse files
committed
Formatting consistent
1 parent 95bb430 commit fbe1bb2

File tree

11 files changed

+2889
-2775
lines changed

11 files changed

+2889
-2775
lines changed

config/config.js

Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,79 +2,77 @@ const userSettings = require('./settings.json') || {}; // User settings
22
const path = require('path');
33
env = process.env.NODE_ENV || 'production';
44
const appdata = process.env.APPDATA || process.env.HOME;
5-
const dataPath = process.env.APPDATA? path.join(appdata, 'CI') : path.join(appdata, '.ci');
5+
const dataPath = process.env.APPDATA ? path.join(appdata, 'CI') : path.join(appdata, '.ci');
66
const fixtureDir = path.resolve(__dirname, '..', 'test', 'fixtures');
77
const dbFilename = '.db.json';
88
let settings;
99

1010
// Defaults for when there's no user file; will almost certainly fail
11-
defaults = {
11+
const defaults = {
1212
setup_function: null,
1313
test_function: null,
1414
listen_port: 3000,
15-
timeout: 8*60000,
16-
program: "python",
15+
timeout: 8 * 60000,
16+
program: 'python',
1717
strict_coverage: false,
1818
events: {
1919
push: {
2020
checks: null,
21-
ref_ignore: ["documentation", "gh-pages"]
21+
ref_ignore: ['documentation', 'gh-pages']
2222
},
2323
pull_request: {
24-
checks: ["continuous-integration", "coverage"],
25-
actions: ["opened", "synchronize", "reopen"],
26-
ref_ignore: ["documentation", "gh-pages"]
24+
checks: ['continuous-integration', 'coverage'],
25+
actions: ['opened', 'synchronize', 'reopen'],
26+
ref_ignore: ['documentation', 'gh-pages']
2727
}
2828
},
2929
dataPath: dataPath,
3030
dbFile: path.join(dataPath, dbFilename)
31-
}
31+
};
3232

3333
// Settings for the tests
34-
testing = {
34+
const testing = {
3535
listen_port: 3000,
3636
timeout: 60000,
3737
events: {
3838
push: {
39-
checks: "continuous-integration",
40-
ref_ignore: "documentation"
39+
checks: 'continuous-integration',
40+
ref_ignore: 'documentation'
4141
},
4242
pull_request: {
43-
checks: ["coverage", "continuous-integration"],
44-
actions: ["opened", "synchronize"],
45-
ref_ignore: ["documentation", "gh-pages"],
43+
checks: ['coverage', 'continuous-integration'],
44+
actions: ['opened', 'synchronize'],
45+
ref_ignore: ['documentation', 'gh-pages']
4646
}
4747
},
4848
routines: {
49-
'*': ["prep_env.BAT", "run_tests.BAT"]
49+
'*': ['prep_env.BAT', 'run_tests.BAT']
5050
},
5151
dataPath: fixtureDir,
5252
dbFile: path.join(fixtureDir, dbFilename) // cache of test results
53-
}
53+
};
5454

5555
// Pick the settings to return
5656
if (env.startsWith('test')) {
57-
settings = testing;
57+
settings = testing;
5858
} else if (userSettings) {
59-
settings = userSettings;
60-
if (!('dbFile' in settings)) {
61-
settings.dbFile = path.join(dataPath, dbFilename)
62-
}
63-
if (!('dataPath' in settings)) {
64-
settings.dataPath = dataPath;
65-
}
59+
settings = userSettings;
60+
if (!('dbFile' in settings)) settings.dbFile = path.join(dataPath, dbFilename);
61+
if (!('dataPath' in settings)) settings.dataPath = dataPath;
6662
} else {
67-
settings = defaults;
63+
settings = defaults;
6864
}
6965

7066
// Check ENV set up correctly
7167
required = ['GITHUB_PRIVATE_KEY', 'GITHUB_APP_IDENTIFIER', 'GITHUB_WEBHOOK_SECRET',
72-
'WEBHOOK_PROXY_URL', 'REPO_PATH', 'REPO_NAME', 'REPO_OWNER', 'TUNNEL_HOST',
73-
'TUNNEL_SUBDOMAIN'];
74-
missing = required.filter(o => { return !process.env[o] });
68+
'WEBHOOK_PROXY_URL', 'REPO_PATH', 'REPO_NAME', 'REPO_OWNER', 'TUNNEL_HOST',
69+
'TUNNEL_SUBDOMAIN'];
70+
missing = required.filter(o => {
71+
return !process.env[o];
72+
});
7573
if (missing.length > 0) {
76-
errMsg = `Env not set correctly; the following variables not found: \n${missing.join(', ')}`
77-
throw ReferenceError(errMsg)
74+
errMsg = `Env not set correctly; the following variables not found: \n${missing.join(', ')}`;
75+
throw ReferenceError(errMsg);
7876
}
7977

80-
module.exports = { settings }
78+
module.exports = {settings};

coverage.js

Lines changed: 64 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ var token = process.env.COVERALLS_TOKEN;
3434
* @returns {Object} key `Hash` contains MD5 digest string of file; `count` contains number of lines in source file
3535
*/
3636
function md5(path) {
37-
const hash = crypto.createHash('md5'); // Creating hash object
38-
const buf = fs.readFileSync(path, 'utf-8'); // Read in file
39-
const count = buf.split(/\r\n|\r|\n/).length; // Count the number of lines
40-
hash.update(buf, 'utf-8'); // Update hash
37+
const hash = crypto.createHash('md5'); // Creating hash object
38+
const buf = fs.readFileSync(path, 'utf-8'); // Read in file
39+
const count = buf.split(/\r\n|\r|\n/).length; // Count the number of lines
40+
hash.update(buf, 'utf-8'); // Update hash
4141

42-
return {hash: hash.digest('hex'), count: count};
42+
return {hash: hash.digest('hex'), count: count};
4343
}
4444

4545

@@ -53,35 +53,37 @@ function md5(path) {
5353
* @todo Generalize path default
5454
*/
5555
async function formatCoverage(classList, srcPath, sha) {
56-
var job = {};
57-
var sourceFiles = [];
58-
var digest;
59-
srcPath = typeof srcPath != "undefined" ? srcPath : process.env.REPO_PATH; // default to home dir
60-
// For each class, create file object containing array of lines covered and add to sourceFile array
61-
await Promise.all(classList.map(async c => {
62-
let file = {}; // Initialize file object
63-
let fullPath = c.$.filename.startsWith(srcPath)? c.$.filename : path.join(srcPath, c.$.filename);
64-
digest = md5(fullPath); // Create digest and line count for file
65-
let lines = new Array(digest.count).fill(null); // Initialize line array the size of source code file
66-
c.lines[0].line.forEach(ln => {
67-
let n = Number(ln.$.number);
68-
if (n <= digest.count) {lines[n] = Number(ln.$.hits) }
69-
});
70-
// create source file object
71-
file.name = c.$.filename;
72-
file.source_digest = digest.hash;
73-
file.coverage = lines; // file.coverage[0] == line 1
74-
sourceFiles.push(file);
75-
}));
56+
var job = {};
57+
var sourceFiles = [];
58+
var digest;
59+
srcPath = typeof srcPath != 'undefined' ? srcPath : process.env.REPO_PATH; // default to home dir
60+
// For each class, create file object containing array of lines covered and add to sourceFile array
61+
await Promise.all(classList.map(async c => {
62+
let file = {}; // Initialize file object
63+
let fullPath = c.$.filename.startsWith(srcPath) ? c.$.filename : path.join(srcPath, c.$.filename);
64+
digest = md5(fullPath); // Create digest and line count for file
65+
let lines = new Array(digest.count).fill(null); // Initialize line array the size of source code file
66+
c.lines[0].line.forEach(ln => {
67+
let n = Number(ln.$.number);
68+
if (n <= digest.count) {
69+
lines[n] = Number(ln.$.hits);
70+
}
71+
});
72+
// create source file object
73+
file.name = c.$.filename;
74+
file.source_digest = digest.hash;
75+
file.coverage = lines; // file.coverage[0] == line 1
76+
sourceFiles.push(file);
77+
}));
7678

77-
job.repo_token = token; // env secret token
78-
job.service_name = `coverage/${process.env.USERDOMAIN}`;
79-
// The associated pull request ID of the build. Used for updating the status and/or commenting.
80-
job.service_pull_request = '';
81-
job.source_files = sourceFiles;
82-
job.commit_sha = sha;
83-
job.run_at = timestamp; // "2013-02-18 00:52:48 -0800"
84-
return job;
79+
job.repo_token = token; // env secret token
80+
job.service_name = `coverage/${process.env.USERDOMAIN}`;
81+
// The associated pull request ID of the build. Used for updating the status and/or commenting.
82+
job.service_pull_request = '';
83+
job.source_files = sourceFiles;
84+
job.commit_sha = sha;
85+
job.run_at = timestamp; // "2013-02-18 00:52:48 -0800"
86+
return job;
8587
}
8688

8789
/**
@@ -94,37 +96,39 @@ async function formatCoverage(classList, srcPath, sha) {
9496
* @see {@link https://github.com/cobertura/cobertura/wiki|Cobertura Wiki}
9597
*/
9698
function coverage(path, repo, sha, submodules) {
97-
return fs.promises.readFile(path) // Read in XML file
98-
.then(parser.parseStringPromise) // Parse XML
99-
.then(result => {
100-
// Extract root code path
101-
const rootPath = (result.coverage.sources[0].source[0] || process.env.REPO_PATH).replace(/[\/|\\]+$/, '')
102-
timestamp = new Date(result.coverage.$.timestamp*1000); // Convert UNIX timestamp to Date object
103-
let classes = []; // Initialize classes array
99+
return fs.promises.readFile(path) // Read in XML file
100+
.then(parser.parseStringPromise) // Parse XML
101+
.then(result => {
102+
// Extract root code path
103+
const rootPath = (result.coverage.sources[0].source[0] || process.env.REPO_PATH)
104+
.replace(/[\/|\\]+$/, '');
105+
timestamp = new Date(result.coverage.$.timestamp * 1000); // Convert UNIX timestamp to Date object
106+
let classes = []; // Initialize classes array
104107

105-
const packages = result.coverage.packages[0].package;
106-
packages.forEach(pkg => { classes.push(pkg.classes[0].class) }); // Get all classes
107-
classes = classes.reduce((acc, val) => acc.concat(val), []); // Flatten
108+
const packages = result.coverage.packages[0].package;
109+
packages.forEach(pkg => { classes.push(pkg.classes[0].class); }); // Get all classes
110+
classes = classes.reduce((acc, val) => acc.concat(val), []); // Flatten
108111

109-
// The submodules
110-
const byModule = {'main' : []};
111-
submodules.forEach((x) => { byModule[x] = []; }); // initialize submodules
112+
// The submodules
113+
const byModule = {'main': []};
114+
submodules.forEach((x) => { byModule[x] = []; }); // initialize submodules
112115

113-
// Sort into piles
114-
byModule['main'] = classes.filter(function (e) {
115-
if (e.$.filename.search(/(tests\\|_.*test|docs\\)/i) !== -1) {return false;} // Filter out tests and docs
116-
if (!Array.isArray(e.lines[0].line)) {return false;} // Filter out files with no functional lines
117-
for (let submodule of submodules) {
118-
if (e.$.filename.startsWith(submodule)) {
119-
byModule[submodule].push(e); return false;
120-
}
121-
}
122-
return true;
116+
// Sort into piles
117+
byModule['main'] = classes.filter(function (e) {
118+
if (e.$.filename.search(/(tests\\|_.*test|docs\\)/i) !== -1) return false; // Filter out tests and docs
119+
if (!Array.isArray(e.lines[0].line)) return false; // Filter out files with no functional lines
120+
for (let submodule of submodules) {
121+
if (e.$.filename.startsWith(submodule)) {
122+
byModule[submodule].push(e);
123+
return false;
124+
}
125+
}
126+
return true;
127+
});
128+
// Select module
129+
let modules = byModule[repo] || byModule['main'];
130+
return formatCoverage(modules, rootPath, sha);
123131
});
124-
// Select module
125-
let modules = byModule[repo] || byModule['main'];
126-
return formatCoverage(modules, rootPath, sha);
127-
});
128132
}
129133

130134

0 commit comments

Comments
 (0)