Skip to content

Commit

Permalink
refactor: getBucket
Browse files Browse the repository at this point in the history
  • Loading branch information
rarkins committed Feb 12, 2021
1 parent b9e0840 commit 0f456d0
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions lib/workers/repository/process/lookup/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,24 +112,33 @@ function getFromVersion(
return version.getSatisfyingVersion(useVersions, currentValue);
}

function getBucket(config: LookupUpdateConfig, update: LookupUpdate): string {
function getBucket(
config: LookupUpdateConfig,
fromVersion: string,
toVersion: string,
versioning: allVersioning.VersioningApi
): string {
const {
separateMajorMinor,
separateMultipleMajor,
separateMinorPatch,
} = config;
const { updateType, newMajor } = update;
if (!separateMajorMinor) {
return 'latest';
}
if (updateType === 'major') {
const fromMajor = versioning.getMajor(fromVersion);
const toMajor = versioning.getMajor(toVersion);
if (fromMajor !== toMajor) {
if (separateMultipleMajor) {
return `major-${newMajor}`;
return `major-${toMajor}`;
}
return 'major';
}
if (separateMinorPatch) {
return updateType;
if (versioning.getMinor(fromVersion) === versioning.getMinor(toVersion)) {
return 'patch';
}
return 'minor';
}
return 'non-major';
}
Expand Down Expand Up @@ -341,7 +350,7 @@ export async function lookupUpdates(
update.updateType =
update.updateType || getType(config, fromVersion, toVersion);

const bucket = getBucket(config, update);
const bucket = getBucket(config, fromVersion, toVersion, versioning);
if (buckets[bucket]) {
buckets[bucket].push(update);
} else {
Expand Down

0 comments on commit 0f456d0

Please sign in to comment.