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

943: remote: GitLab: You can only delete protected branches using the web interface #1105

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
@@ -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)) {