-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New API for registering services - v2
- Loading branch information
Showing
5 changed files
with
199 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
'use strict'; | ||
|
||
const BaseService = require('./BaseService'); | ||
const loadLogos = require('../lib/load-logos'); | ||
|
||
/** | ||
* AppVeyor CI integration. | ||
*/ | ||
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 {buffer, res} = await this._sendAndCacheRequest(apiUrl, { | ||
headers: { 'Accept': 'application/json' } | ||
}); | ||
|
||
if (res.statusCode === 404) { | ||
return {text: 'project not found or access denied'}; | ||
} | ||
|
||
const data = JSON.parse(buffer); | ||
const status = data.build.status; | ||
if (status === 'success') { | ||
return {text: 'passing', colorscheme: 'brightgreen'}; | ||
} else if (status !== 'running' && status !== 'queued') { | ||
return {text: 'failing', colorscheme: 'red'}; | ||
} else { | ||
return {text: status}; | ||
} | ||
} | ||
|
||
// Metadata | ||
static get category() { | ||
return 'build'; | ||
} | ||
|
||
static get uri() { | ||
return { | ||
format: '/appveyor/ci/([^/]+/[^/]+)(?:/(.+))?', | ||
capture: ['repo', 'branch'] | ||
}; | ||
} | ||
|
||
static get defaultBadgeData() { | ||
return { | ||
logo: loadLogos().appveyor, | ||
}; | ||
} | ||
|
||
static getExamples() { | ||
return [ | ||
{ | ||
uri: '/appveyor/ci/gruntjs/grunt', | ||
}, | ||
{ | ||
name: 'Branch', | ||
uri: '/appveyor/ci/gruntjs/grunt/master', | ||
}, | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
'use strict'; | ||
|
||
module.exports = class BaseService { | ||
constructor({sendAndCacheRequest}) { | ||
this._sendAndCacheRequest = sendAndCacheRequest; | ||
} | ||
|
||
/** | ||
* Asynchronous function to handle requests for this service. Takes the URI | ||
* parameters (as defined in the `uri` property), performs a request using | ||
* `this._sendAndCacheRequest`, and returns the badge data. | ||
*/ | ||
async handle(namedParams) { | ||
throw new Error( | ||
`Handler not implemented for ${this.constructor.name}` | ||
); | ||
} | ||
|
||
// Metadata | ||
|
||
/** | ||
* Name of the category to sort this badge into (eg. "build"). Used to sort | ||
* the badges on the main shields.io website. | ||
*/ | ||
static get category() { | ||
return 'unknown'; | ||
} | ||
/** | ||
* Returns an object with two fields: | ||
* - format: Regular expression to use for URIs for this service's badges | ||
* - capture: Array of names for the capture groups in the regular | ||
* expression. The handler will be passed an object containing | ||
* the matches. | ||
*/ | ||
static get uri() { | ||
throw new Error(`URI not defined for ${this.name}`); | ||
} | ||
|
||
/** | ||
* Default data for the badge. Can include things such as default logo, color, | ||
* etc. These defaults will be used if the value is not explicitly overridden | ||
* by either the handler or by the user via URL parameters. | ||
*/ | ||
static get defaultBadgeData() { | ||
return {}; | ||
} | ||
|
||
/** | ||
* Example URIs for this service. These should use the format | ||
* specified in `uri`, and can be used to demonstrate how to use badges for | ||
* this service. | ||
*/ | ||
static getExamples() { | ||
return []; | ||
} | ||
} |