[ReadTheDocs] Add initial support (#1150)

Close #136
This commit is contained in:
Delgan
2017-10-10 12:11:24 -04:00
committed by Paul Melnikow
parent 6f24a1ec5c
commit 088f307ddf
3 changed files with 82 additions and 0 deletions
+37
View File
@@ -2897,6 +2897,43 @@ cache(function(data, match, sendBadge, request) {
});
}));
// ReadTheDocs build
camp.route(/^\/readthedocs\/([^\/]+)(?:\/(.+))?.(svg|png|gif|jpg|json)$/,
cache(function(data, match, sendBadge, request) {
var project = match[1];
var version = match[2];
var format = match[3];
var badgeData = getBadgeData('docs', data);
var url = 'https://readthedocs.org/projects/' + encodeURIComponent(project) + '/badge/';
if (version != null) {
url += '?version=' + encodeURIComponent(version);
}
fetchFromSvg(request, url, function(err, res) {
if (err != null) {
badgeData.text[1] = 'inaccessible';
sendBadge(format, badgeData);
return;
}
try {
badgeData.text[1] = res;
if (res === 'passing') {
badgeData.colorscheme = 'brightgreen';
} else if (res === 'failing') {
badgeData.colorscheme = 'red';
} else if (res === 'unknown') {
badgeData.colorscheme = 'yellow';
} else {
badgeData.colorscheme = 'red';
}
sendBadge(format, badgeData);
} catch(e) {
badgeData.text[1] = 'invalid';
sendBadge(format, badgeData);
}
});
}));
camp.route(/^\/codacy\/coverage\/(?!grade\/)([^\/]+)(?:\/(.+))?\.(svg|png|gif|jpg|json)$/,
cache(function(data, match, sendBadge, request) {
var projectId = match[1]; // eg. e27821fb6289410b8f58338c7e0bc686
+37
View File
@@ -0,0 +1,37 @@
'use strict';
const Joi = require('joi');
const ServiceTester = require('./runner/service-tester');
const t = new ServiceTester({ id: 'readthedocs', title: 'Read the Docs' })
module.exports = t;
t.create('build status')
.get('/pip.json')
.expectJSONTypes(Joi.object().keys({
name: 'docs',
value: Joi.equal('failing', 'passing', 'unknown')
}));
t.create('build status for named version')
.get('/pip/stable.json')
.expectJSONTypes(Joi.object().keys({
name: 'docs',
value: Joi.equal('failing', 'passing', 'unknown')
}));
t.create('build status for named semantic version')
.get('/scrapy/1.0.json')
.expectJSONTypes(Joi.object().keys({
name: 'docs',
value: Joi.equal('failing', 'passing', 'unknown')
}));
t.create('unknown project')
.get('/this-repo/does-not-exist.json')
.expectJSON({ name: 'docs', value: 'unknown' });
t.create('connection error')
.get('/pip.json')
.networkOff()
.expectJSON({ name: 'docs', value: 'inaccessible' });
+8
View File
@@ -248,6 +248,14 @@ Pixel-perfect   Retina-ready   Fast   Consistent   Hackable
<td><img src='/continuousphp/git-hub/doctrine/dbal/master.svg' alt=''/></td>
<td><code>https://img.shields.io/continuousphp/git-hub/doctrine/dbal/master.svg</code></td>
</tr>
<tr><th data-keywords='documentation'>Read the Docs:</th>
<td><img src='/readthedocs/pip.svg' alt=''/></td>
<td><code>https://img.shields.io/readthedocs/pip.svg</code></td>
</tr>
<tr><th data-keywords='documentation'>Read the Docs (version):</th>
<td><img src='/readthedocs/pip/stable.svg' alt=''/></td>
<td><code>https://img.shields.io/readthedocs/pip/stable.svg</code></td>
</tr>
</tbody></table>
<h3 id="downloads"> Downloads </h3>
<table class='badge'><tbody>