Files
shields/services/github/github-milestone.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

82 lines
1.8 KiB
JavaScript

import Joi from 'joi'
import { metric } from '../text-formatters.js'
import { GithubAuthV3Service } from './github-auth-service.js'
import { documentation, httpErrorsFor } from './github-helpers.js'
const schema = Joi.array()
.items(
Joi.object({
state: Joi.string().required(),
}),
)
.required()
export default class GithubMilestone extends GithubAuthV3Service {
static category = 'issue-tracking'
static route = {
base: 'github/milestones',
pattern: ':variant(open|closed|all)/:user/:repo',
}
static examples = [
{
title: 'GitHub milestones',
namedParams: {
user: 'badges',
repo: 'shields',
variant: 'open',
},
staticPreview: {
label: 'milestones',
message: '2',
color: 'red',
},
documentation,
},
]
static defaultBadgeData = {
label: 'milestones',
color: 'informational',
}
static render({ user, repo, variant, milestones }) {
const milestoneLength = milestones.length
let color
let qualifier = ''
switch (variant) {
case 'all':
color = 'blue'
break
case 'open':
color = 'red'
qualifier = 'active'
break
case 'closed':
color = 'green'
qualifier = 'completed'
break
}
return {
label: `${qualifier}${qualifier ? ' ' : ''}milestones`,
message: metric(milestoneLength),
color,
}
}
async fetch({ user, repo, variant }) {
return this._requestJson({
url: `/repos/${user}/${repo}/milestones?state=${variant}`,
schema,
httpErrors: httpErrorsFor('repo not found'),
})
}
async handle({ user, repo, variant }) {
const milestones = await this.fetch({ user, repo, variant })
return this.constructor.render({ user, repo, variant, milestones })
}
}