Skip to content

Commit

Permalink
handle [BitbucketPipelines] responses with missing result key (#10163)
Browse files Browse the repository at this point in the history
  • Loading branch information
chris48s committed May 27, 2024
1 parent 427b24c commit d4ede2e
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
12 changes: 10 additions & 2 deletions services/bitbucket/bitbucket-pipelines.service.js
Original file line number Diff line number Diff line change
@@ -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()
Expand All @@ -16,7 +21,7 @@ const bitbucketPipelinesSchema = Joi.object({
'STOPPED',
'EXPIRED',
),
}).required(),
}),
}).required(),
}),
)
Expand Down Expand Up @@ -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'
Expand Down
33 changes: 33 additions & 0 deletions services/bitbucket/bitbucket-pipelines.tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')

0 comments on commit d4ede2e

Please sign in to comment.