* add helper functions for generating Open API path/query params with defaults * tweak Open API schema - make description optional - allow null example + allowEmptyValue (for boolean query params) * convert examples --> openApi in amo * convert examples --> openApi in ansible * convert examples --> openApi in appveyor build/job * add re-usable Open API query param for test-results badges we can use these for all the 'test results' badges * convert examples --> openApi in appveyor tests * DRY up existing dynamic/endpoint param definitions * DRY up queryParam * allow enum param in serviceDefinition schema * improve misleading param name * check route and openApi are consistent on service load * fix mistake in ansible role route * documentation --> description * add pathParams and queryParams helpers +docstrings * give everything a search-friendly summary, check for duplicate summary * prettier fixup
111 lines
2.4 KiB
JavaScript
111 lines
2.4 KiB
JavaScript
import {
|
|
testResultQueryParamSchema,
|
|
testResultOpenApiQueryParams,
|
|
renderTestResultBadge,
|
|
documentation as description,
|
|
} from '../test-results.js'
|
|
import { pathParams } from '../index.js'
|
|
import AppVeyorBase from './appveyor-base.js'
|
|
|
|
export default class AppVeyorTests extends AppVeyorBase {
|
|
static category = 'test-results'
|
|
static route = {
|
|
...this.buildRoute('appveyor/tests'),
|
|
queryParamSchema: testResultQueryParamSchema,
|
|
}
|
|
|
|
static openApi = {
|
|
'/appveyor/tests/{user}/{repo}': {
|
|
get: {
|
|
summary: 'AppVeyor tests',
|
|
description,
|
|
parameters: [
|
|
...pathParams(
|
|
{ name: 'user', example: 'NZSmartie' },
|
|
{ name: 'repo', example: 'coap-net-iu0to' },
|
|
),
|
|
...testResultOpenApiQueryParams,
|
|
],
|
|
},
|
|
},
|
|
'/appveyor/tests/{user}/{repo}/{branch}': {
|
|
get: {
|
|
summary: 'AppVeyor tests (with branch)',
|
|
description,
|
|
parameters: [
|
|
...pathParams(
|
|
{ name: 'user', example: 'NZSmartie' },
|
|
{ name: 'repo', example: 'coap-net-iu0to' },
|
|
{ name: 'branch', example: 'master' },
|
|
),
|
|
...testResultOpenApiQueryParams,
|
|
],
|
|
},
|
|
},
|
|
}
|
|
|
|
static defaultBadgeData = {
|
|
label: 'tests',
|
|
}
|
|
|
|
static render({
|
|
passed,
|
|
failed,
|
|
skipped,
|
|
total,
|
|
passedLabel,
|
|
failedLabel,
|
|
skippedLabel,
|
|
isCompact,
|
|
}) {
|
|
return renderTestResultBadge({
|
|
passed,
|
|
failed,
|
|
skipped,
|
|
total,
|
|
passedLabel,
|
|
failedLabel,
|
|
skippedLabel,
|
|
isCompact,
|
|
})
|
|
}
|
|
|
|
async handle(
|
|
{ user, repo, branch },
|
|
{
|
|
compact_message: compactMessage,
|
|
passed_label: passedLabel,
|
|
failed_label: failedLabel,
|
|
skipped_label: skippedLabel,
|
|
},
|
|
) {
|
|
const isCompact = compactMessage !== undefined
|
|
const data = await this.fetch({ user, repo, branch })
|
|
|
|
if (!('build' in data)) {
|
|
return { message: 'no builds found' }
|
|
}
|
|
|
|
let total = 0
|
|
let passed = 0
|
|
let failed = 0
|
|
data.build.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,
|
|
passedLabel,
|
|
failedLabel,
|
|
skippedLabel,
|
|
isCompact,
|
|
})
|
|
}
|
|
}
|