diff --git a/lib/api/github.js b/lib/api/github.js index 4f06826c4a178c934b5c2cd881c9caa0289d583f..83e6df20b8e34f265715dd4f24c61d710baa8016 100644 --- a/lib/api/github.js +++ b/lib/api/github.js @@ -328,15 +328,8 @@ async function isBranchStale(branchName) { // Returns the Pull Request for a branch. Null if not exists. async function getBranchPr(branchName) { logger.debug(`getBranchPr(${branchName})`); - const gotString = - `repos/${config.repoName}/pulls?` + - `state=open&base=${config.baseBranch}&head=${config.owner}:${branchName}`; - const res = await get(gotString); - if (!res.body.length) { - return null; - } - const prNo = res.body[0].number; - return getPr(prNo); + const existingPr = await findPr(branchName, null, 'open'); + return existingPr ? getPr(existingPr.number) : null; } // Returns the combined status for a branch. diff --git a/test/api/__snapshots__/github.spec.js.snap b/test/api/__snapshots__/github.spec.js.snap index 1131991ccb40c0ce8e93ce01c446ae2dbe55f9c3..41434f94ecdf1d1f885f71fcfdf927d991a7b6d8 100644 --- a/test/api/__snapshots__/github.spec.js.snap +++ b/test/api/__snapshots__/github.spec.js.snap @@ -481,7 +481,7 @@ Array [ exports[`api/github getBranchLastCommitTime should return a Date 1`] = `2011-04-14T16:00:49.000Z`; -exports[`api/github getBranchPr(branchName) should return null if no PR exists 1`] = ` +exports[`api/github getBranchPr(branchName) should return the PR object 1`] = ` Array [ Array [ "repos/some/repo", @@ -503,54 +503,15 @@ Array [ }, ], Array [ - "repos/some/repo/pulls?state=open&base=master&head=theowner:somebranch", - ], -] -`; - -exports[`api/github getBranchPr(branchName) should return the PR object 1`] = ` -Array [ - Array [ - "repos/some/repo", + "repos/some/repo/pulls?per_page=100&state=all", Object { - "headers": Object { - "accept": "application/vnd.github.loki-preview+json", - }, + "paginate": true, }, ], - Array [ - "repos/some/repo/git/refs/heads/master", - ], - Array [ - "repos/some/repo/branches/master/protection/required_status_checks", - Object { - "headers": Object { - "accept": "application/vnd.github.loki-preview+json", - }, - }, - ], - Array [ - "repos/some/repo/pulls?state=open&base=master&head=theowner:somebranch", - ], - Array [ - "repos/some/repo/pulls/91", - ], ] `; -exports[`api/github getBranchPr(branchName) should return the PR object 2`] = ` -Object { - "additions": 1, - "base": Object { - "sha": "1234", - }, - "canRebase": true, - "commits": 1, - "deletions": 1, - "displayNumber": "Pull Request #91", - "number": 91, -} -`; +exports[`api/github getBranchPr(branchName) should return the PR object 2`] = `null`; exports[`api/github getCommitMessages() returns commits messages 1`] = ` Array [ diff --git a/test/api/github.spec.js b/test/api/github.spec.js index 115d80a28c4e65573203edc882b65a55e411602b..91f81948e789d9b0d583e4506a7230c588293847 100644 --- a/test/api/github.spec.js +++ b/test/api/github.spec.js @@ -677,13 +677,12 @@ describe('api/github', () => { body: [], })); const pr = await github.getBranchPr('somebranch'); - expect(get.mock.calls).toMatchSnapshot(); expect(pr).toBe(null); }); it('should return the PR object', async () => { await initRepo('some/repo', 'token'); get.mockImplementationOnce(() => ({ - body: [{ number: 91 }], + body: [{ number: 91, head: {} }], })); get.mockImplementationOnce(() => ({ body: { diff --git a/test/workers/repository/cleanup.spec.js b/test/workers/repository/cleanup.spec.js index ca38b2759b9cecf1eac61663b457035bc30dd72f..756404eb8ffc006a281ed41c392156983acec01f 100644 --- a/test/workers/repository/cleanup.spec.js +++ b/test/workers/repository/cleanup.spec.js @@ -11,7 +11,6 @@ describe('workers/repository/cleanup', () => { config = { ...defaultConfig }; config.api = { getAllRenovateBranches: jest.fn(), - getAllPrs: jest.fn(), getPr: jest.fn(), deleteBranch: jest.fn(), }; @@ -27,7 +26,6 @@ describe('workers/repository/cleanup', () => { config.api.getAllRenovateBranches.mockReturnValueOnce(branchNames); await cleanup.pruneStaleBranches(config, branchNames); expect(config.api.getAllRenovateBranches.mock.calls).toHaveLength(1); - expect(config.api.getAllPrs.mock.calls).toHaveLength(0); }); it('deletes remaining branch', async () => { branchNames = ['renovate/a', 'renovate/b'];