Files
shields/services/github/github-labels.service.js
Caleb Cartwright ec5b976c0d convert some service classes to static fields, run [GitHubForks GitHubGoMod GitHubIssueDetail GitHubIssues GitHubLabels GitHubLanguageCount GitHubLastCommit] (#5590)
* refactor(githubforks): convert to static fields

* refactor(githubgomod): convert to static fields

* refactor(githubissuedetail): convert to static fields

* refactor(githubissues): convert to static fields

* refactor(githublabels): convert to static fields

* refactor(githublanguagecount): convert to static fields

* refactor(githublastcommit): convert to static fields

Co-authored-by: Paul Melnikow <github@paulmelnikow.com>
2020-09-22 18:18:54 -05:00

49 lines
1.2 KiB
JavaScript

'use strict'
const Joi = require('@hapi/joi')
const { GithubAuthV3Service } = require('./github-auth-service')
const { documentation, errorMessagesFor } = require('./github-helpers')
const schema = Joi.object({
color: Joi.string().hex().required(),
}).required()
module.exports = class GithubLabels extends GithubAuthV3Service {
static category = 'issue-tracking'
static route = { base: 'github/labels', pattern: ':user/:repo/:name' }
static examples = [
{
title: 'GitHub labels',
namedParams: {
user: 'atom',
repo: 'atom',
name: 'help-wanted',
},
staticPreview: this.render({ name: 'help-wanted', color: '#159818' }),
documentation,
},
]
static defaultBadgeData = { label: ' ' }
static render({ name, color }) {
return {
message: name,
color,
}
}
async fetch({ user, repo, name }) {
return this._requestJson({
url: `/repos/${user}/${repo}/labels/${name}`,
schema,
errorMessages: errorMessagesFor(`repo or label not found`),
})
}
async handle({ user, repo, name }) {
const { color } = await this.fetch({ user, repo, name })
return this.constructor.render({ name, color })
}
}