Skip to content

Commit

Permalink
1.1.6
Browse files Browse the repository at this point in the history
- uses the correct values for git
- reduces error in calculating coverage points by abstracting to helper method
- ensures that the history is sorted correctly
- fixes the generation of graphs to be more accurate (using total data instead of just a single file)
- fixes the generation of badges to be more accurate (using total data instead of just a single file)
- updates dependencies
- fixes the calculation of source files
  • Loading branch information
gabrielcsapo committed Oct 26, 2017
1 parent 9edc40b commit 32e5df1
Show file tree
Hide file tree
Showing 22 changed files with 316 additions and 251 deletions.
3 changes: 2 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
node_modules
coverage
/coverage
/test/fixtures
docs
dist
npm-debug.log
Expand Down
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# 1.1.6 (10/25/2017)

- uses the correct values for git
- reduces error in calculating coverage points by abstracting to helper method
- ensures that the history is sorted correctly
- fixes the generation of graphs to be more accurate (using total data instead of just a single file)
- fixes the generation of badges to be more accurate (using total data instead of just a single file)
- updates dependencies
- fixes the calculation of source files

# 1.1.5 (10/25/2017)

- guards retrieval of values
Expand Down
10 changes: 5 additions & 5 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.

8 changes: 4 additions & 4 deletions docs/code/Coverage.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ <h4 class="name" id="Coverage"><span class="type-signature"></span>new Coverage<

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="coverage.js.html">coverage.js</a>, <a href="coverage.js.html#line3">line 3</a>
<a href="coverage.js.html">coverage.js</a>, <a href="coverage.js.html#line4">line 4</a>
</li></ul></dd>


Expand Down Expand Up @@ -1255,7 +1255,7 @@ <h4 class="name" id=".get"><span class="type-signature">(static) </span>get<span

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="coverage.js.html">coverage.js</a>, <a href="coverage.js.html#line151">line 151</a>
<a href="coverage.js.html">coverage.js</a>, <a href="coverage.js.html#line152">line 152</a>
</li></ul></dd>


Expand Down Expand Up @@ -1455,7 +1455,7 @@ <h4 class="name" id=".repos"><span class="type-signature">(static) </span>repos<

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="coverage.js.html">coverage.js</a>, <a href="coverage.js.html#line123">line 123</a>
<a href="coverage.js.html">coverage.js</a>, <a href="coverage.js.html#line124">line 124</a>
</li></ul></dd>


Expand Down Expand Up @@ -1612,7 +1612,7 @@ <h4 class="name" id=".save"><span class="type-signature">(static) </span>save<sp

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="coverage.js.html">coverage.js</a>, <a href="coverage.js.html#line101">line 101</a>
<a href="coverage.js.html">coverage.js</a>, <a href="coverage.js.html#line102">line 102</a>
</li></ul></dd>


Expand Down
20 changes: 17 additions & 3 deletions docs/code/coverage.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ <h1 class="page-title">coverage.js</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>const mongoose = require('mongoose');
const moment = require('moment');

