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
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
@@ -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
}