* fix: support scrutinizer branches with only failed builds * tests: increase timeout for microbadger tests * tests: increase timeouts for jsdelivr and microbadger tests
48 lines
1.3 KiB
JavaScript
48 lines
1.3 KiB
JavaScript
'use strict'
|
|
|
|
const { BaseJsonService, NotFound, InvalidResponse } = require('..')
|
|
|
|
module.exports = 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}`,
|
|
errorMessages: {
|
|
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] }
|
|
}
|
|
}
|