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

Support for Bintray version badge. #517

Merged
merged 2 commits into from
Sep 7, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 4 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,10 @@ <h3 id="version"> Version </h3>
<td><img src='https://img.shields.io/packagist/vpre/symfony/symfony.svg' alt=''/></td>
<td><code>https://img.shields.io/packagist/vpre/symfony/symfony.svg</code></td>
</tr>
<tr><th> Bintray: </th>
<td><img src='https://img.shields.io/bintray/v/asciidoctor/maven/asciidoctorj.svg' alt=''/></td>
<td><code>https://img.shields.io/bintray/v/asciidoctor/maven/asciidoctorj.svg</code></td>
</tr>
<tr><th> Clojars: </th>
<td><img src='https://img.shields.io/clojars/v/prismic.svg' alt=''/></td>
<td><code>https://img.shields.io/clojars/v/prismic.svg</code></td>
Expand Down
41 changes: 41 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -1348,6 +1348,47 @@ cache(function(data, match, sendBadge, request) {
});
}));

// Bintray version integration
camp.route(/^\/bintray\/v\/(.+)\.(svg|png|gif|jpg|json)$/,
cache(function(data, match, sendBadge, request) {
var path = match[1]; // :subject/:repo/:package (e.g. asciidoctor/maven/asciidoctorj)
var format = match[2];

var options = {
method: 'GET',
uri: 'https://bintray.com/api/v1/packages/' + path + '/versions/_latest',
headers: {
Accept: 'application/json'
}
};

if (serverSecrets && serverSecrets.bintray_user) {
options.auth = {
user: serverSecrets.bintray_user,
pass: serverSecrets.bintray_apikey
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The use of those credentials seem unfortunately necessary. I have created a BinTray account, but I cannot find where in my profile page I get the API key.

It is similarly unfortunate that the rate limit is so low, we'll see what consequences that has, pending that I find the API key.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's in a strange place. If you edit your profile there's an API key section.

}
}

var badgeData = getBadgeData('bintray', data);
request(options, function(err, res, buffer) {
if (err !== null) {
badgeData.text[1] = 'inaccessible';
sendBadge(format, badgeData);
return;
}
try {
var data = JSON.parse(buffer);
var vdata = versionColor(data.name);
badgeData.text[1] = 'v' + data.name;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use vdata.version instead of 'v' + data.name.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, I'll change that.

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

// Clojars version integration
camp.route(/^\/clojars\/v\/(.+)\.(svg|png|gif|jpg|json)$/,
cache(function(data, match, sendBadge, request) {
Expand Down
4 changes: 4 additions & 0 deletions try.html
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,10 @@ <h3 id="version"> Version </h3>
<td><img src='/packagist/vpre/symfony/symfony.svg' alt=''/></td>
<td><code>https://img.shields.io/packagist/vpre/symfony/symfony.svg</code></td>
</tr>
<tr><th> Bintray: </th>
<td><img src='/bintray/v/asciidoctor/maven/asciidoctorj.svg' alt=''/></td>
<td><code>https://img.shields.io/bintray/v/asciidoctor/maven/asciidoctorj.svg</code></td>
</tr>
<tr><th> Clojars: </th>
<td><img src='/clojars/v/prismic.svg' alt=''/></td>
<td><code>https://img.shields.io/clojars/v/prismic.svg</code></td>
Expand Down