Skip to content
Permalink
Browse files
Refactor notifier bot constructors
Reviewed-by: ehelin
  • Loading branch information
rwestberg committed Feb 17, 2020
1 parent a0b9185 commit 2ef003b5d6be929ecdd81c9416857d08aed7870d
@@ -202,7 +202,7 @@ private String subjectPrefix() {
var branchName = pr.targetRef();
var repoName = Path.of(pr.repository().name()).getFileName().toString();
var useBranchInSubject = bot.branchInSubject().matcher(branchName).matches();
var useRepoInSubject = bot.repoInSubject().matcher(repoName).matches();
var useRepoInSubject = bot.repoInSubject();

if (useBranchInSubject || useRepoInSubject) {
ret.append("[");
@@ -53,7 +53,7 @@ public class MailingListBridgeBot implements Bot {
private final PullRequestUpdateCache updateCache;
private final Duration sendInterval;
private final Duration cooldown;
private final Pattern repoInSubject;
private final boolean repoInSubject;
private final Pattern branchInSubject;
private final Path seedStorage;
private final CooldownQuarantine cooldownQuarantine;
@@ -69,7 +69,7 @@ public class MailingListBridgeBot implements Bot {
HostedRepository webrevStorageRepository, String webrevStorageRef,
Path webrevStorageBase, URI webrevStorageBaseUri, Set<String> readyLabels,
Map<String, Pattern> readyComments, URI issueTracker, Map<String, String> headers,
Duration sendInterval, Duration cooldown, Pattern repoInSubject, Pattern branchInSubject,
Duration sendInterval, Duration cooldown, boolean repoInSubject, Pattern branchInSubject,
Path seedStorage) {
emailAddress = from;
codeRepo = repo;
@@ -174,7 +174,7 @@ URI issueTracker() {
return issueTracker;
}

Pattern repoInSubject() {
boolean repoInSubject() {
return repoInSubject;
}

@@ -53,8 +53,8 @@ public class MailingListBridgeBotBuilder {
private Map<String, String> headers = Map.of();
private Duration sendInterval = Duration.ZERO;
private Duration cooldown = Duration.ZERO;
private Pattern repoInSubject = Pattern.compile("a^"); // Does not match anything
private Pattern branchInSubject = Pattern.compile("a^");
private boolean repoInSubject = false;
private Pattern branchInSubject = Pattern.compile("a^"); // Does not match anything
private Path seedStorage = null;

MailingListBridgeBotBuilder() {
@@ -165,7 +165,7 @@ public MailingListBridgeBotBuilder cooldown(Duration cooldown) {
return this;
}

public MailingListBridgeBotBuilder repoInSubject(Pattern repoInSubject) {
public MailingListBridgeBotBuilder repoInSubject(boolean repoInSubject) {
this.repoInSubject = repoInSubject;
return this;
}
@@ -114,7 +114,7 @@ public List<Bot> create(BotConfiguration configuration) {
.seedStorage(configuration.storageFolder().resolve("seeds"));

if (repoConfig.contains("reponame")) {
botBuilder.repoInSubject(Pattern.compile(repoConfig.get("reponame").asString()));
botBuilder.repoInSubject(repoConfig.get("reponame").asBoolean());
}
if (repoConfig.contains("branchname")) {
botBuilder.branchInSubject(Pattern.compile(repoConfig.get("branchname").asString()));
@@ -1767,7 +1767,7 @@ void repoPrefix(TestInfo testInfo) throws IOException {
.webrevStorageBase(Path.of("test"))
.webrevStorageBaseUri(webrevServer.uri())
.issueTracker(URIBuilder.base("http://issues.test/browse/").build())
.repoInSubject(Pattern.compile(".*"))
.repoInSubject(true)
.build();

// Populate the projects repository
@@ -1824,7 +1824,7 @@ void repoAndBranchPrefix(TestInfo testInfo) throws IOException {
.webrevStorageBase(Path.of("test"))
.webrevStorageBaseUri(webrevServer.uri())
.issueTracker(URIBuilder.base("http://issues.test/browse/").build())
.repoInSubject(Pattern.compile(".*"))
.repoInSubject(true)
.branchInSubject(Pattern.compile(".*"))
.build();

@@ -62,6 +62,10 @@ public class IssueUpdater implements RepositoryUpdateConsumer, PullRequestUpdate
this.prOnly = prOnly;
}

static IssueUpdaterBuilder newBuilder() {
return new IssueUpdaterBuilder();
}

private final static Set<String> primaryTypes = Set.of("Bug", "New Feature", "Enhancement", "Task", "Sub-task");

private boolean isPrimaryIssue(Issue issue) {
@@ -0,0 +1,89 @@
/*
* Copyright (c) 2020, 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.bots.notify;

import org.openjdk.skara.issuetracker.IssueProject;

import java.net.URI;
import java.util.Map;

public class IssueUpdaterBuilder {
private IssueProject issueProject;
private boolean reviewLink = true;
private URI reviewIcon = null;
private boolean commitLink = true;
private URI commitIcon = null;
private boolean setFixVersion = false;
private Map<String, String> fixVersions = null;
private boolean prOnly = false;

public IssueUpdaterBuilder issueProject(IssueProject issueProject) {
this.issueProject = issueProject;
return this;
}

public IssueUpdaterBuilder reviewLink(boolean reviewLink) {
this.reviewLink = reviewLink;
return this;
}

public IssueUpdaterBuilder reviewIcon(URI reviewIcon) {
this.reviewIcon = reviewIcon;
return this;
}

public IssueUpdaterBuilder commitLink(boolean commitLink) {
this.commitLink = commitLink;
return this;
}

public IssueUpdaterBuilder commitIcon(URI commitIcon) {
this.commitIcon = commitIcon;
return this;
}

public IssueUpdaterBuilder setFixVersion(boolean setFixVersion) {
if (setFixVersion && prOnly) {
throw new IllegalArgumentException("Cannot combine setFixVersion with prOnly");
}
this.setFixVersion = setFixVersion;
return this;
}

public IssueUpdaterBuilder fixVersions(Map<String, String> fixVersions) {
this.fixVersions = fixVersions;
return this;
}

public IssueUpdaterBuilder prOnly(boolean prOnly) {
if (prOnly && setFixVersion) {
throw new IllegalArgumentException("Cannot combine prOnly with setFixVersion");
}
this.prOnly = prOnly;
return this;
}

public IssueUpdater build() {
return new IssueUpdater(issueProject, reviewLink, reviewIcon, commitLink, commitIcon, setFixVersion, fixVersions, prOnly);
}
}
@@ -72,6 +72,10 @@ enum Mode {
this.allowedAuthorDomains = allowedAuthorDomains;
}

static MailingListUpdaterBuilder newBuilder() {
return new MailingListUpdaterBuilder();
}

private String tagAnnotationToText(HostedRepository repository, Tag.Annotated annotation) {
var writer = new StringWriter();
var printer = new PrintWriter(writer);
@@ -0,0 +1,103 @@
/*
* Copyright (c) 2020, 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.bots.notify;

import org.openjdk.skara.email.EmailAddress;
import org.openjdk.skara.mailinglist.MailingList;

import java.util.Map;
import java.util.regex.Pattern;

public class MailingListUpdaterBuilder {
private MailingList list;
private EmailAddress recipient;
private EmailAddress sender;
private EmailAddress author = null;
private boolean includeBranch = false;
private boolean reportNewTags = true;
private boolean reportNewBranches = true;
private boolean reportNewBuilds = true;
private MailingListUpdater.Mode mode = MailingListUpdater.Mode.ALL;
private Map<String, String> headers = Map.of();
private Pattern allowedAuthorDomains = Pattern.compile(".*");

public MailingListUpdaterBuilder list(MailingList list) {
this.list = list;
return this;
}

public MailingListUpdaterBuilder recipient(EmailAddress recipient) {
this.recipient = recipient;
return this;
}

public MailingListUpdaterBuilder sender(EmailAddress sender) {
this.sender = sender;
return this;
}

public MailingListUpdaterBuilder author(EmailAddress author) {
this.author = author;
return this;
}

public MailingListUpdaterBuilder includeBranch(boolean includeBranch) {
this.includeBranch = includeBranch;
return this;
}

public MailingListUpdaterBuilder reportNewTags(boolean reportNewTags) {
this.reportNewTags = reportNewTags;
return this;
}

public MailingListUpdaterBuilder reportNewBranches(boolean reportNewBranches) {
this.reportNewBranches = reportNewBranches;
return this;
}

public MailingListUpdaterBuilder reportNewBuilds(boolean reportNewBuilds) {
this.reportNewBuilds = reportNewBuilds;
return this;
}

public MailingListUpdaterBuilder mode(MailingListUpdater.Mode mode) {
this.mode = mode;
return this;
}

public MailingListUpdaterBuilder headers(Map<String, String> headers) {
this.headers = headers;
return this;
}

public MailingListUpdaterBuilder allowedAuthorDomains(Pattern allowedAuthorDomains) {
this.allowedAuthorDomains = allowedAuthorDomains;
return this;
}

public MailingListUpdater build() {
return new MailingListUpdater(list, recipient, sender, author, includeBranch, reportNewTags, reportNewBranches,
reportNewBuilds, mode, headers, allowedAuthorDomains);
}
}
@@ -63,6 +63,10 @@ class NotifyBot implements Bot {
this.readyComments = readyComments;
}

static NotifyBotBuilder newBuilder() {
return new NotifyBotBuilder();
}

private boolean isReady(PullRequest pr) {
var labels = new HashSet<>(pr.labels());
for (var readyLabel : readyLabels) {

0 comments on commit 2ef003b

Please sign in to comment.