-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
/
Copy pathazure-devops-tests.service.js
189 lines (173 loc) · 5.14 KB
/
azure-devops-tests.service.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
import Joi from 'joi'
import { pathParam } from '../index.js'
import {
testResultOpenApiQueryParams,
testResultQueryParamSchema,
renderTestResultBadge,
documentation as commonDocumentation,
} from '../test-results.js'
import AzureDevOpsBase from './azure-devops-base.js'
const description = `
[Azure Devops](https://dev.azure.com/) (formerly VSO, VSTS) is Microsoft Azure's CI/CD platform.
To obtain your own badge, you need to get 3 pieces of information:
\`ORGANIZATION\`, \`PROJECT\`, \`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 openApi = {
'/azure-devops/tests/{organization}/{project}/{definitionId}': {
get: {
summary: 'Azure DevOps tests',
description,
parameters: [
pathParam({
name: 'organization',
example: 'azuredevops-powershell',
}),
pathParam({
name: 'project',
example: 'azuredevops-powershell',
}),
pathParam({
name: 'definitionId',
example: '1',
}),
...testResultOpenApiQueryParams,
],
},
},
'/azure-devops/tests/{organization}/{project}/{definitionId}/{branch}': {
get: {
summary: 'Azure DevOps tests (branch)',
description,
parameters: [
pathParam({
name: 'organization',
example: 'azuredevops-powershell',
}),
pathParam({
name: 'project',
example: 'azuredevops-powershell',
}),
pathParam({
name: 'definitionId',
example: '1',
}),
pathParam({
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,
})
}
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,
})
}
}