Skip to content
Snippets Groups Projects
Unverified Commit dcdfc0d0 authored by Rhys Arkins's avatar Rhys Arkins Committed by GitHub
Browse files

fix: refactor pin dependencies first using array.some (#1094)

parent 935a70e8
No related branches found
No related tags found
No related merge requests found
......@@ -13,20 +13,9 @@ const { checkMonorepos } = require('../../manager/npm/monorepos');
const { ensureOnboardingPr } = require('./onboarding/pr');
module.exports = {
pinDependenciesFirst,
renovateRepository,
};
function pinDependenciesFirst(a, b) {
if (a.type === 'pin') {
return false;
}
if (b.type === 'pin') {
return true;
}
return a.branchName > b.branchName;
}
async function renovateRepository(repoConfig, token) {
let config = { ...repoConfig };
const { logger } = config;
......@@ -115,16 +104,20 @@ async function renovateRepository(repoConfig, token) {
const res = await upgrades.branchifyUpgrades(allUpgrades, logger);
config.errors = config.errors.concat(res.errors);
config.warnings = config.warnings.concat(res.warnings);
let branchUpgrades = res.upgrades.sort(pinDependenciesFirst);
let branchUpgrades = res.upgrades;
logger.info(
{ branches: branchUpgrades.map(upg => upg.branchName) },
'branchUpgrades'
);
logger.debug(`Updating ${branchUpgrades.length} branch(es)`);
logger.trace({ config: branchUpgrades }, 'branchUpgrades');
if (config.repoIsOnboarded) {
logger.info(`Processing ${branchUpgrades.length} branch(es)`);
const branchStartTime = process.hrtime();
branchList = branchUpgrades.map(upgrade => upgrade.branchName);
if (branchUpgrades.length && branchUpgrades[0].isPin) {
if (branchUpgrades.some(upg => upg.isPin)) {
logger.info('Processing only pin branches first');
branchUpgrades = branchUpgrades.filter(upg => upg.isPin);
logger.info(`Processing ${branchUpgrades.length} "pin" PRs first`);
}
for (const branchUpgrade of branchUpgrades) {
const branchResult = await branchWorker.processBranch(
......
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`workers/repository pinDependenciesFirst returns pin first 1`] = `
Array [
Object {
"branchName": "d",
"type": "pin",
},
Object {
"branchName": "a",
},
Object {
"branchName": "b",
},
Object {
"branchName": "c",
},
]
`;
exports[`workers/repository pinDependenciesFirst returns pin first 2`] = `
Array [
Object {
"branchName": "d",
"type": "pin",
},
Object {
"branchName": "a",
},
Object {
"branchName": "b",
},
Object {
"branchName": "c",
},
]
`;
exports[`workers/repository pinDependenciesFirst returns sorted if no pin 1`] = `
Array [
Object {
"branchName": "a",
},
Object {
"branchName": "b",
},
Object {
"branchName": "c",
},
]
`;
......@@ -12,37 +12,6 @@ const onboardingPr = require('../../../lib/workers/repository/onboarding/pr');
jest.mock('../../../lib/workers/repository/onboarding/pr');
describe('workers/repository', () => {
describe('pinDependenciesFirst', () => {
it('returns sorted if no pin', () => {
const arr = [
{ branchName: 'a' },
{ branchName: 'c' },
{ branchName: 'b' },
];
arr.sort(repositoryWorker.pinDependenciesFirst);
expect(arr).toMatchSnapshot();
});
it('returns pin first', () => {
const arr = [
{ branchName: 'a' },
{ branchName: 'c' },
{ branchName: 'd', type: 'pin' },
{ branchName: 'b' },
];
arr.sort(repositoryWorker.pinDependenciesFirst);
expect(arr).toMatchSnapshot();
});
it('returns pin first', () => {
const arr = [
{ branchName: 'd', type: 'pin' },
{ branchName: 'a' },
{ branchName: 'c' },
{ branchName: 'b' },
];
arr.sort(repositoryWorker.pinDependenciesFirst);
expect(arr).toMatchSnapshot();
});
});
describe('renovateRepository', () => {
let config;
beforeEach(() => {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment