[changelog] Search for previous tag when appropriate. Relates to
@@ -32,7 +32,6 @@ import org.jreleaser.model.releaser.spi.User;
import org.jreleaser.util.CollectionUtils;
import org.jreleaser.util.JavaModuleVersion;
import org.jreleaser.util.JavaRuntimeVersion;
-import org.jreleaser.util.StringUtils;
import org.jreleaser.util.Version;
import java.io.IOException;
@@ -204,12 +203,26 @@ public class ChangelogGenerator {
.filter(ref -> extractTagName(ref).equals(effectiveTagName))
.findFirst();
+ Optional<Ref> previousTag = Optional.empty();
+ String previousTagName = gitService.getConfiguredPreviousTagName();
+ if (isNotBlank(previousTagName)) {
+ context.getLogger().debug("looking for previous tag '{}'", previousTagName);
+ previousTag = tags.stream()
+ .filter(ref -> extractTagName(ref).equals(previousTagName))
+ .findFirst();
+ }
+
// tag: early-access
if (context.getModel().getProject().isSnapshot()) {
Project.Snapshot snapshot = context.getModel().getProject().getSnapshot();
String effectiveLabel = snapshot.getEffectiveLabel();
if (effectiveLabel.equals(effectiveTagName)) {
if (!tag.isPresent() || snapshot.isFullChangelog()) {
+ if (previousTag.isPresent()) {
+ tag = previousTag;
+ }
+
+ if (!tag.isPresent()) {
context.getLogger().debug("looking for tags that match '{}', excluding '{}'", tagPattern, effectiveTagName);
tag = tags.stream()
@@ -217,6 +230,7 @@ public class ChangelogGenerator {
.filter(ref -> extractTagName(ref).matches(tagPattern))
.findFirst();
}
+ }
if (tag.isPresent()) {
context.getLogger().debug("found tag {}", extractTagName(tag.get()));
@@ -230,12 +244,17 @@ public class ChangelogGenerator {
// tag: latest
if (!tag.isPresent()) {
- context.getLogger().debug("looking for tags that match '{}', excluding '{}'", tagPattern, effectiveTagName);
+ if (previousTag.isPresent()) {
+ tag = previousTag;
+ }
+ if (!tag.isPresent()) {
+ context.getLogger().debug("looking for tags that match '{}', excluding '{}'", tagPattern, effectiveTagName);
tag = tags.stream()
.filter(ref -> !extractTagName(ref).equals(effectiveTagName))
.filter(ref -> extractTagName(ref).matches(tagPattern))
.findFirst();
+ }
if (tag.isPresent()) {
context.getLogger().debug("found tag {}", extractTagName(tag.get()));
@@ -247,18 +266,9 @@ public class ChangelogGenerator {
}
// tag: somewhere in the middle
- context.getLogger().debug("looking for a tag before '{}' that matches '{}'", effectiveTagName, tagPattern);
-
Comparable currentVersion = version(context, tag.get(), versionPattern);
-
- String previousTagName = gitService.getConfiguredPreviousTagName();
- Optional<Ref> previousTag;
-
- if (StringUtils.isNotBlank(previousTagName)) {
- previousTag = tags.stream()
- .filter(ref -> extractTagName(ref).equals(previousTagName))
- .findFirst();
- } else {
+ if (!previousTag.isPresent()) {
+ context.getLogger().debug("looking for a tag before '{}' that matches '{}'", effectiveTagName, tagPattern);
previousTag = tags.stream()
.filter(ref -> extractTagName(ref).matches(tagPattern))
.filter(ref -> lessThan(version(context, ref, versionPattern), currentVersion))
@@ -335,7 +345,7 @@ public class ChangelogGenerator {
}
changes.append(categories.get(UNCATEGORIZED).stream()
- .map(c -> applyTemplate(changelog.getChange(), c.asContext(changelog.isLinks(), commitsUrl)))
+ .map(c -> applyTemplate(changelog.getFormat(), c.asContext(changelog.isLinks(), commitsUrl)))
.collect(Collectors.joining(lineSeparator)))
.append(lineSeparator)
.append(lineSeparator());
