Skip to content

Commit 9af4628

Browse files
committedJun 14, 2023
1948: User not getting push access to backport branch
Reviewed-by: zsong
1 parent b6a8254 commit 9af4628

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed
 

‎bots/pr/src/main/java/org/openjdk/skara/bots/pr/BackportCommand.java

+8-1
Original file line numberDiff line numberDiff line change
@@ -322,8 +322,15 @@ public void handle(PullRequestBot bot, HostedCommit commit, LimitedCensusInstanc
322322

323323
if (!fork.canPush(realUser)) {
324324
fork.addCollaborator(realUser, true);
325+
} else {
326+
// It's not possible to add branch level push protection unless the user
327+
// already has push permissions in the repository. If we try to restrict
328+
// it anyway, nobody can push to the branch. At least this way, if the
329+
// user already has push permissions, the branch will be protected,
330+
// otherwise anyone with push permissions in the repository will be able
331+
// to push to the branch.
332+
fork.restrictPushAccess(new Branch(backportBranchName), realUser);
325333
}
326-
fork.restrictPushAccess(new Branch(backportBranchName), realUser);
327334

328335
var message = CommitMessageParsers.v1.parse(commit);
329336
var formatter = DateTimeFormatter.ofPattern("d MMM uuuu");

‎forge/src/test/java/org/openjdk/skara/forge/github/GitHubRestApiTests.java

+8
Original file line numberDiff line numberDiff line change
@@ -268,4 +268,12 @@ void testDeleteDeployKey() {
268268
var githubRepo = githubRepoOpt.get();
269269
githubRepo.deleteDeployKeys(Duration.ofHours(24));
270270
}
271+
272+
@Test
273+
void restrictPushAccess() {
274+
var gitHubRepo = githubHost.repository(settings.getProperty("github.repository")).orElseThrow();
275+
var branch = new Branch(settings.getProperty("github.repository.branch"));
276+
var user = githubHost.user(settings.getProperty("github.user2")).orElseThrow();
277+
gitHubRepo.restrictPushAccess(branch, user);
278+
}
271279
}

1 commit comments

Comments
 (1)

openjdk-notifier[bot] commented on Jun 14, 2023

@openjdk-notifier[bot]
Please sign in to comment.