Files
shields/services/bugzilla/bugzilla.service.js
dependabot-preview[bot] 294aa1e1df Build(deps-dev): bump eslint-plugin-import from 2.17.3 to 2.18.0; autofixes (#3671)
* Build(deps-dev): bump eslint-plugin-import from 2.17.3 to 2.18.0

Bumps [eslint-plugin-import](https://github.com/benmosher/eslint-plugin-import) from 2.17.3 to 2.18.0.
- [Release notes](https://github.com/benmosher/eslint-plugin-import/releases)
- [Changelog](https://github.com/benmosher/eslint-plugin-import/blob/master/CHANGELOG.md)
- [Commits](https://github.com/benmosher/eslint-plugin-import/compare/v2.17.3...v2.18.0)

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

* Autofixes
2019-07-08 12:13:46 -04:00

132 lines
3.0 KiB
JavaScript

'use strict'
const Joi = require('@hapi/joi')
const { optionalUrl } = require('../validators')
const { BaseJsonService } = require('..')
const queryParamSchema = Joi.object({
baseUrl: optionalUrl,
}).required()
const schema = Joi.object({
bugs: Joi.array()
.items(
Joi.object({
status: Joi.string().required(),
resolution: Joi.string().required(),
}).required()
)
.min(1)
.required(),
}).required()
const documentation = `
<p>
If your Bugzilla badge errors, it might be because you are trying to load a private bug.
</p>
`
module.exports = class Bugzilla extends BaseJsonService {
static get category() {
return 'issue-tracking'
}
static get route() {
return {
base: 'bugzilla',
pattern: ':bugNumber',
queryParamSchema,
}
}
static get examples() {
return [
{
title: 'Bugzilla bug status (Mozilla)',
namedParams: {
bugNumber: '996038',
},
staticPreview: this.render({
bugNumber: 996038,
status: 'FIXED',
resolution: '',
}),
documentation,
},
{
title: 'Bugzilla bug status (non-Mozilla)',
namedParams: {
bugNumber: '545424',
},
queryParams: { baseUrl: 'https://bugs.eclipse.org/bugs' },
staticPreview: this.render({
bugNumber: 545424,
status: 'RESOLVED',
resolution: 'FIXED',
}),
documentation,
},
]
}
static get defaultBadgeData() {
return { 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,
})
}
}