* allow serviceData to override cacheSeconds with a longer value * prevent [endpoint] json cacheSeconds property exceeding service default * allow ShieldsRuntimeError to specify a cacheSeconds property By default error responses use the cacheLength of the service class throwing the error. This allows error to tell the handling layer the maxAge that should be set on the error badge response. * add customExceptions param This 1. allows us to specify custom properties to pass to the exception constructor if we throw any of the standard got errors e.g: `ETIMEDOUT`, `ECONNRESET`, etc 2. uses a custom `cacheSeconds` property (if set on the exception) to set the response maxAge * customExceptions --> systemErrors * errorMessages --> httpErrors
27 lines
759 B
JavaScript
27 lines
759 B
JavaScript
import Joi from 'joi'
|
|
import { nonNegativeInteger } from '../validators.js'
|
|
import { GithubAuthV3Service } from './github-auth-service.js'
|
|
import { httpErrorsFor } from './github-helpers.js'
|
|
|
|
/*
|
|
We're expecting a response like { "Python": 39624, "Shell": 104 }
|
|
The keys could be anything and {} is a valid response (e.g: for an empty repo)
|
|
*/
|
|
const schema = Joi.object().pattern(/./, nonNegativeInteger)
|
|
|
|
class BaseGithubLanguage extends GithubAuthV3Service {
|
|
async fetch({ user, repo }) {
|
|
return this._requestJson({
|
|
url: `/repos/${user}/${repo}/languages`,
|
|
schema,
|
|
httpErrors: httpErrorsFor(),
|
|
})
|
|
}
|
|
|
|
getTotalSize(data) {
|
|
return Object.values(data).reduce((acc, size) => acc + size, 0)
|
|
}
|
|
}
|
|
|
|
export { BaseGithubLanguage }
|