* 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
46 lines
1.3 KiB
JavaScript
46 lines
1.3 KiB
JavaScript
import { BaseJsonService, NotFound, InvalidResponse } from '../index.js'
|
|
|
|
export default class ScrutinizerBase extends BaseJsonService {
|
|
// https://scrutinizer-ci.com/docs/api/#repository-details
|
|
async fetch({ schema, vcs, slug }) {
|
|
return this._requestJson({
|
|
schema,
|
|
url: `https://scrutinizer-ci.com/api/repositories/${vcs}/${slug}`,
|
|
httpErrors: {
|
|
401: 'not authorized to access project',
|
|
404: 'project not found',
|
|
},
|
|
})
|
|
}
|
|
|
|
transformBranchInfo({ json, wantedBranch }) {
|
|
const branch = wantedBranch || json.default_branch
|
|
const noBranchInfoMessage = wantedBranch
|
|
? 'branch not found'
|
|
: 'unavailable for default branch'
|
|
|
|
const branchInfo = json.applications[branch]
|
|
if (!branchInfo) {
|
|
throw new NotFound({ prettyMessage: noBranchInfoMessage })
|
|
}
|
|
|
|
return branchInfo
|
|
}
|
|
|
|
transformBranchInfoMetricValue({ json, branch, metric }) {
|
|
const branchInfo = this.transformBranchInfo({ json, wantedBranch: branch })
|
|
if (!branchInfo.index) {
|
|
throw new InvalidResponse({ prettyMessage: 'metrics missing for branch' })
|
|
}
|
|
const {
|
|
index: {
|
|
_embedded: {
|
|
project: { metric_values: metricValues },
|
|
},
|
|
},
|
|
} = branchInfo
|
|
|
|
return { value: metricValues[metric] }
|
|
}
|
|
}
|