Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Cauditor] Replace with error message #1502

Merged
merged 3 commits into from
Mar 5, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions lib/all-badge-examples.js
Original file line number Diff line number Diff line change
Expand Up @@ -1791,10 +1791,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
65 changes: 4 additions & 61 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -6823,67 +6823,10 @@ cache(function(data, match, sendBadge, request) {
// Cauditor integration
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);
badgeData.text[1] = 'no longer available';
sendBadge(format, badgeData);
}));

// Mozilla addons integration
Expand Down
13 changes: 13 additions & 0 deletions service-tests/cauditor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'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')
.expectJSON({
name: 'cauditor',
value: 'no longer available',
});