Skip to content
Permalink
Browse files
Use a different (empty) thread prefix for failed automerge PRs
Reviewed-by: ehelin
  • Loading branch information
rwestberg committed Mar 26, 2020
1 parent 4b702e7 commit c2bf15e60bbf6044a6d22d481133139bc8c5c6f4
Showing 5 changed files with 67 additions and 7 deletions.
@@ -494,11 +494,13 @@ public void run(Path scratchPath) {
message.add("Thanks,");
message.add("J. Duke");

fork.createPullRequest(prTarget,
toBranch.name(),
branchDesc,
title,
message);
var prFromFork = fork.createPullRequest(prTarget,
toBranch.name(),
branchDesc,
title,
message);
var prFromTarget = prTarget.pullRequest(prFromFork.id());
prFromTarget.addLabel("failed-auto-merge");
}
}
} catch (IOException e) {
@@ -184,6 +184,7 @@ void failingMergeTest(TestInfo testInfo) throws IOException {
assertEquals(1, pullRequests.size());
var pr = pullRequests.get(0);
assertEquals("Cannot automatically merge test:master to master", pr.title());
assertTrue(pr.labels().contains("failed-auto-merge"));
}
}

@@ -53,7 +53,7 @@ static ArchiveItem from(PullRequest pr, Repository localRepo, HostUserToEmailAut
return new ArchiveItem(null, "fc", created, updated, pr.author(), Map.of("PR-Head-Hash", head.hex(),
"PR-Base-Hash", base.hex(),
"PR-Thread-Prefix", threadPrefix),
() -> subjectPrefix + threadPrefix + ": " + pr.title(),
() -> subjectPrefix + threadPrefix + (threadPrefix.isEmpty() ? "" : ": ") + pr.title(),
() -> "",
() -> ArchiveMessages.composeConversation(pr, localRepo, base, head),
() -> {
@@ -112,7 +112,7 @@ static ArchiveItem from(PullRequest pr, Repository localRepo, HostUserToEmailAut
ZonedDateTime created, ZonedDateTime updated, Hash lastBase, Hash lastHead, Hash base,
Hash head, int index, ArchiveItem parent, String subjectPrefix, String threadPrefix) {
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: %s[Rev %02d] %s: %s", subjectPrefix, index, threadPrefix, pr.title()),
() -> String.format("Re: %s[Rev %02d] %s%s", subjectPrefix, index, threadPrefix + (threadPrefix.isEmpty() ? "" : ": "), pr.title()),
() -> "",
() -> {
if (lastBase.equals(base)) {
@@ -70,6 +70,8 @@ private List<ArchiveItem> generateArchiveItems(List<Email> sentEmails, Repositor
} else {
if (pr.state() != Issue.State.OPEN) {
threadPrefix = "FYI";
} else if (pr.labels().contains("failed-auto-merge")) {
threadPrefix = "";
}
}

@@ -423,6 +423,61 @@ void archiveIntegratedRetainPrefix(TestInfo testInfo) throws IOException {
}
}

@Test
void archiveFailedAutoMerge(TestInfo testInfo) throws IOException {
try (var credentials = new HostCredentials(testInfo);
var tempFolder = new TemporaryDirectory();
var archiveFolder = new TemporaryDirectory();
var webrevFolder = new TemporaryDirectory();
var listServer = new TestMailmanServer();
var webrevServer = new TestWebrevServer()) {
var author = credentials.getHostedRepository();
var archive = credentials.getHostedRepository();
var ignored = credentials.getHostedRepository();
var listAddress = EmailAddress.parse(listServer.createList("test"));
var censusBuilder = credentials.getCensusBuilder()
.addAuthor(author.forge().currentUser().id());
var from = EmailAddress.from("test", "test@test.mail");
var mlBot = MailingListBridgeBot.newBuilder()
.from(from)
.repo(author)
.archive(archive)
.censusRepo(censusBuilder.build())
.list(listAddress)
.ignoredUsers(Set.of(ignored.forge().currentUser().userName()))
.listArchive(listServer.getArchive())
.smtpServer(listServer.getSMTP())
.webrevStorageRepository(archive)
.webrevStorageRef("webrev")
.webrevStorageBase(Path.of("test"))
.webrevStorageBaseUri(webrevServer.uri())
.issueTracker(URIBuilder.base("http://issues.test/browse/").build())
.build();

// Populate the projects repository
var localRepo = CheckableRepository.init(tempFolder.path(), author.repositoryType());
var masterHash = localRepo.resolve("master").orElseThrow();
localRepo.push(masterHash, author.url(), "master", true);
localRepo.push(masterHash, archive.url(), "webrev", true);

// Make a change with a corresponding PR
var editHash = CheckableRepository.appendAndCommit(localRepo, "A simple change",
"Change msg\n\nWith several lines");
localRepo.push(editHash, author.url(), "edit", true);
var pr = credentials.createPullRequest(archive, "master", "edit", "Cannot automatically merge");
pr.setBody("This is an automated merge PR");
pr.addLabel("failed-auto-merge");

// Run an archive pass
TestBotRunner.runPeriodicItems(mlBot);
TestBotRunner.runPeriodicItems(mlBot);

// The archive should contain an entry
Repository.materialize(archiveFolder.path(), archive.url(), "master");
assertTrue(archiveContains(archiveFolder.path(), "Subject: Cannot automatically merge"));
}
}

@Test
void reviewComment(TestInfo testInfo) throws IOException {
try (var credentials = new HostCredentials(testInfo);

0 comments on commit c2bf15e

Please sign in to comment.