handle [BitbucketPipelines] responses with missing result key (#10163)

This commit is contained in:
chris48s
2024-05-27 20:52:28 +01:00
committed by GitHub
parent 427b24c98a
commit d4ede2e7cf
2 changed files with 43 additions and 2 deletions

View File

@@ -1,6 +1,11 @@
import Joi from 'joi'
import { renderBuildStatusBadge } from '../build-status.js'
import { BaseJsonService, redirector, pathParams } from '../index.js'
import {
BaseJsonService,
redirector,
pathParams,
InvalidResponse,
} from '../index.js'
const bitbucketPipelinesSchema = Joi.object({
values: Joi.array()
@@ -16,7 +21,7 @@ const bitbucketPipelinesSchema = Joi.object({
'STOPPED',
'EXPIRED',
),
}).required(),
}),
}).required(),
}),
)
@@ -82,6 +87,9 @@ class BitbucketPipelines extends BaseJsonService {
value => value.state && value.state.name === 'COMPLETED',
)
if (values.length > 0) {
if (!values[0].state?.result?.name) {
throw new InvalidResponse({ prettyMessage: 'invalid response data' })
}
return values[0].state.result.name
}
return 'never built'

View File

@@ -96,6 +96,39 @@ t.create('build result (unexpected status)')
)
.expectBadge({ label: 'build', message: 'invalid response data' })
// regression test for https://github.com/badges/shields/issues/10137
t.create('build result (with manual build steps)')
.get('/shields-io/test-repo/main.json')
.intercept(nock =>
nock('https://api.bitbucket.org')
.get(/^\/2.0\/.*/)
.reply(200, {
values: [
{
state: {
name: 'IN_PROGRESS',
type: 'pipeline_state_in_progress',
stage: {
name: 'PAUSED',
type: 'pipeline_state_in_progress_paused',
},
},
},
{
state: {
name: 'COMPLETED',
type: 'pipeline_state_completed',
result: {
name: 'SUCCESSFUL',
type: 'pipeline_state_completed_successful',
},
},
},
],
}),
)
.expectBadge({ label: 'build', message: 'passing' })
t.create('build result no branch redirect')
.get('/shields-io/test-repo.svg')
.expectRedirect('/bitbucket/pipelines/shields-io/test-repo/master.svg')