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

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
first attempt
  • Loading branch information
reeceappling authored Aug 11, 2023
commit 0c0f77f5cdea867563dee9999f0acd7c0922f5d3
16 changes: 10 additions & 6 deletions services/bitbucket/bitbucket-pipelines.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ const bitbucketPipelinesSchema = Joi.object({
'STOPPED',
'EXPIRED',
),
}).optional(),
}).required(),
}),
stage: Joi.object({
name: Joi.string().required(),
type: Joi.string().optional(),
}),
}).required().or('result','stage'),
}),
)
.required(),
Expand Down Expand Up @@ -69,13 +73,13 @@ 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) {
if !values[0].state.hasOwnProperty('result') { // DID THIS ------------------------------------------------------------------
return 'HALTED'
if (values[0].state.hasOwnProperty('result')) {
return values[0].state.result.name
}
return values[0].state.result.name
return values[0].state.stage.name
}
return 'never built'
}
Expand Down
23 changes: 23 additions & 0 deletions services/bitbucket/bitbucket-pipelines.tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,20 @@ 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 +56,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