Skip to content

Commit

Permalink
reuse instance
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaosongzs committed Oct 12, 2023
1 parent f850eff commit df3d930
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ class ArchiveWorkItem implements WorkItem {
private final Consumer<RuntimeException> exceptionConsumer;
private final Consumer<Instant> retryConsumer;
private final Logger log = Logger.getLogger("org.openjdk.skara.bots.mlbridge");
private Repository jsonLocalStorage;
private Repository htmlLocalStorage;

ArchiveWorkItem(PullRequest pr, MailingListBridgeBot bot, Consumer<RuntimeException> exceptionConsumer, Consumer<Instant> retryConsumer) {
this.pr = pr;
Expand Down Expand Up @@ -398,7 +400,15 @@ public Collection<WorkItem> run(Path scratchPath) {
archiver.addReviewComment(reviewComment);
}

var webrevGenerator = bot.webrevStorage().generator(pr, localRepo, webrevPath, bot.seedStorage().orElse(scratchPath.resolve("seeds")));
var webrevStorage = bot.webrevStorage();
if (jsonLocalStorage == null) {
jsonLocalStorage = webrevStorage.getJsonLocalStorage(hostedRepositoryPool, webrevPath);
}
if (htmlLocalStorage == null) {
htmlLocalStorage = webrevStorage.getHtmlLocalStorage(hostedRepositoryPool, webrevPath);
}
var webrevGenerator = webrevStorage.generator(pr, localRepo, webrevPath, jsonLocalStorage, htmlLocalStorage);

var newMails = archiver.generateNewEmails(sentMails, bot.cooldown(), localRepo, bot.issueTracker(), jbs.toUpperCase(), webrevGenerator,
(index, webrevs) -> updateWebrevComment(comments, index, webrevs),
user -> getAuthorAddress(census, user),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,8 @@ private void awaitPublication(URI uri, Duration timeout) throws IOException {
throw new RuntimeException("No success response from " + uri + " within " + timeout);
}

private URI createAndArchive(PullRequest pr, Repository localRepository, Path scratchPath, Diff diff, Hash base, Hash head, String identifier, Path seedPath) {
private URI createAndArchive(PullRequest pr, Repository localRepository, Path scratchPath, Diff diff, Hash base, Hash head, String identifier,
Repository jsonLocalStorage, Repository htmlLocalStorage) {
try {
if (!generateHTML && !generateJSON) {
return null;
Expand All @@ -294,10 +295,7 @@ private URI createAndArchive(PullRequest pr, Repository localRepository, Path sc
var placeholder = generatePlaceholder(pr, base, head);
URI uri = null;

var hostedRepositoryPool = new HostedRepositoryPool(seedPath);

if (generateJSON) {
var jsonLocalStorage = hostedRepositoryPool.checkout(jsonStorage, storageRef, scratchPath);
if (Files.exists(outputFolder)) {
clearDirectory(outputFolder);
}
Expand All @@ -309,7 +307,6 @@ private URI createAndArchive(PullRequest pr, Repository localRepository, Path sc
uri = URI.create(baseUri.toString() + "?repo=" + repoName + "&pr=" + pr.id() + "&range=" + identifier);
}
if (generateHTML) {
var htmlLocalStorage = hostedRepositoryPool.checkout(htmlStorage, storageRef, scratchPath);
if (Files.exists(outputFolder)) {
clearDirectory(outputFolder);
}
Expand All @@ -326,22 +323,30 @@ private URI createAndArchive(PullRequest pr, Repository localRepository, Path sc
}
}

public Repository getJsonLocalStorage(HostedRepositoryPool hostedRepositoryPool, Path scratchPath) throws IOException {
return hostedRepositoryPool.checkout(jsonStorage, storageRef, scratchPath);
}

public Repository getHtmlLocalStorage(HostedRepositoryPool hostedRepositoryPool, Path scratchPath) throws IOException {
return hostedRepositoryPool.checkout(htmlStorage, storageRef, scratchPath);
}

interface WebrevGenerator {
WebrevDescription generate(Hash base, Hash head, String identifier, WebrevDescription.Type type);
WebrevDescription generate(Diff diff, String identifier, WebrevDescription.Type type, String description);
}

WebrevGenerator generator(PullRequest pr, Repository localRepository, Path scratchPath, Path seedPath) {
WebrevGenerator generator(PullRequest pr, Repository localRepository, Path scratchPath, Repository jsonLocalStorage, Repository htmlLocalStorage) {
return new WebrevGenerator() {
@Override
public WebrevDescription generate(Hash base, Hash head, String identifier, WebrevDescription.Type type) {
var uri = createAndArchive(pr, localRepository, scratchPath, null, base, head, identifier, seedPath);
var uri = createAndArchive(pr, localRepository, scratchPath, null, base, head, identifier, jsonLocalStorage, htmlLocalStorage);
return new WebrevDescription(uri, type);
}

@Override
public WebrevDescription generate(Diff diff, String identifier, WebrevDescription.Type type, String description) {
var uri = createAndArchive(pr, localRepository, scratchPath, diff, diff.from(), diff.to(), identifier, seedPath);
var uri = createAndArchive(pr, localRepository, scratchPath, diff, diff.from(), diff.to(), identifier, jsonLocalStorage, htmlLocalStorage);
return new WebrevDescription(uri, type, description);
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import org.openjdk.skara.email.EmailAddress;
import org.openjdk.skara.forge.HostedRepository;
import org.openjdk.skara.forge.HostedRepositoryPool;
import org.openjdk.skara.test.*;
import org.openjdk.skara.vcs.*;

Expand Down Expand Up @@ -71,7 +72,10 @@ void overwriteExisting(TestInfo testInfo) throws IOException {
var prRepo = Repository.materialize(prFolder, pr.repository().authenticatedUrl(), "edit");
var scratchFolder = tempFolder.path().resolve("scratch");
var seedPath = tempFolder.path().resolve("seed");
var generator = storage.generator(pr, prRepo, scratchFolder, seedPath);
var hostedRepositoryPool = new HostedRepositoryPool(seedPath);
var jsonLocalStorage = storage.getJsonLocalStorage(hostedRepositoryPool, scratchFolder);
var htmlLocalStorage = storage.getHtmlLocalStorage(hostedRepositoryPool, scratchFolder);
var generator = storage.generator(pr, prRepo, scratchFolder, jsonLocalStorage, htmlLocalStorage);
generator.generate(masterHash, editHash, "00", WebrevDescription.Type.FULL);

// Check that the web link has been verified now and followed the redirect
Expand Down Expand Up @@ -125,7 +129,10 @@ void dropLarge(TestInfo testInfo) throws IOException {
var prRepo = Repository.materialize(prFolder, pr.repository().authenticatedUrl(), "edit");
var scratchFolder = tempFolder.path().resolve("scratch");
var seedPath = tempFolder.path().resolve("seed");
var generator = storage.generator(pr, prRepo, scratchFolder, seedPath);
var hostedRepositoryPool = new HostedRepositoryPool(seedPath);
var jsonLocalStorage = storage.getJsonLocalStorage(hostedRepositoryPool, scratchFolder);
var htmlLocalStorage = storage.getHtmlLocalStorage(hostedRepositoryPool, scratchFolder);
var generator = storage.generator(pr, prRepo, scratchFolder, jsonLocalStorage, htmlLocalStorage);
generator.generate(masterHash, editHash, "00", WebrevDescription.Type.FULL);

// Update the local repository and check that the webrev has been generated
Expand Down Expand Up @@ -210,7 +217,10 @@ void retryConcurrentPush(TestInfo testInfo) throws IOException {
var scratchFolder = tempFolder.path().resolve("scratch");
var generatorProgressMarker = scratchFolder.resolve("test/" + pr.id() + "/00/nanoduke.ico");
var seedPath = tempFolder.path().resolve("seed");
var generator = storage.generator(pr, prRepo, scratchFolder, seedPath);
var hostedRepositoryPool = new HostedRepositoryPool(seedPath);
var jsonLocalStorage = storage.getJsonLocalStorage(hostedRepositoryPool, scratchFolder);
var htmlLocalStorage = storage.getHtmlLocalStorage(hostedRepositoryPool, scratchFolder);
var generator = storage.generator(pr, prRepo, scratchFolder, jsonLocalStorage, htmlLocalStorage);

// Commit something during generation
var interceptFolder = tempFolder.path().resolve("intercept");
Expand Down

0 comments on commit df3d930

Please sign in to comment.