From 991b398c552f9277bda8afd122f03750be1ff768 Mon Sep 17 00:00:00 2001 From: Steve Riesenberg Date: Wed, 12 Jul 2023 14:58:56 -0500 Subject: [PATCH] Create release with full docs path Closes gh-13500 --- .../gradle/sagan/SaganCreateReleaseTask.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/buildSrc/src/main/java/org/springframework/gradle/sagan/SaganCreateReleaseTask.java b/buildSrc/src/main/java/org/springframework/gradle/sagan/SaganCreateReleaseTask.java index c4064407fe..55f4102d8b 100644 --- a/buildSrc/src/main/java/org/springframework/gradle/sagan/SaganCreateReleaseTask.java +++ b/buildSrc/src/main/java/org/springframework/gradle/sagan/SaganCreateReleaseTask.java @@ -16,6 +16,10 @@ package org.springframework.gradle.sagan; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.eclipse.core.runtime.Assert; import org.gradle.api.DefaultTask; import org.gradle.api.tasks.Input; import org.gradle.api.tasks.TaskAction; @@ -25,6 +29,8 @@ import org.springframework.gradle.github.user.User; public class SaganCreateReleaseTask extends DefaultTask { + private static final Pattern VERSION_PATTERN = Pattern.compile("^([0-9]+)\\.([0-9]+)\\.([0-9]+)(-.+)?$"); + @Input private String gitHubAccessToken; @Input @@ -44,9 +50,12 @@ public class SaganCreateReleaseTask extends DefaultTask { // Antora reference docs URLs for snapshots do not contain -SNAPSHOT String referenceDocUrl = this.referenceDocUrl; if (this.version.endsWith("-SNAPSHOT")) { - referenceDocUrl = this.referenceDocUrl - .replace("{version}", this.version) - .replace("-SNAPSHOT", ""); + Matcher versionMatcher = VERSION_PATTERN.matcher(this.version); + Assert.isTrue(versionMatcher.matches(), "Version " + this.version + " does not match expected pattern"); + var majorVersion = versionMatcher.group(1); + var minorVersion = versionMatcher.group(2); + var majorMinorVersion = "%s.%s-SNAPSHOT".formatted(majorVersion, minorVersion); + referenceDocUrl = this.referenceDocUrl.replace("{version}", majorMinorVersion); } SaganApi sagan = new SaganApi(user.getLogin(), this.gitHubAccessToken);