Skip to content

Commit

Permalink
[Cauditor] Replace with error message (#1502)
Browse files Browse the repository at this point in the history
* Depreciate Cauditor

* explicitly set color to lightgray, update test

* add message for date of badge depreciation
  • Loading branch information
RedSparr0w authored Mar 5, 2018
1 parent 0640356 commit f4d5c41
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 66 deletions.
4 changes: 0 additions & 4 deletions lib/all-badge-examples.js
Original file line number Diff line number Diff line change
Expand Up @@ -1795,10 +1795,6 @@ const allBadgeExamples = [
title: 'Codacy branch coverage',
previewUri: '/codacy/coverage/c44df2d9c89a4809896914fd1a40bedd/master.svg'
},
{
title: 'Cauditor',
previewUri: '/cauditor/mi/matthiasmullie/scrapbook/master.svg'
},
{
title: 'Libscore',
previewUri: '/libscore/s/jQuery.svg'
Expand Down
68 changes: 6 additions & 62 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -6851,70 +6851,14 @@ cache(function(data, match, sendBadge, request) {
});
}));

// Cauditor integration
// Cauditor integration - Badge deprectiated as of March 2018
camp.route(/^\/cauditor\/(mi|ccn|npath|hi|i|ca|ce|dit)\/([^/]+)\/([^/]+)\/(.+)\.(svg|png|gif|jpg|json)$/,
cache(function(data, match, sendBadge, request) {
var labels = {
'mi': 'maintainability',
'ccn': 'cyclomatic complexity',
'npath': 'npath complexity',
'hi': 'intelligent content',
'i': 'instability',
'ca': 'afferent coupling',
'ce': 'efferent coupling',
'dit': 'depth of inheritance'
};
// values for color ranges (left = green, right = red)
var colors = {
'mi': [70, 55, 45, 35],
'ccn': [2, 4, 7, 11],
'npath': [2, 25, 60, 200],
'hi': [2, 20, 45, 80],
'i': [.2, .5, .75, .8],
'ca': [2, 4, 7, 10],
'ce': [2, 7, 13, 20],
'dit': [2, 3, 4, 5]
};
var metric = match[1];
var user = match[2];
var repo = match[3];
var branch = match[4];
var format = match[5];
var badgeData = getBadgeData(labels[metric], data);
var url = 'https://www.cauditor.org/api/v1/' + user + '/' + repo + '/' + branch + '/HEAD';
request(url, function(err, res, buffer) {
if (err != null || res.statusCode !== 200) {
badgeData.text[1] = 'inaccessible';
sendBadge(format, badgeData);
return;
}

var data = JSON.parse(buffer);
var value = data.metrics.weighed[metric];
var range = colors[metric];

badgeData.text[1] = Math.round(value);
if (metric === 'mi') {
badgeData.text[1] += '%';
}

// calculate colors: anything in the given range is green to yellow
if (value >= Math.min(range[0], range[1]) && value < Math.max(range[0], range[1])) {
badgeData.colorscheme = 'green';
} else if (value >= Math.min(range[1], range[2]) && value < Math.max(range[1], range[2])) {
badgeData.colorscheme = 'yellowgreen';
} else if (value >= Math.min(range[2], range[3]) && value < Math.max(range[2], range[3])) {
badgeData.colorscheme = 'yellow';
// anything higher than (or lower, in case of 'mi') first value is green
} else if ((value < range[0] && range[0] < range[1]) || (value > range[0] && range[0] > range[1])) {
badgeData.colorscheme = 'brightgreen';
// anything not yet matched is bad!
} else {
badgeData.colorscheme = 'red';
}

sendBadge(format, badgeData);
});
const format = match[5];
const badgeData = getBadgeData('cauditor', data);
setBadgeColor(badgeData, 'lightgray');
badgeData.text[1] = 'no longer available';
sendBadge(format, badgeData);
}));

// Mozilla addons integration
Expand Down
14 changes: 14 additions & 0 deletions service-tests/cauditor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'use strict';

const ServiceTester = require('./runner/service-tester');

const t = new ServiceTester({ id: 'cauditor', title: 'Cauditor' });
module.exports = t;

t.create('no longer available')
.get('/mi/matthiasmullie/scrapbook/master.json?style=_shields_test')
.expectJSON({
name: 'cauditor',
value: 'no longer available',
colorB: '#9f9f9f',
});

0 comments on commit f4d5c41

Please sign in to comment.