Files
shields/services/testspace/testspace-test-pass-ratio.service.js
chris48s 0bc512707f migrate examples to openApi part 7; affects [reuse sourceforge sourcegraph spack stackexchange testspace treeware twitch] (#9464)
* migrate some services from examples to openApi

* capitalize all words in sourceforge titles
2023-09-04 11:02:05 +01:00

52 lines
1.2 KiB
JavaScript

import { pathParams } from '../index.js'
import TestspaceBase from './testspace-base.js'
export default class TestspacePassRatio extends TestspaceBase {
static route = {
base: 'testspace/pass-ratio',
pattern: ':org/:project/:space+',
}
static openApi = {
'/testspace/pass-ratio/{org}/{project}/{space}': {
get: {
summary: 'Testspace pass ratio',
parameters: pathParams(
{
name: 'org',
example: 'swellaby',
},
{
name: 'project',
example: 'swellaby:testspace-sample',
},
{
name: 'space',
example: 'main',
},
),
},
},
}
static render({ passed, total }) {
const ratio = ((passed / total) * 100).toFixed(0)
return {
message: `${ratio}%`,
color: ratio === '100' ? 'success' : 'critical',
}
}
transform(json) {
const { passed, failed, errored } = this.transformCaseCounts(json)
return { passed, total: passed + failed + errored }
}
async handle({ org, project, space }) {
const json = await this.fetch({ org, project, space })
const { passed, total } = this.transform(json)
return this.constructor.render({ passed, total })
}
}