-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: move lookup functions into own files
- Loading branch information
Showing
4 changed files
with
101 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import * as allVersioning from '../../../../versioning'; | ||
import { LookupUpdateConfig } from './common'; | ||
|
||
export function getBucket( | ||
config: LookupUpdateConfig, | ||
currentVersion: string, | ||
newVersion: string, | ||
versioning: allVersioning.VersioningApi | ||
): string { | ||
const { | ||
separateMajorMinor, | ||
separateMultipleMajor, | ||
separateMinorPatch, | ||
} = config; | ||
if (!separateMajorMinor) { | ||
return 'latest'; | ||
} | ||
const fromMajor = versioning.getMajor(currentVersion); | ||
const toMajor = versioning.getMajor(newVersion); | ||
if (fromMajor !== toMajor) { | ||
if (separateMultipleMajor) { | ||
return `major-${toMajor}`; | ||
} | ||
return 'major'; | ||
} | ||
if (separateMinorPatch) { | ||
if ( | ||
versioning.getMinor(currentVersion) === versioning.getMinor(newVersion) | ||
) { | ||
return 'patch'; | ||
} | ||
return 'minor'; | ||
} | ||
return 'non-major'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { logger } from '../../../../logger'; | ||
import * as allVersioning from '../../../../versioning'; | ||
import { LookupUpdateConfig } from './common'; | ||
|
||
export function getCurrentVersion( | ||
config: LookupUpdateConfig, | ||
rangeStrategy: string, | ||
latestVersion: string, | ||
allVersions: string[] | ||
): string | null { | ||
const { currentValue, lockedVersion, versioning } = config; | ||
const version = allVersioning.get(versioning); | ||
if (version.isVersion(currentValue)) { | ||
return currentValue; | ||
} | ||
if (version.isSingleVersion(currentValue)) { | ||
return currentValue.replace(/=/g, '').trim(); | ||
} | ||
logger.trace(`currentValue ${currentValue} is range`); | ||
let useVersions = allVersions.filter((v) => version.matches(v, currentValue)); | ||
if (latestVersion && version.matches(latestVersion, currentValue)) { | ||
useVersions = useVersions.filter( | ||
(v) => !version.isGreaterThan(v, latestVersion) | ||
); | ||
} | ||
if (rangeStrategy === 'pin') { | ||
return ( | ||
lockedVersion || version.getSatisfyingVersion(useVersions, currentValue) | ||
); | ||
} | ||
if (rangeStrategy === 'bump') { | ||
// Use the lowest version in the current range | ||
return version.minSatisfyingVersion(useVersions, currentValue); | ||
} | ||
// Use the highest version in the current range | ||
return version.getSatisfyingVersion(useVersions, currentValue); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { UpdateType } from '../../../../config'; | ||
import * as allVersioning from '../../../../versioning'; | ||
import { LookupUpdateConfig } from './common'; | ||
|
||
export function getUpdateType( | ||
config: LookupUpdateConfig, | ||
currentVersion: string, | ||
newVersion: string | ||
): UpdateType { | ||
const { versioning } = config; | ||
const version = allVersioning.get(versioning); | ||
if (version.getMajor(newVersion) > version.getMajor(currentVersion)) { | ||
return 'major'; | ||
} | ||
if (version.getMinor(newVersion) > version.getMinor(currentVersion)) { | ||
return 'minor'; | ||
} | ||
if (config.separateMinorPatch) { | ||
return 'patch'; | ||
} | ||
if (config.patch.automerge && !config.minor.automerge) { | ||
return 'patch'; | ||
} | ||
return 'minor'; | ||
} |