Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(lookup): Extract isUnconstrained function #26

Draft
wants to merge 1 commit into
base: refactor/lookup-updates-config
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions lib/workers/repository/process/lookup/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,17 @@ import {
isReplacementRulesConfigured,
} from './utils';

function isUnconstrained(config: LookupUpdateConfig): boolean {
return !!config.lockedVersion && is.undefined(config.currentValue);
}

export async function lookupUpdates(
inconfig: LookupUpdateConfig
): Promise<UpdateResult> {
let config: LookupUpdateConfig = { ...inconfig };
config.versioning ??= getDefaultVersioning(config.datasource);

const versioning = allVersioning.get(config.versioning);
const unconstrainedValue =
!!config.lockedVersion && is.undefined(config.currentValue);

let dependency: ReleaseResult | null = null;
const res: UpdateResult = {
Expand Down Expand Up @@ -70,7 +72,7 @@ export async function lookupUpdates(
const isValid =
is.string(config.currentValue) && versioning.isValid(config.currentValue);

if (unconstrainedValue || isValid) {
if (isUnconstrained(config) || isValid) {
if (
!config.updatePinnedDependencies &&
// TODO #22198
Expand Down Expand Up @@ -168,7 +170,7 @@ export async function lookupUpdates(
const allSatisfyingVersions = allVersions.filter(
(v) =>
// TODO #22198
unconstrainedValue ||
isUnconstrained(config) ||
versioning.matches(v.version, config.currentValue!)
);
if (config.rollbackPrs && !allSatisfyingVersions.length) {
Expand Down Expand Up @@ -268,7 +270,7 @@ export async function lookupUpdates(
).filter(
(v) =>
// Leave only compatible versions
unconstrainedValue ||
isUnconstrained(config) ||
versioning.isCompatible(v.version, config.currentValue)
);
if (config.isVulnerabilityAlert && !config.osvVulnerabilityAlerts) {
Expand Down Expand Up @@ -508,7 +510,7 @@ export async function lookupUpdates(
rollbackPrs: config.rollbackPrs,
isVulnerabilityAlert: config.isVulnerabilityAlert,
updatePinnedDependencies: config.updatePinnedDependencies,
unconstrainedValue,
unconstrainedValue: isUnconstrained(config),
err,
},
'lookupUpdates error'
Expand Down