From 704ca63f5a8d329efc86e6a1eef414ebf4d80b43 Mon Sep 17 00:00:00 2001 From: Andres Almiray Date: Mon, 4 Oct 2021 17:45:07 +0200 Subject: [PATCH] [changelog] accept regex: prefix in labeler's label. Resolves #386 --- .../jreleaser/sdk/git/ChangelogGenerator.java | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/sdks/git-sdk/src/main/java/org/jreleaser/sdk/git/ChangelogGenerator.java b/sdks/git-sdk/src/main/java/org/jreleaser/sdk/git/ChangelogGenerator.java index e5c4d7d9..c23ddb61 100644 --- a/sdks/git-sdk/src/main/java/org/jreleaser/sdk/git/ChangelogGenerator.java +++ b/sdks/git-sdk/src/main/java/org/jreleaser/sdk/git/ChangelogGenerator.java @@ -67,6 +67,7 @@ import static org.jreleaser.util.StringUtils.toSafeRegexPattern; */ public class ChangelogGenerator { private static final String UNCATEGORIZED = "<>"; + private static final String REGEX_PREFIX = "regex:"; public static String generate(JReleaserContext context) throws IOException { if (!context.getModel().getRelease().getGitService().getChangelog().isEnabled()) { @@ -413,13 +414,25 @@ public class ChangelogGenerator { private static void applyLabels(Commit commit, Set labelers) { for (Changelog.Labeler labeler : labelers) { if (isNotBlank(labeler.getTitle())) { - if (commit.title.contains(labeler.getTitle()) || commit.title.matches(toSafeRegexPattern(labeler.getTitle()))) { - commit.labels.add(labeler.getLabel()); + if (labeler.getTitle().startsWith(REGEX_PREFIX)) { + if (commit.title.matches(labeler.getTitle().substring(REGEX_PREFIX.length()))) { + commit.labels.add(labeler.getLabel()); + } + } else { + if (commit.title.contains(labeler.getTitle()) || commit.title.matches(toSafeRegexPattern(labeler.getTitle()))) { + commit.labels.add(labeler.getLabel()); + } } } if (isNotBlank(labeler.getBody())) { - if (commit.body.contains(labeler.getBody()) || commit.body.matches(toSafeRegexPattern(labeler.getBody()))) { - commit.labels.add(labeler.getLabel()); + if (labeler.getTitle().startsWith(REGEX_PREFIX)) { + if (commit.body.matches(labeler.getBody().substring(REGEX_PREFIX.length()))) { + commit.labels.add(labeler.getLabel()); + } + } else { + if (commit.body.contains(labeler.getBody()) || commit.body.matches(toSafeRegexPattern(labeler.getBody()))) { + commit.labels.add(labeler.getLabel()); + } } } }