Skip to content

Commit

Permalink
Add JitPack version badge; fixes #900
Browse files Browse the repository at this point in the history
  • Loading branch information
kariminf authored and paulmelnikow committed Sep 22, 2017
1 parent cafb66b commit 0f65d86
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 0 deletions.
44 changes: 44 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -6077,6 +6077,49 @@ cache(function(data, match, sendBadge, request) {
});
}));

// jitPack version integration.
camp.route(/^\/jitpack\/v\/([^\/]*)\/([^\/]*)\.(svg|png|gif|jpg|json)$/,
cache(function(data, match, sendBadge, request) {
var groupId = 'com.github.' + match[1]; // github user
var artifactId = match[2]; // the project's name
var format = match[3]; // "svg"
var name = 'JitPack';

var pkg = groupId + '/' + artifactId + '/latest';
var apiUrl = 'https://jitpack.io/api/builds/' + pkg ;

var badgeData = getBadgeData(name, data);

request(apiUrl, function(err, res, buffer) {
if (err != null) {
badgeData.text[1] = 'inaccessible';
sendBadge(format, badgeData);
return;
}
if (res.statusCode === 404) {
badgeData.text[1] = 'not found';
sendBadge(format, badgeData);
return;
}
try {
var data = JSON.parse(buffer);
var version = 'v' + data['version'];
var status = data['status'];
var color = 'brightgreen';
if(status !== 'ok'){
color = 'red';
version = 'unknown';
}
badgeData.text[1] = version;
badgeData.colorscheme = color;
sendBadge(format, badgeData);
} catch(e) {
badgeData.text[1] = 'invalid';
sendBadge(format, badgeData);
}
});
}));

// Test if a webpage is online
camp.route(/^\/website(-(([^-/]|--|\/\/)+)-(([^-/]|--|\/\/)+)(-(([^-/]|--|\/\/)+)-(([^-/]|--|\/\/)+))?)?\/([^/]+)\/(.+)\.(svg|png|gif|jpg|json)$/,
cache(function(data, match, sendBadge, request) {
Expand Down Expand Up @@ -6738,4 +6781,5 @@ function mapNpmDownloads(urlComponent, apiUriComponent) {
}
});
}));

}
28 changes: 28 additions & 0 deletions service-tests/jitpack.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
'use strict';

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

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

t.create('version')
.get('/v/jitpack/maven-simple.json')
.expectJSONTypes(Joi.object().keys({
name: Joi.equal('JitPack'),
value: Joi.string().regex(/^v.+$/)//Github allows versions with chars, etc.
}));

t.create('unknown package')
.get('/v/some-bogus-user/project.json')
.expectJSON({ name: 'JitPack', value: 'invalid' });

t.create('unknown info')
.get('/z/devtools.json')
.expectStatus(404)
.expectJSON({ name: '404', value: 'badge not found' });

t.create('connection error')
.get('/v/jitpack/maven-simple.json')
.networkOff()
.expectJSON({ name: 'JitPack', value: 'inaccessible' });
4 changes: 4 additions & 0 deletions try.html
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,10 @@ <h3 id="version"> Version </h3>
<td><img src='/itunes/v/803453959.svg' alt=''/></td>
<td><code>https://img.shields.io/itunes/v/BUNDLE_ID.svg</code></td>
</tr>
<tr><th data-keywords='jitpack java maven'> JitPack: </th>
<td><img src='/jitpack/v/jitpack/maven-simple.svg' alt=''/></td>
<td><code>https://img.shields.io/jitpack/v/jitpack/maven-simple.svg</code></td>
</tr>
</tbody></table>

<h3 id="social"> Social </h3>
Expand Down

0 comments on commit 0f65d86

Please sign in to comment.