-
-
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.
Rewrite [appveyor] tests badge (#1940)
- Loading branch information
1 parent
77061fe
commit 656326d
Showing
6 changed files
with
152 additions
and
127 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,44 @@ | ||
'use strict' | ||
|
||
const Joi = require('joi') | ||
const BaseJsonService = require('../base-json') | ||
const { nonNegativeInteger } = require('../validators') | ||
|
||
const schema = Joi.object({ | ||
build: Joi.object({ | ||
status: Joi.string().required(), | ||
jobs: Joi.array() | ||
.items({ | ||
testsCount: nonNegativeInteger, | ||
passedTestsCount: nonNegativeInteger, | ||
failedTestsCount: nonNegativeInteger, | ||
}) | ||
.required(), | ||
}), | ||
}).required() | ||
|
||
module.exports = class AppVeyorBase extends BaseJsonService { | ||
static get category() { | ||
return 'build' | ||
} | ||
|
||
async fetch({ repo, branch }) { | ||
let url = `https://ci.appveyor.com/api/projects/${repo}` | ||
if (branch != null) { | ||
url += `/branch/${branch}` | ||
} | ||
return this._requestJson({ | ||
schema, | ||
url, | ||
errorMessages: { 404: 'project not found or access denied' }, | ||
}) | ||
} | ||
|
||
static buildUrl(base) { | ||
return { | ||
base, | ||
format: '([^/]+/[^/]+)(?:/(.+))?', | ||
capture: ['repo', 'branch'], | ||
} | ||
} | ||
} |
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,39 @@ | ||
'use strict' | ||
|
||
const AppVeyorBase = require('./appveyor-base') | ||
|
||
module.exports = class AppVeyorCi extends AppVeyorBase { | ||
static get url() { | ||
return this.buildUrl('appveyor/ci') | ||
} | ||
|
||
static get examples() { | ||
return [ | ||
{ | ||
title: 'AppVeyor', | ||
previewUrl: 'gruntjs/grunt', | ||
}, | ||
{ | ||
title: 'AppVeyor branch', | ||
previewUrl: 'gruntjs/grunt/master', | ||
}, | ||
] | ||
} | ||
|
||
static render({ status }) { | ||
if (status === 'success') { | ||
return { message: 'passing', color: 'brightgreen' } | ||
} else if (status !== 'running' && status !== 'queued') { | ||
return { message: 'failing', color: 'red' } | ||
} else { | ||
return { message: status } | ||
} | ||
} | ||
|
||
async handle({ repo, branch }) { | ||
const { | ||
build: { status }, | ||
} = await this.fetch({ repo, branch }) | ||
return this.constructor.render({ status }) | ||
} | ||
} |
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,69 @@ | ||
'use strict' | ||
|
||
const AppVeyorBase = require('./appveyor-base') | ||
|
||
module.exports = class AppVeyorTests extends AppVeyorBase { | ||
static get url() { | ||
return this.buildUrl('appveyor/tests') | ||
} | ||
|
||
static get defaultBadgeData() { | ||
return { | ||
label: 'tests', | ||
} | ||
} | ||
|
||
static get examples() { | ||
return [ | ||
{ | ||
title: 'AppVeyor tests', | ||
previewUrl: 'NZSmartie/coap-net-iu0to', | ||
}, | ||
{ | ||
title: 'AppVeyor tests branch', | ||
previewUrl: 'NZSmartie/coap-net-iu0to/master', | ||
}, | ||
] | ||
} | ||
|
||
static render({ passed, failed, skipped, total }) { | ||
let message = `${passed} passed` | ||
if (failed > 0) { | ||
message += `, ${failed} failed` | ||
} | ||
if (skipped > 0) { | ||
message += `, ${skipped} skipped` | ||
} | ||
|
||
let color | ||
if (passed === total) { | ||
color = 'brightgreen' | ||
} else if (failed === 0) { | ||
color = 'green' | ||
} else if (passed === 0) { | ||
color = 'red' | ||
} else { | ||
color = 'orange' | ||
} | ||
|
||
return { message, color } | ||
} | ||
|
||
async handle({ repo, branch }) { | ||
const { | ||
build: { jobs }, | ||
} = await this.fetch({ repo, branch }) | ||
|
||
let total = 0, | ||
passed = 0, | ||
failed = 0 | ||
jobs.forEach(job => { | ||
total += job.testsCount | ||
passed += job.passedTestsCount | ||
failed += job.failedTestsCount | ||
}) | ||
const skipped = total - passed - failed | ||
|
||
return this.constructor.render({ passed, failed, skipped, total }) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.