From 6c45f516d2064ebf70fa1b9aab3e93d6d2c900d8 Mon Sep 17 00:00:00 2001 From: mikaelkolkinn <mikaelkolkinn@users.noreply.github.com> Date: Sun, 13 Oct 2019 06:37:44 +0200 Subject: [PATCH] fix(bitbucket): Branch automerges too early on Bitbucket Cloud (#4631) --- lib/platform/bitbucket/index.ts | 16 ++++++++++--- .../platform/bitbucket/_fixtures/responses.js | 24 +++++++++++++++++++ test/platform/bitbucket/index.spec.ts | 4 ++++ 3 files changed, 41 insertions(+), 3 deletions(-) diff --git a/lib/platform/bitbucket/index.ts b/lib/platform/bitbucket/index.ts index db3d2908b9..2ae735f1f3 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 0c47566b7b..045997aad6 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 7d4768201f..fe3e6f7f21 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' + ); }); }); -- GitLab