Skip to content
Permalink
Browse files
forge: add HostedRepository.restrictPushAccess
Reviewed-by: rwestberg
  • Loading branch information
edvbld committed Mar 11, 2021
1 parent a1337d8 commit fd80e0a6f2c6fc7346c58d88efd6c263578d6d09
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 0 deletions.
@@ -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;
}

1 comment on commit fd80e0a

@openjdk-notifier
Copy link

@openjdk-notifier openjdk-notifier bot commented on fd80e0a Mar 11, 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.