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

1003: GitHubRepository.restrictAccess sends incomplete query #1141

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down