diff --git a/lib/platform/bitbucket/index.ts b/lib/platform/bitbucket/index.ts index db3d2908b979bb7b332082ee0861bb6e77974be0..2ae735f1f37f2a8575985e270964d5b632fe9c10 100644 --- a/lib/platform/bitbucket/index.ts +++ b/lib/platform/bitbucket/index.ts @@ -249,16 +249,26 @@ export async function getBranchStatus( const statuses = await utils.accumulateValues( `/2.0/repositories/${config.repository}/commit/${sha}/statuses` ); - const noOfFailures = statuses.filter( - (status: { state: string }) => status.state === 'FAILED' - ).length; logger.debug( { branch: branchName, sha, statuses }, 'branch status check result' ); + if (!statuses.length) { + logger.debug('empty branch status check result = returning "pending"'); + return 'pending'; + } + const noOfFailures = statuses.filter( + (status: { state: string }) => status.state === 'FAILED' + ).length; if (noOfFailures) { return 'failed'; } + const noOfPending = statuses.filter( + (status: { state: string }) => status.state === 'INPROGRESS' + ).length; + if (noOfPending) { + return 'pending'; + } return 'success'; } diff --git a/test/platform/bitbucket/_fixtures/responses.js b/test/platform/bitbucket/_fixtures/responses.js index 0c47566b7bd4a126294b4128593d6a337ff406aa..045997aad67e214df45255024cf8d3418daa3c60 100644 --- a/test/platform/bitbucket/_fixtures/responses.js +++ b/test/platform/bitbucket/_fixtures/responses.js @@ -89,6 +89,7 @@ module.exports = { { name: 'branch' }, { name: 'renovate/branch' }, { name: 'renovate/upgrade' }, + { name: 'pending/branch' }, ], }, '/2.0/repositories/some/repo/refs/branches/master': { @@ -102,6 +103,13 @@ module.exports = { parents: [{ hash: 'master_hash' }], }, }, + '/2.0/repositories/some/repo/refs/branches/pending/branch': { + name: 'pending/branch', + target: { + hash: 'pending/branch_hash', + parents: [{ hash: 'master_hash' }], + }, + }, '/2.0/repositories/some/repo/refs/branches/not_found': notFound, '/!api/1.0/repositories/some/repo/directory/master_hash': { values: ['foo_folder/foo_file', 'bar_file'], @@ -150,4 +158,20 @@ module.exports = { }, ], }, + '/2.0/repositories/some/repo/commit/branch_hash/statuses': { + values: [ + { + key: 'foo', + state: 'SUCCESSFUL', + }, + ], + }, + '/2.0/repositories/some/repo/commit/pending/branch_hash/statuses': { + values: [ + { + key: 'foo', + state: 'INPROGRESS', + }, + ], + }, }; diff --git a/test/platform/bitbucket/index.spec.ts b/test/platform/bitbucket/index.spec.ts index 7d4768201f6710044ff22aa582ddddb604fec655..fe3e6f7f217ebb8455aaab629135e51de9d2ad7d 100644 --- a/test/platform/bitbucket/index.spec.ts +++ b/test/platform/bitbucket/index.spec.ts @@ -198,6 +198,10 @@ describe('platform/bitbucket', () => { expect(await getBranchStatus('master', ['foo'])).toBe('failed'); expect(await getBranchStatus('master', true)).toBe('failed'); expect(await getBranchStatus('branch', true)).toBe('success'); + expect(await getBranchStatus('pending/branch', true)).toBe('pending'); + expect(await getBranchStatus('branch-with-empty-status', true)).toBe( + 'pending' + ); }); });