Skip to content

Commit

Permalink
[GitHub] Repository size badge (#1174)
Browse files Browse the repository at this point in the history
  • Loading branch information
PyvesB authored and paulmelnikow committed Oct 14, 2017
1 parent 14286e1 commit b0f2eed
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
29 changes: 29 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -4083,6 +4083,35 @@ cache(function(data, match, sendBadge, request) {
});
}));

//GitHub repository size integration.
camp.route(/^\/github\/repo-size\/([^/]+)\/([^/]+)\.(svg|png|gif|jpg|json)$/,
cache(function(data, match, sendBadge, request) {
var user = match[1];
var repo = match[2];
var format = match[3];
var apiUrl = githubApiUrl + '/repos/' + user + '/' + repo;
var badgeData = getBadgeData('repo size', data);
if (badgeData.template === 'social') {
badgeData.logo = getLogo('github', data);
}
githubAuth.request(request, apiUrl, {}, function(err, res, buffer) {
if (err != null) {
badgeData.text[1] = 'inaccessible';
sendBadge(format, badgeData);
return;
}
try {
const parsedData = JSON.parse(buffer);
badgeData.text[1] = prettyBytes(parseInt(parsedData.size) * 1024);
badgeData.colorscheme = 'blue';
sendBadge(format, badgeData);
} catch(e) {
badgeData.text[1] = 'invalid';
sendBadge(format, badgeData);
}
});
}));

// Bitbucket issues integration.
camp.route(/^\/bitbucket\/issues(-raw)?\/([^/]+)\/([^/]+)\.(svg|png|gif|jpg|json)$/,
cache(function(data, match, sendBadge, request) {
Expand Down
7 changes: 7 additions & 0 deletions service-tests/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -446,3 +446,10 @@ t.create('code size in bytes for all languages')
name: Joi.equal('code size'),
value: isFileSize,
}));

t.create('repository size')
.get('/repo-size/badges/shields.json')
.expectJSONTypes(Joi.object().keys({
name: Joi.equal('repo size'),
value: isFileSize,
}));
4 changes: 4 additions & 0 deletions try.html
Original file line number Diff line number Diff line change
Expand Up @@ -1001,6 +1001,10 @@ <h3 id="miscellaneous"> Miscellaneous </h3>
<td><img src='/github/languages/code-size/badges/shields.svg' alt=''/></td>
<td><code>https://img.shields.io/github/languages/code-size/badges/shields.svg</code></td>
</tr>
<tr><th data-keywords='GitHub repo size' data-doc='githubDoc'> GitHub repo size in bytes: </th>
<td><img src='/github/repo-size/badges/shields.svg' alt=''/></td>
<td><code>https://img.shields.io/github/repo-size/badges/shields.svg</code></td>
</tr>
<tr><th> Bitbucket issues: </th>
<td><img src='/bitbucket/issues/atlassian/python-bitbucket.svg' alt=''/></td>
<td><code>https://img.shields.io/bitbucket/issues/atlassian/python-bitbucket.svg</code></td>
Expand Down

0 comments on commit b0f2eed

Please sign in to comment.