Skip to content
Snippets Groups Projects
Unverified Commit 40bd20cf authored by Sergei Zharinov's avatar Sergei Zharinov Committed by GitHub
Browse files

refactor(versioning/docker): Enable strict null checks (#14004)

parent 1a1d1c2b
Branches
No related tags found
No related merge requests found
......@@ -22,16 +22,15 @@ class DockerVersioningApi extends GenericVersioningApi {
return null;
}
const versionPieces = version.replace(regEx(/^v/), '').split('-');
const prefix = versionPieces.shift();
const suffix = versionPieces.join('-');
const m = versionPattern.exec(prefix);
if (!m?.groups) {
const [prefix, ...suffixPieces] = versionPieces;
const matchGroups = prefix?.match(versionPattern)?.groups;
if (!matchGroups) {
return null;
}
const { version: ver, prerelease } = m.groups;
const { version: ver, prerelease } = matchGroups;
const release = ver.split('.').map(Number);
return { release, suffix, prerelease };
return { release, suffix: suffixPieces.join('-'), prerelease };
}
protected override _compare(version: string, other: string): number {
......@@ -65,16 +64,23 @@ class DockerVersioningApi extends GenericVersioningApi {
return -1;
}
// alphabetic order
if (parsed1.prerelease && parsed2.prerelease) {
return parsed1.prerelease.localeCompare(parsed2.prerelease);
}
}
// equals
return parsed2.suffix.localeCompare(parsed1.suffix);
const suffix1 = parsed1.suffix ?? '';
const suffix2 = parsed2.suffix ?? '';
return suffix2.localeCompare(suffix1);
}
override isCompatible(version: string, current: string): boolean {
const parsed1 = this._parse(version);
const parsed2 = this._parse(current);
return (
return !!(
parsed1 &&
parsed2 &&
parsed1.suffix === parsed2.suffix &&
parsed1.release.length === parsed2.release.length
);
......
......@@ -391,7 +391,6 @@
"lib/versioning/aws-machine-image/index.ts",
"lib/versioning/common.ts",
"lib/versioning/composer/index.ts",
"lib/versioning/docker/index.ts",
"lib/versioning/generic.ts",
"lib/versioning/git/index.ts",
"lib/versioning/hashicorp/index.ts",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment