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

Allow a remote pre-integration branch to be missing #892

Closed
wants to merge 1 commit 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
@@ -29,9 +29,11 @@

import java.io.*;
import java.nio.file.Path;
import java.util.logging.Logger;

public class PullRequestBranchNotifier implements Notifier, PullRequestListener {
private final Path seedFolder;
private final Logger log = Logger.getLogger("org.openjdk.skara.bots.notify");

public PullRequestBranchNotifier(Path seedFolder) {
this.seedFolder = seedFolder;
@@ -53,6 +55,14 @@ private void pushBranch(PullRequest pr) {
}

private void deleteBranch(PullRequest pr) {
var branchExists = pr.repository().branches().stream()
.map(HostedBranch::name)
.anyMatch(name -> name.equals(PreIntegrations.preIntegrateBranch(pr)));
if (!branchExists) {
log.info("Pull request pre-integration branch " + PreIntegrations.preIntegrateBranch(pr) + " doesn't exist on remote - ignoring");
return;
}

var hostedRepositoryPool = new HostedRepositoryPool(seedFolder);
try {
var seedRepo = hostedRepositoryPool.seedRepository(pr.repository(), false);
@@ -24,9 +24,10 @@

import org.junit.jupiter.api.*;
import org.openjdk.skara.forge.*;
import org.openjdk.skara.issuetracker.*;
import org.openjdk.skara.json.*;
import org.openjdk.skara.issuetracker.Issue;
import org.openjdk.skara.json.JSON;
import org.openjdk.skara.test.*;
import org.openjdk.skara.vcs.Branch;

import java.io.IOException;
import java.nio.file.Path;
@@ -137,4 +138,42 @@ void updated(TestInfo testInfo) throws IOException {
assertEquals(updatedHash, hash);
}
}

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

var repo = credentials.getHostedRepository();
var repoFolder = tempFolder.path().resolve("repo");
var localRepo = CheckableRepository.init(repoFolder, repo.repositoryType());
credentials.commitLock(localRepo);
localRepo.pushAll(repo.url());

var storageFolder = tempFolder.path().resolve("storage");
var notifyBot = testBotBuilder(repo, storageFolder).create("notify", JSON.object());

// Initialize history
TestBotRunner.runPeriodicItems(notifyBot);

// Create a PR
var editHash = CheckableRepository.appendAndCommit(localRepo, "Another line");
localRepo.push(editHash, repo.url(), "source", true);
var pr = credentials.createPullRequest(repo, "master", "source", "This is a PR", false);
pr.addLabel("rfr");
TestBotRunner.runPeriodicItems(notifyBot);

// The target repo should now contain the new branch
var hash = localRepo.fetch(repo.url(), PreIntegrations.preIntegrateBranch(pr));
assertEquals(editHash, hash);
try {
localRepo.prune(new Branch(PreIntegrations.preIntegrateBranch(pr)), repo.url().toString());
} catch (IOException ignored) {
}

// Now close it - no exception should be raised
pr.setState(Issue.State.CLOSED);
TestBotRunner.runPeriodicItems(notifyBot);
}
}
}