Skip to content

Commit

Permalink
1.1.8
Browse files Browse the repository at this point in the history
- fixes coverage api to sort before limit is run
- adds more examples to storybook
- fixes error not propagating on main coverage page
- fixes a bug when parsing coverage which stops NaN values from being added to array
- abstracts CLI functionality into library to add more extensive tests
  • Loading branch information
gabrielcsapo committed Oct 28, 2017
1 parent 8ef37a1 commit a08fe83
Show file tree
Hide file tree
Showing 52 changed files with 695 additions and 421 deletions.
2 changes: 2 additions & 0 deletions .storybook/config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'psychic.css/dist/psychic.min.css';

import { configure } from '@storybook/react';

function loadStories() {
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# 1.1.8 (10/27/2017)

- fixes coverage api to sort before limit is run
- adds more examples to storybook
- fixes error not propagating on main coverage page
- fixes a bug when parsing coverage which stops NaN values from being added to array
- abstracts CLI functionality into library to add more extensive tests

# 1.1.7 (10/25/2017)

- includes moment as a production dependency
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# lcov-server [docs](https://www.gabrielcsapo.com/lcov-server)
# lcov-server [[docs](https://www.gabrielcsapo.com/lcov-server)][[hosted](https://lcov-server.gabrielcsapo.com)]

> 🎯 A simple lcov server & cli parser
Expand Down
104 changes: 10 additions & 94 deletions bin/lcov-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,9 @@
require('babel-polyfill');

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 cli = require('../lib/cli');

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

Expand All @@ -43,95 +32,22 @@ if(serve) {

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 'cobertura':
_lcov = await cobertura.parse(input);
break;
case 'golang':
_lcov = await golang.parse(input);
break;
case 'jacoco':
_lcov = await jacoco.parse(input);
break;
default:
_lcov = await lcov.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;
try {
let response = cli({ parser, input, url: upload, basePath });
if(response.error) {
console.error(`coverage not sent with reason:\n ${response.error}`); // eslint-disable-line
} else {
console.log('\n coverage sent successfully 💚 \n'); // eslint-disable-line
}
} catch(ex) {
console.error(`coverage could not be parsed with reason:\n ${ex.toString()}`); // eslint-disable-line
}

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();
}));
}
22 changes: 11 additions & 11 deletions dist/bundle.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/vendor.bundle.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion docs/code/coverage.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ <h1 class="page-title">coverage.js</h1>
module.exports.get = function get(repo, limit) {
return new Promise((resolve, reject) => {
let options = [
{ $sort: { "run_at": -1 } },
{ $match: { "git.remotes.url": repo } },
{ $limit: parseInt(limit) },
{
Expand All @@ -211,7 +212,7 @@ <h1 class="page-title">coverage.js</h1>
}];

if(!limit) {
delete options[1];
delete options[2];
options = options.filter((n) => n !== undefined);
}

Expand Down
2 changes: 1 addition & 1 deletion docs/code/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Coverage.


<section class="readme">
<article><h1>lcov-server <a href="https://www.gabrielcsapo.com/lcov-server">docs</a></h1><blockquote>
<article><h1>lcov-server [<a href="https://www.gabrielcsapo.com/lcov-server">docs</a>][<a href="https://lcov-server.gabrielcsapo.com">hosted</a>]</h1><blockquote>
<p>🎯 A simple lcov server &amp; cli parser</p>
</blockquote>
<p><a href="https://www.npmjs.com/package/lcov-server"><img src="https://img.shields.io/npm/v/lcov-server.svg" alt="Npm Version"></a>
Expand Down
Binary file added docs/example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions docs/index.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/storybook/iframe.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<body>
<div id="root"></div>
<div id="error-display"></div>
<script src="static/preview.01ae41e870d6bfc88cfd.bundle.js"></script>
<script src="static/preview.a8c92ec89fd752a174d8.bundle.js"></script>
</body>
</html>

4 changes: 2 additions & 2 deletions docs/storybook/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="storybook-version" content="3.2.12">
<meta name="storybook-version" content="3.2.13">
<meta content="IE=edge" http-equiv="X-UA-Compatible" />
<title>Storybook</title>
<style>
Expand Down Expand Up @@ -40,7 +40,7 @@
</head>
<body style="margin: 0;">
<div id="root"></div>
<script src="static/manager.636402f6d36656349933.bundle.js"></script>
<script src="static/manager.09f65c282c57cf833204.bundle.js"></script>
</body>
</html>

Large diffs are not rendered by default.

This file was deleted.

This file was deleted.

Large diffs are not rendered by default.

103 changes: 103 additions & 0 deletions lib/cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
const fs = require('fs');
const Path = require('path');
const Url = require('url');
const http = require('http');
const https = require('https');

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');

module.exports = function cli({ parser, input, url, basePath }) {
const parsedUrl = Url.parse(url);

return new Promise(async function(resolve, reject) {
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 'cobertura':
_lcov = await cobertura.parse(input);
break;
case 'golang':
_lcov = await golang.parse(input);
break;
case 'jacoco':
_lcov = await jacoco.parse(input);
break;
default:
_lcov = await lcov.parse(input);
break;
}

// 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;

if(fs.existsSync(path)) {
_lcov[i].source = fs.readFileSync(path).toString('utf8');
_lcov[i].title = _lcov[i].file.substring(_lcov[i].file.lastIndexOf('/') + 1, _lcov[i].file.length);
} else {
return reject(`can not find file at ${path}`);
}
}

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

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) {
return reject(response.error); // eslint-disable-line
} else {
return resolve(response);
}
} catch(ex) {
return reject(ex);
}
});
});
req.write(JSON.stringify(output));
req.end();
});
};
3 changes: 2 additions & 1 deletion lib/coverage.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ module.exports.repos = function repos(repo) {
module.exports.get = function get(repo, limit) {
return new Promise((resolve, reject) => {
let options = [
{ $sort: { "run_at": -1 } },
{ $match: { "git.remotes.url": repo } },
{ $limit: parseInt(limit) },
{
Expand All @@ -172,7 +173,7 @@ module.exports.get = function get(repo, limit) {
}];

if(!limit) {
delete options[1];
delete options[2];
options = options.filter((n) => n !== undefined);
}

Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lcov-server",
"version": "1.1.7",
"version": "1.1.8",
"description": "🎯 A simple lcov server & cli parser",
"main": "index.js",
"homepage": "https://github.com/gabrielcsapo/lcov-server#readme",
Expand All @@ -24,7 +24,7 @@
"start": "./bin/lcov-server.js --serve",
"dev": "NODE_ENV=development webpack-dev-server --hot --port 5000",
"pack": "pkg bin/lcov-server.js -c package.json -o packed/lcov-server",
"generate-docs": "tryitout --template=landing --output=./docs && jsdoc -c jsdoc.json",
"generate-docs": "tryitout --output=docs --template=product && jsdoc -c jsdoc.json",
"storybook": "start-storybook -p 6006",
"build-storybook": "build-storybook --output-dir ./docs/storybook"
},
Expand Down Expand Up @@ -75,7 +75,7 @@
"body-parser": "^1.18.2",
"css-loader": "^0.28.7",
"docdash": "^0.4.0",
"eslint": "^4.9.0",
"eslint": "^4.10.0",
"eslint-plugin-react": "^7.4.0",
"getstorybook": "^1.7.0",
"highlight.js": "^9.12.0",
Expand All @@ -91,7 +91,7 @@
"style-loader": "^0.19.0",
"tap": "^10.7.2",
"tape": "^4.8.0",
"tryitout": "^0.3.6",
"tryitout": "^0.3.7",
"webpack": "^3.8.1",
"webpack-dev-server": "^2.9.3",
"whatwg-fetch": "^2.0.3"
Expand Down
1 change: 0 additions & 1 deletion src/app.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'whatwg-fetch';
import 'psychic.css/dist/psychic.min.css';
import './style.css';

Expand Down
4 changes: 1 addition & 3 deletions src/components/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class Table extends React.Component {
return <td key={`${k}/${i}`}> <div className={ k === 'Commit' ? 'coverage-commit-message' : ''}>{ h[k] }</div> </td>;
})}
</tr>);
}) }
}, []) }
</tbody>
</table>
{ data.length > 1 ?
Expand All @@ -65,13 +65,11 @@ class Table extends React.Component {

Table.propTypes = {
data: PropTypes.array,
sort: PropTypes.string,
chunk: PropTypes.number
};

Table.defaultProps = {
data: [],
sort: '',
chunk: 5
};

Expand Down
2 changes: 1 addition & 1 deletion src/coverage/coverage.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class Coverage extends React.Component {
<h4> Source Files ({ history[0].source_files.length })</h4>
<Table data={history[0].source_files.map(this.reduceSourceFiles.bind(this))} chunk={5}/>
<h4> Recent Builds ({ history.length })</h4>
<Table data={history.map(this.reduceBuilds)} sort={"Recieved"} chunk={9}/>
<Table data={history.map(this.reduceBuilds)} chunk={9}/>
</div>
</div>);
} else {
Expand Down
Loading

0 comments on commit a08fe83

Please sign in to comment.