* 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>
86 lines
2.3 KiB
JavaScript
86 lines
2.3 KiB
JavaScript
import Joi from 'joi'
|
|
import { isBuildStatus, renderBuildStatusBadge } from '../build-status.js'
|
|
import { optionalUrl } from '../validators.js'
|
|
import { BaseJsonService } from '../index.js'
|
|
|
|
const schema = Joi.object({
|
|
status: Joi.alternatives()
|
|
.try(isBuildStatus, Joi.equal('none'), Joi.equal('killed'))
|
|
.required(),
|
|
}).required()
|
|
|
|
const queryParamSchema = Joi.object({
|
|
server: optionalUrl,
|
|
}).required()
|
|
|
|
export default class DroneBuild extends BaseJsonService {
|
|
static category = 'build'
|
|
static route = {
|
|
base: 'drone/build',
|
|
pattern: ':user/:repo/:branch*',
|
|
queryParamSchema,
|
|
}
|
|
|
|
static auth = { passKey: 'drone_token', serviceKey: 'drone' }
|
|
static examples = [
|
|
{
|
|
title: 'Drone (cloud)',
|
|
pattern: ':user/:repo',
|
|
namedParams: {
|
|
user: 'harness',
|
|
repo: 'drone',
|
|
},
|
|
staticPreview: renderBuildStatusBadge({ status: 'success' }),
|
|
},
|
|
{
|
|
title: 'Drone (cloud) with branch',
|
|
pattern: ':user/:repo/:branch',
|
|
namedParams: {
|
|
user: 'harness',
|
|
repo: 'drone',
|
|
branch: 'master',
|
|
},
|
|
staticPreview: renderBuildStatusBadge({ status: 'success' }),
|
|
},
|
|
{
|
|
title: 'Drone (self-hosted)',
|
|
pattern: ':user/:repo',
|
|
queryParams: { server: 'https://drone.shields.io' },
|
|
namedParams: {
|
|
user: 'badges',
|
|
repo: 'shields',
|
|
},
|
|
staticPreview: renderBuildStatusBadge({ status: 'success' }),
|
|
},
|
|
{
|
|
title: 'Drone (self-hosted) with branch',
|
|
pattern: ':user/:repo/:branch',
|
|
queryParams: { server: 'https://drone.shields.io' },
|
|
namedParams: {
|
|
user: 'badges',
|
|
repo: 'shields',
|
|
branch: 'feat/awesome-thing',
|
|
},
|
|
staticPreview: renderBuildStatusBadge({ status: 'success' }),
|
|
},
|
|
]
|
|
|
|
static defaultBadgeData = { label: 'build' }
|
|
|
|
async handle({ user, repo, branch }, { server = 'https://cloud.drone.io' }) {
|
|
const json = await this._requestJson(
|
|
this.authHelper.withBearerAuthHeader({
|
|
schema,
|
|
url: `${server}/api/repos/${user}/${repo}/builds/latest`,
|
|
options: {
|
|
searchParams: { ref: branch ? `refs/heads/${branch}` : undefined },
|
|
},
|
|
httpErrors: {
|
|
401: 'repo not found or not authorized',
|
|
},
|
|
}),
|
|
)
|
|
return renderBuildStatusBadge({ status: json.status })
|
|
}
|
|
}
|