diff --git a/lib/workers/repository/index.js b/lib/workers/repository/index.js index b5c175ba3b4028b774fad89029ba369f0cfcdf2c..b451acf8f1fbd37501047e3f5ae69410d088f107 100644 --- a/lib/workers/repository/index.js +++ b/lib/workers/repository/index.js @@ -63,9 +63,15 @@ async function renovateRepository(repoConfig, token, loop = 1) { 'major', 'lockFileMaintenance', ]; - config.branches.sort( - (a, b) => sortOrder.indexOf(a.type) - sortOrder.indexOf(b.type) - ); + config.branches.sort((a, b) => { + const sortDiff = sortOrder.indexOf(a.type) - sortOrder.indexOf(b.type); + if (sortDiff !== 0) { + // type is different + return sortDiff; + } + // Sort by prTitle + return a.prTitle < b.prTitle ? -1 : 1; + }); const res = config.repoIsOnboarded ? await writeUpdates(config) : await ensureOnboardingPr(config); diff --git a/test/workers/repository/__snapshots__/index.spec.js.snap b/test/workers/repository/__snapshots__/index.spec.js.snap index d617b64e2b85551bd8d40f896d0e7cc0229e123c..c0b0a555be40a2839da520eec202a8320ae6ee62 100644 --- a/test/workers/repository/__snapshots__/index.spec.js.snap +++ b/test/workers/repository/__snapshots__/index.spec.js.snap @@ -2,6 +2,23 @@ exports[`workers/repository renovateRepository() ensures onboarding pr 1`] = `"onboarding"`; +exports[`workers/repository renovateRepository() ensures onboarding pr 2`] = ` +Array [ + Object { + "prTitle": "aaa", + "type": "pin", + }, + Object { + "prTitle": "bbb", + "type": "pin", + }, + Object { + "prTitle": "aaa", + "type": "minor", + }, +] +`; + exports[`workers/repository renovateRepository() exits after 6 loops 1`] = `"loops>5"`; exports[`workers/repository renovateRepository() handles baseBranches 1`] = `"onboarded"`; diff --git a/test/workers/repository/index.spec.js b/test/workers/repository/index.spec.js index 2dd664e9bdb7ea601162c0cb009d8fa4e819b0e0..4a821c5b99ad05590df47477ef54d171a529030c 100644 --- a/test/workers/repository/index.spec.js +++ b/test/workers/repository/index.spec.js @@ -41,11 +41,25 @@ describe('workers/repository', () => { initRepo.mockReturnValue({}); determineUpdates.mockReturnValue({ repoIsOnboarded: false, - branches: [], + branches: [ + { + type: 'pin', + prTitle: 'bbb', + }, + { + type: 'pin', + prTitle: 'aaa', + }, + { + type: 'minor', + prTitle: 'aaa', + }, + ], }); ensureOnboardingPr.mockReturnValue('onboarding'); const res = await renovateRepository(config, 'some-token'); expect(res).toMatchSnapshot(); + expect(ensureOnboardingPr.mock.calls[0][0].branches).toMatchSnapshot(); }); it('handles baseBranches', async () => { initRepo.mockReturnValue({ baseBranches: ['master', 'next'] });