From 8dd019f14fb585e1d25b1e94e2ffa1b355e12566 Mon Sep 17 00:00:00 2001 From: Michael Kriese <michael.kriese@visualon.de> Date: Fri, 26 Jul 2019 13:43:36 +0200 Subject: [PATCH] fix(bitbucket): size can be undefined (#4192) fix(bitbucket): size can be undefined --- lib/platform/bitbucket/index.ts | 19 ++++++++----------- lib/platform/bitbucket/utils.ts | 3 ++- .../__snapshots__/index.spec.ts.snap | 6 +++--- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/lib/platform/bitbucket/index.ts b/lib/platform/bitbucket/index.ts index 9a9ee67562..acb30e8f01 100644 --- a/lib/platform/bitbucket/index.ts +++ b/lib/platform/bitbucket/index.ts @@ -592,19 +592,16 @@ export async function getPr(prNo: number) { // TODO: Is that correct? Should we check getBranchStatus like gitlab? res.canMerge = !res.isConflicted; - // we only want the first commit, because size tells us the overall number - const { body } = await api.get<utils.PagedResult<Commit>>( - pr.links.commits.href + '?pagelen=1' - ); + // we only want the first two commits, because size tells us the overall number + const url = pr.links.commits.href + '?pagelen=2'; + const { body } = await api.get<utils.PagedResult<Commit>>(url); + const size = body.size || body.values.length; // istanbul ignore if - if (body.size === undefined) { - logger.warn( - { prNo, url: pr.links.commits.href + '?pagelen=1', body }, - 'invalid response so can rebase' - ); + if (size === undefined) { + logger.warn({ prNo, url, body }, 'invalid response so can rebase'); pr.canRebase = true; - } else if (body.size === 1) { + } else if (size === 1) { if (global.gitAuthor) { const author = addrs.parseOneAddress( body.values[0].author.raw @@ -630,7 +627,7 @@ export async function getPr(prNo: number) { pr.canRebase = true; } } else { - logger.debug({ prNo }, `${body.size} commits so cannot rebase`); + logger.debug({ prNo }, `${size} commits so cannot rebase`); pr.canRebase = false; } } diff --git a/lib/platform/bitbucket/utils.ts b/lib/platform/bitbucket/utils.ts index a9b214a9b4..4b087591b5 100644 --- a/lib/platform/bitbucket/utils.ts +++ b/lib/platform/bitbucket/utils.ts @@ -19,7 +19,8 @@ export interface Config { } export interface PagedResult<T = any> { - size: number; + pagelen: number; + size?: number; next?: string; values: T[]; } diff --git a/test/platform/bitbucket/__snapshots__/index.spec.ts.snap b/test/platform/bitbucket/__snapshots__/index.spec.ts.snap index 2eda4163f0..43a5c359ec 100644 --- a/test/platform/bitbucket/__snapshots__/index.spec.ts.snap +++ b/test/platform/bitbucket/__snapshots__/index.spec.ts.snap @@ -214,7 +214,7 @@ Array [ }, ], Array [ - "https://api.bitbucket.org/2.0/repositories/some/repo/pullrequests/3/commits?pagelen=1", + "https://api.bitbucket.org/2.0/repositories/some/repo/pullrequests/3/commits?pagelen=2", ], Array [ "/2.0/repositories/some/repo/pullrequests/5", @@ -226,7 +226,7 @@ Array [ }, ], Array [ - "https://api.bitbucket.org/2.0/repositories/some/repo/pullrequests/5/commits?pagelen=1", + "https://api.bitbucket.org/2.0/repositories/some/repo/pullrequests/5/commits?pagelen=2", ], Array [ "/2.0/repositories/some/repo/pullrequests/5", @@ -238,7 +238,7 @@ Array [ }, ], Array [ - "https://api.bitbucket.org/2.0/repositories/some/repo/pullrequests/5/commits?pagelen=1", + "https://api.bitbucket.org/2.0/repositories/some/repo/pullrequests/5/commits?pagelen=2", ], ] `; -- GitLab