-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
/
Copy pathbugzilla.service.js
108 lines (97 loc) · 2.8 KB
/
bugzilla.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
import Joi from 'joi'
import { optionalUrl } from '../validators.js'
import { BaseJsonService, pathParam, queryParam } from '../index.js'
const queryParamSchema = Joi.object({
baseUrl: optionalUrl,
}).required()
const schema = Joi.object({
bugs: Joi.array()
.items(
Joi.object({
status: Joi.string().required(),
resolution: Joi.string().allow('').required(),
}).required(),
)
.min(1)
.required(),
}).required()
const description = `
Use the <code>baseUrl</code> query parameter to target different Bugzilla deployments.
If your Bugzilla badge errors, it might be because you are trying to load a private bug.
`
export default class Bugzilla extends BaseJsonService {
static category = 'issue-tracking'
static route = { base: 'bugzilla', pattern: ':bugNumber', queryParamSchema }
static openApi = {
'/bugzilla/{bugNumber}': {
get: {
summary: 'Bugzilla bug status',
description,
parameters: [
pathParam({
name: 'bugNumber',
example: '545424',
}),
queryParam({
name: 'baseUrl',
example: 'https://bugs.eclipse.org/bugs',
description:
'When not specified, this will default to `https://bugzilla.mozilla.org`.',
}),
],
},
},
}
static defaultBadgeData = { label: 'bugzilla' }
static getDisplayStatus({ status, resolution }) {
let displayStatus =
status === 'RESOLVED' ? resolution.toLowerCase() : status.toLowerCase()
if (displayStatus === 'worksforme') {
displayStatus = 'works for me'
}
if (displayStatus === 'wontfix') {
displayStatus = "won't fix"
}
return displayStatus
}
static getColor({ displayStatus }) {
const colorMap = {
unconfirmed: 'blue',
new: 'blue',
assigned: 'green',
fixed: 'brightgreen',
invalid: 'yellow',
"won't fix": 'orange',
duplicate: 'lightgrey',
'works for me': 'yellowgreen',
incomplete: 'red',
}
if (displayStatus in colorMap) {
return colorMap[displayStatus]
}
return 'lightgrey'
}
static render({ bugNumber, status, resolution }) {
const displayStatus = this.getDisplayStatus({ status, resolution })
const color = this.getColor({ displayStatus })
return {
label: `bug ${bugNumber}`,
message: displayStatus,
color,
}
}
async fetch({ bugNumber, baseUrl }) {
return this._requestJson({
schema,
url: `${baseUrl}/rest/bug/${bugNumber}`,
})
}
async handle({ bugNumber }, { baseUrl = 'https://bugzilla.mozilla.org' }) {
const data = await this.fetch({ bugNumber, baseUrl })
return this.constructor.render({
bugNumber,
status: data.bugs[0].status,
resolution: data.bugs[0].resolution,
})
}
}