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

Add [JitPack] version badge; fixes #900 #1049

Merged
merged 1 commit into from
Sep 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
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
44 changes: 44 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -5927,6 +5927,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 @@ -6588,4 +6631,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 @@ -622,6 +622,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