* allow services to export >1 classes
This change to loadServiceClasses() allows us to define
services which either export a single service class e.g:
module.exports = class Cdnjs extends BaseService {
//...
}
or more than one. e.g:
module.exports = {
GemVersion,
GemDownloads,
GemOwner,
GemRank,
}
* refactor ruby gem badges
- move badge code to service classes
- throw exceptions for errors
- use let and const
- change tests to expect 'downloads' label for error badges
- general tidying
* fix typo in tests
* Don't always use class name in example label
This allows (for example) GemVersion and GemDownloads
both to use the example label 'Gem'
55 lines
1.3 KiB
JavaScript
55 lines
1.3 KiB
JavaScript
'use strict';
|
|
|
|
const BaseService = require('../base');
|
|
const {
|
|
checkErrorResponse,
|
|
asJson,
|
|
} = require('../../lib/error-helper');
|
|
|
|
module.exports = class AppVeyor extends BaseService {
|
|
async handle({repo, branch}) {
|
|
let apiUrl = 'https://ci.appveyor.com/api/projects/' + repo;
|
|
if (branch != null) {
|
|
apiUrl += '/branch/' + branch;
|
|
}
|
|
const json = await this._sendAndCacheRequest(apiUrl, {
|
|
headers: { 'Accept': 'application/json' }
|
|
}).then(checkErrorResponse.asPromise({ notFoundMessage: 'project not found or access denied' }))
|
|
.then(asJson);
|
|
|
|
const { build: { status } } = json;
|
|
if (status === 'success') {
|
|
return {message: 'passing', color: 'brightgreen'};
|
|
} else if (status !== 'running' && status !== 'queued') {
|
|
return {message: 'failing', color: 'red'};
|
|
} else {
|
|
return {message: status};
|
|
}
|
|
}
|
|
|
|
// Metadata
|
|
static get category() {
|
|
return 'build';
|
|
}
|
|
|
|
static get url() {
|
|
return {
|
|
base: 'appveyor/ci',
|
|
format: '([^/]+/[^/]+)(?:/(.+))?',
|
|
capture: ['repo', 'branch']
|
|
};
|
|
}
|
|
|
|
static get examples() {
|
|
return [
|
|
{
|
|
previewUrl: 'gruntjs/grunt',
|
|
},
|
|
{
|
|
title: `${this.name} branch`,
|
|
previewUrl: 'gruntjs/grunt/master',
|
|
},
|
|
];
|
|
}
|
|
};
|