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

forge: add HostedRepository.restrictPushAccess #1048

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -204,4 +204,8 @@ public void addCollaborator(HostUser user, boolean canPush) {
public boolean canPush(HostUser user) {
return false;
}

@Override
public void restrictPushAccess(Branch branch, List<HostUser> users) {
}
}
@@ -85,6 +85,7 @@ URI createPullRequestUrl(HostedRepository target,
String sourceRef);
void addCollaborator(HostUser user, boolean canPush);
boolean canPush(HostUser user);
void restrictPushAccess(Branch branch, List<HostUser> users);

default PullRequest createPullRequest(HostedRepository target,
String targetRef,
@@ -532,4 +532,17 @@ public boolean canPush(HostUser user) {
.asString();
return permission.equals("admin") || permission.equals("write");
}

@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));
request.put("branches/" + branch.name() + "/protection")
.body(query)
.execute();
}
}
@@ -565,4 +565,10 @@ public boolean canPush(HostUser user) {
.asInt();
return accessLevel >= 30;
}

@Override
public void restrictPushAccess(Branch branch, List<HostUser> users) {
// Not possible to implement using GitLab Community Edition.
// Must work around in admin web UI using groups.
}
}
@@ -287,6 +287,11 @@ public boolean canPush(HostUser user) {
return collaborators.getOrDefault(user.username(), false);
}

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

Repository localRepository() {
return localRepository;
}