Skip to content

Commit

Permalink
Added [codetally] (#1069)
Browse files Browse the repository at this point in the history
  • Loading branch information
triggerman722 authored and paulmelnikow committed Sep 24, 2017
1 parent 13502b3 commit 20ab540
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
26 changes: 26 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -1150,6 +1150,32 @@ cache(function(data, match, sendBadge, request) {
});
}));

// Codetally integration.
camp.route(/^\/codetally\/(.*)\/(.*)\.(svg|png|gif|jpg|json)$/,
cache(function(data, match, sendBadge, request) {
var owner = match[1]; // eg, triggerman722.
var repo = match[2]; // eg, colorstrap
var format = match[3];
var apiUrl = 'http://www.codetally.com/formattedshield/' + owner + '/' + repo;
var badgeData = getBadgeData('codetally', data);
request(apiUrl, function dealWithData(err, res, buffer) {
if (err != null) {
badgeData.text[1] = 'inaccessible';
sendBadge(format, badgeData);
return;
}
try {
var data = JSON.parse(buffer);
badgeData.text[1] = " " + data.currency_sign + data.amount + " " + data.multiplier;
badgeData.colorscheme = null;
badgeData.colorB = '#2E8B57';
sendBadge(format, badgeData);
} catch(e) {
badgeData.text[1] = 'invalid';
sendBadge(format, badgeData);
}
});
}));


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

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

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

// This test will extract the currency value from the
// string value response from the server.
// \b = Asset position at word boundary
// \d+ = match a digit [0-9]
// credit for this regex goes to:
// https://stackoverflow.com/questions/38074000/how-to-get-float-value-from-string-using-regex

t.create('Codetally')
.get('/triggerman722/colorstrap.json')
.expectJSONTypes(Joi.object().keys({
name: Joi.equal('codetally'),
value: Joi.string().regex(/\b\d+(?:.\d+)?/)
}));


t.create('Empty')
.get('/triggerman722/colorstrap.json')
.intercept(nock => nock('http://www.codetally.com')
.get('/formattedshield/triggerman722/colorstrap')
.reply(200, { currency_sign:'$', amount:'0.00', multiplier:'', currency_abbreviation:'CAD' })
)
.expectJSON({ name: 'codetally', value: ' $0.00 '});
4 changes: 4 additions & 0 deletions try.html
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,10 @@ <h3 id="miscellaneous"> Miscellaneous </h3>
<td><img src='/codeclimate/issues/github/me-and/mdf.svg' alt=''/></td>
<td><code>https://img.shields.io/codeclimate/issues/github/me-and/mdf.svg</code></td>
</tr>
<tr><th> Codetally:</th>
<td><img src='/codetally/triggerman722/colorstrap.svg' alt=''/></td>
<td><code>https://img.shields.io/codetally/triggerman722/colorstrap.svg</code></td>
</tr>
<tr><th> bitHound: </th>
<td><img src='/bithound/code/github/rexxars/sse-channel.svg' alt=''/></td>
<td><code>https://img.shields.io/bithound/code/github/rexxars/sse-channel.svg</code></td>
Expand Down

0 comments on commit 20ab540

Please sign in to comment.