/**
* @class Coverage
Expand Down Expand Up @@ -199,7 +200,6 @@ <h1 class="page-title">coverage.js</h1>
return new Promise((resolve, reject) => {
let options = [
{ $match: { "git.remotes.url": repo } },
{ $sort : { "run_at" : -1 } },
{ $limit: parseInt(limit) },
{
$group: {
Expand All @@ -211,12 +211,26 @@ <h1 class="page-title">coverage.js</h1>
}];

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

Coverage.aggregate(options, (err, docs) => {
if(err) { return reject(err); }
// this might happen if the data is malformed
if(docs.length > 1) {
var condensed = docs[0];
for(var i = 1; i &lt; docs.length; i++) {
condensed.history = condensed.history.concat(docs[i].history);
}
condensed.history = condensed.history.sort((a, b) => {
return moment(a['run_at']) - moment(b['run_at']) > 0 ? -1 : 1;
});
return resolve([condensed]);
}
docs[0].history = docs[0].history.sort((a, b) => {
return moment(a['run_at']) - moment(b['run_at']) > 0 ? -1 : 1;
});
return resolve(docs);
});
});
Expand Down
2 changes: 1 addition & 1 deletion docs/index.html

Large diffs are not rendered by default.

14 changes: 10 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,16 @@ app.get('/badge/:service/:owner/:repo.svg', asyncMiddleware(async (req, res) =>
const coverages = await Coverage.get(new RegExp(`${service.replace(/%2E/g, '.')}.*/${owner}/${repo}`), 1);
const coverage = coverages[0];
const { history } = coverage;
const lastRun = history[history.length - 1];
const { lines } = lastRun.source_files[0];
const percentage = parseInt((lines.hit / lines.found) * 100);
const color = percentage >= 90 ? '#3DB712' : percentage <= 89 && percentage >= 80 ? '#caa300' : '#cc5338';
const { source_files } = history[0];
let found = 0;
let hit = 0;
source_files.forEach((file) => {
const { lines={hit: 0, found: 0}, branches={hit: 0, found: 0}, functions={hit: 0, found: 0} } = file;
found += lines.found + branches.found + functions.found;
hit += lines.hit + branches.hit + functions.hit;
});
const percentage = parseInt((hit / found) * 100);
const color = percentage >= 85 ? '#3DB712' : percentage <= 85 && percentage >= 70 ? '#caa300' : '#cc5338';

Badge({ color: { right: color }, text: ['coverage', `${percentage}%`] }, function(err, badge) {
if(err) { throw new Error(err); }
Expand Down
20 changes: 17 additions & 3 deletions lib/coverage.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const mongoose = require('mongoose');
const moment = require('moment');

/**
* @class Coverage
Expand Down Expand Up @@ -160,7 +161,6 @@ module.exports.get = function get(repo, limit) {
return new Promise((resolve, reject) => {
let options = [
{ $match: { "git.remotes.url": repo } },
{ $sort : { "run_at" : -1 } },
{ $limit: parseInt(limit) },
{
$group: {
Expand All @@ -172,12 +172,26 @@ module.exports.get = function get(repo, limit) {
}];

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

Coverage.aggregate(options, (err, docs) => {
if(err) { return reject(err); }
// this might happen if the data is malformed
if(docs.length > 1) {
var condensed = docs[0];
for(var i = 1; i < docs.length; i++) {
condensed.history = condensed.history.concat(docs[i].history);
}
condensed.history = condensed.history.sort((a, b) => {
return moment(a['run_at']) - moment(b['run_at']) > 0 ? -1 : 1;
});
return resolve([condensed]);
}
docs[0].history = docs[0].history.sort((a, b) => {
return moment(a['run_at']) - moment(b['run_at']) > 0 ? -1 : 1;
});
return resolve(docs);
});
});
Expand Down
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lcov-server",
"version": "1.1.5",
"version": "1.1.6",
"description": "🎯 A simple lcov server & cli parser",
"main": "index.js",
"homepage": "https://github.com/gabrielcsapo/lcov-server#readme",
Expand Down Expand Up @@ -56,15 +56,15 @@
"compression": "^1.7.1",
"express": "^4.16.2",
"git-url-parse": "^7.0.1",
"mongoose": "^4.12.1",
"mongoose": "^4.12.4",
"openbadge": "^1.0.4",
"serve-static": "^1.13.1",
"update-notifier": "^2.3.0",
"xml2js": "^0.4.19"
},
"devDependencies": {
"@storybook/addon-knobs": "^3.2.12",
"@storybook/react": "^3.2.12",
"@storybook/addon-knobs": "^3.2.13",
"@storybook/react": "^3.2.13",
"babel-cli": "^6.26.0",
"babel-core": "^6.26.0",
"babel-loader": "^7.1.2",
Expand All @@ -74,7 +74,7 @@
"body-parser": "^1.18.2",
"css-loader": "^0.28.7",
"docdash": "^0.4.0",
"eslint": "^4.8.0",
"eslint": "^4.9.0",
"eslint-plugin-react": "^7.4.0",
"getstorybook": "^1.7.0",
"highlight.js": "^9.12.0",
Expand All @@ -91,9 +91,9 @@
"style-loader": "^0.19.0",
"tap": "^10.7.2",
"tape": "^4.8.0",
"tryitout": "^0.3.4",
"webpack": "^3.7.1",
"webpack-dev-server": "^2.9.1",
"tryitout": "^0.3.6",
"webpack": "^3.8.1",
"webpack-dev-server": "^2.9.3",
"whatwg-fetch": "^2.0.3"
}
}
13 changes: 10 additions & 3 deletions src/coverage/chart.js → src/components/coverageChart.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import React from 'react';
import PropTypes from 'prop-types';

import LineChart from '../lib/chart/line';

class CoverageChart extends React.Component {
render() {
const { data, height, width, axis } = this.props;
const { data, height, width } = this.props;

const opt = {
data,
colors: ['#9a8585', '#a7daff', '#f7ca97'],
labels: ['Lines', 'Branches', 'Functions'],
axis,
width,
height,
lines: true,
Expand All @@ -21,8 +22,14 @@ class CoverageChart extends React.Component {

return (
<LineChart {...opt} />
)
);
}
}

CoverageChart.propTypes = {
data: PropTypes.array,
height: PropTypes.number,
width: PropTypes.number
};

export default CoverageChart;
2 changes: 2 additions & 0 deletions src/components/error.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class Error extends React.Component {
<pre style={{width: '50%', margin: '0 auto'}}>
{ error || 'Page not found' }
</pre>
<br/>
<a href="/"> Go Somewhere Safe 🏝 </a>
</div>);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/fileView.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
border: 0;
}

.table-fileView td, .hljs-string, .hljs-keyword, .hljs-comment, .hljs-meta, .hljs-params, .hljs-function, .hljs-attr, .hljs-built_in, .hljs-title, .hljs-literal {
.table-fileView tr, .table-fileView tr > *, .table-fileView td span {
font-family: monospace;
}
6 changes: 4 additions & 2 deletions src/components/loading.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import React from 'react';

class Loading extends React.Component {
render() {
return (<div className="text-center" style={{width:"100%",position: "absolute",top: "50%",transform: "translateY(-50%)"}}>
Loading 🌪
return (<div className="coverage text-center" style={{ border: "1px solid #dedede", position: "relative", height: "300px" }}>
<div style={{width:"100%",position: "absolute",top: "50%",transform: "translateY(-50%)"}}>
<div className="spinner spinner-black"></div>
</div>
</div>);
}
}
Expand Down
13 changes: 13 additions & 0 deletions src/components/noCoverage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import React from 'react';

class noCoverage extends React.Component {
render() {
return (<div className="coverage text-center" style={{ border: "1px solid #dedede", position: "relative", height: "300px" }}>
<div style={{width:"100%",position: "absolute",top: "50%",transform: "translateY(-50%)"}}>
No Coverage 🌧
</div>
</div>);
}
}

export default noCoverage;
16 changes: 9 additions & 7 deletions src/components/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ class Table extends React.Component {
page: 1
};
}

nextPage() {
const { page, data } = this.state;

Expand Down Expand Up @@ -42,12 +41,13 @@ class Table extends React.Component {
</tr>
</thead>
<tbody>
{data[page - 1].map((h, i) => {
return (<tr key={`${page}/${i}`}>
{ Object.keys(h).map((k) => {
return <td key={`${k}/${i}`}> <div className={ k === 'Commit' ? 'coverage-commit-message' : ''}>{ h[k] }</div> </td>;
})}
</tr>); })}
{ data[page - 1].map((h, i) => {
return (<tr key={`${page}/${i}`}>
{ Object.keys(h).map((k) => {
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,11 +65,13 @@ class Table extends React.Component {

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

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

Expand Down
Loading

0 comments on commit 32e5df1

Please sign in to comment.