Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bitbucketpipelines] resolve "invalid response data" for halted pipelines #9472

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 16 additions & 4 deletions services/bitbucket/bitbucket-pipelines.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,14 @@ const bitbucketPipelinesSchema = Joi.object({
'STOPPED',
'EXPIRED',
),
}).required(),
}).required(),
}),
stage: Joi.object({
name: Joi.string().required(),
type: Joi.string().optional(),
}),
})
.required()
.or('result', 'stage'),
}),
)
.required(),
Expand Down Expand Up @@ -69,10 +75,16 @@ class BitbucketPipelines extends BaseJsonService {

static transform(data) {
const values = data.values.filter(
value => value.state && value.state.name === 'COMPLETED',
value =>
value.state &&
(value.state.name === 'COMPLETED' ||
value.state.name === 'IN_PROGRESS'),
)
if (values.length > 0) {
return values[0].state.result.name
if (Object.prototype.hasOwnProperty.call(values[0].state, 'result')) {
return values[0].state.result.name
}
return values[0].state.stage.name
}
return 'never built'
}
Expand Down
26 changes: 26 additions & 0 deletions services/bitbucket/bitbucket-pipelines.tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,23 @@ function bitbucketApiResponse(status) {
})
}

function bitbucketNoResultResponse(stageName) {
return JSON.stringify({
values: [
{
state: {
type: 'pipeline_state_in_progress',
name: 'IN_PROGRESS',
stage: {
name: stageName,
type: 'pipeline_state_in_progress_halted',
},
},
},
],
})
}

t.create('master build result (not found)')
.get('/atlassian/not-a-repo/master.json')
.expectBadge({ label: 'build', message: 'not found' })
Expand All @@ -42,6 +59,15 @@ t.create('branch build result (never built)')
.get('/atlassian/adf-builder-javascript/some/new/branch.json')
.expectBadge({ label: 'build', message: 'never built' })

t.create('build result (stage only)')
.get('/atlassian/adf-builder-javascript/master.json')
.intercept(nock =>
nock('https://api.bitbucket.org')
.get(/^\/2.0\/.*/)
.reply(200, bitbucketNoResultResponse('HALTED')),
)
.expectBadge({ label: 'build', message: 'HALTED' })

t.create('build result (passing)')
.get('/atlassian/adf-builder-javascript/master.json')
.intercept(nock =>
Expand Down