Skip to content
Permalink
Browse files
1003: GitHubRepository.restrictAccess sends incomplete query
Reviewed-by: rwestberg, erikj
  • Loading branch information
edvbld committed Apr 29, 2021
1 parent d27723d commit 62e23e04ccd40d102c5471b04ef2a315b1ba98d8
Showing 6 changed files with 18 additions and 12 deletions.
@@ -162,7 +162,7 @@ public void handle(PullRequestBot bot, HostedCommit commit, CensusInstance censu
if (!fork.canPush(command.user())) {
fork.addCollaborator(command.user(), true);
}
fork.restrictPushAccess(new Branch(backportBranchName), List.of(command.user()));
fork.restrictPushAccess(new Branch(backportBranchName), command.user());

var message = CommitMessageParsers.v1.parse(commit);
var formatter = DateTimeFormatter.ofPattern("d MMM uuuu");
@@ -216,7 +216,7 @@ public boolean canPush(HostUser user) {
}

@Override
public void restrictPushAccess(Branch branch, List<HostUser> users) {
public void restrictPushAccess(Branch branch, HostUser user) {
}

@Override
@@ -88,7 +88,7 @@ URI createPullRequestUrl(HostedRepository target,
String sourceRef);
void addCollaborator(HostUser user, boolean canPush);
boolean canPush(HostUser user);
void restrictPushAccess(Branch branch, List<HostUser> users);
void restrictPushAccess(Branch branch, HostUser users);
List<Label> labels();

default PullRequest createPullRequest(HostedRepository target,
@@ -551,13 +551,19 @@ public boolean canPush(HostUser user) {
}

@Override
public void restrictPushAccess(Branch branch, List<HostUser> users) {
var usernames = JSON.array();
for (var user : users) {
usernames.add(user.username());
}
var query = JSON.object()
.put("restrictions", JSON.object().put("users", usernames));
public void restrictPushAccess(Branch branch, HostUser user) {
var restrictions =
JSON.object()
.put("users", JSON.array().add(user.username()))
.put("teams", JSON.array())
.put("apps", JSON.array());
var query =
JSON.object()
.put("required_status_checks", JSON.of())
.put("enforce_admins", JSON.of())
.put("required_pull_request_reviews", JSON.of())
.put("restrictions", restrictions);

request.put("branches/" + branch.name() + "/protection")
.body(query)
.execute();
@@ -589,7 +589,7 @@ public boolean canPush(HostUser user) {
}

@Override
public void restrictPushAccess(Branch branch, List<HostUser> users) {
public void restrictPushAccess(Branch branch, HostUser user) {
// Not possible to implement using GitLab Community Edition.
// Must work around in admin web UI using groups.
}
@@ -304,7 +304,7 @@ public boolean canPush(HostUser user) {
}

@Override
public void restrictPushAccess(Branch branch, List<HostUser> users) {
public void restrictPushAccess(Branch branch, HostUser user) {
// Not possible to simulate
}

1 comment on commit 62e23e0

@openjdk-notifier
Copy link

@openjdk-notifier openjdk-notifier bot commented on 62e23e0 Apr 29, 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.