Skip to content

Commit

Permalink
fix(managers/gradle): allow dot annotation in version.ref (#21820)
Browse files Browse the repository at this point in the history
Signed-off-by: Jinna C <jinnatim@gmail.com>
Co-authored-by: Johannes Feichtner <343448+Churro@users.noreply.github.com>
  • Loading branch information
cjtim and Churro committed May 4, 2023
1 parent 3f68122 commit e3e6de9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
Expand Up @@ -17,5 +17,5 @@ kotest = [ "kotest-runner-junit5", "kotest-assertions-core-jvm" ]

[plugins]
detekt = { id = "io.gitlab.arturbosch.detekt", version.ref = "detekt" }
publish-on-central = { id = "org.danilopianini.publish-on-central", version.ref = "publish-on-central" }
publish-on-central = { id = "org.danilopianini.publish-on-central", version.ref = "publish.on.central" }
grgit = { id = "org.ajoberstar.grgit", version.unknown = "this will fail" }
Expand Up @@ -7,4 +7,4 @@ junit = "1.4.9"

[libraries]
junit-legacy = { module = "junit:junit", version.ref = "junit" }
mocha-junit = { module = "mocha-junit:mocha-junit", version.ref = "mocha-junit-reporter" }
mocha-junit = { module = "mocha-junit:mocha-junit", version.ref = "mocha.junit.reporter" }
13 changes: 9 additions & 4 deletions lib/modules/manager/gradle/extract/catalog.ts
Expand Up @@ -55,6 +55,10 @@ function isVersionPointer(
return hasKey('ref', obj);
}

function normalizeVersionPointer(versionPointer: string): string {
return versionPointer.replace(regEx(/[._]/g), '-');
}

interface VersionExtract {
currentValue?: string;
fileReplacePosition?: number;
Expand All @@ -79,12 +83,13 @@ function extractVersion({
versionSubContent: string;
}): VersionExtract {
if (isVersionPointer(version)) {
const parsedVersion = normalizeVersionPointer(version.ref);
// everything else is ignored
return extractLiteralVersion({
version: versions[version.ref],
version: versions[parsedVersion],
depStartIndex: versionStartIndex,
depSubContent: versionSubContent,
sectionKey: version.ref,
sectionKey: parsedVersion,
});
} else {
return extractLiteralVersion({
Expand Down Expand Up @@ -205,7 +210,7 @@ function extractDependency({
};
}
const versionRef = isVersionPointer(descriptor.version)
? descriptor.version.ref
? normalizeVersionPointer(descriptor.version.ref)
: null;
if (isArtifactDescriptor(descriptor)) {
const { group, name } = descriptor;
Expand Down Expand Up @@ -284,7 +289,7 @@ export function parseCatalog(
dependency.skipReason = skipReason;
}
if (isVersionPointer(version) && dependency.commitMessageTopic) {
dependency.groupName = version.ref;
dependency.groupName = normalizeVersionPointer(version.ref);
delete dependency.commitMessageTopic;
}

Expand Down

0 comments on commit e3e6de9

Please sign in to comment.