Skip to content

Commit

Permalink
Handle unknown Git versions appropriately
Browse files Browse the repository at this point in the history
In the event that some Git version was recorded that isn’t known to the
Git release database, this patch introduces an “unknown” dataset that is
invisible otherwise.
  • Loading branch information
pluehne committed May 27, 2019
1 parent 30b6e35 commit 0fe15fd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
13 changes: 13 additions & 0 deletions docs/assets/js/_partials/chart-recommended-git-versions.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ class RecommendedGitVersionsChart extends AreaChart
vulnerable: 'red',
outdated: 'yellow',
recommended: 'green',
unknown: 'grey',
},
datasets: ['recommended', 'outdated', 'vulnerable'],
views:
[
{
Expand Down Expand Up @@ -91,6 +93,7 @@ class RecommendedGitVersionsChart extends AreaChart
recommended: 0,
outdated: 0,
vulnerable: 0,
unknown: 0,
};

while (version.split('.').length < 3)
Expand All @@ -104,6 +107,16 @@ class RecommendedGitVersionsChart extends AreaChart
continue;
}

if (!(version in gitReleases))
{
// If an unknown version was found, show the “unknown” dataset
if (this.config.datasets.indexOf('unknown') === -1)
this.config.datasets.push('unknown');

result[date].unknown += users;
continue;
}

if ('vulnerableSince' in gitReleases[version]
&& gitReleases[version].vulnerableSince < date)
{
Expand Down
3 changes: 3 additions & 0 deletions docs/spec/chart-recommended-git-versions.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,19 @@ describe('Recommended Git versions chart', function()
expect(chartData[287].vulnerable).toEqual(200);
expect(chartData[287].outdated).toEqual(188);
expect(chartData[287].recommended).toEqual(60);
expect(chartData[287].unknown).toEqual(0);

expect(chartData[84].date).toEqual(new Date('2018-10-08'));
expect(chartData[84].vulnerable).toEqual(657);
expect(chartData[84].outdated).toEqual(0);
expect(chartData[84].recommended).toEqual(51);
expect(chartData[84].unknown).toEqual(0);

expect(chartData[21].date).toEqual(new Date('2018-12-10'));
expect(chartData[21].vulnerable).toEqual(713);
expect(chartData[21].outdated).toEqual(146);
expect(chartData[21].recommended).toEqual(178);
expect(chartData[21].unknown).toEqual(0);

done();
});
Expand Down

0 comments on commit 0fe15fd

Please sign in to comment.