Skip to content
Permalink
Browse files
jcheck: allow pattern for merge commit messages
Reviewed-by: rwestberg
  • Loading branch information
edvbld committed Mar 5, 2020
1 parent 07f98f6 commit 0ef146d234a4f736defe084fbbf352292b49a14d
Showing 2 changed files with 16 additions and 3 deletions.
@@ -27,6 +27,7 @@

import java.util.Iterator;
import java.util.logging.Logger;
import java.util.regex.Pattern;

public class MergeMessageCheck extends CommitCheck {
private final Logger log = Logger.getLogger("org.openjdk.skara.jcheck.merge");
@@ -36,11 +37,11 @@ Iterator<Issue> check(Commit commit, CommitMessage message, JCheckConfiguration
return iterator();
}

var expected = conf.checks().merge().message();
if (commit.message().size() != 1 || !commit.message().get(0).equals(expected)) {
var pattern = Pattern.compile(conf.checks().merge().message());
if (commit.message().size() != 1 || !pattern.matcher(commit.message().get(0)).matches()) {
var metadata = CommitIssue.metadata(commit, message, conf, this);
log.finer("issue: wrong merge message");
return iterator(new MergeMessageIssue(expected, metadata));
return iterator(new MergeMessageIssue(pattern.toString(), metadata));
}

return iterator();
@@ -103,4 +103,16 @@ void multiLineMessageShouldFail() throws IOException {
assertEquals(1, issues.size());
assertTrue(issues.get(0) instanceof MergeMessageIssue);
}

@Test
void usingRegexShouldWork() throws IOException {
var commit = commit(List.of("Merge 'feature' into 'master'"));
var message = message(commit);
var check = new MergeMessageCheck();
var conf = new ArrayList<>(CONFIGURATION);
conf.set(conf.size() - 1, "message = Merge \\'[a-z]+\\' into \\'[a-z]+\\'");
var issues = toList(check.check(commit, message, JCheckConfiguration.parse(conf)));

assertEquals(List.of(), issues);
}
}

0 comments on commit 0ef146d

Please sign in to comment.