Skip to content

Commit

Permalink
1.1.0
Browse files Browse the repository at this point in the history
- adds the ability to parse ,  and
- packages entire application as global executable using pkg
- instantly fails the process if process can't connect to mongo
- adds a limit option to coverage.get to speed up badge generation
- utilizes async await in main router
- utilizes async await in tests
- moved from  to
- uses the right environment variables for travis-ci
- compiles module with babel, allowing it to be used over multiple versions of node (previously older versions were not supported)
- sets a limit to only retrieve 10 builds on the list-item view (reduces data on the wire)
- adds viewport meta tag to scale on multiple devices
- adds other meta tags to ensure SEO
- moves version of release to the footer
  • Loading branch information
gabrielcsapo committed Oct 24, 2017
1 parent 35641e3 commit b8aae1d
Show file tree
Hide file tree
Showing 65 changed files with 7,193 additions and 396 deletions.
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"browser": true
},
"parserOptions": {
"ecmaVersion": 6,
"ecmaVersion": "2017",
"sourceType": "module",
"ecmaFeatures": {
"jsx": true
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ node_modules
.DS_Store
npm-debug.log
package-lock.json
packed
distributed
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ script:
- npm run coverage
- cat coverage/lcov.info | lcov-server --upload https://lcov-server.gabrielcsapo.com
node_js:
- "6"
- "8"
os:
- linux
Expand Down
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
# 1.1.0 (10/24/2017)

- adds the ability to parse `cobertura`, `golang` and `jacoco`
- packages entire application as global executable using pkg
- instantly fails the process if process can't connect to mongo
- adds a limit option to coverage.get to speed up badge generation
- utilizes async await in main router
- utilizes async await in tests
- moved from `psychic-ui` to `psychic.css`
- uses the right environment variables for travis-ci
- compiles module with babel, allowing it to be used over multiple versions of node (previously older versions were not supported)
- sets a limit to only retrieve 10 builds on the list-item view (reduces data on the wire)
- adds viewport meta tag to scale on multiple devices
- adds other meta tags to ensure SEO
- moves version of release to the footer

# 1.0.6 (10/23/2017)

- adds monospace font-family to fileView
Expand Down
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,13 @@ Usage: lcov-server [options]
Options:
-V, --version output the version number
-u, --upload [server] Set the url to upload lcov data too
-s, --serve Pass this option to startup a lcov-server instance
-d, --db [db] Set the db connection
-h, --help output usage information
-V, --version output the version number
-u, --upload [server] Set the url to upload lcov data too
-s, --serve Pass this option to startup a lcov-server instance
-d, --db [db] Set the db connection
-p, --parser <parser> Set the parser value [lcov, cobertura, golang, jacoco], defaults to lcov
-bp, --basePath <path> The path that defines the base directory where the files that were covered will be located
-h, --help output usage information
```

## Upload
Expand Down
4 changes: 0 additions & 4 deletions TODO.md

This file was deleted.

133 changes: 133 additions & 0 deletions bin/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
const program = require('commander');
const http = require('http');
const https = require('https');
const fs = require('fs');
const Path = require('path');
const Url = require('url');
const updateNotifier = require('update-notifier');

const lcov = require('../lib/lcov');
const cobertura = require('../lib/cobertura');
const golang = require('../lib/golang');
const jacoco = require('../lib/jacoco');

const git = require('../lib/git');
const ci = require('../lib/ci');

const pkg = require('../package.json');

updateNotifier({pkg}).notify();

program
.version(pkg.version)
.option('-u, --upload [server]', 'Set the url to upload lcov data too', 'http://localhost:8080')
.option('-s, --serve', 'Pass this option to startup a lcov-server instance')
.option('-d, --db [db]', 'Set the db connection', 'mongodb://localhost:32768/lcov-server')
.option('-p, --parser <parser>', 'Set the parser value [lcov, cobertura, golang, jacoco], defaults to lcov', 'lcov')
.option('-bp, --basePath <path>', 'The path that defines the base directory where the files that were covered will be located')
.parse(process.argv);

const { parser, upload, serve, db, basePath } = program;

if(parser && ['lcov', 'cobertura', 'golang', 'jacoco'].indexOf(parser) === -1) {
console.error(`parser ${parser} not supported`); // eslint-disable-line
process.exit(1);
}

if(serve) {
process.env.MONGO_URL = process.env.MONGO_URL || db;

require('../index');
} else {
const parsedUrl = Url.parse(upload);

let input = '';
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', (chunk) => {
input += chunk;
});
process.stdin.on('end', (async () => {
const env = ci();
const output = {
service_job_id: env.service_job_id,
service_pull_request: env.service_pull_request,
service_name: env.service_name,
source_files: [],
git: {
commit: env.commit,
branch: env.branch,
message: env.message,
committer_name: env.committer_name,
committer_email: env.committer_email
},
run_at: new Date()
};

let _lcov = {};
switch(parser) {
case 'lcov':
_lcov = await lcov.parse(input);
break;
case 'cobertura':
_lcov = await cobertura.parse(input);
break;
case 'golang':
_lcov = await golang.parse(input);
break;
case 'jacoco':
_lcov = await jacoco.parse(input);
break;
}

const _git = await git.parse();

// Go through and set the file contents
for (let i = 0; i < _lcov.length; i++) {
let path = basePath ? Path.resolve(process.cwd(), basePath, _lcov[i].file) : _lcov[i].file;

_lcov[i].source = fs.readFileSync(path).toString('utf8');
_lcov[i].title = _lcov[i].file.substring(_lcov[i].file.lastIndexOf('/') + 1, _lcov[i].file.length);
}

output['source_files'] = _lcov;
output['git'] = Object.assign(output['git'], _git);

const options = {
hostname: parsedUrl.hostname,
port: parsedUrl.port || 80,
path: '/api/upload',
method: 'POST',
headers: {
'Content-Type': 'application/json',
}
};
let operation = http;
let data = '';

if(parsedUrl.protocol == 'https:') {
options.port = 443;
operation = https;
}

let req = operation.request(options, (res) => {
res.on('data', (chunk) => {
data += chunk;
});
res.on('end', () => {
try {
const response = JSON.parse(data);
if(response.error) {
console.error(response.error); // eslint-disable-line
} else {
console.log(`\n coverage sent successfully 💚 \n`); // eslint-disable-line
}
} catch(ex) {
console.log(`\n uhoh something went wrong, ${ex.toString()}`); // eslint-disable-line
}
});
});
req.write(JSON.stringify(output));
req.end();
}));
}
121 changes: 7 additions & 114 deletions bin/lcov-server.js
Original file line number Diff line number Diff line change
@@ -1,118 +1,11 @@
#!/usr/bin/env node

const program = require('commander');
const http = require('http');
const https = require('https');
const fs = require('fs');
const Url = require('url');
const updateNotifier = require('update-notifier');
const semver = require('semver');

const lcov = require('../lib/lcov');
const git = require('../lib/git');
const ci = require('../lib/ci');

const pkg = require('../package.json');

updateNotifier({pkg}).notify();

program
.version(pkg.version)
.option('-u, --upload [server]', 'Set the url to upload lcov data too', 'http://localhost:8080')
.option('-s, --serve', 'Pass this option to startup a lcov-server instance')
.option('-d, --db [db]', 'Set the db connection', 'mongodb://localhost:32768/lcov-server')
.parse(process.argv);

const { upload, serve, db } = program;

if(serve) {
process.env.MONGO_URL = process.env.MONGO_URL || db;

require('../index');
} else {
const parsedUrl = Url.parse(upload);

let input = '';
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', (chunk) => {
input += chunk;
});
process.stdin.on('end', () => {
const env = ci();
const output = {
service_job_id: env.service_job_id,
service_pull_request: env.service_pull_request,
service_name: env.service_name,
source_files: [],
git: {
commit: env.commit,
branch: env.branch,
message: env.message,
committer_name: env.committer_name,
committer_email: env.committer_email
},
run_at: new Date()
};

lcov.parse(input)
.then((_lcov) => {
// Go through and set the file contents
for (let i = 0; i < _lcov.length; i++) {
_lcov[i].source = fs.readFileSync(_lcov[i].file).toString('utf8');
_lcov[i].title = _lcov[i].file.substring(_lcov[i].file.lastIndexOf('/') + 1, _lcov[i].file.length);
}
output['source_files'] = _lcov;

git.parse()
.then(function(_git) {
output['git'] = Object.assign(output['git'], _git);

const options = {
hostname: parsedUrl.hostname,
port: parsedUrl.port || 80,
path: '/api/upload',
method: 'POST',
headers: {
'Content-Type': 'application/json',
}
};

let req, operation, data = '';
if(parsedUrl.protocol == 'https:') {
options.port = 443;
operation = https;
} else {
operation = http;
}

req = operation.request(options, (res) => {
res.on('data', (chunk) => {
data += chunk;
});
res.on('end', () => {
try {
const response = JSON.parse(data);
if(response.error) {
console.error(response.error); // eslint-disable-line
} else {
console.log(`\n coverage sent successfully 💚 \n`); // eslint-disable-line
}
} catch(ex) {
console.log(`\n uhoh something went wrong, ${ex.toString()}`); // eslint-disable-line
}
});
});
req.write(JSON.stringify(output));
req.end();
})
.catch((err) => {
console.log(err); // eslint-disable-line
process.exit(1);
});
})
.catch((err) => {
console.log(`could not parse lcov report correctly: ${err}`); // eslint-disable-line
process.exit(1);
});
});
if (semver.lt(process.version, '8.5.0')) {
// only shim pre 8 binaries
require('babel-register');
require('babel-polyfill');
}

require('./index.js');
Loading

0 comments on commit b8aae1d

Please sign in to comment.