Merge branch '5.7.x' into 5.8.x

This commit is contained in:
Steve Riesenberg 2023-07-12 15:52:55 -05:00
commit a642fdb004
No known key found for this signature in database
GPG Key ID: 5F311AB48A55D521
1 changed files with 12 additions and 3 deletions

View File

@ -16,6 +16,10 @@
package org.springframework.gradle.sagan; 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.DefaultTask;
import org.gradle.api.tasks.Input; import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.TaskAction; import org.gradle.api.tasks.TaskAction;
@ -25,6 +29,8 @@ import org.springframework.gradle.github.user.User;
public class SaganCreateReleaseTask extends DefaultTask { public class SaganCreateReleaseTask extends DefaultTask {
private static final Pattern VERSION_PATTERN = Pattern.compile("^([0-9]+)\\.([0-9]+)\\.([0-9]+)(-.+)?$");
@Input @Input
private String gitHubAccessToken; private String gitHubAccessToken;
@Input @Input
@ -44,9 +50,12 @@ public class SaganCreateReleaseTask extends DefaultTask {
// Antora reference docs URLs for snapshots do not contain -SNAPSHOT // Antora reference docs URLs for snapshots do not contain -SNAPSHOT
String referenceDocUrl = this.referenceDocUrl; String referenceDocUrl = this.referenceDocUrl;
if (this.version.endsWith("-SNAPSHOT")) { if (this.version.endsWith("-SNAPSHOT")) {
referenceDocUrl = this.referenceDocUrl Matcher versionMatcher = VERSION_PATTERN.matcher(this.version);
.replace("{version}", this.version) Assert.isTrue(versionMatcher.matches(), "Version " + this.version + " does not match expected pattern");
.replace("-SNAPSHOT", ""); 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); SaganApi sagan = new SaganApi(user.getLogin(), this.gitHubAccessToken);