Fix [Scrutinizer] error when using default branch without analysis data (#3962)

This commit is contained in:
Pierre-Yves B
2019-09-08 22:09:00 +01:00
committed by repo-ranger[bot]
parent a75b9b3c8c
commit c6d52e40b8
2 changed files with 36 additions and 8 deletions

View File

@@ -16,16 +16,17 @@ module.exports = class ScrutinizerBase extends BaseJsonService {
}
transformBranchInfo({ json, wantedBranch }) {
if (!wantedBranch) {
return json.applications[json.default_branch]
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 })
}
const branch = json.applications[wantedBranch]
if (!branch) {
throw new NotFound({ prettyMessage: ' branch not found' })
}
return branch
return branchInfo
}
transformBranchInfoMetricValue({ json, branch, metric }) {

View File

@@ -44,3 +44,30 @@ t.create('code quality nonexistent project')
label: 'code quality',
message: 'project not found',
})
t.create('code quality data missing for default branch')
.get('/g/filp/whoops.json')
.intercept(nock =>
nock('https://scrutinizer-ci.com')
.get('/api/repositories/g/filp/whoops')
.reply(200, {
default_branch: 'master',
applications: {
'some-other-branch': {
index: {
_embedded: {
project: {
metric_values: {
'scrutinizer.quality': 3.4395604395604398,
},
},
},
},
},
},
})
)
.expectBadge({
label: 'code quality',
message: 'unavailable for default branch',
})