Files
shields/services/azure-devops/azure-devops-tests.service.js
dependabot[bot] b9d96755ec chore(deps-dev): bump prettier from 2.8.8 to 3.0.0 (#9357)
* chore(deps-dev): bump prettier from 2.8.8 to 3.0.0

Bumps [prettier](https://github.com/prettier/prettier) from 2.8.8 to 3.0.0.
- [Release notes](https://github.com/prettier/prettier/releases)
- [Changelog](https://github.com/prettier/prettier/blob/main/CHANGELOG.md)
- [Commits](https://github.com/prettier/prettier/compare/2.8.8...3.0.0)

---
updated-dependencies:
- dependency-name: prettier
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

* reformat all the things (prettier 3)

* update tests to await calls to prettier.format()

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: chris48s <git@chris-shaw.dev>
2023-07-10 09:27:51 +00:00

195 lines
5.0 KiB
JavaScript

import Joi from 'joi'
import {
testResultQueryParamSchema,
renderTestResultBadge,
documentation as commonDocumentation,
} from '../test-results.js'
import AzureDevOpsBase from './azure-devops-base.js'
const commonAttrs = {
keywords: ['vso', 'vsts', 'azure-devops'],
namedParams: {
organization: 'azuredevops-powershell',
project: 'azuredevops-powershell',
definitionId: '1',
branch: 'master',
},
queryParams: {
passed_label: 'passed',
failed_label: 'failed',
skipped_label: 'skipped',
compact_message: null,
},
documentation: `
To obtain your own badge, you need to get 3 pieces of information:
\`ORGANIZATION\`, \`PROJECT_ID\`, \`DEFINITION_ID\`.
First, you need to select your build definition and look at the url:
<img
src="https://user-images.githubusercontent.com/3749820/47259976-e2d9ec80-d4b2-11e8-92cc-7c81089a7a2c.png"
alt="ORGANIZATION is after the dev.azure.com part, PROJECT is right after that, DEFINITION_ID is at the end after the id= part." />
Your badge will then have the form:
\`https://img.shields.io/azure-devops/tests/ORGANIZATION/PROJECT/DEFINITION_ID.svg\`.
Optionally, you can specify a named branch:
\`https://img.shields.io/azure-devops/tests/ORGANIZATION/PROJECT/DEFINITION_ID/NAMED_BRANCH.svg\`.
${commonDocumentation}
`,
}
const buildTestResultSummarySchema = Joi.object({
aggregatedResultsAnalysis: Joi.object({
totalTests: Joi.number().required(),
resultsByOutcome: Joi.object({
Passed: Joi.object({
count: Joi.number().required(),
}).optional(),
Failed: Joi.object({
count: Joi.number().required(),
}).optional(),
Skipped: Joi.object({
count: Joi.number().required(),
}).optional(),
}).required(),
}).required(),
}).required()
export default class AzureDevOpsTests extends AzureDevOpsBase {
static category = 'test-results'
static route = {
base: 'azure-devops/tests',
pattern: ':organization/:project/:definitionId/:branch*',
queryParamSchema: testResultQueryParamSchema,
}
static examples = [
{
title: 'Azure DevOps tests',
staticPreview: this.render({
passed: 20,
failed: 1,
skipped: 1,
total: 22,
}),
...commonAttrs,
},
{
title: 'Azure DevOps tests (compact)',
staticPreview: this.render({
passed: 20,
failed: 1,
skipped: 1,
total: 22,
isCompact: true,
}),
...commonAttrs,
},
{
title: 'Azure DevOps tests with custom labels',
queryParams: {
passed_label: 'good',
failed_label: 'bad',
skipped_label: 'n/a',
compact_message: null,
},
staticPreview: this.render({
passed: 20,
failed: 1,
skipped: 1,
total: 22,
passedLabel: 'good',
failedLabel: 'bad',
skippedLabel: 'n/a',
}),
...commonAttrs,
},
]
static defaultBadgeData = { label: 'tests' }
static render({
passed,
failed,
skipped,
total,
passedLabel,
failedLabel,
skippedLabel,
isCompact,
}) {
return renderTestResultBadge({
passed,
failed,
skipped,
total,
passedLabel,
failedLabel,
skippedLabel,
isCompact,
})
}
static transform({ aggregatedResultsAnalysis }) {
const { totalTests: total, resultsByOutcome } = aggregatedResultsAnalysis
const passed = resultsByOutcome.Passed ? resultsByOutcome.Passed.count : 0
const failed = resultsByOutcome.Failed ? resultsByOutcome.Failed.count : 0
// assume the rest has been skipped
const skipped = total - passed - failed
return { passed, failed, skipped, total }
}
async fetchTestResults({ organization, project, definitionId, branch }) {
const httpErrors = {
404: 'build pipeline or test result summary not found',
}
const buildId = await this.getLatestCompletedBuildId(
organization,
project,
definitionId,
branch,
httpErrors,
)
// https://dev.azure.com/azuredevops-powershell/azuredevops-powershell/_apis/test/ResultSummaryByBuild?buildId=20
return await this.fetch({
url: `https://dev.azure.com/${organization}/${project}/_apis/test/ResultSummaryByBuild`,
options: {
searchParams: { buildId },
},
schema: buildTestResultSummarySchema,
httpErrors,
})
}
async handle(
{ organization, project, definitionId, branch },
{
compact_message: compactMessage,
passed_label: passedLabel,
failed_label: failedLabel,
skipped_label: skippedLabel,
},
) {
const json = await this.fetchTestResults({
organization,
project,
definitionId,
branch,
})
const { passed, failed, skipped, total } = this.constructor.transform(json)
return this.constructor.render({
passed,
failed,
skipped,
total,
passedLabel,
failedLabel,
skippedLabel,
isCompact: compactMessage !== undefined,
})
}
}