diff --git a/lib/platform/bitbucket/index.ts b/lib/platform/bitbucket/index.ts index 9a9ee675622e9f8eeee73c0d1efe0b5fab9be268..acb30e8f017c8fc5e075e6b6c72bf281a14552a8 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 a9b214a9b49859a62dffeeb715ad5cd44b908b41..4b087591b50273701adc02c50a8ab9a6a9288690 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 2eda4163f07e9fccc76af8b3196763feade457fd..43a5c359ecd40f1fd04c613d8053046346c9743d 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", ], ] `;