* Add drone build badge based on travis * Fix wrong mocked endpoint for done builder * Refactor service tester using helper method * Add missing failure status to red statuses * Remove extraneous invalid svg test from drone * Test on failure red status in build status spec * refactor(drone): use json service instead of svg * refactor(drone): remove status text and extraneous build path in test * refactor(drone): allow defining self-hosted drone instances * fix(drone): use proper urls in drone examples * fix(drone): add drone token authorization for self-hosted instances * refactor(drone): call render build status badge directly instead of render * refactor(drone): use server query parameter for self-hosted instances * fix(drone): separate url and query params in example * fix(drone): use actual build status message in examples * fix(drone): add missing message for status code 401 Co-Authored-By: byCedric <me@bycedric.com> * refactor(drone): remove color from drone tests * refactor(drone): remove extraneous comments from drone tests * refactor(drone): remove unused static preview method * refactor(drone): remove unused static render method * refactor(drone): reuse render build status badge helper in static previews * fix(drone): test inaccessible repos on new message
75 lines
1.3 KiB
JavaScript
75 lines
1.3 KiB
JavaScript
'use strict'
|
|
|
|
const Joi = require('joi')
|
|
|
|
const greenStatuses = [
|
|
'fixed',
|
|
'passed',
|
|
'passing',
|
|
'succeeded',
|
|
'success',
|
|
'successful',
|
|
]
|
|
|
|
const orangeStatuses = ['partially succeeded', 'unstable', 'timeout']
|
|
|
|
const redStatuses = [
|
|
'error',
|
|
'failed',
|
|
'failing',
|
|
'failure',
|
|
'infrastructure_failure',
|
|
]
|
|
|
|
const otherStatuses = [
|
|
'building',
|
|
'canceled',
|
|
'cancelled',
|
|
'expired',
|
|
'initiated',
|
|
'no tests',
|
|
'not built',
|
|
'not run',
|
|
'pending',
|
|
'processing',
|
|
'queued',
|
|
'running',
|
|
'scheduled',
|
|
'skipped',
|
|
'starting',
|
|
'stopped',
|
|
'testing',
|
|
'waiting',
|
|
]
|
|
|
|
const isBuildStatus = Joi.equal(
|
|
greenStatuses
|
|
.concat(orangeStatuses)
|
|
.concat(redStatuses)
|
|
.concat(otherStatuses)
|
|
)
|
|
|
|
function renderBuildStatusBadge({ label, status }) {
|
|
let message
|
|
let color
|
|
if (greenStatuses.includes(status)) {
|
|
message = 'passing'
|
|
color = 'brightgreen'
|
|
} else if (orangeStatuses.includes(status)) {
|
|
message = status === 'partially succeeded' ? 'passing' : status
|
|
color = 'orange'
|
|
} else if (redStatuses.includes(status)) {
|
|
message = status === 'failed' ? 'failing' : status
|
|
color = 'red'
|
|
} else {
|
|
message = status
|
|
}
|
|
return {
|
|
label,
|
|
message,
|
|
color,
|
|
}
|
|
}
|
|
|
|
module.exports = { isBuildStatus, renderBuildStatusBadge }
|