Skip to content

Commit

Permalink
Add Support for Codacy #260
Browse files Browse the repository at this point in the history
  • Loading branch information
Nico Lindemann authored and espadrine committed Nov 23, 2014
1 parent ed68a39 commit bfbe3ca
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -1464,6 +1464,50 @@ cache(function(data, match, sendBadge, request) {
});
}));

// Codacy integration
camp.route(/^\/codacy\/(.+)\.(svg|png|gif|jpg|json)$/,
cache(function(data, match, sendBadge, request) {
var projectId = match[1];
var format = match[2];
var url = 'https://www.codacy.com/project/badge/' + projectId;
var badgeData = getBadgeData('code quality', data);
fetchFromSvg(request, url, function(err, res) {
console.log(res);

if (err != null) {
badgeData.text[1] = 'inaccessible';
sendBadge(format, badgeData);
return;
}
try {
badgeData.text[1] = res;
if (res === 'A') {
badgeData.colorscheme = 'brightgreen';
} else if (res === 'B') {
badgeData.colorscheme = 'green';
} else if (res === 'C') {
badgeData.colorscheme = 'yellowgreen';
} else if (res === 'D') {
badgeData.colorscheme = 'yellow';
} else if (res === 'E') {
badgeData.colorscheme = 'orange';
} else if (res === 'F') {
badgeData.colorscheme = 'red';
} else if (res === 'X') {
badgeData.text[1] = 'invalid';
badgeData.colorscheme = 'lightgrey';
} else {
badgeData.colorscheme = 'red';
}
sendBadge(format, badgeData);

} catch(e) {
badgeData.text[1] = 'invalid';
sendBadge(format, badgeData);
}
});
}));

// Hackage version integration.
camp.route(/^\/hackage\/v\/(.*)\.(svg|png|gif|jpg|json)$/,
cache(function(data, match, sendBadge, request) {
Expand Down

0 comments on commit bfbe3ca

Please sign in to comment.