Skip to content
Snippets Groups Projects
Unverified Commit ad9d2b97 authored by RahulGautamSingh's avatar RahulGautamSingh Committed by GitHub
Browse files

fix(versioning/pep440): log debug message if `newVersion` is excluded from range (#28950)

parent 5de7eee2
No related branches found
Tags 37.351.4
No related merge requests found
import { checkRangeAndRemoveUnnecessaryRangeLimit } from './range'; import { logger } from '../../../logger';
import { checkRangeAndRemoveUnnecessaryRangeLimit, getNewValue } from './range';
it.each` describe('modules/versioning/pep440/range', () => {
rangeInput | newVersion | expected it.each`
${'==4.1.*,>=3.2.2'} | ${'4.1.1'} | ${'==4.1.*'} rangeInput | newVersion | expected
${'==4.0.*,>=3.2.2'} | ${'4.0.0'} | ${'==4.0.*'} ${'==4.1.*,>=3.2.2'} | ${'4.1.1'} | ${'==4.1.*'}
${'==7.2.*'} | ${'7.2.0'} | ${'==7.2.*'} ${'==4.0.*,>=3.2.2'} | ${'4.0.0'} | ${'==4.0.*'}
`( ${'==7.2.*'} | ${'7.2.0'} | ${'==7.2.*'}
'checkRange("$rangeInput, "$newVersion"") === "$expected"', `(
({ rangeInput, newVersion, expected }) => { 'checkRange("$rangeInput, "$newVersion"") === "$expected"',
const res = checkRangeAndRemoveUnnecessaryRangeLimit( ({ rangeInput, newVersion, expected }) => {
rangeInput, const res = checkRangeAndRemoveUnnecessaryRangeLimit(
newVersion, rangeInput,
newVersion,
);
expect(res).toEqual(expected);
},
);
it('returns null without warning if new version is excluded from range', () => {
const res = getNewValue({
currentValue: '>=1.25.0,<2,!=1.32.0',
rangeStrategy: 'auto',
newVersion: '1.32.0',
currentVersion: '1.25.0',
});
expect(res).toBeNull();
expect(logger.debug).toHaveBeenCalledWith(
'Cannot calculate new value as the newVersion:`1.32.0` is excluded from range: `>=1.25.0,<2,!=1.32.0`',
); );
expect(res).toEqual(expected); expect(logger.warn).not.toHaveBeenCalled();
}, });
); });
...@@ -129,6 +129,18 @@ export function getNewValue({ ...@@ -129,6 +129,18 @@ export function getNewValue({
return null; return null;
} }
// return early if newVersion is excluded from range
if (
ranges.some(
(range) => range.operator === '!=' && range.version === newVersion,
)
) {
logger.debug(
`Cannot calculate new value as the newVersion:\`${newVersion}\` is excluded from range: \`${currentValue}\``,
);
return null;
}
switch (rangeStrategy) { switch (rangeStrategy) {
case 'auto': case 'auto':
case 'replace': case 'replace':
...@@ -191,6 +203,7 @@ export function getNewValue({ ...@@ -191,6 +203,7 @@ export function getNewValue({
newVersion, newVersion,
); );
// istanbul ignore if
if (!satisfies(newVersion, checkedResult)) { if (!satisfies(newVersion, checkedResult)) {
// we failed at creating the range // we failed at creating the range
logger.warn( logger.warn(
......
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