Skip to content

Commit

Permalink
feat(pep440): support complex minor ranges (#14598)
Browse files Browse the repository at this point in the history
  • Loading branch information
MaronHatoum committed Mar 11, 2022
1 parent 7d13826 commit 1cef6f0
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
3 changes: 3 additions & 0 deletions lib/modules/versioning/pep440/index.spec.ts
Expand Up @@ -165,6 +165,9 @@ describe('modules/versioning/pep440/index', () => {
${'~=7.2'} | ${'replace'} | ${'7.2.0'} | ${'8.0.1'} | ${'~=8.0'}
${'~=7.2'} | ${'replace'} | ${'7.2.0'} | ${'8'} | ${'~=8.0'}
${'~=7.2.0'} | ${'replace'} | ${'7.2.0'} | ${'8.2'} | ${'~=8.2.0'}
${'==3.2.*,>=3.2.2'} | ${'replace'} | ${'3.2.2'} | ${'4.1.1'} | ${'==4.1.*'}
${'==3.2.*,>=3.2.2'} | ${'replace'} | ${'3.2.2'} | ${'4.0.0'} | ${'==4.0.*'}
${'>=1.0.0,<1.1.0'} | ${'replace'} | ${'1.0.0'} | ${'1.2.0'} | ${'>=1.2.0,<1.3.0'}
`(
'getNewValue("$currentValue", "$rangeStrategy", "$currentVersion", "$newVersion") === "$expected"',
({ currentValue, rangeStrategy, currentVersion, newVersion, expected }) => {
Expand Down
17 changes: 17 additions & 0 deletions lib/modules/versioning/pep440/range.spec.ts
@@ -0,0 +1,17 @@
import { checkRangeAndRemoveUnnecessaryRangeLimit } from './range';

test.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);
}
);
31 changes: 29 additions & 2 deletions lib/modules/versioning/pep440/range.ts
Expand Up @@ -176,16 +176,20 @@ export function getNewValue({
if (result.includes(', ') && !currentValue.includes(', ')) {
result = result.replace(regEx(/, /g), ',');
}
const checkedResult = checkRangeAndRemoveUnnecessaryRangeLimit(
result,
newVersion
);

if (!satisfies(newVersion, result)) {
if (!satisfies(newVersion, checkedResult)) {
// we failed at creating the range
logger.warn(
{ result, newVersion, currentValue },
'pep440: failed to calculate newValue'
);
return null;
}
return result;
return checkedResult;
}

export function isLessThanRange(input: string, range: string): boolean {
Expand Down Expand Up @@ -480,3 +484,26 @@ function handleBumpStrategy(
);
});
}

export function checkRangeAndRemoveUnnecessaryRangeLimit(
rangeInput: string,
newVersion: string
): string {
let newRange: string = rangeInput;
if (rangeInput.includes(',')) {
const newRes = rangeInput.split(',');
if (
newRes[0].includes('.*') &&
newRes[0].includes('==') &&
newRes[1].includes('>=')
) {
if (satisfies(newVersion, newRes[0])) {
newRange = newRes[0];
}
}
} else {
return rangeInput;
}

return newRange;
}

0 comments on commit 1cef6f0

Please sign in to comment.