-
-
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.
- Loading branch information
Showing
4 changed files
with
102 additions
and
85 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
'use strict' | ||
|
||
const Joi = require('joi') | ||
const BaseJsonService = require('../base-json') | ||
|
||
const werckerSchema = Joi.array() | ||
.items( | ||
Joi.object({ | ||
status: Joi.string().required(), | ||
result: Joi.string().required(), | ||
}) | ||
) | ||
.min(1) | ||
.required() | ||
|
||
module.exports = class Wercker extends BaseJsonService { | ||
async fetch({ applicationName, projectId, branch }) { | ||
const url = applicationName | ||
? `https://app.wercker.com/api/v3/applications/${applicationName}/builds?limit=1` | ||
: `https://app.wercker.com/getbuilds/${projectId}?limit=1` | ||
return this._requestJson({ | ||
schema: werckerSchema, | ||
url, | ||
options: { qs: { branch } }, | ||
errorMessages: { | ||
401: 'private application not supported', | ||
404: 'application not found', | ||
}, | ||
}) | ||
} | ||
|
||
static render({ status, result }) { | ||
if (status === 'finished') { | ||
if (result === 'passed') { | ||
return { message: 'passing', color: 'brightgreen' } | ||
} else { | ||
return { message: result, color: 'red' } | ||
} | ||
} | ||
return { message: status } | ||
} | ||
|
||
async handle({ applicationName, projectId, branch }) { | ||
const json = await this.fetch({ applicationName, projectId, branch }) | ||
const { status, result } = json[0] | ||
return this.constructor.render({ status, result }) | ||
} | ||
|
||
// Metadata | ||
static get category() { | ||
return 'build' | ||
} | ||
|
||
static get url() { | ||
return { | ||
base: 'wercker/ci', | ||
format: '(?:([^/]+/[^/]+)|([a-fA-F0-9]+))(?:/(.+))?', | ||
capture: ['applicationName', 'projectId', 'branch'], | ||
} | ||
} | ||
|
||
static get examples() { | ||
return [ | ||
{ | ||
previewUrl: 'wercker/go-wercker-api', | ||
}, | ||
{ | ||
title: `${this.name} branch`, | ||
previewUrl: 'wercker/go-wercker-api/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,29 @@ | ||
'use strict' | ||
|
||
const Joi = require('joi') | ||
const ServiceTester = require('../service-tester') | ||
|
||
const { isBuildStatus } = require('../test-validators') | ||
|
||
const t = new ServiceTester({ id: 'wercker', title: 'Wercker' }) | ||
module.exports = t | ||
|
||
t.create('CI build status') | ||
.get('/ci/wercker/go-wercker-api.json') | ||
.expectJSONTypes(Joi.object().keys({ name: 'build', value: isBuildStatus })) | ||
|
||
t.create('CI build status (branch)') | ||
.get('/ci/wercker/go-wercker-api/master.json') | ||
.expectJSONTypes(Joi.object().keys({ name: 'build', value: isBuildStatus })) | ||
|
||
t.create('CI build status (old v1 API)') | ||
.get('/ci/559e33c8e982fc615500b357.json') | ||
.expectJSONTypes(Joi.object().keys({ name: 'build', value: isBuildStatus })) | ||
|
||
t.create('CI application not found') | ||
.get('/ci/somerandomproject/thatdoesntexits.json') | ||
.expectJSON({ name: 'build', value: 'application not found' }) | ||
|
||
t.create('CI private application') | ||
.get('/ci/wercker/blueprint.json') | ||
.expectJSON({ name: 'build', value: 'private application not supported' }) |