diff --git a/lib/workers/repository/index.js b/lib/workers/repository/index.js index 0c19161c1382dc23513348a1c768302775eb7ce6..6f87d45d01b1937d102135dac027765031ee88c3 100644 --- a/lib/workers/repository/index.js +++ b/lib/workers/repository/index.js @@ -6,6 +6,7 @@ const { handleError } = require('./error'); const { finaliseRepo } = require('./finalise'); const { processResult } = require('./result'); const { resolvePackageFiles } = require('../../manager'); +const { sortBranches } = require('./process/sort'); module.exports = { renovateRepository, @@ -50,25 +51,7 @@ async function renovateRepository(repoConfig) { config = await resolvePackageFiles(config); config = await determineUpdates(config); } - - // Sort branches - const sortOrder = [ - 'pin', - 'digest', - 'patch', - 'minor', - 'major', - 'lockFileMaintenance', - ]; - 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; - }); + sortBranches(config.branches); res = config.repoIsOnboarded ? await writeUpdates(config) : await ensureOnboardingPr(config, config.branches); diff --git a/lib/workers/repository/process/sort.js b/lib/workers/repository/process/sort.js new file mode 100644 index 0000000000000000000000000000000000000000..6186d3904495ea7482ba7e65215f3b00dfc35f48 --- /dev/null +++ b/lib/workers/repository/process/sort.js @@ -0,0 +1,22 @@ +module.exports = { sortBranches }; + +function sortBranches(branches) { + // Sort branches + const sortOrder = [ + 'pin', + 'digest', + 'patch', + 'minor', + 'major', + 'lockFileMaintenance', + ]; + logger.debug({ branches }, 'branches'); + branches.sort((a, b) => { + const sortDiff = sortOrder.indexOf(a.type) - sortOrder.indexOf(b.type); + if (sortDiff !== 0) { + return sortDiff; + } + // Sort by prTitle if type is the same + return a.prTitle < b.prTitle ? -1 : 1; + }); +}