Skip to content

Commit

Permalink
fix(versioning/pep440): log debug message if newVersion is excluded…
Browse files Browse the repository at this point in the history
… from range (#28950)
  • Loading branch information
RahulGautamSingh committed May 9, 2024
1 parent 5de7eee commit ad9d2b9
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 15 deletions.
47 changes: 32 additions & 15 deletions lib/modules/versioning/pep440/range.spec.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,34 @@
import { checkRangeAndRemoveUnnecessaryRangeLimit } from './range';
import { logger } from '../../../logger';
import { checkRangeAndRemoveUnnecessaryRangeLimit, getNewValue } from './range';

it.each`
rangeInput | newVersion | expected
${'==4.1.*,>=3.2.2'} | ${'4.1.1'} | ${'==4.1.*'}
${'==4.0.*,>=3.2.2'} | ${'4.0.0'} | ${'==4.0.*'}
${'==7.2.*'} | ${'7.2.0'} | ${'==7.2.*'}
`(
'checkRange("$rangeInput, "$newVersion"") === "$expected"',
({ rangeInput, newVersion, expected }) => {
const res = checkRangeAndRemoveUnnecessaryRangeLimit(
rangeInput,
newVersion,
describe('modules/versioning/pep440/range', () => {
it.each`
rangeInput | newVersion | expected
${'==4.1.*,>=3.2.2'} | ${'4.1.1'} | ${'==4.1.*'}
${'==4.0.*,>=3.2.2'} | ${'4.0.0'} | ${'==4.0.*'}
${'==7.2.*'} | ${'7.2.0'} | ${'==7.2.*'}
`(
'checkRange("$rangeInput, "$newVersion"") === "$expected"',
({ rangeInput, newVersion, expected }) => {
const res = checkRangeAndRemoveUnnecessaryRangeLimit(
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();
});
});
13 changes: 13 additions & 0 deletions lib/modules/versioning/pep440/range.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,18 @@ export function getNewValue({
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) {
case 'auto':
case 'replace':
Expand Down Expand Up @@ -191,6 +203,7 @@ export function getNewValue({
newVersion,
);

// istanbul ignore if
if (!satisfies(newVersion, checkedResult)) {
// we failed at creating the range
logger.warn(
Expand Down

0 comments on commit ad9d2b9

Please sign in to comment.