Skip to content
Permalink
Browse files

80: Allow valid bug ID format to be configurable

Reviewed-by: rwestberg
  • Loading branch information
kevinrushforth authored and Robin Westberg committed Sep 26, 2019
1 parent 76d0158 commit 527967e081555d3a0ef602abd53398874ac40feb
@@ -35,27 +35,31 @@
WhitespaceConfiguration.DEFAULT,
ReviewersConfiguration.DEFAULT,
MergeConfiguration.DEFAULT,
CommitterConfiguration.DEFAULT);
CommitterConfiguration.DEFAULT,
IssuesConfiguration.DEFAULT);

private final List<String> error;
private final List<String> warning;
private final WhitespaceConfiguration whitespace;
private final ReviewersConfiguration reviewers;
private final MergeConfiguration merge;
private final CommitterConfiguration committer;
private final IssuesConfiguration issues;

ChecksConfiguration(List<String> error,
List<String> warning,
WhitespaceConfiguration whitespace,
ReviewersConfiguration reviewers,
MergeConfiguration merge,
CommitterConfiguration committer) {
CommitterConfiguration committer,
IssuesConfiguration issues) {
this.error = error;
this.warning = warning;
this.whitespace = whitespace;
this.reviewers = reviewers;
this.merge = merge;
this.committer = committer;
this.issues = issues;
}

public List<String> error() {
@@ -100,6 +104,10 @@ public CommitterConfiguration committer() {
return committer;
}

public IssuesConfiguration issues() {
return issues;
}

static String name() {
return "checks";
}
@@ -116,7 +124,8 @@ static ChecksConfiguration parse(Section s) {
var reviewers = ReviewersConfiguration.parse(s.subsection(ReviewersConfiguration.name()));
var merge = MergeConfiguration.parse(s.subsection(MergeConfiguration.name()));
var committer = CommitterConfiguration.parse(s.subsection(CommitterConfiguration.name()));
var issues = IssuesConfiguration.parse(s.subsection(IssuesConfiguration.name()));

return new ChecksConfiguration(error, warning, whitespace, reviewers, merge, committer);
return new ChecksConfiguration(error, warning, whitespace, reviewers, merge, committer, issues);
}
}
@@ -27,6 +27,7 @@

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

public class IssuesCheck extends CommitCheck {
private final Logger log = Logger.getLogger("org.openjdk.skara.jcheck.issues");
@@ -42,12 +43,19 @@
return iterator();
}

var metadata = CommitIssue.metadata(commit, message, conf, this);
if (commit.message().isEmpty() || message.issues().isEmpty()) {
var metadata = CommitIssue.metadata(commit, message, conf, this);
log.finer("isuse: no reference to a JBS issue");
log.finer("issue: no reference to a JBS issue");
return iterator(new IssuesIssue(metadata));
}

var pattern = Pattern.compile(conf.checks().issues().pattern());
for (var issue : message.issues()) {
if (!pattern.matcher(issue.toString()).matches()) {
return iterator(new IssuesIssue(metadata));
}
}

return iterator();
}

@@ -0,0 +1,57 @@
/*
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package org.openjdk.skara.jcheck;

import org.openjdk.skara.ini.Section;

import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

public class IssuesConfiguration {
static final IssuesConfiguration DEFAULT =
new IssuesConfiguration("^(([A-Z][A-Z0-9]+-)?[0-9]+): (\\S.*)$");

private final String pattern;

IssuesConfiguration(String pattern) {
this.pattern = pattern;
}

public String pattern() {
return pattern;
}

static String name() {
return "issues";
}

static IssuesConfiguration parse(Section s) {
if (s == null) {
return DEFAULT;
}

var pattern = s.get("pattern", DEFAULT.pattern());
return new IssuesConfiguration(pattern);
}
}
@@ -125,6 +125,9 @@ private static INI convert(INI old) {
config.add("[checks \"committer\"]");
config.add("role=contributor");

config.add("[checks \"issues\"]");
config.add("pattern=^([124-8][0-9]{6}): (\\S.*)$");

return INI.parse(config);
}

0 comments on commit 527967e

Please sign in to comment.
You can’t perform that action at this time.