Fix [Scrutinizer] error when using default branch without analysis data (#3962)
This commit is contained in:
committed by
repo-ranger[bot]
parent
a75b9b3c8c
commit
c6d52e40b8
@@ -16,16 +16,17 @@ module.exports = class ScrutinizerBase extends BaseJsonService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
transformBranchInfo({ json, wantedBranch }) {
|
transformBranchInfo({ json, wantedBranch }) {
|
||||||
if (!wantedBranch) {
|
const branch = wantedBranch || json.default_branch
|
||||||
return json.applications[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]
|
return branchInfo
|
||||||
if (!branch) {
|
|
||||||
throw new NotFound({ prettyMessage: ' branch not found' })
|
|
||||||
}
|
|
||||||
|
|
||||||
return branch
|
|
||||||
}
|
}
|
||||||
|
|
||||||
transformBranchInfoMetricValue({ json, branch, metric }) {
|
transformBranchInfoMetricValue({ json, branch, metric }) {
|
||||||
|
|||||||
@@ -44,3 +44,30 @@ t.create('code quality nonexistent project')
|
|||||||
label: 'code quality',
|
label: 'code quality',
|
||||||
message: 'project not found',
|
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',
|
||||||
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user