Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

263: Add target repo and branch to subject of RFR email #431

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -39,9 +39,9 @@ private ArchiveItem(ArchiveItem parent, String id, ZonedDateTime created, ZonedD

static ArchiveItem from(PullRequest pr, Repository localRepo, URI issueTracker, String issuePrefix,
WebrevStorage.WebrevGenerator webrevGenerator, WebrevNotification webrevNotification,
ZonedDateTime created, ZonedDateTime updated, Hash base, Hash head) {
ZonedDateTime created, ZonedDateTime updated, Hash base, Hash head, String subjectPrefix) {
return new ArchiveItem(null, "fc", created, updated, pr.author(), Map.of("PR-Head-Hash", head.hex(), "PR-Base-Hash", base.hex()),
() -> "RFR: " + pr.title(),
() -> subjectPrefix + "RFR: " + pr.title(),
() -> "",
() -> ArchiveMessages.composeConversation(pr, base, head),
() -> {
@@ -53,9 +53,9 @@ static ArchiveItem from(PullRequest pr, Repository localRepo, URI issueTracker,

static ArchiveItem from(PullRequest pr, Repository localRepo, WebrevStorage.WebrevGenerator webrevGenerator,
WebrevNotification webrevNotification, ZonedDateTime created, ZonedDateTime updated,
Hash lastBase, Hash lastHead, Hash base, Hash head, int index, ArchiveItem parent) {
Hash lastBase, Hash lastHead, Hash base, Hash head, int index, ArchiveItem parent, String subjectPrefix) {
return new ArchiveItem(parent,"ha" + head.hex(), created, updated, pr.author(), Map.of("PR-Head-Hash", head.hex(), "PR-Base-Hash", base.hex()),
() -> String.format("Re: [Rev %02d] RFR: %s", index, pr.title()),
() -> String.format("Re: %s[Rev %02d] RFR: %s", subjectPrefix, index, pr.title()),
() -> "",
() -> ArchiveMessages.composeRevision(pr, localRepo, base, head, lastBase, lastHead),
() -> {
@@ -197,6 +197,29 @@ private String getAuthorRole(CensusInstance censusInstance, HostUser originalAut
return "no project role";
}

private String subjectPrefix() {
var ret = new StringBuilder();
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();

if (useBranchInSubject || useRepoInSubject) {
ret.append("[");
if (useRepoInSubject) {
ret.append(repoName);
if (useBranchInSubject) {
ret.append(":");
}
}
if (useBranchInSubject) {
ret.append(branchName);
}
ret.append("] ");
}
return ret.toString();
}

@Override
public void run(Path scratchPath) {
var path = scratchPath.resolve("mlbridge");
@@ -297,7 +320,9 @@ public void run(Path scratchPath) {
user -> getAuthorAddress(census, user),
user -> getAuthorUserName(census, user),
user -> getAuthorRole(census, user),
retryConsumer);
subjectPrefix(),
retryConsumer
);
if (newMails.isEmpty()) {
return;
}
@@ -52,6 +52,8 @@ public class MailingListBridgeBot implements Bot {
private final PullRequestUpdateCache updateCache;
private final Duration sendInterval;
private final Duration cooldown;
private final Pattern repoInSubject;
private final Pattern branchInSubject;
private final Path seedStorage;
private final CooldownQuarantine cooldownQuarantine;

@@ -61,7 +63,8 @@ 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, Path seedStorage) {
Duration sendInterval, Duration cooldown, Pattern repoInSubject, Pattern branchInSubject,
Path seedStorage) {
emailAddress = from;
codeRepo = repo;
archiveRepo = archive;
@@ -79,6 +82,8 @@ public class MailingListBridgeBot implements Bot {
this.issueTracker = issueTracker;
this.sendInterval = sendInterval;
this.cooldown = cooldown;
this.repoInSubject = repoInSubject;
this.branchInSubject = branchInSubject;
this.seedStorage = seedStorage;

webrevStorage = new WebrevStorage(webrevStorageRepository, webrevStorageRef, webrevStorageBase,
@@ -163,6 +168,14 @@ URI issueTracker() {
return issueTracker;
}

Pattern repoInSubject() {
return repoInSubject;
}

Pattern branchInSubject() {
return branchInSubject;
}

Optional<Path> seedStorage() {
return Optional.ofNullable(seedStorage);
}
@@ -53,6 +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 Path seedStorage = null;

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

public MailingListBridgeBotBuilder repoInSubject(Pattern repoInSubject) {
this.repoInSubject = repoInSubject;
return this;
}

public MailingListBridgeBotBuilder branchInSubject(Pattern branchInSubject) {
this.branchInSubject = branchInSubject;
return this;
}

public MailingListBridgeBotBuilder seedStorage(Path seedStorage) {
this.seedStorage = seedStorage;
return this;
@@ -173,6 +185,6 @@ public MailingListBridgeBot build() {
ignoredUsers, ignoredComments, listArchive, smtpServer,
webrevStorageRepository, webrevStorageRef, webrevStorageBase, webrevStorageBaseUri,
readyLabels, readyComments, issueTracker, headers, sendInterval, cooldown,
seedStorage);
repoInSubject, branchInSubject, seedStorage);
}
}
@@ -90,30 +90,36 @@ public List<Bot> create(BotConfiguration configuration) {

var list = EmailAddress.parse(repoConfig.get("list").asString());
var folder = repoConfig.contains("folder") ? repoConfig.get("folder").asString() : configuration.repositoryName(repo);
var bot = MailingListBridgeBot.newBuilder().from(from)
.repo(configuration.repository(repo))
.archive(archiveRepo)
.archiveRef(archiveRef)
.censusRepo(censusRepo)
.censusRef(censusRef)
.list(list)
.ignoredUsers(ignoredUsers)
.ignoredComments(ignoredComments)
.listArchive(listArchive)
.smtpServer(listSmtp)
.webrevStorageRepository(webrevRepo)
.webrevStorageRef(webrevRef)
.webrevStorageBase(Path.of(folder))
.webrevStorageBaseUri(URIBuilder.base(webrevWeb).build())
.readyLabels(readyLabels)
.readyComments(readyComments)
.issueTracker(issueTracker)
.headers(headers)
.sendInterval(interval)
.cooldown(cooldown)
.seedStorage(configuration.storageFolder().resolve("seeds"))
.build();
ret.add(bot);
var botBuilder = MailingListBridgeBot.newBuilder().from(from)
.repo(configuration.repository(repo))
.archive(archiveRepo)
.archiveRef(archiveRef)
.censusRepo(censusRepo)
.censusRef(censusRef)
.list(list)
.ignoredUsers(ignoredUsers)
.ignoredComments(ignoredComments)
.listArchive(listArchive)
.smtpServer(listSmtp)
.webrevStorageRepository(webrevRepo)
.webrevStorageRef(webrevRef)
.webrevStorageBase(Path.of(folder))
.webrevStorageBaseUri(URIBuilder.base(webrevWeb).build())
.readyLabels(readyLabels)
.readyComments(readyComments)
.issueTracker(issueTracker)
.headers(headers)
.sendInterval(interval)
.cooldown(cooldown)
.seedStorage(configuration.storageFolder().resolve("seeds"));

if (repoConfig.contains("reponame")) {
botBuilder.repoInSubject(Pattern.compile(repoConfig.get("reponame").asString()));
}
if (repoConfig.contains("branchname")) {
botBuilder.branchInSubject(Pattern.compile(repoConfig.get("branchname").asString()));
}
ret.add(botBuilder.build());

allListNames.add(list);
allRepositories.add(configuration.repository(repo));
@@ -55,7 +55,7 @@ private Optional<ArchiveItem> findPreviousReplyBy(List<ArchiveItem> generated, H
.findAny();
}

private List<ArchiveItem> generateArchiveItems(List<Email> sentEmails, Repository localRepo, URI issueTracker, String issuePrefix, HostUserToEmailAuthor hostUserToEmailAuthor, HostUserToUserName hostUserToUserName, HostUserToRole hostUserToRole, WebrevStorage.WebrevGenerator webrevGenerator, WebrevNotification webrevNotification) {
private List<ArchiveItem> generateArchiveItems(List<Email> sentEmails, Repository localRepo, URI issueTracker, String issuePrefix, HostUserToEmailAuthor hostUserToEmailAuthor, HostUserToUserName hostUserToUserName, HostUserToRole hostUserToRole, WebrevStorage.WebrevGenerator webrevGenerator, WebrevNotification webrevNotification, String subjectPrefix) {
var generated = new ArrayList<ArchiveItem>();
Hash lastBase = null;
Hash lastHead = null;
@@ -69,10 +69,10 @@ private List<ArchiveItem> generateArchiveItems(List<Email> sentEmails, Repositor
var created = email.date();

if (generated.isEmpty()) {
var first = ArchiveItem.from(pr, localRepo, issueTracker, issuePrefix, webrevGenerator, webrevNotification, pr.createdAt(), pr.updatedAt(), curBase, curHead);
var first = ArchiveItem.from(pr, localRepo, issueTracker, issuePrefix, webrevGenerator, webrevNotification, pr.createdAt(), pr.updatedAt(), curBase, curHead, subjectPrefix);
generated.add(first);
} else {
var revision = ArchiveItem.from(pr, localRepo, webrevGenerator, webrevNotification, created, created, lastBase, lastHead, curBase, curHead, ++revisionIndex, generated.get(0));
var revision = ArchiveItem.from(pr, localRepo, webrevGenerator, webrevNotification, created, created, lastBase, lastHead, curBase, curHead, ++revisionIndex, generated.get(0), subjectPrefix);
generated.add(revision);
}

@@ -84,10 +84,10 @@ private List<ArchiveItem> generateArchiveItems(List<Email> sentEmails, Repositor
// Check if we're at a revision not previously reported
if (!base.equals(lastBase) || !head.equals(lastHead)) {
if (generated.isEmpty()) {
var first = ArchiveItem.from(pr, localRepo, issueTracker, issuePrefix, webrevGenerator, webrevNotification, pr.createdAt(), pr.updatedAt(), base, head);
var first = ArchiveItem.from(pr, localRepo, issueTracker, issuePrefix, webrevGenerator, webrevNotification, pr.createdAt(), pr.updatedAt(), base, head, subjectPrefix);
generated.add(first);
} else {
var revision = ArchiveItem.from(pr, localRepo, webrevGenerator, webrevNotification, pr.updatedAt(), pr.updatedAt(), lastBase, lastHead, base, head, ++revisionIndex, generated.get(0));
var revision = ArchiveItem.from(pr, localRepo, webrevGenerator, webrevNotification, pr.updatedAt(), pr.updatedAt(), lastBase, lastHead, base, head, ++revisionIndex, generated.get(0), subjectPrefix);
generated.add(revision);
}
}
@@ -178,9 +178,9 @@ private String getStableMessageId(EmailAddress uniqueMessageId) {
return uniqueMessageId.localPart().split("\\.")[0];
}

List<Email> generateNewEmails(List<Email> sentEmails, Duration cooldown, Repository localRepo, URI issueTracker, String issuePrefix, WebrevStorage.WebrevGenerator webrevGenerator, WebrevNotification webrevNotification, HostUserToEmailAuthor hostUserToEmailAuthor, HostUserToUserName hostUserToUserName, HostUserToRole hostUserToRole, Consumer<Instant> retryConsumer) {
List<Email> generateNewEmails(List<Email> sentEmails, Duration cooldown, Repository localRepo, URI issueTracker, String issuePrefix, WebrevStorage.WebrevGenerator webrevGenerator, WebrevNotification webrevNotification, HostUserToEmailAuthor hostUserToEmailAuthor, HostUserToUserName hostUserToUserName, HostUserToRole hostUserToRole, String subjectPrefix, Consumer<Instant> retryConsumer) {
var ret = new ArrayList<Email>();
var allItems = generateArchiveItems(sentEmails, localRepo, issueTracker, issuePrefix, hostUserToEmailAuthor, hostUserToUserName, hostUserToRole, webrevGenerator, webrevNotification);
var allItems = generateArchiveItems(sentEmails, localRepo, issueTracker, issuePrefix, hostUserToEmailAuthor, hostUserToUserName, hostUserToRole, webrevGenerator, webrevNotification, subjectPrefix);
var sentItemIds = sentItemIds(sentEmails);
var unsentItems = allItems.stream()
.filter(item -> !sentItemIds.contains(getStableMessageId(getUniqueMessageId(item.id()))))