Skip to content
Permalink
Browse files
943: remote: GitLab: You can only delete protected branches using the…
… web interface

Reviewed-by: ehelin
  • Loading branch information
rwestberg committed Mar 31, 2021
1 parent 74c9069 commit 3d6d56f58af1459a0c51fe234d90f22435ce2422
@@ -63,14 +63,7 @@ private void deleteBranch(PullRequest pr) {
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);
seedRepo.prune(new Branch(PreIntegrations.preIntegrateBranch(pr)), pr.repository().url().toString());
} catch (IOException e) {
throw new UncheckedIOException(e);
}
pr.repository().deleteBranch(PreIntegrations.preIntegrateBranch(pr));
}

@Override
@@ -131,6 +131,17 @@ void updated(TestInfo testInfo) throws IOException {
// Push another change
var updatedHash = CheckableRepository.appendAndCommit(localRepo, "Yet another line");
localRepo.push(updatedHash, repo.url(), "source");

// Make sure that the push registered
var lastHeadHash = pr.headHash();
var refreshCount = 0;
do {
pr = repo.pullRequest(pr.id());
if (refreshCount++ > 100) {
fail("The PR did not update after the new push");
}
} while (pr.headHash().equals(lastHeadHash));

TestBotRunner.runPeriodicItems(notifyBot);

// The branch should have been updated
@@ -153,6 +153,10 @@ public List<HostedBranch> branches() {
return List.of();
}

@Override
public void deleteBranch(String ref) {
}

@Override
public List<CommitComment> commitComments(Hash commit) {
return List.of();
@@ -72,6 +72,7 @@ PullRequest createPullRequest(HostedRepository target,
long id();
Hash branchHash(String ref);
List<HostedBranch> branches();
void deleteBranch(String ref);
List<CommitComment> commitComments(Hash hash);
default List<CommitComment> recentCommitComments() {
return recentCommitComments(Map.of(), Set.of());
@@ -270,6 +270,12 @@ public List<HostedBranch> branches() {
.collect(Collectors.toList());
}

@Override
public void deleteBranch(String ref) {
request.delete("git/refs/heads/" + ref)
.execute();
}

private CommitComment toCommitComment(JSONValue o) {
var hash = new Hash(o.get("commit_id").asString());
var line = o.get("line").isNull()? -1 : o.get("line").asInt();
@@ -313,6 +313,12 @@ public List<HostedBranch> branches() {
.collect(Collectors.toList());
}

@Override
public void deleteBranch(String ref) {
request.delete("repository/branches/" + URLEncoder.encode(ref, StandardCharsets.US_ASCII))
.execute();
}

private CommitComment toCommitComment(Hash hash, JSONValue o) {
var line = o.get("line").isNull()? -1 : o.get("line").asInt();
var path = o.get("path").isNull()? null : Path.of(o.get("path").asString());
@@ -204,6 +204,15 @@ public List<HostedBranch> branches() {
}
}

@Override
public void deleteBranch(String ref) {
try {
localRepository.delete(new Branch(ref));
} catch (IOException e) {
throw new RuntimeException(e);
}
}

@Override
public List<CommitComment> commitComments(Hash hash) {
if (!commitComments.containsKey(hash)) {

1 comment on commit 3d6d56f

@openjdk-notifier
Copy link

@openjdk-notifier openjdk-notifier bot commented on 3d6d56f Mar 31, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.