This moves a few helpers from `lib/` to `services/`: build-status.js build-status.spec.js color-formatters.js color-formatters.spec.js contributor-count.js licenses.js licenses.spec.js php-version.js php-version.spec.js text-formatters.js text-formatters.spec.js version.js version.spec.js And one from `lib/` to `core/`: unhandled-rejection.spec.js The diff is long, but the changes are straightforward. Ref #2832
67 lines
1.5 KiB
JavaScript
67 lines
1.5 KiB
JavaScript
'use strict'
|
|
|
|
const Joi = require('joi')
|
|
const { metric } = require('../text-formatters')
|
|
const { nonNegativeInteger } = require('../validators')
|
|
const { GithubAuthService } = require('./github-auth-service')
|
|
const { errorMessagesFor, documentation } = require('./github-helpers')
|
|
|
|
const schema = Joi.object({ total_count: nonNegativeInteger }).required()
|
|
|
|
module.exports = class GithubSearch extends GithubAuthService {
|
|
static get category() {
|
|
return 'analysis'
|
|
}
|
|
|
|
static get route() {
|
|
return {
|
|
base: 'github/search',
|
|
pattern: ':user/:repo/:query+',
|
|
}
|
|
}
|
|
|
|
static get examples() {
|
|
return [
|
|
{
|
|
title: 'GitHub search hit counter',
|
|
pattern: ':user/:repo/:query',
|
|
namedParams: {
|
|
user: 'torvalds',
|
|
repo: 'linux',
|
|
query: 'goto',
|
|
},
|
|
staticPreview: this.render({ query: 'goto', totalCount: 14000 }),
|
|
documentation,
|
|
},
|
|
]
|
|
}
|
|
|
|
static get defaultBadgeData() {
|
|
return {
|
|
label: 'counter',
|
|
}
|
|
}
|
|
|
|
static render({ query, totalCount }) {
|
|
return {
|
|
label: `${query} counter`,
|
|
message: metric(totalCount),
|
|
color: 'blue',
|
|
}
|
|
}
|
|
|
|
async handle({ user, repo, query }) {
|
|
const { total_count: totalCount } = await this._requestJson({
|
|
url: '/search/code',
|
|
options: {
|
|
qs: {
|
|
q: `${query} repo:${user}/${repo}`,
|
|
},
|
|
},
|
|
schema,
|
|
errorMessages: errorMessagesFor('repo not found'),
|
|
})
|
|
return this.constructor.render({ query, totalCount })
|
|
}
|
|
}
|