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

Adds puppet forge (versioning) support. #171

Merged
merged 3 commits into from
May 9, 2014
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
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"es6-promise": "~0.1.1",
"request": "~2.34.0",
"redis": "~0.10.1",
"camp": "~13.11.9"
"camp": "~13.11.9",
"semver": "~2.3.0"
},
"devDependencies": {
"ass": "~0.0.4",
Expand Down
48 changes: 48 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ var fs = require('fs');
var LruCache = require('./lru-cache.js');
var badge = require('./badge.js');
var svg2img = require('./svg-to-img.js');
var semver = require('semver');
var serverStartTime = new Date((new Date()).toGMTString());

var validTemplates = ['default', 'flat'];
Expand Down Expand Up @@ -962,6 +963,53 @@ cache(function(data, match, sendBadge) {
});
}));

// Puppet Forge
camp.route(/^\/puppetforge\/v\/([^\/]+\/[^\/]+)\.(svg|png|gif|jpg)$/,
cache(function(data, match, sendBadge) {
var userRepo = match[1];
var format = match[2];
var options = {
json: true,
uri: 'https://forge.puppetlabs.com/api/v1/releases.json?module=' + userRepo
};
var badgeData = getBadgeData('puppetforge', data);
request(options, function dealWithData(err, res, json) {
if (err != null || (json.length !== undefined && json.length === 0)) {
badgeData.text[1] = 'inaccessible';
sendBadge(format, badgeData);
return
}
try {
var unstable = function(ver) { return /-[0-9A-Za-z.-]+(?:\+[0-9A-Za-z.-]+)?$/.test(ver); };
var releases = json[userRepo];
if (releases.length == 0) {
badgeData.text[1] = 'none';
badgeData.colorscheme = 'lightgrey';
sendBadge(format, badgeData);
return;
}
var version = releases[0].version;
for (var i = 0; i < releases.length; i++) {
var current = releases[i].version;
if (semver.gt(current, version)) {
version = current;
}
}
if (unstable(version)) {
badgeData.colorscheme = "yellow";
} else {
badgeData.colorscheme = "blue";
}
badgeData.text[1] = "v" + version;
sendBadge(format, badgeData);

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

// Any badge.
camp.route(/^\/(:|badge\/)(([^-]|--)+)-(([^-]|--)+)-(([^-]|--)+)\.(svg|png|gif|jpg)$/,
function(data, match, end, ask) {
Expand Down
4 changes: 4 additions & 0 deletions try.html
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,10 @@ <h3> Version </h3>
<td><img src='/nuget/v/Nuget.Core.svg' alt=''/></td>
<td><code>http://img.shields.io/nuget/v/Nuget.Core.svg</code></td>
</tr>
<tr><th> Puppet Forge: </th>
<td><img src='/puppetforge/v/vStone/percona.svg' alt=''/></td>
<td><code>http://img.shields.io/puppetforge/v/vStone/percona.svg</code></td>
</tr>
</tbody></table>

<h3> Flat Style </h3>
Expand Down